|
|
@@ -7,11 +7,12 @@
|
|
|
<h3 class="question">- {{ element.text }}</h3>
|
|
|
<span v-if="element.optional"> (Optional)</span>
|
|
|
<br>
|
|
|
- <ApplicationInputSwitch class="textfield" :highlight="highlight" :type="element.type" :options="element.options" :ref="index"></ApplicationInputSwitch>
|
|
|
+ <ApplicationInputSwitch class="textfield" @okchange="onOkUpdate" @update="onUpdate" :highlight="highlight" :type="element.type" :options="element.options" :ref="index"/>
|
|
|
<span class="hint">{{ element.hint }}</span>
|
|
|
</div>
|
|
|
- <button @click="update">Create/Update</button>
|
|
|
+ <button class="button" @click="onSubmit" :disabled="!(changed && !pending)">Create/Update</button>
|
|
|
<span class="error"> {{ error }}</span>
|
|
|
+ <span> {{ message }}</span>
|
|
|
</div>
|
|
|
<span v-else>You are not logged in.</span>
|
|
|
</div>
|
|
|
@@ -23,16 +24,38 @@
|
|
|
export default {
|
|
|
data () {
|
|
|
return {
|
|
|
+ //The instruction and questions sent by server
|
|
|
instruction: '',
|
|
|
pattern: null,
|
|
|
- highlight: false,
|
|
|
+ //Stores the questions inserted as Vue Components from the application pattern
|
|
|
+ questions: null,
|
|
|
+
|
|
|
+ //Shows issues with posting the application
|
|
|
error: '',
|
|
|
+ message: '',
|
|
|
+ highlightMessage: false,
|
|
|
+
|
|
|
+ //State of the application:
|
|
|
+ pending: false, //true when the app is being sent to server
|
|
|
+ okay: false, //true if it all requirements are fullfilled
|
|
|
+ changed: false, //true if it changed after submitting
|
|
|
+
|
|
|
+ //Advanced error highlighting per question
|
|
|
+ highlight: false,
|
|
|
}
|
|
|
},
|
|
|
created () {
|
|
|
this.core.get('/app-pattern').then((response) => {
|
|
|
this.instruction = response.data.instruction;
|
|
|
this.pattern = response.data.fields;
|
|
|
+ this.$nextTick(() => {
|
|
|
+ let childreen = []
|
|
|
+ for(let key in this.$refs) {
|
|
|
+ let el = this.$refs[key][0];
|
|
|
+ childreen.push(el)
|
|
|
+ }
|
|
|
+ this.questions = childreen
|
|
|
+ })
|
|
|
})
|
|
|
},
|
|
|
computed: {
|
|
|
@@ -41,18 +64,6 @@
|
|
|
},
|
|
|
},
|
|
|
methods: {
|
|
|
- isReady() {
|
|
|
- for(let key in this.$refs) {
|
|
|
- //TBI What is that 0
|
|
|
- let el = this.$refs[key][0]
|
|
|
-
|
|
|
- if(!el.isOkay) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return true
|
|
|
- },
|
|
|
getContent() {
|
|
|
let answers = []
|
|
|
for(let key in this.$refs) {
|
|
|
@@ -62,23 +73,57 @@
|
|
|
|
|
|
return answers
|
|
|
},
|
|
|
- update() {
|
|
|
- if(this.isReady()) {
|
|
|
- this.core.post('/application', {
|
|
|
+ onOkUpdate() {
|
|
|
+ for(let ok of this.questions) {
|
|
|
+ if(!ok.isOkay) {
|
|
|
+ this.okay = false
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.okay = true
|
|
|
+
|
|
|
+ //Remove the error messsage, cause the user fixed it.
|
|
|
+ if(this.highlightMessage) {
|
|
|
+ this.error = ''
|
|
|
+ }
|
|
|
+ },
|
|
|
+ onUpdate() {
|
|
|
+ this.changed = true
|
|
|
+ },
|
|
|
+ onSubmit() {
|
|
|
+ if(this.okay) {
|
|
|
+ this.pending = true //Set the state to pending => Blocks button
|
|
|
+ this.changed = false //Reset the change state, prevent submitting the same app plenty times.
|
|
|
+ this.setMessage('Sending to server...')
|
|
|
+
|
|
|
+ this.core.postCatchFWD('/application', {
|
|
|
//TODO: Pattern, User-token
|
|
|
answers: this.getContent(),
|
|
|
creator: this.user.username,
|
|
|
}).then((response) => {
|
|
|
-
|
|
|
- console.log('Response: ', response.data);
|
|
|
+ this.setMessage('Updated application')
|
|
|
+ }).catch(() => {
|
|
|
+ this.changed = true //The submission failed, it was possible to submit before, revert the state, no matter if it is still changed.
|
|
|
+ this.setError('Could not submit the app to the server. Please try again.')
|
|
|
+ }).then(() => {
|
|
|
+ this.pending = false //Finally no longer pending.
|
|
|
});
|
|
|
-
|
|
|
- this.error = ''
|
|
|
} else {
|
|
|
- this.highlight = true
|
|
|
- this.error = 'Please fill the required fields'
|
|
|
+ this.highlight = true //Highlight if a question has issues or not.
|
|
|
+ this.setError('Please fill/correct the red marked fields.')
|
|
|
+ this.highlightMessage = true //Set the highlight message flag, to easily remove the message later on.
|
|
|
}
|
|
|
},
|
|
|
+ setError(text) {
|
|
|
+ this.error = text
|
|
|
+ this.message = ''
|
|
|
+ this.highlightMessage = false
|
|
|
+ },
|
|
|
+ setMessage(text) {
|
|
|
+ this.error = ''
|
|
|
+ this.message = text
|
|
|
+ this.highlightMessage = false
|
|
|
+ }
|
|
|
},
|
|
|
components: {
|
|
|
ApplicationInputSwitch,
|
|
|
@@ -103,4 +148,22 @@
|
|
|
.error {
|
|
|
color: red;
|
|
|
}
|
|
|
+
|
|
|
+ button {
|
|
|
+ font-size: 1em;
|
|
|
+ border: none;
|
|
|
+
|
|
|
+ color: #bbb;
|
|
|
+ background-color: #555;
|
|
|
+ }
|
|
|
+
|
|
|
+ button:hover {
|
|
|
+ color: #fff;
|
|
|
+ background-color: #777;
|
|
|
+ }
|
|
|
+
|
|
|
+ button:disabled {
|
|
|
+ color: #555;
|
|
|
+ background-color: #333;
|
|
|
+ }
|
|
|
</style>
|