Properly update question

Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
This commit is contained in:
John Molakvoæ (skjnldsv) 2020-04-27 18:27:51 +02:00
parent 50594f0a01
commit 491941a3e8
No known key found for this signature in database
GPG key ID: 60C25B8C072916CF
4 changed files with 29 additions and 2 deletions

View file

@ -135,6 +135,7 @@ export default {
questionId: answer.question_id,
text: answer.text,
})
console.debug('Created answer', answer)
// Was synced once, this is now up to date with the server
delete answer.local

View file

@ -42,7 +42,8 @@
minlength="1"
maxlength="256"
required
@input="onInput">
@input="onInput"
@keyup="onTitleChange">
<h3 v-else class="question__header-title" v-text="text" />
<Actions class="question__header-menu" :force-menu="true">
<ActionButton icon="icon-delete" @click="onDelete">
@ -57,7 +58,12 @@
</template>
<script>
import axios from '@nextcloud/axios'
import debounce from 'debounce'
import { generateUrl } from '@nextcloud/router'
import { showError } from '@nextcloud/dialogs'
import { directive as ClickOutside } from 'v-click-outside'
import Actions from '@nextcloud/vue/dist/Components/Actions'
import ActionButton from '@nextcloud/vue/dist/Components/ActionButton'
@ -117,6 +123,25 @@ export default {
onDelete() {
this.$emit('delete')
},
onTitleChange: debounce(function() {
this.saveQuestionProperty('text')
}, 200),
async saveQuestionProperty(key) {
try {
// TODO: add loading status feedback ?
await axios.post(generateUrl('/apps/forms/api/v1/question/update'), {
id: this.id,
keyValuePairs: {
[key]: this[key],
},
})
} catch (error) {
showError(t('forms', 'Error while saving question'))
console.error(error)
}
},
},
}
</script>

View file

@ -23,6 +23,7 @@ import Question from '../components/Questions/Question'
export default {
inheritAttrs: false,
props: {
/**
* The question title
*/

View file

@ -1,6 +1,6 @@
/**
* @copyright Copyright (c) 2018 John Molakvoæ <skjnldsv@protonmail.com>
* @copyright Copyright (c) 2020 John Molakvoæ <skjnldsv@protonmail.com>
*
* @author John Molakvoæ <skjnldsv@protonmail.com>
*