@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 5.48 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import{__decorate as e}from"tslib";import t from"../../core/Error.js";import{makeHandle as i,abortHandle as a}from"../../core/handleUtils.js";import r from"../../core/Logger.js";import{isAborted as o}from"../../core/promiseUtils.js";import{watch as s}from"../../core/reactiveUtils.js";import{property as l,subclass as n}from"../../core/accessorSupport/decorators.js";import d from"../../views/draw/support/HighlightHelper.js";import{temporaryHighlightName as c}from"../../views/support/HighlightDefaults.js";import h from"./UpdateRecordWorkflowData.js";import u from"./Workflow.js";import{fetchFullFeatures as p}from"./workflowUtils.js";import m from"../FeatureForm/FeatureFormViewModel.js";var g;const f={exit:Symbol()};let w=class extends u{static{g=this}constructor(e){super(e),this._highlightHelper=null,this.fullFeature=null,this.type="update-table-record"}initialize(){const{data:e}=this,{edits:s}=e,{view:l}=e.viewModel,n=s.feature;l&&(this._highlightHelper=new d({view:l,highlightName:c}),this.addHandles(i(()=>this._highlightHelper?.removeAll())));const h=new AbortController;this.addHandles(a(h)),this._updatingHandles.addPromise(p([n],n.sourceLayer,e.viewModel.view.spatialReference,h.signal).then(([e])=>{o(h)||(this._onFullFeatureLoaded(e),this._initializeFormViewModel())},e=>(r.getLogger(this).error("initialize()","Failed to fetch full feature for update workflow.",e),this.cancel({force:!0,error:new t("editor:failed-to-fetch-full-feature","Failed to retrieve all information for this feature. The update cannot proceed.",{detail:{error:e}})}))))}get allowSave(){return!this.data.readOnly&&this.hasPendingEdits&&!this.updating}get editorItem(){return this.data.editorItem}get formViewModel(){return this._formViewModel}get hasInvalidFormTemplate(){return this.data.editorItem.hasInvalidFormTemplate}get hasPendingEdits(){return this.data.edits.modified&&!this.data.readOnly}get layer(){return this.data.editorItem.layer}get parent(){return this.data.parent}get saveActionLabel(){return"update"}get shouldShowAttachments(){return this.editorItem.capabilities.attachments.enabled}get shouldAllowAttachmentEditing(){return this.editorItem.capabilities.update.attachments.enabled}get reliesOnOwnerAdminPrivileges(){const e=this.editorItem.capabilities;return e.update.reliesOnOwnerAdminPrivileges||e.delete.reliesOnOwnerAdminPrivileges}async enter(){this._configureAttachmentsViewModel()}exit(e){this.removeHandles(f.exit)}async start(){return await super.start(),null}_configureAttachmentsViewModel(){const{data:e,fullFeature:t}=this,{attachmentsCapabilities:a,viewModel:r}=e,{attachmentsViewModel:o}=r,l=e.readOnly?{editing:!1}:a;o.set({capabilities:l,graphic:t,filesEnabled:!1,mode:"view"}),this.addHandles([i(()=>o.fileInfos.removeAll()),s(()=>o.mode,e=>{switch(e){case"add":this.go("adding-attachment");break;case"edit":this.go("editing-attachment")}})],f.exit)}_initializeFormViewModel(){const{association:e,edits:t,formTemplate:i,viewModel:{view:a},readOnly:r}=this.data,o=this._formViewModel=new m({activeAssociation:e,editType:"UPDATE",feature:this.fullFeature,formTemplate:i,highlightHelper:this._highlightHelper,map:a?.map,spatialReference:a.spatialReference,timeZone:a?.timeZone,disabled:r});o.callbacks={...this.data.featureFormCallbacks,showAllRelatedRecords:e=>o.relationshipId=e.relationshipId,viewAssociatedLayers:e=>o.associationId=e.associationId,viewAssociatedFeatures:e=>o.associatedLayer=e.associatedLayer};const{initialFeature:l}=t;l&&o.overrideInitialFeature(l),this.addHandles([o.on("value-change",()=>{t.updateAttributes(o.getValues()),this.fullFeature.attributes=t.feature.attributes}),s(()=>a?.timeZone,e=>o.timeZone=e)])}_onFullFeatureLoaded(e){this.fullFeature=e;const{edits:t}=this.data;t.updateAttributes(e.attributes),t.trackChanges()}static async create(e){const t=new g({data:await h.create(e),onCommit:this._onCommitFactory(e.applyEdits)});return t._set("steps",this._createWorkflowSteps(t)),t}static _createWorkflowSteps(e){const{attachmentsViewModel:t}=e.data.viewModel;return[{id:"editing-attributes",async setUp(){},async tearDown(){}},{id:"adding-attachment",async setUp(){},async tearDown(){t.mode="view"}},{id:"editing-attachment",async setUp(){},async tearDown(){t.mode="view"}}]}static{this._onCommitFactory=e=>async t=>{const{edits:i}=t,{feature:a}=i;if(!a)return;const r=a.sourceLayer,o=a.clone();if(!i.attributesModified||i.stagedForDelete){const e=r.objectIdField;if(o.attributes={[e]:a.getAttribute(e)},"scene"===r.type&&null!=r.infoFor3D){const e=r.associatedLayer?.globalIdField;null!=e&&o.setAttribute(e,a.getAttribute(e))}}i.geometryModified&&!i.stagedForDelete||(o.geometry=null);const s=i.stagedForDelete?"deleteFeatures":"updateFeatures";await e(r,{[s]:[o]})}}};e([l()],w.prototype,"_formViewModel",void 0),e([l()],w.prototype,"allowSave",null),e([l()],w.prototype,"editorItem",null),e([l()],w.prototype,"formViewModel",null),e([l()],w.prototype,"fullFeature",void 0),e([l()],w.prototype,"hasInvalidFormTemplate",null),e([l()],w.prototype,"hasPendingEdits",null),e([l()],w.prototype,"layer",null),e([l()],w.prototype,"parent",null),e([l()],w.prototype,"saveActionLabel",null),e([l()],w.prototype,"shouldShowAttachments",null),e([l()],w.prototype,"shouldAllowAttachmentEditing",null),e([l()],w.prototype,"reliesOnOwnerAdminPrivileges",null),w=g=e([n("esri.widgets.Editor.UpdateRecordWorkflow")],w);export{w as UpdateRecordWorkflow,f as handleKeys};