nervatura-client
Version:
Business Management Application
2 lines (1 loc) • 15.8 kB
JavaScript
import{b as e,T as t,M as r,d as a,l as i,S as s,a as n}from"./main-DXT0hpEA.js";import"./module-FRmUNWHB.js";import"./module-CC7fmSsS.js";import"./module-C1fQGCtD.js";class o{constructor(e){this.host=e,this.app=e.app,this.store=e.app.store,this.module={},this.changePassword=this.changePassword.bind(this),this.checkSetting=this.checkSetting.bind(this),this.deleteSetting=this.deleteSetting.bind(this),this.editItem=this.editItem.bind(this),this.loadLog=this.loadLog.bind(this),this.loadSetting=this.loadSetting.bind(this),this.onSettingEvent=this.onSettingEvent.bind(this),this.onSideEvent=this.onSideEvent.bind(this),this.saveSetting=this.saveSetting.bind(this),this.setProgramForm=this.setProgramForm.bind(this),this.setSettingData=this.setSettingData.bind(this),this.setSettingForm=this.setSettingForm.bind(this),this.setFormActions=this.setFormActions.bind(this),this.tableValues=this.tableValues.bind(this),e.addController(this)}setModule(e){this.module=e}async changePassword(){const{requestData:r,resultError:a,showToast:i,msg:s}=this.app,{data:n}=this.store,{username:o,password_1:l,password_2:d}=n[e.SETTING].current.form;if(""===o||null===o)return i(t.ERROR,s("",{id:"ms_password_username"}));if(l!==d)return i(t.ERROR,s("",{id:"ms_password_pswerr"}));const u={method:"POST",data:{username:o,password:l,confirm:d}},p=await r("/auth/password",u);return p&&p.error?a(p):i(t.SUCCESS,s("",{id:"msg_password_ok"}))}checkSetting(t,i){const{inputBox:n}=this.host,{msg:o}=this.app,{setData:l,data:d}=this.store,u={[s.LOAD_SETTING]:()=>this.loadSetting(t),[s.PASSWORD_FORM]:()=>this.setPasswordForm(t.username)};if(!0===d[e.SETTING].dirty){const t=n({title:o("",{id:"msg_warning"}),message:o("",{id:"msg_dirty_text"}),infoText:o("",{id:"msg_delete_info"}),defaultOK:!0,onEvent:{onModalEvent:async t=>{if(l("current",{modalForm:null}),t.key===r.OK){const t=await this.saveSetting();t&&(l(e.SETTING,t),u[i]())}else u[i]()}}});return l("current",{modalForm:t,side:a.HIDE})}return u[i]()}deleteSetting(i){const{inputBox:s}=this.host,{data:n,setData:o}=this.store,{sql:l}=this.app.modules,{resultError:d,requestData:u,getSql:p,showToast:m,msg:c}=this.app,h=async()=>{const t="usergroup"===n[e.SETTING].type?"/groups":`/${n[e.SETTING].type}`,r=await u(t,{method:"DELETE",query:{id:i.id}});r&&r.error?d(r):this.loadSetting({type:n[e.SETTING].type})},f=s({title:c("",{id:"msg_warning"}),message:c("",{id:"msg_delete_text"}),infoText:c("",{id:"msg_delete_info"}),onEvent:{onModalEvent:async a=>{if(o("current",{modalForm:null}),a.key===r.OK)if(void 0!==l[n[e.SETTING].type].delete_state){const r=p(n[e.LOGIN].data.engine,l[n[e.SETTING].type].delete_state()),a={method:"POST",data:[{key:"state",text:r.sql,values:Array(r.prmCount).fill(i.id)}]},s=await u("/view",a);s.error?d(s):s.state[0].sco>0?m(t.ERROR,c("",{id:"msg_integrity_err"})):h()}else h()}}});o("current",{modalForm:f,side:a.HIDE})}editItem(t){const{setData:r,data:a}=this.store;let i={...a[e.SETTING]};"program"===i.type?(i={...i,current:{...i.current,form:{...i.current.form,[t.name]:t.value}}},localStorage.setItem(t.name,t.value)):"log_search"===t.name?this.loadLog():("all"!==i.audit&&"update"!==i.audit||(i={...i,dirty:!0}),i="fieldvalue_value"===t.name||"fieldvalue_notes"===t.name?{...i,current:{...i.current,fieldvalue:{...i.current.fieldvalue,[t.name]:t.value},form:{...i.current.form,[t.name.split("_")[1]]:t.value.toString()}}}:{...i,current:{...i.current,form:{...i.current.form,[t.name]:t.value}}}),r(e.SETTING,i)}async loadLog(){const{sql:r}=this.app.modules,{getSql:a,requestData:i,resultError:s,showToast:n,msg:o}=this.app,{setData:l,data:d}=this.store,u={customer:{inner_join:["customer c","on",["l.ref_id","=","c.id"]],select:"c.custnumber as refnumber"},employee:{inner_join:["employee em","on",["l.ref_id","=","em.id"]],select:"em.empnumber as refnumber"},event:{inner_join:["event ev","on",["l.ref_id","=","ev.id"]],select:"ev.calnumber as refnumber"},place:{inner_join:["place p","on",["l.ref_id","=","p.id"]],select:"p.planumber as refnumber"},product:{inner_join:["product p","on",["l.ref_id","=","p.id"]],select:"p.partnumber as refnumber"},project:{inner_join:["project p","on",["l.ref_id","=","p.id"]],select:"p.pronumber as refnumber"},tool:{inner_join:["tool t","on",["l.ref_id","=","t.id"]],select:"t.serial as refnumber"},trans:{inner_join:["trans t","on",["l.ref_id","=","t.id"]],select:"t.transnumber as refnumber"}};let p={...d[e.SETTING],view:{...d[e.SETTING].view,result:[]}};const m=r.log.result();let c=[];if(!["login","logout"].includes(p.current.form.logstate)){if(m.inner_join=[...m.inner_join,["groups nt","on",[["l.nervatype","=","nt.id"],["and","nt.groupvalue","=","?"]]]],c=[...c,p.current.form.nervatype],!u[p.current.form.nervatype])return n(t.ERROR,`${o("",{id:"msg_required"})} ${o("",{id:"log_nervatype"})}`);m.inner_join=[...m.inner_join,u[p.current.form.nervatype].inner_join],m.select[4]=u[p.current.form.nervatype].select}m.where=[...m.where,["ls.groupvalue","=","?"]],c=[...c,p.current.form.logstate],p.current.form.empnumber&&""!==p.current.form.empnumber&&(m.where=[...m.where,["and","lower(e.empnumber)","like",`{CCS}{JOKER}{SEP}lower('${p.current.form.empnumber}'){SEP}{JOKER}{CCE}`]]),p.current.form.fromdate&&""!==p.current.form.fromdate&&(m.where=[...m.where,["and","{FMS_DATE}l.crdate{FME_DATE}",">=","?"]],c=[...c,p.current.form.fromdate]),p.current.form.todate&&""!==p.current.form.todate&&(m.where=[...m.where,["and","{FMS_DATE}l.crdate{FME_DATE}","<=","?"]],c=[...c,p.current.form.todate]);const h={method:"POST",data:[{key:"log",text:a(d.login.data.engine,m).sql,values:c}]},f=await i("/view",h);return f.error?s(f):(p={...p,view:{...p.view,result:f.log}},l(e.SETTING,p),!0)}async loadSetting(t){const{dataSet:r,sql:i}=this.app.modules,{getSql:s,requestData:n,resultError:o,currentModule:l}=this.app,{data:d}=this.store;let u={...t,dataset:{},dirty:!1};if(r[u.type]){let t=[];r[u.type]().forEach((r=>{let a={};"table"===r.infoType?(a={select:["*"],from:r.classAlias},r.where&&(a.where=r.where),r.order&&(a.order_by=r.order)):a=void 0!==i[u.type][r.infoName]?i[u.type][r.infoName](u.type):i.all[r.infoName](u.type);const n=s(d[e.LOGIN].data.engine,a);null!==u.id||0===n.prmCount?t=[...t,{key:r.infoName,text:n.sql,values:n.prmCount>0&&null!==u.id?Array(n.prmCount).fill(u.id):[]}]:u={...u,dataset:{...u.dataset,[r.infoName]:[]}}}));const p={method:"POST",data:t},m=await n("/view",p);if(m.error)return o(m);if(u={...u,dataset:{...u.dataset,...m}},"template"===u.type&&void 0!==u.id)return l({data:{module:e.TEMPLATE,side:a.HIDE},content:{fkey:"setTemplate",args:[u]}})}return this.setSettingData(u)}onSettingEvent({key:t,data:r}){const{setData:a}=this.store;switch(t){case i.CURRENT_PAGE:a(e.SETTING,{page:r.value});break;case i.FORM_ACTION:this.setFormActions(r);break;case i.EDIT_ITEM:this.editItem(r)}return!0}async onSideEvent({key:t,data:r}){const{showHelp:i,currentModule:o}=this.app,{setData:l}=this.store,d=this.store.data[e.SETTING],u=this.store.data[e.EDIT];switch(t){case s.BACK:let t=d.type;"password"===t?(t="setting",l(e.SETTING,{group_key:"group_admin"}),this.loadSetting({type:"setting"})):this.checkSetting({type:t},s.LOAD_SETTING);break;case s.CHANGE:l(e.SETTING,{[r.fieldname]:r.value});break;case s.SAVE:if(l("current",{side:a.HIDE}),"password"===d.type)this.changePassword();else{const e=await this.saveSetting();e&&this.loadSetting({type:e.type,id:e.current.form.id})}break;case s.DELETE:this.deleteSetting(r.value);break;case s.CHECK:r[0].ntype?o({data:{module:e.EDIT,side:a.HIDE},content:{fkey:"checkEditor",args:[{ntype:"customer",ttype:null,id:1},n.LOAD_EDITOR]}}):this.checkSetting(...r);break;case s.LOAD_SETTING:this.loadSetting(r);break;case s.PROGRAM_SETTING:this.setProgramForm();break;case s.PASSWORD:let p=r.username;!p&&u.current&&(p=u.dataset[u.current.type][0].username),this.checkSetting({username:p},s.PASSWORD_FORM);break;case s.HELP:i(r.value)}return!0}async saveSetting(){const{initItem:t,validator:r}=this.app.modules,{resultError:a,requestData:i}=this.app,{data:s}=this.store;let n={...s[e.SETTING]},o=this.tableValues(n.ntype,n.current.form);if(o=await r(n.ntype,o),o.error)return a(o);let l=await i(`/${n.ntype}`,{method:"POST",data:[o]});if(l.error)return a(l),null;if(null===n.current.form.id&&(n={...n,current:{...n.current,form:{...n.current.form,id:l[0]}}}),n={...n,dirty:!1},"usergroup"===n.type){const r=s[e.LOGIN].data.groups.filter((e=>e.id===n.current.form.transfilter))[0].groupvalue;if(null!==n.current.form.translink||"all"!==r){const r={...t({tablename:"link",dataset:n.dataset,current:n.current}),id:n.current.form.translink,nervatype_1:s[e.LOGIN].data.groups.filter((e=>"nervatype"===e.groupname&&"groups"===e.groupvalue))[0].id,ref_id_1:n.current.form.id,nervatype_2:s[e.LOGIN].data.groups.filter((e=>"nervatype"===e.groupname&&"groups"===e.groupvalue))[0].id,ref_id_2:n.current.form.transfilter};if(l=await i("/link",{method:"POST",data:[r]}),l.error)return a(l),null}}return n}setPasswordForm(t){const{forms:r}=this.app.modules,{setData:a}=this.store,i={username:t,password_1:"",password_2:""},s=r.password(i),n={type:"password",dataset:{},current:{form:i,template:s},panel:s.options.panel,caption:s.options.title,icon:s.options.icon,filter:"",result:[],dirty:!1,audit:"all",view:{type:"password",result:[]}};a(e.SETTING,n)}setProgramForm(){const{forms:t}=this.app.modules,{getSetting:r}=this.app,{setData:a}=this.store,i=t.program(),s={type:"program",dataset:{},current:{form:{paginationPage:r("paginationPage"),history:r("history"),page_size:r("page_size"),export_sep:r("export_sep")},template:i},filter:"",result:[],dirty:!1,panel:null,caption:i.options.title,icon:i.options.icon,view:{type:"program",result:[]}};a(e.SETTING,s)}setSettingData(t){const{forms:r,initItem:a}=this.app.modules,{getAuditFilter:i}=this.app,{data:s,setData:o}=this.store,l=r[t.type](),d=i(t.type)[0],u={...t,current:"log"===t.type?{form:a({tablename:"log"}),template:l}:null,panel:null,filter:"",result:[],ntype:l.options.data,caption:l.options.title,icon:l.options.icon,view:{type:l.view.setting.type,result:t.dataset[`${t.type}_view`],fields:l.view.setting.fields?l.view.setting.fields:null},actions:{new:"all"!==d?null:l.view.setting.actions.new,edit:l.view.setting.actions.edit,delete:"all"!==d?null:l.view.setting.actions.delete},audit:d,template:null,page:s[e.SETTING].type===t.type&&s[e.SETTING].page||0};o(e.SETTING,u),"usergroup"!==t.type&&"ui_menu"!==t.type||!t.id?void 0!==t.id&&this.setSettingForm(t.id,u):this.setFormActions({params:{action:n.EDIT_ITEM,setting:u},row:{id:t.id}})}setSettingForm(t,r){const{forms:a,initItem:i}=this.app.modules,{data:s,setData:n}=this.store;let o={...r||s[e.SETTING],current:{}};if(null!==t){const e=o.dataset[`${o.type}_view`].filter((e=>e.id===parseInt(t,10)))[0];o={...o,dirty:!1,current:{form:e}},"fieldvalue"===o.ntype&&(o={...o,current:{...o.current,fieldvalue:{rowtype:"fieldvalue",id:e.id,fieldname:e.fieldname,fieldvalue_value:e.value,fieldvalue_notes:e.notes||"",label:e.lslabel,description:"valuelist"===e.fieldtype?e.valuelist.split("|"):e.value,disabled:"false",fieldtype:e.fieldtype,datatype:"urlink"===e.fieldtype?"text":e.fieldtype}}})}else o={...o,dirty:!("all"!==o.audit&&"update"!==o.audit),current:{form:i({tablename:o.type,dataset:o.dataset,current:o.current})}};"usergroup"===o.type&&null===o.current.form.transfilter&&(o.current.form.transfilter=o.dataset.transfilter.filter((e=>"all"===e.groupvalue))[0].id),o={...o,current:{...o.current,template:a[o.type](o.current.form,o)}},o={...o,panel:o.current.template.options.panel},"readonly"===o.audit&&(o.panel.save=!1),"all"!==o.audit&&(o.panel.delete=!1,o.panel.new=!1),n(e.SETTING,o)}async setFormActions(t){const{modalAudit:i,modalMenu:o}=this.module,{inputBox:l}=this.host,{sql:d,initItem:u}=this.app.modules,{getSql:p,requestData:m,resultError:c,currentModule:h,msg:f}=this.app,{setData:g,data:T}=this.store,E=t.row||{};switch(t.params.action){case n.NEW_ITEM:this.checkSetting({type:T[e.SETTING].type,id:null},s.LOAD_SETTING);break;case n.EDIT_ITEM:switch(T[e.SETTING].type){case"template":this.checkSetting({type:T[e.SETTING].type,id:E.id},s.LOAD_SETTING);break;case"place":h({data:{module:e.EDIT,side:a.HIDE},content:{fkey:"checkEditor",args:[{ntype:T[e.SETTING].type,ttype:null,id:E.id||null},n.LOAD_EDITOR]}});break;case"usergroup":const r={method:"POST",data:[{key:"audit",text:p(T.login.data.engine,d.usergroup.audit()).sql,values:[E.id]}]},i=await m("/view",r);if(i.error)c(i);else{let r={...t.params.setting||T[e.SETTING]};r={...r,dataset:{...r.dataset,audit:i.audit}},this.setSettingForm(E.id,r)}break;case"ui_menu":const o={method:"POST",data:[{key:"menufields",text:p(T.login.data.engine,d.ui_menu.ui_menufields()).sql,values:[E.id]}]},l=await m("/view",o);if(l.error)c(l);else{let r={...t.params.setting||T[e.SETTING]};r={...r,dataset:{...r.dataset,ui_menufields:l.menufields}},this.setSettingForm(E.id,r)}break;default:this.setSettingForm(E.id)}break;case n.DELETE_ITEM:this.deleteSetting(E);break;case n.EDIT_AUDIT:let y=E;y.id||(y={...u({tablename:"link",dataset:T[e.SETTING].dataset,current:T[e.SETTING].current}),usergroup:T[e.SETTING].current.form.id,nervatype:T[e.SETTING].dataset.nervatype.filter((e=>"customer"===e.groupvalue))[0].id,inputfilter:T[e.SETTING].dataset.inputfilter.filter((e=>"all"===e.groupvalue))[0].id});const S=i({idKey:y.id,usergroup:y.usergroup,nervatype:y.nervatype,subtype:y.subtype,inputfilter:y.inputfilter,supervisor:y.supervisor,typeOptions:T[e.SETTING].dataset.nervatype.map((e=>({value:String(e.id),text:e.groupvalue}))),subtypeOptions:T[e.SETTING].dataset.transtype.map((e=>({value:String(e.id),text:e.groupvalue,type:"trans"}))).concat(T[e.SETTING].dataset.reportkey.map((e=>({value:String(e.id),text:e.reportkey,type:"report"}))),T[e.SETTING].dataset.menukey.map((e=>({value:String(e.id),text:e.menukey,type:"menu"})))),inputfilterOptions:T[e.SETTING].dataset.inputfilter.map((e=>({value:String(e.id),text:e.groupvalue}))),onEvent:{onModalEvent:async t=>{if(g("current",{modalForm:null}),t.key===r.OK){const r=await m("/ui_audit",{method:"POST",data:[this.tableValues("audit",t.data.value)]});r.error?c(r):this.setFormActions({params:{action:n.EDIT_ITEM},row:T[e.SETTING].current.form})}}}});g("current",{modalForm:S,side:a.HIDE});break;case n.EDIT_MENU_FIELD:let v=E;v.id||(v={...u({tablename:"ui_menufields",dataset:T[e.SETTING].dataset,current:T[e.SETTING].current}),menu_id:T[e.SETTING].current.form.id,fieldtype:T[e.SETTING].dataset.fieldtype.filter((e=>"string"===e.groupvalue))[0].id,orderby:T[e.SETTING].dataset.ui_menufields.length});const _=o({idKey:v.id,menu_id:v.menu_id,fieldname:v.fieldname,description:v.description,fieldtype:v.fieldtype,orderby:v.orderby,fieldtypeOptions:T[e.SETTING].dataset.fieldtype.map((e=>({value:String(e.id),text:e.groupvalue}))),onEvent:{onModalEvent:async t=>{if(g("current",{modalForm:null}),t.key===r.OK){const r=await m("/ui_menufields",{method:"POST",data:[this.tableValues("ui_menufields",t.data.value)]});r.error?c(r):this.setFormActions({params:{action:n.EDIT_ITEM},row:T[e.SETTING].current.form})}}}});g("current",{modalForm:_,side:a.HIDE});break;case n.DELETE_ITEM_ROW:const I=l({title:f("",{id:"msg_warning"}),message:f("",{id:"msg_delete_text"}),infoText:f("",{id:"msg_delete_info"}),onEvent:{onModalEvent:async a=>{if(g("current",{modalForm:null}),a.key===r.OK){const r=await m(`/${t.params.table}`,{method:"DELETE",query:{id:E.id}});r&&r.error?c(r):this.setFormActions({params:{action:n.EDIT_ITEM},row:T[e.SETTING].current.form})}}}});g("current",{modalForm:I,side:a.HIDE})}}tableValues(t,r){const{initItem:a}=this.app.modules,{data:i}=this.store,s={},n=a({tablename:t,dataset:i[e.SETTING].dataset,current:i[e.SETTING].current});return Object.keys(r).forEach((e=>{void 0!==n[e]&&(s[e]=r[e])})),s}}export{o as SettingController};