"use strict";(self.webpackChunk_aidoop_aidoop_r=self.webpackChunk_aidoop_aidoop_r||[]).push([[8694],{78492:(e,t,i)=>{i.r(t),i.d(t,{CommonApprovalLineTemplatesPage:()=>f});var o=i(50493),r=i(68784),a=(i(7981),i(15633)),s=i(77675),n=i(94430),d=i(56765),l=i(69292),p=i(27805),c=i(53421),m=i(37077),g=i(64312),h=i(36179),u=i(28120),v=i(16682);let f=class extends((0,u.$)(s.h)((0,c.NC)(c.z2)((0,l.f)(s.B4)))){constructor(){super(...arguments),this.mode=(0,h.s2)()?"CARD":"GRID"}get context(){var e;return{title:c.z2.t("title.common-approval-line template list"),search:{handler:e=>{this.grist.searchText=e},value:(null===(e=this.grist)||void 0===e?void 0:e.searchText)||""},filter:{handler:()=>{this.grist.toggleHeadroom()}},help:"organization/approval-line",actions:[Object.assign({title:c.z2.t("button.save"),action:this.updateApprovalLines.bind(this)},a.jO.save),Object.assign({title:c.z2.t("button.delete"),action:this.deleteApprovalLines.bind(this)},a.jO.delete)]}}render(){const e=this.mode||((0,h.s2)()?"CARD":"GRID");return n.dy`
      <ox-grist .mode=${e} .config=${this.gristConfig} .fetchHandler=${this.fetchHandler.bind(this)}>
        <div slot="headroom">
          <div id="filters">
            <ox-filters-form autofocus without-search></ox-filters-form>
          </div>

          <div id="sorters">
            Sort
            <mwc-icon
              @click=${e=>{const t=e.currentTarget;this.sortersControl.open({right:0,top:t.offsetTop+t.offsetHeight})}}
              >expand_more</mwc-icon
            >
            <ox-popup id="sorter-control">
              <ox-sorters-control> </ox-sorters-control>
            </ox-popup>
          </div>

          <div id="modes">
            <mwc-icon @click=${()=>this.mode="GRID"} ?active=${"GRID"==e}>grid_on</mwc-icon>
            <mwc-icon @click=${()=>this.mode="LIST"} ?active=${"LIST"==e}>format_list_bulleted</mwc-icon>
            <mwc-icon @click=${()=>this.mode="CARD"} ?active=${"CARD"==e}>apps</mwc-icon>
          </div>
        </div>
      </ox-grist>
    `}async pageInitialized(e){this.gristConfig={list:{fields:["name","description"],details:["updatedAt"]},columns:[{type:"gutter",gutterName:"sequence"},{type:"gutter",gutterName:"row-selector",multiple:!0},{type:"gutter",gutterName:"button",icon:"reorder",handlers:{click:(e,t,i,o,r)=>{if(!o.id)return;const{id:a,model:s}=o;(0,m.Mw)(n.dy`
                  <approval-line-items-editor-popup
                    .confirmCallback=${async e=>{await this.updateApprovalLine(a,e),await this.grist.fetch()}}
                    .value=${s}
                  ></approval-line-items-editor-popup>
                `,{backdrop:!0,help:"organization/approval-line-items-editor",size:"large",title:c.z2.t("title.approval-line item list")}).onclosed=()=>{var e;null===(e=this.grist)||void 0===e||e.fetch()}}}},{type:"string",name:"name",header:c.z2.t("field.name"),record:{editable:!0},filter:"search",sortable:!0,width:300},{type:"string",name:"description",header:c.z2.t("field.description"),record:{editable:!0},filter:"search",width:325},{type:"string",name:"ownerType",header:c.z2.t("field.owner-type"),width:120},{type:"resource-object",name:"owner",header:c.z2.t("field.owner"),record:{editable:!1,renderer:function(e,t,i,o,a){var s={};if("Employee"===i.ownerType){s={valueField:"id",nameField:"name",descriptionField:"controlNo"};var n=Object.assign(Object.assign({},t.record),{options:s});return(0,r.Bp)(t.type)(e,Object.assign(Object.assign({},t),{record:n}),i,o,a)}}},width:180},{type:"resource-object",name:"updater",header:c.z2.t("field.updater"),sortable:!0,width:90},{type:"datetime",name:"updatedAt",header:c.z2.t("field.updated_at"),sortable:!0,width:180}],rows:{selectable:{multiple:!0}},sorters:[{name:"name"}]}}async pageUpdated(e,t){this.active}async fetchHandler({page:e=1,limit:t=100,sortings:i=[],filters:o=[]}){const r=await p.Lp.query({query:v.ZP`
        query ($filters: [Filter!], $pagination: Pagination, $sortings: [Sorting!]) {
          responses: approvalLines(filters: $filters, pagination: $pagination, sortings: $sortings) {
            items {
              id
              name
              description
              ownerType
              owner {
                id
                name
                description
                controlNo
              }
              model {
                type
                approver {
                  id
                  name
                  description
                  controlNo
                }
              }
              updater {
                id
                name
              }
              updatedAt
            }
            total
          }
        }
      `,variables:{filters:(0,h.tm)(o,[{name:"ownerType",operator:"eq",value:"Common"}]),pagination:{page:e,limit:t},sortings:i}});return{total:r.data.responses.total||0,records:r.data.responses.items||[]}}async deleteApprovalLines(){if(confirm(c.z2.t("text.sure_to_x",{x:c.z2.t("text.delete")}))){const e=this.grist.selected.map((e=>e.id));if(e&&e.length>0){(await p.Lp.mutate({mutation:v.ZP`
            mutation ($ids: [String!]!) {
              deleteApprovalLines(ids: $ids)
            }
          `,variables:{ids:e}})).errors||(this.grist.fetch(),(0,m.h4)({message:c.z2.t("text.info_x_successfully",{x:c.z2.t("text.delete")})}))}}}async updateApprovalLines(){let e=this.grist.dirtyRecords;if(e&&e.length){e=e.map((e=>{let t=e.id?{id:e.id}:{};const i=e.__dirtyfields__;for(let e in i)t[e]=i[e].after;return t.ownerType="Common",t.owner=null,t.cuFlag=e.__dirty__,t}));(await p.Lp.mutate({mutation:v.ZP`
          mutation ($patches: [ApprovalLinePatch!]!) {
            updateMultipleApprovalLine(patches: $patches) {
              name
            }
          }
        `,variables:{patches:e}})).errors||this.grist.fetch()}}async updateApprovalLine(e,t){(await p.Lp.mutate({mutation:v.ZP`
        mutation ($id: String!, $patch: ApprovalLinePatch!) {
          updateApprovalLine(id: $id, patch: $patch) {
            id
            name
            model {
              type
              approver {
                id
                name
                description
                controlNo
              }
            }
          }
        }
      `,variables:{id:e,patch:{model:t,cuFlag:"M"}}})).errors||await document.dispatchEvent(new CustomEvent("notify",{detail:{message:c.z2.t("text.info_x_successfully",{x:c.z2.t("button.save")})}}))}};f.styles=[a.Ix,a.Pn,n.iv`
      :host {
        display: flex;

        width: 100%;

        --grid-record-emphasized-background-color: red;
        --grid-record-emphasized-color: yellow;
      }
    `],(0,o.gn)([(0,d.Cb)({type:Object}),(0,o.w6)("design:type",Object)],f.prototype,"gristConfig",void 0),(0,o.gn)([(0,d.Cb)({type:String}),(0,o.w6)("design:type",String)],f.prototype,"mode",void 0),(0,o.gn)([(0,d.IO)("ox-grist"),(0,o.w6)("design:type",r.Nw)],f.prototype,"grist",void 0),(0,o.gn)([(0,d.IO)("#sorter-control"),(0,o.w6)("design:type",g.WP)],f.prototype,"sortersControl",void 0),f=(0,o.gn)([(0,d.Mo)("common-approval-line-templates-page")],f)}}]);