mirror of
				https://github.com/scinote-eln/scinote-web.git
				synced 2025-10-25 13:37:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			181 lines
		
	
	
	
		
			6.4 KiB
		
	
	
	
		
			Vue
		
	
	
	
	
	
			
		
		
	
	
			181 lines
		
	
	
	
		
			6.4 KiB
		
	
	
	
		
			Vue
		
	
	
	
	
	
| <template>
 | |
|   <div ref="modal" class="modal" tabindex="-1" role="dialog">
 | |
|     <div class="modal-dialog" role="document">
 | |
|       <div class="modal-content">
 | |
|         <div class="modal-header">
 | |
|           <button type="button" class="close" data-dismiss="modal" aria-label="Close">
 | |
|             <i class="sn-icon sn-icon-close"></i>
 | |
|           </button>
 | |
|           <h4 class="modal-title truncate !block">
 | |
|             {{ i18n.t('protocols.index.versions.title', { protocol: protocol.name }) }}
 | |
|           </h4>
 | |
|         </div>
 | |
|         <div class="modal-body">
 | |
|           <div class="max-h-[400px] overflow-y-auto">
 | |
|             <div v-if="draft">
 | |
|               <div class="flex items-center gap-4">
 | |
|                 <a :href="draft.urls.show" class="hover:no-underline cursor-pointer shrink-0">
 | |
|                   <span v-if="draft.previous_number"
 | |
|                         v-html="i18n.t('protocols.index.versions.draft_html', {
 | |
|                           parent_version: draft.previous_number
 | |
|                         })"
 | |
|                   ></span>
 | |
|                   <span v-else v-html="i18n.t('protocols.index.versions.first_draft_html')"></span>
 | |
|                 </a>
 | |
|                 <span class="text-xs" v-if="draft.modified_by">
 | |
|                   {{
 | |
|                       i18n.t('protocols.index.versions.draft_full_modification_info', {
 | |
|                         modified_on: draft.modified_on,
 | |
|                         modified_by: draft.modified_by
 | |
|                       })
 | |
|                   }}
 | |
|                 </span>
 | |
|                 <span class="text-xs" v-else>
 | |
|                   {{
 | |
|                       i18n.t('protocols.index.versions.draft_update_modification_info', {
 | |
|                         modified_on: draft.modified_on
 | |
|                       })
 | |
|                   }}
 | |
|                 </span>
 | |
|                 <div class="flex items-center gap-2 ml-auto">
 | |
|                   <button v-if="draft.urls.publish" class="btn btn-light" @click="publishDraft">
 | |
|                     {{ i18n.t('protocols.index.versions.publish') }}
 | |
|                   </button>
 | |
|                   <button v-if="draft.urls.destroy" @click="destroyDraft" class="btn btn-light icon-btn">
 | |
|                     <i class="sn-icon sn-icon-delete"></i>
 | |
|                   </button>
 | |
|                 </div>
 | |
|               </div>
 | |
|               <InlineEdit
 | |
|                   :class="{ 'pointer-events-none': !draft.urls.comment }"
 | |
|                   class="mb-4"
 | |
|                   :value="draft.comment"
 | |
|                   :characterLimit="10000"
 | |
|                   :placeholder="i18n.t('protocols.index.versions.comment_placeholder')"
 | |
|                   :allowBlank="true"
 | |
|                   :singleLine="false"
 | |
|                   :attributeName="`${i18n.t('Draft')} ${i18n.t('comment')}`"
 | |
|                   @update="updateComment"
 | |
|                 />
 | |
|             </div>
 | |
|             <div v-for="version in publishedVersions" :key="version.number">
 | |
|               <div class="flex items-center gap-4">
 | |
|                 <a :href="version.urls.show" class="hover:no-underline cursor-pointer shrink-0">
 | |
|                   <b>
 | |
|                     {{ i18n.t('protocols.index.versions.revision', { version: version.number }) }}
 | |
|                   </b>
 | |
|                 </a>
 | |
|                 <span class="text-xs">
 | |
|                   {{
 | |
|                       i18n.t('protocols.index.versions.revision_publishing_info', {
 | |
|                         published_on: version.published_on,
 | |
|                         published_by: version.published_by
 | |
|                       })
 | |
|                   }}
 | |
|                 </span>
 | |
|                 <button
 | |
