diff --git a/resources/js/components/templates/PreviewTemplate.vue b/resources/js/components/templates/PreviewTemplate.vue index bc3e181763..84e61f65e5 100644 --- a/resources/js/components/templates/PreviewTemplate.vue +++ b/resources/js/components/templates/PreviewTemplate.vue @@ -122,7 +122,16 @@ watch: { selectedTemplateOptions() { this.$emit('template-options-selected', this.selectedTemplateOptions); - } + }, + template: { + deep: true, + handler() { + this.templateData = this.template?.template ? this.template.template : this.template; + this.type = this.templateData?.type; + this.showCssPreview = false; + this.code = ""; + }, + }, }, methods: { hidePreview() { @@ -193,4 +202,4 @@ .css-preview-card .css-preview .editor { height: inherit; } - \ No newline at end of file + diff --git a/resources/js/processes/screen-templates/components/MyTemplatesListing.vue b/resources/js/processes/screen-templates/components/MyTemplatesListing.vue index 96525d3e6e..4875f3671c 100644 --- a/resources/js/processes/screen-templates/components/MyTemplatesListing.vue +++ b/resources/js/processes/screen-templates/components/MyTemplatesListing.vue @@ -160,6 +160,7 @@ @@ -251,7 +252,17 @@ export default { this.loading = false; }); }, + mounted() { + this.bindPreviewTabClose("#nav-myTemplates-tab"); + }, + beforeDestroy() { + this.unbindPreviewTabClose(); + }, methods: { + handleSelectTemplate(template) { + this.selectedTemplate = template; + this.markSelectedRow(template.id); + }, fetch() { this.loading = true; this.apiDataLoading = true; diff --git a/resources/js/processes/screen-templates/components/PublicTemplatesListing.vue b/resources/js/processes/screen-templates/components/PublicTemplatesListing.vue index 8ecb59ad10..d6aec98fd0 100644 --- a/resources/js/processes/screen-templates/components/PublicTemplatesListing.vue +++ b/resources/js/processes/screen-templates/components/PublicTemplatesListing.vue @@ -162,6 +162,7 @@ @@ -260,7 +261,17 @@ export default { this.apiNoResults = false; }); }, + mounted() { + this.bindPreviewTabClose("#nav-publicTemplates-tab"); + }, + beforeDestroy() { + this.unbindPreviewTabClose(); + }, methods: { + handleSelectTemplate(template) { + this.selectedTemplate = template; + this.markSelectedRow(template.id); + }, fetch() { this.loading = true; this.apiDataLoading = true; diff --git a/resources/js/processes/screen-templates/components/TemplatePreviewContainer.vue b/resources/js/processes/screen-templates/components/TemplatePreviewContainer.vue index 5c33ba9acd..e9de797c0f 100644 --- a/resources/js/processes/screen-templates/components/TemplatePreviewContainer.vue +++ b/resources/js/processes/screen-templates/components/TemplatePreviewContainer.vue @@ -17,6 +17,24 @@ :close="onClose" :templateId="template.id" > + + + + + + + +
{ + this.closePreviewFrame(); + }; + $(tabSelector).on("hide.bs.tab.templatePreview", this._previewTabHandler); + }, + unbindPreviewTabClose() { + if (!this._previewTabSelector || typeof $ === "undefined") { + return; + } + $(this._previewTabSelector).off("hide.bs.tab.templatePreview", this._previewTabHandler); + this._previewTabSelector = null; + this._previewTabHandler = null; + }, onClose() { this.$emit('mark-selected-row', 0); this.showPreview = false; @@ -99,6 +133,56 @@ const templatePreviewMixin = { this.isLoading = ""; this.stopFrame = false; this.size = 50; + this.prevTemplate = {}; + this.nextTemplate = {}; + this.existPrev = false; + this.existNext = false; + }, + defineNextPrevTemplate() { + if (!Array.isArray(this.data)) { + this.prevTemplate = {}; + this.nextTemplate = {}; + this.existPrev = false; + this.existNext = false; + return; + } + + let prevTemplate = {}; + let nextTemplate = {}; + let seeNextTemplate = false; + for (const templateIndex in this.data) { + if (!seeNextTemplate) { + if (this.data[templateIndex] === this.template) { + seeNextTemplate = true; + } else { + prevTemplate = this.data[templateIndex]; + this.existPrev = true; + } + } else { + nextTemplate = this.data[templateIndex]; + this.existNext = true; + break; + } + } + this.prevTemplate = prevTemplate; + this.nextTemplate = nextTemplate; + }, + goPrevNext(action) { + let targetTemplate = null; + if (action === "Next" && this.existNext) { + targetTemplate = this.nextTemplate; + } + if (action === "Prev" && this.existPrev) { + targetTemplate = this.prevTemplate; + } + + if (!targetTemplate) { + return; + } + + this.$emit("select-template", targetTemplate); + this.$emit("mark-selected-row", targetTemplate.id); + this.showSideBar(targetTemplate, this.data); }, }, };