"use strict";(self.webpackChunk_aidoop_aidoop_r=self.webpackChunk_aidoop_aidoop_r||[]).push([[8459],{69338:(e,t,a)=>{a.d(t,{w:()=>l});var i=a(50493),n=(a(68784),a(16682)),r=a(94430),d=a(56765),s=a(27805),o=a(53421),p=a(36179);class l extends r.oi{constructor(){super(...arguments),this.departments=[],this.columns={list:{fields:["name","description"]},pagination:{infinite:!0},columns:[{type:"string",name:"name",header:o.z2.t("field.name"),width:150},{type:"string",name:"description",header:o.z2.t("field.description"),width:200},{type:"checkbox",name:"active",header:o.z2.t("field.active"),width:60}]}}render(){return r.dy`
      <ox-grist
        .mode=${(0,p.s2)()?"LIST":"GRID"}
        .config=${this.columns}
        .data=${{records:this.departments}}
      ></ox-grist>

      <div class="button-container">
        <mwc-button raised @click="${this.save.bind(this)}">${o.z2.t("button.save")}</mwc-button>
      </div>
    `}async save(){var e;(null===(e=(await s.Lp.mutate({mutation:n.ZP`
        mutation importDepartments($departments: [DepartmentPatch!]!) {
          importDepartments(departments: $departments)
        }
      `,variables:{departments:this.departments}})).errors)||void 0===e?void 0:e.length)||this.dispatchEvent(new CustomEvent("imported"))}}l.styles=[r.iv`
      :host {
        display: flex;
        flex-direction: column;

        background-color: #fff;
      }

      ox-grist {
        flex: 1;
      }

      .button-container {
        display: flex;
        margin-left: auto;
        padding: var(--padding-default);
      }

      mwc-button {
        margin-left: var(--margin-default);
      }
    `],(0,i.gn)([(0,d.Cb)({type:Array}),(0,i.w6)("design:type",Array)],l.prototype,"departments",void 0),(0,i.gn)([(0,d.Cb)({type:Object}),(0,i.w6)("design:type",Object)],l.prototype,"columns",void 0)},88459:(e,t,a)=>{a.r(t),a.d(t,{DepartmentListPage:()=>g});var i=a(50493),n=(a(54477),a(15633)),r=a(77675),d=a(94430),s=a(56765),o=a(69292),p=a(27805),l=a(53421),c=a(28120),m=a(16682),h=a(69338),u=a(51728);a(74688),a(72696);let y=class extends((0,l.NC)(l.z2)((0,o.f)(d.oi))){firstUpdated(e){this.properties=[{type:"string",name:"controlNo",label:"control-no"},{type:"string",name:"name",label:"name"},{type:"string",name:"description",label:"description"},{type:"resource-object",name:"manager",label:"manager",property:{title:l.z2.t("title.employee list"),queryName:"employees",columns:[{name:"id",hidden:!0},{name:"controlNo",header:{renderer:()=>l.z2.t("field.control-no")},filter:"search"},{name:"name",header:{renderer:()=>l.z2.t("field.name")},filter:"search"},{name:"email",header:{renderer:()=>l.z2.t("field.email")}}],list:{fields:["controlNo","name","email"]},valueField:"id",nameField:"name",descriptionField:"controlNo"}},{type:"boolean",name:"active",label:"active"},{type:"image",name:"picture",label:"picture"}]}render(){return d.dy`
      <ox-properties-dynamic-view
        .props=${this.properties}
        .value=${this.department}
        @property-change=${this.onPropertyChange.bind(this)}
      ></ox-properties-dynamic-view>
    `}onPropertyChange(e){this.department=e.detail}};y.styles=[n.Ix,d.iv`
      :host {
        display: flex;
        flex-direction: column;

        overflow: auto;
      }

      ox-properties-dynamic-view {
        flex: 1;
      }
    `],(0,i.gn)([(0,s.Cb)({type:Object}),(0,i.w6)("design:type",Object)],y.prototype,"department",void 0),(0,i.gn)([(0,s.IO)("ox-properties-dynamic-view"),(0,i.w6)("design:type",Object)],y.prototype,"dynamicView",void 0),(0,i.gn)([(0,s.SB)(),(0,i.w6)("design:type",Object)],y.prototype,"properties",void 0),y=(0,i.gn)([(0,s.Mo)("department-view")],y);const v=m.ZP`
  fragment Department_department on Department {
    id
    controlNo
    name
    description

    manager {
      id
      name
      controlNo
      photo
      email
    }
    active
    state
    picture

    updater {
      id
      name
    }
    updatedAt
  }
`;let g=class extends((0,c.$)(r.h)((0,l.NC)(l.z2)((0,o.f)(r.B4)))){static get scopedElements(){return{"department-importer":h.w}}get context(){return{title:l.z2.t("title.department list"),help:"organization/department",actions:[this.selected?Object.assign({title:l.z2.t("button.save"),action:this.save.bind(this)},n.jO.save):null,Object.assign({title:l.z2.t("button.add"),action:this.create.bind(this)},n.jO.add),Object.assign({title:l.z2.t("button.reset"),action:this.reset.bind(this)},n.jO.save),Object.assign({title:l.z2.t("button.delete"),action:this.delete.bind(this)},n.jO.delete)].filter(Boolean),exportable:{name:l.z2.t("title.department list"),data:this.exportHandler.bind(this)},importable:{handler:this.importHandler.bind(this)}}}render(){return d.dy`
      <ox-tree-vertical
        .data=${this.root}
        .selected=${this.selected}
        @select=${this.onSelect.bind(this)}
        label-property="name"
      ></ox-tree-vertical>

      <department-view .department=${this.selected}></department-view>
    `}onSelect(e){this.selected=e.detail,this.updateContext()}reset(){this.departmentView.department={}}async create(){const{id:e}=this.selected||{},{controlNo:t,name:a,description:i,state:n,picture:r,active:d,manager:s}=this.departmentView.department;var o={controlNo:t,name:a,description:i,state:n,manager:s,active:d};r instanceof File&&(o.picture=r),e&&(o.parent={id:e});const l=await p.Lp.mutate({mutation:m.ZP`
        mutation ($department: NewDepartment!) {
          createDepartment(department: $department) {
            ...Department_department
          }
        }

        ${v}
      `,variables:{department:o},context:{hasUpload:!0}});this.selected=l.data.createDepartment,this.updateContext(),await this.fetch()}async save(){const{id:e,controlNo:t,name:a,description:i,state:n,picture:r,active:d,manager:s}=this.departmentView.department;e||alert("Please select department first.");var o={controlNo:t,name:a,description:i,state:n,active:d,manager:s};r instanceof File&&(o.picture=r);const l=await p.Lp.mutate({mutation:m.ZP`
        mutation ($id: String!, $patch: DepartmentPatch!) {
          updateDepartment(id: $id, patch: $patch) {
            ...Department_department
          }
        }

        ${v}
      `,variables:{id:e,patch:o},context:{hasUpload:!0}});this.selected=l.data.updateDepartment,this.fetch()}async delete(){var e;this.selected||alert("select department first.");const t=null===(e=this.selected)||void 0===e?void 0:e.children;if(t&&t.length>0&&alert("Department having children cannot be deleted."),confirm(l.z2.t("text.sure_to_x",{x:l.z2.t("text.delete")}))){const{id:e}=this.selected||{};await p.Lp.mutate({mutation:m.ZP`
          mutation ($id: String!) {
            deleteDepartment(id: $id)
          }
        `,variables:{id:e}});this.selected={},this.updateContext(),await this.fetch()}}async pageInitialized(e){this.fetch()}async pageUpdated(e,t){this.active}async fetch(){const e=await p.Lp.query({query:m.ZP`
        query {
          responses: departmentRoot {
            ...Department_department
            children {
              ...Department_department
              children {
                ...Department_department
                children {
                  ...Department_department
                  children {
                    ...Department_department
                    children {
                      ...Department_department
                      children {
                        ...Department_department
                        children {
                          ...Department_department
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }

        ${v}
      `});this.root=e.data.responses}async exportHandler(){}async importHandler(e){}};g.styles=[n.Ix,d.iv`
      :host {
        display: flex;
        flex-direction: column;

        width: 100%;
        overflow: auto;
      }

      ox-tree-vertical {
        flex: 1;
      }

      department-view {
        flex: 1;

        max-width: 500px;
        align-self: center;
      }
    `],(0,i.gn)([(0,s.SB)(),(0,i.w6)("design:type",u.y)],g.prototype,"root",void 0),(0,i.gn)([(0,s.SB)(),(0,i.w6)("design:type",u.y)],g.prototype,"selected",void 0),(0,i.gn)([(0,s.IO)("department-view"),(0,i.w6)("design:type",y)],g.prototype,"departmentView",void 0),g=(0,i.gn)([(0,s.Mo)("department-list-page")],g)}}]);