nervatura-client
Version:
Business Management Application
2 lines (1 loc) • 29.2 kB
JavaScript
import{b as t,M as e,d as a,S as n,m as r,T as i}from"./main-DXT0hpEA.js";import"./module-FRmUNWHB.js";import"./module-CC7fmSsS.js";import"./module-C1fQGCtD.js";const l=({msg:t})=>{const e=e=>t(e,{id:e});return{report:{options:{title:"REPORT"},rows:[{rowtype:"flip",name:"title",datatype:"string",default:"Nervatura Report"},{rowtype:"flip",name:"author",datatype:"string"},{rowtype:"flip",name:"creator",datatype:"string"},{rowtype:"flip",name:"subject",datatype:"string"},{rowtype:"flip",name:"keywords",datatype:"string"},{rowtype:"groupline"},{rowtype:"flip",name:"font-style",datatype:"select",default:"",options:[["",""],["bold","bold"],["italic","italic"],["bolditalic","bolditalic"]],info:e("info_font-style")},{rowtype:"flip",name:"font-size",datatype:"integer",default:12},{rowtype:"flip",name:"color",datatype:"color",info:e("info_color")},{rowtype:"flip",name:"border-color",datatype:"integer",default:0,max:255,min:0,info:e("info_border-color")},{rowtype:"flip",name:"background-color",datatype:"integer",default:0,max:255,min:0,info:e("info_background-color")},{rowtype:"groupline"},{rowtype:"flip",name:"left-margin",datatype:"integer",default:12},{rowtype:"flip",name:"right-margin",datatype:"integer",default:12},{rowtype:"flip",name:"top-margin",datatype:"integer",default:12}]},row:{options:{title:"ROW"},rows:[{rowtype:"flip",name:"height",datatype:"float",default:0},{rowtype:"flip",name:"hgap",datatype:"integer",default:0,info:e("info_hgap")},{rowtype:"flip",name:"visible",datatype:"string",info:e("info_visible")}]},cell:{options:{title:"CELL"},rows:[{rowtype:"flip",name:"name",datatype:"string",default:"head",info:e("info_name")},{rowtype:"flip",name:"value",datatype:"string",info:e("info_value")},{rowtype:"flip",name:"width",datatype:"percent",info:e("info_width")},{rowtype:"flip",name:"align",datatype:"select",default:"left",options:[["left","left"],["right","right"],["center","center"]],info:e("info_align")},{rowtype:"flip",name:"multiline",datatype:"select",default:"false",options:[["false","false"],["true","true"]],info:e("info_multiline")},{rowtype:"groupline"},{rowtype:"flip",name:"font-style",datatype:"select",default:"",options:[["",""],["bold","bold"],["italic","italic"],["bolditalic","bolditalic"]],info:e("info_font-style")},{rowtype:"flip",name:"font-size",datatype:"integer",default:12},{rowtype:"flip",name:"color",datatype:"color",info:e("info_color")},{rowtype:"flip",name:"border-color",datatype:"integer",default:0,max:255,min:0,info:e("info_border-color")},{rowtype:"flip",name:"background-color",datatype:"integer",default:0,max:255,min:0,info:e("info_background-color")},{rowtype:"flip",name:"border",datatype:"checklist",values:["1|All","L|Left","T|Top","R|Right","B|Bottom"]}]},image:{options:{title:"IMAGE"},rows:[{rowtype:"flip",name:"src",datatype:"image",info:e("info_src")},{rowtype:"flip",name:"height",datatype:"float",default:0,info:e("info_height_image")}]},barcode:{options:{title:"BARCODE"},rows:[{rowtype:"flip",name:"code-type",datatype:"select",default:"ITF",options:[["ITF","ITF"],["CODE_39","CODE_39"],["CODE_128","CODE_128"],["EAN","EAN"],["QR","QR"]],info:e("info_code-type")},{rowtype:"flip",name:"value",datatype:"string",default:"",info:e("info_barcode_value")},{rowtype:"flip",name:"visible-value",datatype:"select",default:"0",options:[["0","0"],["1","1"]],info:e("info_visible-value")},{rowtype:"flip",name:"wide",datatype:"float",default:0,info:e("info_optional")},{rowtype:"flip",name:"narrow",datatype:"float",default:0,info:e("info_optional")}]},separator:{options:{title:"SEPARATOR"},rows:[{rowtype:"flip",name:"hgap",datatype:"integer",default:0,info:e("info_hgap")}]},vgap:{options:{title:"VGAP"},rows:[{rowtype:"flip",name:"height",datatype:"float",default:0,info:e("info_height")}]},hline:{options:{title:"HLINE"},rows:[{rowtype:"flip",name:"width",datatype:"percent",info:e("info_width")},{rowtype:"flip",name:"gap",datatype:"integer",default:0,info:e("info_gap")},{rowtype:"flip",name:"border-color",datatype:"integer",default:0,max:255,min:0,info:e("info_border-color")}]},html:{options:{title:"HTML"},rows:[{rowtype:"flip",name:"html",datatype:"text",default:"",info:e("info_html")}]},datagrid:{options:{title:"DATAGRID"},rows:[{rowtype:"flip",name:"name",datatype:"string",default:"items",info:e("info_datagrid_name")},{rowtype:"flip",name:"databind",datatype:"string",default:"",info:e("info_databind")},{rowtype:"flip",name:"width",datatype:"percent",info:e("info_width")},{rowtype:"flip",name:"merge",datatype:"select",default:"0",options:[["0","0"],["1","1"]],info:e("info_merge")},{rowtype:"flip",name:"font-size",datatype:"integer",default:12},{rowtype:"flip",name:"border",datatype:"checklist",values:["1|All","L|Left","T|Top","R|Right","B|Bottom"]},{rowtype:"flip",name:"color",datatype:"color",info:e("info_color")},{rowtype:"flip",name:"border-color",datatype:"integer",default:0,max:255,min:0,info:e("info_border-color")},{rowtype:"flip",name:"background-color",datatype:"integer",default:0,max:255,min:0,info:e("info_background-color")},{rowtype:"flip",name:"header-background",datatype:"integer",default:0,max:255,min:0,info:e("info_background-color")},{rowtype:"flip",name:"footer-background",datatype:"integer",default:0,max:255,min:0,info:e("info_background-color")}]},column:{options:{title:"COLUMN"},rows:[{rowtype:"flip",name:"fieldname",datatype:"string",default:"",info:e("info_fieldname")},{rowtype:"flip",name:"label",datatype:"string",default:"",info:e("info_label")},{rowtype:"flip",name:"width",datatype:"percent",info:e("info_width")},{rowtype:"flip",name:"align",datatype:"select",default:"left",options:[["left","left"],["right","right"],["center","center"]],info:e("info_align")},{rowtype:"flip",name:"header-align",datatype:"select",default:"left",options:[["left","left"],["right","right"],["center","center"]],info:e("info_align")},{rowtype:"flip",name:"footer-align",datatype:"select",default:"left",options:[["left","left"],["right","right"],["center","center"]],info:e("info_align")},{rowtype:"flip",name:"thousands",datatype:"string",default:"",info:e("info_thousands")},{rowtype:"flip",name:"digit",datatype:"integer",default:0,info:e("info_digit")},{rowtype:"flip",name:"footer",datatype:"string",default:"",info:e("info_footer")}]},header:{options:{title:"HEADER"},rows:[]},details:{options:{title:"DETAILS"},rows:[]},footer:{options:{title:"FOOTER"},rows:[]}}},s=t=>{let e=[];return Object.keys(t).forEach((a=>{e="string"==typeof t[a]?[...e,{lslabel:a,lsvalue:"string"}]:Array.isArray(t[a])?[...e,{lslabel:a,lsvalue:"table"}]:[...e,{lslabel:a,lsvalue:"list"}]})),e},o=t=>Object.getOwnPropertyNames(t).length>0?Object.getOwnPropertyNames(t)[0]:null,d=t=>{let e=[];return Object.keys(t).forEach((a=>{e=[...e,{lslabel:a,lsvalue:t[a]}]})),e},p=t=>{const e={fields:{},items:[]};if(t.length>0){Object.keys(t[0]).forEach((t=>{e.fields[t]={fieldtype:"string",label:t}}));for(let a=0;a<t.length;a+=1){const n={...t[a],_index:a};e.items=[...e.items,n]}}return e};class m{constructor(t){this.host=t,this.app=t.app,this.store=t.app.store,this.module={},this.addItem=this.addItem.bind(this),this.addTemplateData=this.addTemplateData.bind(this),this.checkTemplate=this.checkTemplate.bind(this),this.createMap=this.createMap.bind(this),this.createTemplate=this.createTemplate.bind(this),this.deleteData=this.deleteData.bind(this),this.deleteDataItem=this.deleteDataItem.bind(this),this.deleteItem=this.deleteItem.bind(this),this.deleteTemplate=this.deleteTemplate.bind(this),this.editDataItem=this.editDataItem.bind(this),this.editItem=this.editItem.bind(this),this.exportTemplate=this.exportTemplate.bind(this),this.goNext=this.goNext.bind(this),this.goPrevious=this.goPrevious.bind(this),this.moveDown=this.moveDown.bind(this),this.moveUp=this.moveUp.bind(this),this.onTemplateEvent=this.onTemplateEvent.bind(this),this.onSideEvent=this.onSideEvent.bind(this),this.saveTemplate=this.saveTemplate.bind(this),this.setCurrent=this.setCurrent.bind(this),this.setCurrentData=this.setCurrentData.bind(this),this.setCurrentDataItem=this.setCurrentDataItem.bind(this),this.setTemplate=this.setTemplate.bind(this),this.showPreview=this.showPreview.bind(this),t.addController(this)}setModule(t){this.module=t}addItem(e){const{data:a}=this.store,{current:n}=a[t.TEMPLATE];if(""!==e){const t=e.toString().toLowerCase(),a={};a[t]={};const r=`${n.id}_${n.item.length.toString()}_${t}`;"datagrid"!==t&&"row"!==t||(a[t].columns=[]),n.item.push(a),this.setCurrent({tmp_id:r,set_dirty:!0})}}addTemplateData(){const{modalTemplate:t}=this.module,{setData:a}=this.store,n=t({type:"string",name:"",columns:"",onEvent:{onModalEvent:async t=>{a("current",{modalForm:null}),t.key===e.OK&&this.setCurrentData({name:"new",type:"new",values:{...t.data.value}})}}});a("current",{modalForm:n})}checkTemplate(r){const{inputBox:i}=this.host,{msg:l,currentModule:s}=this.app,{setData:o,data:d}=this.store,p={[n.BLANK]:()=>this.setTemplate({type:"_blank"}),[n.SAMPLE]:()=>this.setTemplate({type:"_sample"}),[n.LOAD_SETTING]:()=>s({data:{module:t.SETTING,side:a.HIDE},content:{fkey:"checkSetting",args:[{type:"template"},n.LOAD_SETTING]}})};if(!0===d[t.TEMPLATE].dirty){const n=i({title:l("",{id:"msg_warning"}),message:l("",{id:"msg_dirty_text"}),infoText:l("",{id:"msg_delete_info"}),defaultOK:!0,onEvent:{onModalEvent:async a=>{if(o("current",{modalForm:null}),a.key===e.OK){const e=await this.saveTemplate();e&&(o(t.TEMPLATE,e),p[r]())}else p[r]()}}});return o("current",{modalForm:n,side:a.HIDE})}return p[r]()}createMap(e){const{data:a,setData:n}=this.store,{template:r,current:i,mapRef:l}=a[t.TEMPLATE],s=e||l,d=s.getContext("2d");d.clearRect(0,0,s.width,s.height);const p="#CCCCCC",m="#FFFF00",c="#00EE00",u=[];s.height=3;const f=["header","details","footer"];for(let t=0;t<f.length;t+=1)for(let e=0;e<r[f[t]].length;e+=1){const a={};a.type=o(r[f[t]][e]);const n=r[f[t]][e][a.type];if("row"===a.type||"datagrid"===a.type){if(a.cols=r[f[t]][e][a.type].columns.length,a.selected=n.columns===i.item||n.columns===i.parent,a.selcol=-1,a.selected)for(let n=0;n<a.cols;n+=1){const l=o(r[f[t]][e][a.type].columns[n]);r[f[t]][e][a.type].columns[n][l]===i.item&&(a.selcol=n)}9*a.cols+6>s.width&&(s.width=9*a.cols+6)}else a.selected=n===i.item,a.cols=1;switch(a.type){case"vgap":r[f[t]][e][a.type].height>2?a.height=r[f[t]][e][a.type].height:a.height=2,s.height+=a.height;break;case"hline":s.height+=2;break;case"datagrid":s.height+=20;break;default:s.height+=9}r[f[t]]!==i.item&&r.report!==i.item||(a.selected=!0),u.push(a)}s.height+=3,s.height<165&&(s.height=165);let _=3,h=3,y=0;for(let t=0;t<u.length;t+=1){if("row"===u[t].type){y=(s.width-(9*u[t].cols+6))/u[t].cols;for(let e=0;e<u[t].cols;e+=1)u[t].selected?u[t].selcol===e||-1===u[t].selcol?d.fillStyle=c:d.fillStyle=m:d.fillStyle=p,d.fillRect(_,h,8+y,8),_+=8+y+1;h+=9}if("datagrid"===u[t].type){u[t].selected?d.fillStyle=c:d.fillStyle=p,d.fillRect(_,h,s.width-6-1,4),y=(s.width-(9*u[t].cols+6))/u[t].cols;for(let e=0;e<u[t].cols;e+=1)u[t].selected?u[t].selcol===e||-1===u[t].selcol?d.fillStyle=c:d.fillStyle=m:d.fillStyle=p,d.fillRect(_,h+4+1,8+y,4),d.fillRect(_,h+8+2,8+y,4),d.fillRect(_,h+12+3,8+y,4),_+=8+y+1;h+=20}"vgap"===u[t].type&&(u[t].selected&&(d.fillStyle=c,d.fillRect(_,h-1,s.width-6-1,u[t].height)),h+=u[t].height),"vgap"===u[t].type&&(u[t].selected?d.strokeStyle=c:d.strokeStyle=p,d.beginPath(),d.moveTo(_,h),d.lineTo(s.width-3-1,h),d.stroke(),h+=2),"html"===u[t].type&&(u[t].selected?d.fillStyle=c:d.fillStyle=p,d.fillRect(_,h,s.width-6-1,8),h+=9),_=3}e&&n(t.TEMPLATE,{mapRef:s})}createTemplate(){const{inputBox:r}=this.host,{initItem:i}=this.app.modules,{msg:l,currentModule:s,requestData:o,resultError:d}=this.app,{data:p,setData:m}=this.store,c=(e,a)=>{const n={},r=i({tablename:e,dataset:p[t.SETTING].dataset,current:p[t.SETTING].current});return Object.keys(a).forEach((t=>{void 0!==r[t]&&(n[t]=a[t])})),n};let u=p[t.TEMPLATE].template.meta.nervatype;"trans"===u&&(u=`${p[t.TEMPLATE].template.meta.transtype}_${p[t.TEMPLATE].template.meta.direction}`);const f=new Date;u+=`_${new Date(f).toISOString().slice(0,10)}${new Date(f).toLocaleTimeString("en",{hour12:!1}).replace("24","00")}`.replaceAll("-","").replaceAll(":","");const _=r({title:l("",{id:"template_label_new"}),message:u,value:p[t.TEMPLATE].dbtemp.repname,showValue:!0,onEvent:{onModalEvent:async r=>{if(m("current",{modalForm:null}),r.key===e.OK&&""!==r.data.value){const e={...p[t.TEMPLATE].template,meta:{...p[t.TEMPLATE].template.meta,reportkey:u,repname:r.data.value}},{orientation:i,size:l,...m}={...c("report",p[t.TEMPLATE].dbtemp),id:null,reportkey:u,repname:r.data.value,report:JSON.stringify(e)},f=await o("/ui_report",{method:"POST",data:[m]});return f.error?d(f):s({data:{module:t.SETTING,side:a.HIDE},content:{fkey:"checkSetting",args:[{type:"template",id:f[0]},n.LOAD_SETTING]}})}return!0}}});return m("current",{modalForm:_,side:a.HIDE})}deleteData(n){const{inputBox:r}=this.host,{msg:i}=this.app,{setData:l,data:o}=this.store,d=r({title:i("",{id:"msg_warning"}),message:i("",{id:"msg_delete_text"}),infoText:i("",{id:"msg_delete_info"}),defaultOK:!0,onEvent:{onModalEvent:async a=>{if(l("current",{modalForm:null}),a.key===e.OK){const{[n]:e,...a}=o[t.TEMPLATE].template.data;let r={...o[t.TEMPLATE],template:{...o[t.TEMPLATE].template,data:a}};["_blank","_sample"].includes(r.key)||(r={...r,dirty:!0}),r={...r,dataset:[...s(r.template.data)]},l(t.TEMPLATE,r)}}}});return l("current",{modalForm:d,side:a.HIDE})}deleteDataItem(n){const{inputBox:r}=this.host,{msg:i}=this.app,{setData:l,data:o}=this.store,m=r({title:i("",{id:"msg_warning"}),message:i("",{id:"msg_delete_text"}),infoText:i("",{id:"msg_delete_info"}),defaultOK:!0,onEvent:{onModalEvent:async a=>{if(l("current",{modalForm:null}),a.key===e.OK){let e={...o[t.TEMPLATE]};if("list"===e.current_data.type){const{[n.key]:t,...a}=e.template.data[e.current_data.name];e={...e,template:{...e.template,data:{...e.template.data,[e.current_data.name]:a}}},e={...e,current_data:{...e.current_data,items:[...d(e.template.data[e.current_data.name])]}}}else if(1===e.template.data[e.current_data.name].length){const{[e.current_data.name]:t,...a}=e.template.data;e={...e,template:{...e.template,data:a}},e={...e,current_data:null,dataset:[...s(e.template.data)]}}else e.template.data[e.current_data.name]=[...e.template.data[e.current_data.name].slice(0,n._index),...e.template.data[e.current_data.name].slice(n._index+1)],e={...e,current_data:{...e.current_data,items:[...p(e.template.data[e.current_data.name]).items]}};e={...e,dataset:[...s(e.template.data)]},["_blank","_sample"].includes(e.key)||(e={...e,dirty:!0}),l(t.TEMPLATE,e)}}}});return l("current",{modalForm:m,side:a.HIDE})}deleteItem(){const{data:e}=this.store,{current:a}=e[t.TEMPLATE];if(null!==a.parent&&null!==a.index){a.parent.splice(a.index,1);let t=`tmp_${a.section}`;null!==a.parent_index&&(t+=`_${a.parent_index.toString()}_${a.parent_type}`),this.setCurrent({tmp_id:t,set_dirty:!0})}}async deleteTemplate(){const{inputBox:r}=this.host,{msg:i,requestData:l,resultError:s,currentModule:o}=this.app,{setData:d,data:p}=this.store,m=r({title:i("",{id:"msg_warning"}),message:i("",{id:"msg_delete_text"}),infoText:i("",{id:"msg_delete_info"}),onEvent:{onModalEvent:async a=>{if(d("current",{modalForm:null}),a.key===e.OK){const e=await l("/ui_report",{method:"DELETE",query:{id:p[t.TEMPLATE].id}});return e&&e.error?s(e):o({data:{module:t.SETTING},content:{fkey:"checkSetting",args:[{type:"template"},n.LOAD_SETTING]}})}return!0}}});return d("current",{modalForm:m,side:a.HIDE})}editDataItem(e){const{data:a,setData:n}=this.store;let r={...a[t.TEMPLATE]};switch(["_blank","_sample"].includes(r.key)||(r={...r,dirty:!0}),r.current_data.type){case"string":r={...r,template:{...r.template,data:{...r.template.data,[r.current_data.name]:e.value}}};break;case"list":r={...r,template:{...r.template,data:{...r.template.data,[r.current_data.name]:{...r.template.data[r.current_data.name],[r.current_data.item]:e.value}}}},r={...r,current_data:{...r.current_data,items:[...d(r.template.data[r.current_data.name])]}};break;default:r={...r,current_data:{...r.current_data,item:{...r.current_data.item,[e.field]:e.value}},template:{...r.template,data:{...r.template.data,[r.current_data.name]:[...r.template.data[r.current_data.name]]}}},r.template.data[r.current_data.name][e._index]={...r.template.data[r.current_data.name][e._index],[e.field]:e.value},r={...r,current_data:{...r.current_data,items:[...p(r.template.data[r.current_data.name]).items]}}}n(t.TEMPLATE,r)}editItem(e){const{data:a}=this.store;let n={...a[t.TEMPLATE]};const r=n.current.id,i=r.split("_"),l=(t,e)=>{if(null===e){const{[t]:e,...a}=n.current.item_base;n={...n,current:{...n.current,item_base:a}}}else n={...n,current:{...n.current,item_base:{...n.current.item_base,[t]:e}}};n.template[n.current.section][parseInt(i[2],10)][i[3]]={...n.current.item_base,columns:[...n.current.item_base.columns]}},s=(t,e)=>{if(null===e){const{[t]:e,...a}=n.current.item;n={...n,current:{...n.current,item:a}}}else n={...n,current:{...n.current,item:{...n.current.item,[t]:e}}};switch(i.length){case 2:n.template[n.current.section]={...n.current.item};break;case 4:n.template[n.current.section][parseInt(i[2],10)][i[3]]={...n.current.item};break;default:n.template[n.current.section][parseInt(i[2],10)][i[3]].columns[parseInt(i[4],10)][i[5]]={...n.current.item}}};if(["_blank","_sample"].includes(n.key)||(n={...n,dirty:!0}),e.selected){let t="";if(e.value){if(e.defvalue)t=e.defvalue;else switch(e.datatype){case"float":case"integer":t=0;break;default:t=""}n.current.item_base?l(e.name,t):s(e.name,t)}else n.current.item_base?l(e.name,null):s(e.name,null)}else if(e.file){if(e.value.length>0){const t=e.value[0],a=new FileReader;a.onload=t=>{s(e.name,t.target.result),this.setCurrent({tmp_id:r},n)},a.readAsDataURL(t)}}else if(e.checklist){const t=(n.current.item_base?n.current.item_base[e.name]:n.current.item[e.name])||"";let a=e.value;e.checked?"1"!==a&&"1"!==t&&(a=t+a):a=(n.current.item_base,t.replace(a,"")),n.current.item_base?l(e.name,a):s(e.name,a)}else n.current.item_base?l(e.name,e.value):s(e.name,e.value);e.file||this.setCurrent({tmp_id:r},n)}exportTemplate(){const{saveToDisk:e}=this.app,{data:n,setData:r}=this.store;r("current",{side:a.HIDE});const i=JSON.stringify(n[t.TEMPLATE].template);e(URL.createObjectURL(new Blob([i],{type:"text/json;charset=utf-8;"})),`${n[t.TEMPLATE].key}.json`)}goNext(){const{data:e}=this.store,{template:a,current:n}=e[t.TEMPLATE];this.setCurrent((()=>{let t,e,r=n.section,i=n.parent_index,l=n.index;null===n.parent_index&&(i=n.index,l=null);const s=["report","header","details","footer"];if(null!==l&&(t=o(a[r][i]),l<a[r][i][t].columns.length-1))return e=o(a[r][i][t].columns[l+1]),{tmp_id:`tmp_${r}_${i.toString()}_${t}_${(l+1).toString()}_${e}`};if(null!==i){if(null===l&&(t=o(a[r][i]),("row"===t||"datagrid"===t)&&a[r][i][t].columns.length>0))return e=o(a[r][i][t].columns[0]),{tmp_id:`tmp_${r}_${i.toString()}_${t}_0_${e}`};if(i<a[r].length-1)return t=o(a[r][i+1]),{tmp_id:`tmp_${r}_${(i+1).toString()}_${t}`};if("footer"===r)return null!==l?(e=o(a[r][i][t].columns[l]),{tmp_id:`tmp_${r}_${i.toString()}_${t}_${l.toString()}_${e}`}):{tmp_id:`tmp_${r}_${i.toString()}_${t}`};r=s[s.indexOf(r)+1]}return a[r].length>0?(t=o(a[r][0]),{tmp_id:`tmp_${r}_0_${t}`}):("footer"!==r&&(r=s[s.indexOf(r)+1]),{tmp_id:`tmp_${r}`})})())}goPrevious(){const{data:e}=this.store,{template:a,current:n}=e[t.TEMPLATE];this.setCurrent((()=>{let t,e,r=n.section,i=n.parent_index,l=n.index;if(null===n.parent_index&&(i=n.index,l=null),"report"===r)return{tmp_id:"tmp_report"};if(null!==l)return t=o(a[r][i]),l>0?(e=o(a[r][i][t].columns[l-1]),{tmp_id:`tmp_${r}_${i.toString()}_${t}_${(l-1).toString()}_${e}`}):{tmp_id:`tmp_${r}_${i.toString()}_${t}`};if(null!==i)return i>0?(t=o(a[r][i-1]),"row"===t||"datagrid"===t?(l=a[r][i-1][t].columns.length,l>0?(e=o(a[r][i-1][t].columns[l-1]),{tmp_id:`tmp_${r}_${(i-1).toString()}_${t}_${(l-1).toString()}_${e}`}):{tmp_id:`tmp_${r}_${(i-1).toString()}_${t}`}):{tmp_id:`tmp_${r}_${(i-1).toString()}_${t}`}):{tmp_id:`tmp_${r}`};const s=["report","header","details","footer"];return r=s[s.indexOf(r)-1],"report"===r?{tmp_id:"tmp_report"}:(i=a[r].length,i>0?(t=o(a[r][i-1]),"row"===t||"datagrid"===t?(l=a[r][i-1][t].columns.length,l>0?(e=o(a[r][i-1][t].columns[l-1]),{tmp_id:`tmp_${r}_${(i-1).toString()}_${t}_${(l-1).toString()}_${e}`}):{tmp_id:`tmp_${r}_${(i-1).toString()}_${t}`}):{tmp_id:`tmp_${r}_${(i-1).toString()}_${t}`}):{tmp_id:`tmp_${r}`})})())}moveDown(){const{data:e}=this.store,{current:a}=e[t.TEMPLATE];if(null!==a.parent&&null!==a.index&&a.index<a.parent.length-1){const t=a.parent[a.index+1];a.parent[a.index+1]=a.parent[a.index],a.parent[a.index]=t;let e=`tmp_${a.section}_`;null!==a.parent_index&&(e+=`${a.parent_index.toString()}_${a.parent_type}_`),e+=`${(a.index+1).toString()}_${a.type}`,this.setCurrent({tmp_id:e,set_dirty:!0})}}moveUp(){const{data:e}=this.store,{current:a}=e[t.TEMPLATE];if(null!==a.parent&&null!==a.index&&a.index>0){const t=a.parent[a.index-1];a.parent[a.index-1]=a.parent[a.index],a.parent[a.index]=t;let e=`tmp_${a.section}_`;null!==a.parent_index&&(e+=`${a.parent_index.toString()}_${a.parent_type}_`),e+=`${(a.index-1).toString()}_${a.type}`,this.setCurrent({tmp_id:e,set_dirty:!0})}}async onSideEvent({key:e,data:a}){const{showHelp:r}=this.app,{setData:i}=this.store;switch(e){case n.CHANGE:i(t.TEMPLATE,{[a.fieldname]:a.value});break;case n.SAVE:this.saveTemplate(a);break;case n.CREATE_REPORT:this.createTemplate();break;case n.DELETE:this.deleteTemplate();break;case n.CHECK:this.checkTemplate(a.value);break;case n.REPORT_SETTINGS:"JSON"===a.value?this.exportTemplate():this.showPreview();break;case n.HELP:r(a.value)}return!0}onTemplateEvent({key:e,data:a}){const{setData:n}=this.store,i=this.store.data[t.TEMPLATE];switch(e){case r.ADD_ITEM:this.addItem(a);break;case r.CHANGE_TEMPLATE:n(t.TEMPLATE,{[a.key]:a.value});break;case r.CHANGE_CURRENT:n(t.TEMPLATE,{...i,current:{...i.current,[a.key]:a.value}});break;case r.GO_PREVIOUS:this.goPrevious();break;case r.GO_NEXT:this.goNext();break;case r.CREATE_MAP:this.createMap(a.mapRef);break;case r.SET_CURRENT:this.setCurrent(...a);break;case r.MOVE_UP:this.moveUp();break;case r.MOVE_DOWN:this.moveDown();break;case r.DELETE_ITEM:this.deleteItem();break;case r.EDIT_ITEM:this.editItem(a);break;case r.EDIT_DATA_ITEM:this.editDataItem(a);break;case r.SET_CURRENT_DATA:this.setCurrentData(a);break;case r.SET_CURRENT_DATA_ITEM:this.setCurrentDataItem(a);break;case r.ADD_TEMPLATE_DATA:this.addTemplateData();break;case r.DELETE_DATA:this.deleteData(a);break;case r.DELETE_DATA_ITEM:this.deleteDataItem(a)}return!0}async saveTemplate(n){const{inputBox:r}=this.host,{requestData:i,resultError:l,msg:s}=this.app,{setData:o,data:d}=this.store,p=async()=>{let e={...d[t.TEMPLATE]};const a={id:e.id,report:JSON.stringify(e.template)},n=await i("/ui_report",{method:"POST",data:[a]});return n.error?(l(n),null):(e={...e,dirty:!1},e)};if(n){const n=r({title:s("",{id:"template_label_template"}),message:s("",{id:"msg_dirty_info"}),infoText:s("",{id:"msg_delete_info"}),defaultOK:!0,onEvent:{onModalEvent:async a=>{if(o("current",{modalForm:null}),a.key===e.OK){const e=await p();e&&o(t.TEMPLATE,e)}}}});return o("current",{modalForm:n,side:a.HIDE})}return p()}setCurrent(e,a){const{setData:n,data:r}=this.store,{mapRef:i}=r[t.TEMPLATE],{msg:s}=this.app,o=e.tmp_id.split("_");let d={...a||r[t.TEMPLATE],current:{id:e.tmp_id,section:o[1]}};2===o.length&&(d={...d,current:{...d.current,type:o[1],item:d.template[d.current.section],index:null,parent:null,parent_type:null,parent_index:null}}),4===o.length&&(d={...d,current:{...d.current,type:o[3],index:parseInt(o[2],10),parent:d.template[d.current.section],parent_type:d.current.section,parent_index:null}},d=["row","datagrid"].includes(d.current.type)?{...d,current:{...d.current,item:d.template[d.current.section][parseInt(o[2],10)][o[3]].columns,item_base:d.template[d.current.section][parseInt(o[2],10)][o[3]]}}:{...d,current:{...d.current,item:d.template[d.current.section][parseInt(o[2],10)][o[3]]}}),6===o.length&&(d={...d,current:{...d.current,type:o[5],item:d.template[d.current.section][parseInt(o[2],10)][o[3]].columns[parseInt(o[4],10)][o[5]],index:parseInt(o[4],10),parent:d.template[d.current.section][parseInt(o[2],10)][o[3]].columns,parent_type:o[3],parent_index:parseInt(o[2],10)}}),d={...d,current:{...d.current,form:l({msg:s})[d.current.type]}},e.set_dirty&&!["_blank","_sample"].includes(d.key)&&(d={...d,dirty:!0}),n(t.TEMPLATE,d),i&&this.createMap()}setCurrentData(e){const{showToast:a,msg:n}=this.app,{data:r,setData:l}=this.store;let o={...r[t.TEMPLATE]};const m=e,c=e=>{["_blank","_sample"].includes(o.key)||(o={...o,dirty:!0}),o={...o,current_data:e},l(t.TEMPLATE,o)};if(m)switch(m.type){case"new":if(Object.keys(o.template.data).includes(m.values.name)||""===m.values.name)a(i.ERROR,n("",{id:"msg_value_exists"}));else if("table"===m.values.type&&""===m.values.columns)a(i.ERROR,n("",{id:"template_missing_columns"}));else{const t={name:m.values.name,type:m.values.type};switch(t.type){case"list":o={...o,template:{...o.template,data:{...o.template.data,[t.name]:{}}}},t.items=[...d({})];break;case"table":o={...o,template:{...o.template,data:{...o.template.data,[t.name]:[]}}};const e=m.values.columns.split(","),a={};for(let t=0;t<e.length;t+=1)a[String(e[t]).trim()]="";o.template.data[t.name]=[...o.template.data[t.name],a];const n=p([a]);t.items=n.items,t.fields=n.fields;break;default:o={...o,template:{...o.template,data:{...o.template.data,[t.name]:""}}}}o={...o,dataset:[...s(o.template.data)]},c(t)}break;case"list":m.items=d(o.template.data[m.name]),c(m);break;case"table":const t=p(o.template.data[m.name]);m.items=t.items,m.fields=t.fields,c(m);break;default:c(m)}else c(m)}setCurrentDataItem(n){const{inputBox:r}=this.host,{showToast:l,msg:s}=this.app,{data:o,setData:m}=this.store;let c={...o[t.TEMPLATE]};const u=e=>{["_blank","_sample"].includes(c.key)||(c={...c,dirty:!0}),c={...c,current_data:{...c.current_data,item:e}},m(t.TEMPLATE,c)};void 0===n?("list"===c.current_data.type&&(()=>{const t=r({title:s("",{id:"msg_input_title"}),message:s("",{id:"msg_new_fieldname"}),value:"",showValue:!0,onEvent:{onModalEvent:async t=>{m("current",{modalForm:null}),t.key===e.OK&&""!==t.data.value&&(Object.keys(c.template.data[c.current_data.name]).includes(t.data.value)?l(i.ERROR,s("",{id:"msg_value_exists"})):(c={...c,template:{...c.template,data:{...c.template.data,[c.current_data.name]:{...c.template.data[c.current_data.name],[t.data.value]:""}}}},c={...c,current_data:{...c.current_data,items:[...d(c.template.data[c.current_data.name])]}},u(t.data.value)))}}});m("current",{modalForm:t,side:a.HIDE})})(),"table"===c.current_data.type&&(()=>{const t={...c.template.data[c.current_data.name][0],_index:c.template.data[c.current_data.name].length};Object.keys(t).forEach((e=>{"_index"!==e&&(t[e]="")})),c={...c,template:{...c.template,data:{...c.template.data,[c.current_data.name]:[...c.template.data[c.current_data.name],t]}}},c={...c,current_data:{...c.current_data,items:[...p(c.template.data[c.current_data.name]).items]}},u(t)})()):u(n)}async setTemplate(e){const{resultError:n,currentModule:r}=this.app;let i={id:void 0,key:e.type,title:"Nervatura Report",template:{meta:{reportkey:e.type,nervatype:"",transtype:"",direction:"",repname:"Nervatura Report",description:"",filetype:"pdf"},report:{},header:[],details:[],footer:[],sources:{},data:{}},current:{},current_data:null,dataset:[],docnumber:"",tabView:"template",dirty:!1};if("_sample"===e.type){const{sample:t}=await import("./module-DFAYf1YB.js");i={...i,template:{...i.template,...t},dataset:s(t.data)}}if("template"===e.type){let l={};try{l=JSON.parse(e.dataset.template[0].report)}catch(e){return n({error:{message:e.message}}),r({data:{module:t.SETTING,side:a.HIDE}})}i={...i,id:e.dataset.template[0].id,key:e.dataset.template[0].reportkey,title:e.dataset.template[0].repname,template:l,dbtemp:e.dataset.template[0]},i={...i,dataset:s(i.template.data)}}return this.setCurrent({tmp_id:"tmp_report"},i)}showPreview(n){const{inputBox:r}=this.host,{getSetting:i,msg:l,requestData:s,resultError:o}=this.app,{data:d,setData:p}=this.store,m=async t=>{const e=await s("/report",{method:"POST",data:t});if(e.error)o(e);else{const t=URL.createObjectURL(e,{type:"application/pdf"});window.open(t,"_blank")}},c={...d[t.TEMPLATE]},u={reportkey:c.key,orientation:n||i("page_orient"),size:i("page_size"),output:"auto",title:c.title,template:JSON.stringify(c.template)};if(["_blank","_sample"].includes(c.key))u.reportkey="",m(u);else{u.nervatype=c.template.meta.nervatype;const n=r({title:l("",{id:"template_preview_data"}),message:l("",{id:"template_preview_input"}).replace("docname",u.nervatype),value:c.docnumber,showValue:!0,onEvent:{onModalEvent:async a=>{if(p("current",{modalForm:null}),a.key===e.OK&&""!==a.data.value){const e={...c,docnumber:a.data.value};p(t.TEMPLATE,e),u.refnumber=a.data.value,m(u)}return!0}}});p("current",{modalForm:n,side:a.HIDE})}}}export{m as TemplateController,d as getDataList,p as getDataTable,o as getElementType};