Select to view content in your preferred language

Batch Attribute Editor: Almost!

880
1
11-15-2016 06:10 AM
JamesCrandall
MVP Frequent Contributor

Has anyone had success modifying the Batch Attribute Editor Widget to update GDB tables that participate in a relationship class (1-to-many)?

The Edit Widget does this flawlessly.

Tags (1)
0 Kudos
1 Reply
JamesCrandall
MVP Frequent Contributor

In a feeble attempt to implement the desired behavior of updating/inserting into related tables, I took a look a the regular "Edit Widget" (since this does exactly that).

I added the "RelatedRecordsEditor.js" from the Edit Widget and then tried to implement the corresponding code from its "Widget.js" directly into a copied version of the Batch Attribute Edit widget.  When launching the widget I get the error: "Create Widget error: widgets/BatchAttributeEditor2/Widget" and it fails to load.

Again, I simply copied the original, renamed the folder and added the RelatedRecordsEditor.js file:

I did update the manifest.json file's "name" attribute to:

"name": "BatchAttributeEditor2"

Finally, I attempted to implement the corresponding JavaScript out of the Edit widget's Widget.js file and into the BatchAttributeEditor2's Widget.js file:

Adding to the onOpen():

//prepare tableInfosParam data for relatedRecordsEditor

this._getTableInfosParam().then(lang.hitch(this, function(tableInfosParam) {

this.tableInfosParam = tableInfosParam;

this.tableInfosParamClone = this._cloneLayerOrTableInfosParam(this.tableInfosParam);

this._tableInfoParamDef.resolve();

Adding to the define():

'./RelatedRecordsEditor'

And the following methods towards the end of the Widget.js file:

/******************************************

* Methods for prepare edit related records

******************************************/

_createRelatedRecordsEditor: function(feature) {

if(!feature) {

return;

}

// prepare loading shelter

var loadingDomNode = html.create('div', {style:"position: relative"});

html.place(loadingDomNode, this.editor.attributeInspector.domNode, "after");

var loading = new LoadingShelter({

}).placeAt(loadingDomNode);

// get tableInfosParam

this._tableInfoParamDef.then(lang.hitch(this, function() {

try {

if(this._relatedRecordsEditor) {

this._relatedRecordsEditor.destroy();

this._relatedRecordsEditor = null;

}

// create relatedRecordsEditor

this._relatedRecordsEditor = new RelatedRecordsEditor({

originalFeature: feature,

editorATI: this.editor.attributeInspector,

tableInfosParam: this.layerInfosParamClone.concat(this.tableInfosParamClone),

nls: lang.mixin(lang.clone(this.nls), window.jimuNls.common)

});

loading.destroy();

} catch(err) {

console.warn(err.message);

loading.destroy();

this._enableToAnswerEventForEditorATI();

}

}));

},

_disableToAnswerEventForEditorATI: function() {

// disable to answer onSelctionChange for editor ATI.

if(!this._mapInfoStorage.editorATIonLayerSelectionChange) {

this._mapInfoStorage.editorATIonLayerSelectionChange =

this.editor.attributeInspector.onLayerSelectionChange;

this.editor.attributeInspector.onLayerSelectionChange = lang.hitch(this, function(){});

}

},

_enableToAnswerEventForEditorATI: function() {

// enable to answer onSelctionChange for editor ATI.

if(this._mapInfoStorage.editorATIonLayerSelectionChange) {

this.editor.attributeInspector.onLayerSelectionChange =

lang.hitch(this.editor.attributeInspector, this._mapInfoStorage.editorATIonLayerSelectionChange);

this._mapInfoStorage.editorATIonLayerSelectionChange = null;

}

},

_getTableInfosParam: function() {

var tableInfos;

var defs = [];

var resultTableInfosParam = [];

if(!this._configEditor.tableInfos) {

// configured in setting page and no layers checked.

tableInfos = [];

} else if(this._configEditor.tableInfos.length > 0) {

// configured and has been checked.

tableInfos = this._converConfiguredLayerInfos(this._configEditor.tableInfos);

} else {

// has not been configured.

tableInfos = this._getDefaultTableInfos();

}

array.forEach(tableInfos, function(tableInfo) {

var jimuTableInfo = this._jimuLayerInfos.getTableInfoById(tableInfo.featureLayer.id);

if(jimuTableInfo) {

tableInfo.jimuTableInfo = jimuTableInfo;

defs.push(jimuTableInfo.getLayerObject());

}

}, this);

return all(defs).then(lang.hitch(this, function() {

array.forEach(tableInfos, function(tableInfo) {

if(!tableInfo.jimuTableInfo) {

return;

}

var tableObject = tableInfo.jimuTableInfo.layerObject;

var capabilities = tableInfo.jimuTableInfo.getCapabilitiesOfWebMap();

var isEditableInWebMap;

if(capabilities && capabilities.toLowerCase().indexOf('editing') === -1) {

isEditableInWebMap = false;

} else {

isEditableInWebMap = true;

}

if(tableObject &&

tableObject.visible &&//??************

tableObject.isEditable &&

tableObject.isEditable() &&

isEditableInWebMap) {//todo ......

tableInfo.featureLayer = tableInfo.jimuTableInfo.layerObject;

delete tableInfo.jimuTableInfo;

resultTableInfosParam.push(tableInfo);

}

}, this);

return resultTableInfosParam;

}));

},

 

 

/*************************

* Methods for change UI

************************/

_updateDeleteBtnInToolbar: function() {

if(this._canDeleteSelectionFeatures()) {

this._enableDeleBtnInToolbar();

} else {

this._disableDeleteBtnInToolbar();

}

},

_disableDeleteBtnInToolbar: function() {

if(this._configEditor.toolbarVisible) {

query("[class~=deleteFeatureIcon]", this.editor.domNode).style("display", "none");

}

},

_enableDeleBtnInToolbar: function() {

if(this._configEditor.toolbarVisible) {

query("[class~=deleteFeatureIcon]", this.editor.domNode).style("display", "inline-block");

}

},

/*************************

* Response events

************************/

_update: function() {

if(this.editor){

this.editor.templatePicker.update(true);

}

},

resize: function() {

this._update();

},

onClose: function() {

if (this.editor) {

this.editor.destroy();

}

this.editor = null;

// close method will call onDeActive automaticlly

// so do not need to call onDeActive();

this._worksAfterClose();

},

onNormalize: function(){

setTimeout(lang.hitch(this, this._update), 100);

},

onMinimize: function(){

},

onMaximize: function(){

setTimeout(lang.hitch(this, this._update), 100);

},

reClickMap: function(clickEvt) {

this._createOverDef.then(lang.hitch(this, function() {

this.map.onClick(clickEvt);

}));

},

_onGraphicMoveStart: function(evt) {

this._recordsSelectedFeatureInfoWhenMoveStart(evt);

},

_onGraphicMoveStop: function(evt) {

this._recordsSelectedFeatureInfoWhenMoveStop(evt);

this._autoApplyEditWhenGeometryIsModified(evt);

},

_onGraphicChangeStop: function(evt) {

this._autoApplyEditWhenGeometryIsModified(evt);

},

_beforeMapClick: function() {

if(!this._configEditor.autoApplyEditWhenGeometryIsMoved) {

this._checkStickyMoveTolerance();

}

},

_onEditorPopupShow: function() {

// disable event for editorATI

var currentFeature = this.editor.attributeInspector._currentFeature;

//var currentLayer = currentFeature.getLayer();

this._disableToAnswerEventForEditorATI();

this._createRelatedRecordsEditor(currentFeature);

},

_onEditorPopupHide: function() {

// enable event for editorATI

this._enableToAnswerEventForEditorATI();

},

_onNextOfEditorATI: function(evt) {

this._createRelatedRecordsEditor(evt.feature);

},

_onLayerSelectionChange: function() {

if(this._configEditor.toolbarVisible) {

this._updateDeleteBtnInToolbar();

}

}

0 Kudos