scinote-web/app/javascript/vue/protocol/protocolOptions.vue

164 lines
5 KiB
Vue
Raw Normal View History

<template>
2022-06-24 17:21:47 +08:00
<div>
2023-07-12 18:24:12 +08:00
<div class="dropdown protocol-options-dropdown">
2022-06-24 17:21:47 +08:00
<button
class="btn btn-secondary dropdown-toggle"
type="button"
id="dropdownProtocolOptions"
data-toggle="dropdown"
aria-haspopup="true"
aria-expanded="true"
tabindex="0"
2022-06-24 17:21:47 +08:00
>
<span>{{ i18n.t("my_modules.protocol.options_dropdown.title") }}</span>
2023-06-15 21:12:51 +08:00
<span class="sn-icon sn-icon-down"></span>
2022-06-24 17:21:47 +08:00
</button>
<ul
class="dropdown-menu dropdown-menu-right rounded !p-2.5 sn-shadow-menu-sm"
2022-06-24 17:21:47 +08:00
aria-labelledby="dropdownProtocolOptions"
>
<li v-if="protocol.attributes.urls.load_from_repo_url">
<a class="!px-3 !py-2.5 hover:!bg-sn-super-light-blue !text-sn-blue"
2022-06-24 17:21:47 +08:00
ref="loadProtocol"
data-action="load-from-repository"
@click="loadProtocol"
>
<span>{{ i18n.t("my_modules.protocol.options_dropdown.load_from_repo") }}</span>
</a>
</li>
<li>
<a class="!px-3 !py-2.5 hover:!bg-sn-super-light-blue !text-sn-blue"
2023-02-17 21:27:20 +08:00
data-toggle="modal"
data-target="#newProtocolModal"
v-bind:data-protocol-name="protocol.attributes.name"
2022-06-24 17:21:47 +08:00
:class="{ disabled: !protocol.attributes.urls.save_to_repo_url }"
>
<span>{{
i18n.t("my_modules.protocol.options_dropdown.save_to_repo")
}}</span>
</a>
</li>
<li>
<a class="!px-3 !py-2.5 hover:!bg-sn-super-light-blue !text-sn-blue"
2022-06-24 17:21:47 +08:00
data-turbolinks="false"
:href="protocol.attributes.urls.export_url"
:class="{ disabled: !protocol.attributes.urls.export_url }"
>
<span>{{
i18n.t("my_modules.protocol.options_dropdown.export")
}}</span>
</a>
</li>
<li v-if="protocol.attributes.urls.update_protocol_url">
<a class="!px-3 !py-2.5 hover:!bg-sn-super-light-blue !text-sn-blue"
ref="updateProtocol"
data-action="update-self"
@click="updateProtocol"
>
<span>{{
i18n.t("my_modules.protocol.options_dropdown.update_protocol")
}}</span>
</a>
</li>
<li v-if="protocol.attributes.urls.unlink_url">
<a class="!px-3 !py-2.5 hover:!bg-sn-super-light-blue !text-sn-blue"
ref="unlinkProtocol"
data-action="unlink"
@click="unlinkProtocol"
>
<span>{{
i18n.t("my_modules.protocol.options_dropdown.unlink")
}}</span>
</a>
</li>
<li v-if="protocol.attributes.urls.revert_protocol_url">
<a class="!px-3 !py-2.5 hover:!bg-sn-super-light-blue !text-sn-blue"
ref="revertProtocol"
data-action="revert"
@click="revertProtocol"
>
<span>{{
i18n.t("my_modules.protocol.options_dropdown.revert_protocol")
}}</span>
</a>
</li>
2022-06-24 17:21:47 +08:00
<li v-if="canDeleteSteps">
<a class="!px-3 !py-2.5 hover:!bg-sn-super-light-blue !text-sn-blue"
2022-06-24 17:21:47 +08:00
data-turbolinks="false"
2022-07-07 21:56:36 +08:00
@click.prevent="openStepsDeletingModal()"
2022-06-24 17:21:47 +08:00
>
<span>{{
i18n.t("my_modules.protocol.options_dropdown.delete_steps")
}}</span>
</a>
</li>
</ul>
</div>
<DeleteStepsModals v-if="stepsDeleting" @confirm="deleteSteps" @close="closeStartStepsDeletingModal" />
</div>
</template>
<script>
import DeleteStepsModals from './modals/delete_steps'
2022-06-24 17:21:47 +08:00
export default {
2022-06-24 17:21:47 +08:00
name: "ProtocolOptions",
2022-06-24 17:21:47 +08:00
components: { DeleteStepsModals },
data() {
return {
stepsDeleting: false
}
},
props: {
protocol: {
type: Object,
required: true,
},
2022-06-24 17:21:47 +08:00
canDeleteSteps: {
type: Boolean,
required: true
}
},
mounted() {
// Legacy global functions from app/assets/javascripts/my_modules/protocols.js
initLoadFromRepository();
initImport();
initLinkUpdate();
},
methods: {
2022-06-24 17:21:47 +08:00
openStepsDeletingModal() {
this.stepsDeleting = true;
},
closeStartStepsDeletingModal() {
this.stepsDeleting = false;
},
loadProtocol() {
$.get(
this.protocol.attributes.urls.load_from_repo_url + "?type=recent"
).done((data) => {
$(this.$refs.loadProtocol).trigger("ajax:success", data);
});
},
unlinkProtocol() {
$.get(this.protocol.attributes.urls.unlink_url).done((data) => {
$(this.$refs.unlinkProtocol).trigger("ajax:success", data);
});
},
updateProtocol() {
$.get(this.protocol.attributes.urls.update_protocol_url).done((data) => {
$(this.$refs.updateProtocol).trigger("ajax:success", data);
});
},
revertProtocol() {
$.get(this.protocol.attributes.urls.revert_protocol_url).done((data) => {
$(this.$refs.revertProtocol).trigger("ajax:success", data);
});
},
2022-06-24 17:21:47 +08:00
deleteSteps() {
this.$emit('protocol:delete_steps')
}
},
};
</script>