accompanying course comment: autosave the comment

This commit is contained in:
nobohan 2022-03-04 15:09:50 +01:00
parent 6472c554ed
commit 4b692edd7d
3 changed files with 30 additions and 27 deletions

View File

@ -24,7 +24,7 @@
<div v-if="pinnedComment" class="metadata">
{{ $t('comment.created_by', [
pinnedComment.creator.text,
$d(pinnedComment.createdAt.datetime, 'long')
$d(pinnedComment.updatedAt.datetime, 'long')
])
}}
</div>
@ -82,29 +82,34 @@ export default {
},
methods: {
onContentChange() {
console.log('content changed');
console.log(this.pinnedComment)
if (this.pinnedComment) {
let body = this.formData;
Object.assign(body, {id: this.pinnedComment.id})
this.$store.dispatch('updatePinnedComment', body)
.catch(({name, violations}) => {
if (name === 'ValidationException' || name === 'AccessException') {
violations.forEach((violation) => this.$toast.open({message: violation}));
} else {
this.$toast.open({message: 'An error occurred'})
}
});
} else {
this.$store.dispatch('addPinnedComment', this.formData)
.catch(({name, violations}) => {
if (name === 'ValidationException' || name === 'AccessException') {
violations.forEach((violation) => this.$toast.open({message: violation}));
} else {
this.$toast.open({message: 'An error occurred'})
}
});
}
let lastRecordedContent = this.formData.content;
setTimeout(() => {
if (lastRecordedContent === this.formData.content) {
if (this.pinnedComment) {
let body = this.formData;
Object.assign(body, {id: this.pinnedComment.id});
this.$store.dispatch('updatePinnedComment', body)
.catch(({name, violations}) => {
if (name === 'ValidationException' || name === 'AccessException') {
violations.forEach((violation) => this.$toast.open({message: violation}));
} else {
this.$toast.open({message: 'An error occurred'})
}
});
} else {
this.$store.dispatch('addPinnedComment', this.formData)
.catch(({name, violations}) => {
if (name === 'ValidationException' || name === 'AccessException') {
violations.forEach((violation) => this.$toast.open({message: violation}));
} else {
this.$toast.open({message: 'An error occurred'})
}
});
}
lastRecordedContent = null;
}
}, 3000);
},
removeComment() {
this.$store.dispatch('removePinnedComment', {id: this.pinnedComment.id})

View File

@ -122,7 +122,7 @@ const appMessages = {
title: "Observations",
label: "Ajout d'une note",
content: "Rédigez une première note…",
created_by: "créé par {0}, le {1}"
created_by: "créé par {0}, mis à jour le {1}"
},
confirm: {
title: "Confirmation",

View File

@ -370,12 +370,10 @@ let initPromise = (root) => Promise.all([getScopesPromise(root), accompanyingCou
})
},
updatePinnedComment({ commit }, payload) {
console.log(payload)
const url = `/api/1.0/person/accompanying-period/comment/${payload.id}.json`;
return makeFetch('PATCH', url, payload)
.then((response) => {
console.log(response)
commit('addPinnedComment', response);
})
.catch((error) => {