|                   v-if="version.urls.save_as_draft"
 | |
|                   class="btn btn-light icon-btn ml-auto"
 | |
|                   :title="i18n.t('protocols.index.versions.save_as_draft')"
 | |
|                   @click="saveAsDraft(version.urls.save_as_draft)"
 | |
|                   :disabled="draft"
 | |
|                 >
 | |
|                   <i class="sn-icon sn-icon-duplicate"></i>
 | |
|                 </button>
 | |
|               </div>
 | |
|               <div class="mb-4">
 | |
|                 {{  version.comment }}
 | |
|               </div>
 | |
|             </div>
 | |
|           </div>
 | |
|         </div>
 | |
|       </div>
 | |
|     </div>
 | |
|   </div>
 | |
|   <ConfirmationModal
 | |
|     :title="i18n.t('protocols.delete_draft_modal.title')"
 | |
|     :description="`
 | |
|       <p>${i18n.t('protocols.delete_draft_modal.description_1')}</p>
 | |
|       <p><b>${i18n.t('protocols.delete_draft_modal.description_2')}</b></p>
 | |
|     `"
 | |
|     :confirmClass="'btn btn-danger'"
 | |
|     :confirmText="i18n.t('protocols.delete_draft_modal.confirm')"
 | |
|     ref="destroyModal"
 | |
|   ></ConfirmationModal>
 | |
| </template>
 | |
| 
 | |
| <script>
 | |
| 
 | |
| /* global HelperModule */
 | |
| 
 | |
| import SelectDropdown from '../../shared/select_dropdown.vue';
 | |
| import InlineEdit from '../../shared/inline_edit.vue';
 | |
| import axios from '../../../packs/custom_axios.js';
 | |
| import modalMixin from '../../shared/modal_mixin';
 | |
| import ConfirmationModal from '../../shared/confirmation_modal.vue';
 | |
| 
 | |
| export default {
 | |
|   name: 'VersionsModal',
 | |
|   props: {
 | |
|     protocol: Object
 | |
|   },
 | |
|   emits: ['refresh', 'close'],
 | |
|   mixins: [modalMixin],
 | |
|   components: {
 | |
|     SelectDropdown,
 | |
|     InlineEdit,
 | |
|     ConfirmationModal
 | |
|   },
 | |
|   data() {
 | |
|     return {
 | |
|       draft: null,
 | |
|       publishedVersions: []
 | |
|     };
 | |
|   },
 | |
|   mounted() {
 | |
|     this.loadModalData();
 | |
|   },
 | |
|   methods: {
 | |
|     loadModalData() {
 | |
|       axios.get(this.protocol.urls.versions_modal).then((response) => {
 | |
|         this.publishedVersions = response.data.versions;
 | |
|         this.draft = response.data.draft;
 | |
|       });
 | |
|     },
 | |
|     updateComment(comment) {
 | |
|       axios.put(this.draft.urls.comment, { protocol: { version_comment: comment } }).then(() => {
 | |
|         this.draft.comment = comment;
 | |
|       });
 | |
|     },
 | |
|     async destroyDraft() {
 | |
|       const ok = await this.$refs.destroyModal.show();
 | |
|       if (ok) {
 | |
|         axios.post(this.draft.urls.destroy, {
 | |
|           version_modal: true
 | |
|         }).then((response) => {
 | |
|           document.body.style.overflow = 'hidden';
 | |
|           this.$emit('refresh');
 | |
|           this.$emit('redirectToProtocols');
 | |
|           this.loadModalData();
 | |
|           HelperModule.flashAlertMsg(response.data.message, 'success');
 | |
|         });
 | |
|       } else {
 | |
|         document.body.style.overflow = 'hidden';
 | |
|       }
 | |
|     },
 | |
|     saveAsDraft(url) {
 | |
|       axios.post(url).then((response) => {
 | |
|         window.location.href = response.data.url;
 | |
|       }).catch((error) => {
 | |
|         HelperModule.flashAlertMsg(error.response.data.error, 'danger');
 | |
|       });
 | |
|     },
 | |
|     publishDraft() {
 | |
|       axios.post(this.draft.urls.publish).then(() => {
 | |
|         this.loadModalData();
 | |
|         this.$emit('reloadPage');
 | |
|       });
 | |
|     }
 | |
|   }
 | |
| };
 | |
| </script>
 |