SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit 12e483f4 authored by Jean-Sébastien Caux's avatar Jean-Sébastien Caux
Browse files

Basic save draft / mark ready for sending working

parent b39268a1
No related branches found
No related tags found
No related merge requests found
...@@ -100,21 +100,40 @@ ...@@ -100,21 +100,40 @@
></span> ></span>
</b-col> </b-col>
</b-row> </b-row>
<b-button type="savedraft" variant="warning" @click.stop.prevent="saveDraft"> <template v-if="!markReadySuccessful">
Save draft <b-button
</b-button> type="savedraft"
<b-button type="send" variant="success">Send</b-button> variant="warning"
@click.stop.prevent="saveMessage('draft')"
>
Save draft
</b-button>
<b-button
type="send"
variant="success"
@click.stop.prevent="saveMessage('ready')"
>
Queue for sending
</b-button>
</template>
<template v-if="saveDraftSuccessful"> <template v-if="saveDraftSuccessful">
<p class="m-2 p-2 bg-success text-white"> <p class="m-2 p-2 bg-success text-white">
The message draft was successfully saved. The message draft was successfully saved.
</p> </p>
</template> </template>
<template v-else-if="saveDraftSuccessful === false"> <template v-else-if="markReadySuccessful">
<p class="m-2 p-2 bg-success text-white">
The message was successfully queued for sending.
</p>
</template>
<template v-else-if="saveDraftSuccessful === false || markReadySuccessful === false">
<p class="m-2 p-2 bg-danger text-white"> <p class="m-2 p-2 bg-danger text-white">
The server responded with an error, please check and try again The server responded with an error, please check and try again
</p> </p>
</template> </template>
<span v-if="draftLastSaved" size="sm">&emsp;[last saved: {{ draftLastSaved }}]</span> <span v-if="draftLastSaved" size="sm">&emsp;[last saved: {{ draftLastSaved }}]</span>
</b-form> </b-form>
</div> </div>
</template> </template>
...@@ -152,6 +171,7 @@ export default { ...@@ -152,6 +171,7 @@ export default {
response_body_json: null, response_body_json: null,
saveDraftSuccessful: null, saveDraftSuccessful: null,
draftLastSaved: null, draftLastSaved: null,
markReadySuccessful: null,
} }
}, },
computed: { computed: {
...@@ -166,7 +186,7 @@ export default { ...@@ -166,7 +186,7 @@ export default {
.then(data => this.from_account_accesses = data.results) .then(data => this.from_account_accesses = data.results)
.catch(error => console.error(error)) .catch(error => console.error(error))
}, },
saveDraft () { saveMessage (status) {
fetch('/mail/api/composed_message/create', fetch('/mail/api/composed_message/create',
{ {
method: 'POST', method: 'POST',
...@@ -175,6 +195,7 @@ export default { ...@@ -175,6 +195,7 @@ export default {
"Content-Type": "application/json; charset=utf-8" "Content-Type": "application/json; charset=utf-8"
}, },
body: JSON.stringify({ body: JSON.stringify({
'status': status,
'from_account': this.form.from_account, 'from_account': this.form.from_account,
'to_recipient': this.form.torecipient, 'to_recipient': this.form.torecipient,
// 'cc_recipients': this.form.cc, // 'cc_recipients': this.form.cc,
...@@ -187,12 +208,21 @@ export default { ...@@ -187,12 +208,21 @@ export default {
.then(response => { .then(response => {
this.response = response.clone() this.response = response.clone()
if (response.ok) { if (response.ok) {
this.saveDraftSuccessful = true if (status === 'draft') {
this.draftLastSaved = Date().toString() this.saveDraftSuccessful = true
this.draftLastSaved = Date().toString()
}
if (status === 'ready') {
this.markReadySuccessful = true
}
} }
if (!response.ok) { if (!response.ok) {
this.saveDraftSuccessful = false if (status === 'draft') {
// throw new Error('HTTP error, status = ' + response.status); this.saveDraftSuccessful = false
}
if (status === 'ready') {
this.markReadySuccessful = false
}
} }
return response.json() return response.json()
}) })
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment