diff --git a/app/controllers/protocols_controller.rb b/app/controllers/protocols_controller.rb index b86cd8ce0..b0ade7fb4 100644 --- a/app/controllers/protocols_controller.rb +++ b/app/controllers/protocols_controller.rb @@ -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 diff --git a/app/javascript/vue/protocol/protocolMetadata.vue b/app/javascript/vue/protocol/protocolMetadata.vue index f6645a258..54bf6fad2 100644 --- a/app/javascript/vue/protocol/protocolMetadata.vue +++ b/app/javascript/vue/protocol/protocolMetadata.vue @@ -25,7 +25,7 @@ @click="$emit('publish')" class="btn btn-primary"> {{ i18n.t("protocols.header.publish") }} @@ -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) {