mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-11-10 17:36:33 +08:00
Fix draft creation to prevent dupciates [SCI-10598]
This commit is contained in:
parent
0c97ebfafb
commit
70beec648a
2 changed files with 18 additions and 3 deletions
|
@ -371,7 +371,11 @@ class ProtocolsController < ApplicationController
|
|||
|
||||
def save_as_draft
|
||||
Protocol.transaction do
|
||||
draft = @protocol.save_as_draft(current_user)
|
||||
draft = nil
|
||||
|
||||
@protocol.with_lock do
|
||||
draft = @protocol.save_as_draft(current_user)
|
||||
end
|
||||
|
||||
if draft.invalid?
|
||||
render json: { error: draft.errors.messages.map { |_, value| value }.join(' ') }, status: :unprocessable_entity
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
@click="$emit('publish')" class="btn btn-primary">
|
||||
{{ i18n.t("protocols.header.publish") }}</button>
|
||||
<button v-if="protocol.attributes.urls.save_as_draft_url"
|
||||
v-bind:disabled="protocol.attributes.has_draft"
|
||||
:disabled="protocol.attributes.has_draft || creatingDraft"
|
||||
@click="saveAsdraft" class="btn btn-secondary">
|
||||
{{ i18n.t("protocols.header.save_as_draft") }}
|
||||
</button>
|
||||
|
@ -121,7 +121,8 @@ export default {
|
|||
},
|
||||
data() {
|
||||
return {
|
||||
VersionsModalObject: null
|
||||
VersionsModalObject: null,
|
||||
creatingDraft: false
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
|
@ -141,8 +142,18 @@ export default {
|
|||
},
|
||||
methods: {
|
||||
saveAsdraft() {
|
||||
if (this.creatingDraft) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.creatingDraft = true;
|
||||
|
||||
$.post(this.protocol.attributes.urls.save_as_draft_url, (result) => {
|
||||
this.creatingDraft = false;
|
||||
window.location.replace(result.url);
|
||||
}).error(() => {
|
||||
this.creatingDraft = false;
|
||||
HelperModule.flashAlertMsg(this.i18n.t('errors.general'));
|
||||
});
|
||||
},
|
||||
updateAuthors(authors) {
|
||||
|
|
Loading…
Reference in a new issue