mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
accompanying course comment: autosave the comment
This commit is contained in:
parent
6472c554ed
commit
4b692edd7d
@ -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})
|
||||
|
@ -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",
|
||||
|
@ -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) => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user