Files
gustavoo-me/wp-content/plugins/fluent-crm/assets/BuiltinTemplateDrawer.js
T
2026-07-23 22:56:30 -03:00

2 lines
7.0 KiB
JavaScript

import{aC as e,aB as t,ay as a,k as i,ba as s,g as l,U as n,L as r,E as o,aT as m}from"./vendor-element-plus.js?ver=3.1.8";import{W as d,X as c,ab as p,a5 as _,Z as h,aQ as u,Y as g,a8 as f,J as w,az as b,aa as y,a6 as T,a9 as I,a0 as v}from"./vendor.js?ver=3.1.8";import{_ as $,I as k}from"./fc-bits-ui.js?ver=3.1.8";import{P as B}from"./PromoCard.js?ver=3.1.8";const L={class:"build-in-template-loader"},x={class:"fcrm_build_in_templates_item skeleton-box"},S={class:"fcrm_build_in_templates_item--image",style:{padding:"15px",height:"152px"}},C={class:"fcrm_build_in_templates_item--content"},P={class:"fcrm_build_in_templates_item--title"};const D={name:"_BuildInTemplatesList",components:{PromoCard:B,BuildInTemplateLoader:$({name:"BuildInTemplateLoader"},[["render",function(a,i,s,l,n,r){const o=e,m=t;return d(),c("div",L,[p(m,{animated:"",count:8,style:{padding:"0"},class:"fcrm_build_in_templates_list"},{template:_(()=>[h("div",x,[h("div",S,[p(o,{animated:"",variant:"image",style:{width:"100%",height:"100%"}})]),h("div",C,[h("div",P,[p(o,{animated:"",variant:"text",style:{width:"80%"}})])])])]),_:1})])}]]),Icons:k},props:{insertMode:{type:Boolean,default:!1},redirect_on_import:{type:Boolean,default:!0}},emits:["template-imported"],data:()=>({builtInTemplates:[],isLoadingTemplates:!1,importing:!1,templateIdImporting:null,oneTimeFetch:!0,showProModal:!1}),methods:{fetchBuiltInTemplates(){this.oneTimeFetch&&(this.oneTimeFetch=!1,this.isLoadingTemplates=!0,this.$get("templates/built-in-templates").then(e=>{this.builtInTemplates=e.templates}).catch(e=>{this.handleError(e)}).finally(()=>{this.isLoadingTemplates=!1}))},importTemplate(e){this.templateIdImporting=e.id,this.importing=!0,!this.insertMode&&this.redirect_on_import?window.jQuery.post(window.ajaxurl,{body:{file:e.content},action:"fluentcrm_import_template"}).then(e=>{this.$notify.success(e.message),this.$router.push({name:"edit_template",params:{template_id:e.template_id}})}).catch(e=>{this.handleError(e.responseJSON.message)}).always(()=>{this.templateIdImporting=null,this.importing=!1}):this.$post("templates/built-in-template",{file:e.content}).then(e=>{this.$emit("template-imported",e.template)}).catch(e=>{this.handleError(e)}).finally(()=>{this.templateIdImporting=null,this.importing=!1})}},mounted(){this.fetchBuiltInTemplates()}},E={key:1,class:"fcrm_build_in_templates_list"},V={class:"fcrm_build_in_templates_item--image"},j=["src","alt"],F={key:1},M={class:"fcrm_build_in_templates_item--actions"},z=["href"],N={class:"icon"},U={class:"icon"},J={class:"icon"},A={class:"fcrm_build_in_templates_item--content"},O={class:"fcrm_build_in_templates_item--title"};const Q=$(D,[["render",function(e,t,n,r,o,m){const v=u("BuildInTemplateLoader"),$=u("Icons"),k=i,B=s,L=u("PromoCard"),x=l,S=a;return d(),c("div",null,[o.isLoadingTemplates?(d(),g(v,{key:0})):f("",!0),!o.isLoadingTemplates&&o.builtInTemplates.length?(d(),c("div",E,[(d(!0),c(w,null,b(o.builtInTemplates,a=>(d(),c("div",{key:a.id,class:"fcrm_build_in_templates_item"},[h("div",V,[a.cover_image?(d(),c("img",{key:0,src:a.cover_image,alt:a.title},null,8,j)):(d(),c("p",F,y(e.$t("Empty")),1)),h("div",M,[h("a",{href:a.link,class:"el-button preview-btn el-button--small",target:"_blank",rel:"noopener noreferrer"},[h("span",N,[p($,{"icon-name":"eye"})])],8,z),e.has_campaign_pro?T((d(),g(k,{key:0,size:"small",onClick:e=>m.importTemplate(a),disabled:o.importing},{default:_(()=>[h("span",U,[p($,{"icon-name":"import"})]),I(" "+y(e.$t("Import")),1)],void 0),_:1},8,["onClick","disabled"])),[[S,o.importing&&o.templateIdImporting==a.id]]):(d(),g(k,{key:1,size:"small",onClick:t[0]||(t[0]=e=>o.showProModal=!0)},{default:_(()=>[h("span",J,[p($,{"icon-name":"import"})]),I(" "+y(e.$t("Import")),1)],void 0),_:1}))])]),h("div",A,[h("div",O,y(a.title),1)])]))),128))])):f("",!0),o.isLoadingTemplates||o.builtInTemplates.length?f("",!0):(d(),g(B,{key:2,description:e.$t("No Built In Templates Found")},null,8,["description"])),p(x,{modelValue:o.showProModal,"onUpdate:modelValue":t[1]||(t[1]=e=>o.showProModal=e),title:e.$t("Importing Template"),width:"40%"},{default:_(()=>[p(L,{"show-header-upgrade-icon":!1})],void 0),_:1},8,["modelValue","title"])])}]]),Y={name:"BuiltinTemplateDrawer",components:{Icons:k,BuildInTemplatesList:Q,Plus:r,Loading:n},emits:["update:open_drawer"],props:{open_drawer:{type:Boolean,default:()=>!1},create_mode:{type:Boolean,default:()=>!1}},data:()=>({direction:"rtl",show_drawer:!1,creatingScratch:!1,builtInTemplates:[],isLoadingTemplates:!1,importing:!1,templateIdImporting:null,oneTimeFetch:!0,showTemplatePreview:!1,previewTemplateId:"",email_template:{post_title:"",post_content:"",post_excerpt:"",email_subject:"",edit_type:"html",design_template:"simple",settings:{template_config:{}}}}),watch:{open_drawer(e){this.show_drawer=!!e}},computed:{localDrawerVisible:{get(){return this.show_drawer},set(e){this.show_drawer=e,e||this.$emit("update:open_drawer",!1)}}},mounted(){window.fcAdmin&&window.fcAdmin.is_rtl&&(this.direction="ltr")},methods:{getDefaultTemplateTitle(){const e=new Date,t=e=>String(e).padStart(2,"0");return`Untitled - Created at ${`${e.getFullYear()}-${t(e.getMonth()+1)}-${t(e.getDate())} ${t(e.getHours())}:${t(e.getMinutes())}:${t(e.getSeconds())}`}`},createFromStratch(){if(this.creatingScratch)return;this.creatingScratch=!0;const e={post_title:this.getDefaultTemplateTitle(),post_content:" ",post_excerpt:"",email_subject:"",edit_type:"html",design_template:"simple",settings:{template_config:{}}};this.$post("templates",{template:JSON.stringify(e)}).then(e=>{const t=e&&e.template_id?e.template_id:0;if(!t)throw new Error(this.$t("Could not create template"));this.$emit("update:open_drawer",!1),this.show_drawer=!1,this.$router.push({name:"edit_template",params:{template_id:t},query:{is_new:"yes"}})}).catch(e=>{this.handleError?this.handleError(e):this.$notify.error(e.message||this.$t("Could not create template"))}).finally(()=>{this.creatingScratch=!1})}}},q={class:"fc_built_in_templates"},H={class:"icon"},W={class:"fcrm_create_from_scratch_box--content"},X={class:"fcrm_create_from_scratch_box--title fcrm_primary_text font-medium fcrm_mb_4"},Z={class:"fcrm_create_from_scratch_box--desc fcrm_secondary_text small"};const G=$(Y,[["render",function(e,t,a,i,s,l){const n=u("Icons"),r=u("Loading"),w=o,b=u("BuildInTemplatesList"),T=m;return d(),g(T,{direction:s.direction,title:a.create_mode?e.$t("Create New Email Template"):e.$t("Built In Templates"),"append-to-body":!0,"close-on-click-modal":!1,modelValue:l.localDrawerVisible,"onUpdate:modelValue":t[1]||(t[1]=e=>l.localDrawerVisible=e),size:"55%"},{default:_(()=>[h("div",q,[a.create_mode?(d(),c("div",{key:0,class:v(["fcrm_create_from_scratch_box",{"is-creating":s.creatingScratch}]),onClick:t[0]||(t[0]=e=>l.createFromStratch())},[h("span",H,[s.creatingScratch?(d(),g(w,{key:1,class:"is-loading"},{default:_(()=>[p(r)],void 0,!0),_:1})):(d(),g(n,{key:0,"icon-name":"plus"}))]),h("div",W,[h("div",X,y(e.$t("Create from Scratch")),1),h("div",Z,y(e.$t("Design your email template from a blank canvas.")),1)])],2)):f("",!0),p(b)])],void 0),_:1},8,["direction","title","modelValue"])}],["__scopeId","data-v-0cc3b88c"]]);export{G as B,Q as a};