Skip to content

Instantly share code, notes, and snippets.

@gavinr
Last active June 21, 2016 04:21
Show Gist options
  • Save gavinr/f34180d1fa5ef4fd1a831326ff935342 to your computer and use it in GitHub Desktop.
Save gavinr/f34180d1fa5ef4fd1a831326ff935342 to your computer and use it in GitHub Desktop.
// All material copyright ESRI, All Rights Reserved, unless otherwise specified.
// See http://js.arcgis.com/3.16/esri/copyright.txt for details.
//>>built
require({
cache: {
"url:esri/dijit/FeatureTable/templates/FeatureTable.html": '\x3cdiv class\x3d"${baseClass}" \x3e\r\n \x3cdiv id\x3d "${gridBorderContainerId}" class\x3d"esri-feature-table-border-container" data-dojo-attach-point\x3d "_gridBorderContainer" data-dojo-type\x3d"dijit.layout.BorderContainer" gutters\x3d"false"\x3e\r\n \x3cdiv id\x3d "${gridHeaderId}" class\x3d"esri-feature-table-content-pane esri-feature-table-menu" data-dojo-attach-point\x3d "_gridHeaderNode" data-dojo-type\x3d"dijit/layout/ContentPane" data-dojo-props\x3d"region: \'top\'"\x3e\r\n \x3cdiv class\x3d"esri-feature-table-menu-item esri-feature-table-loading-indicator" data-dojo-attach-point\x3d "_gridLoadingIndicatorNode" style\x3d"display:none;"\x3e\x3c/div\x3e\r\n \x3cdiv class\x3d"esri-feature-table-menu-item esri-feature-table-title" data-dojo-attach-point\x3d "_gridTitleNode"\x3e\x3c/div\x3e\r\n \x3cdiv class\x3d"esri-feature-table-menu-item esri-feature-table-closer-container"\x3e\x3ca class\x3d "esri-feature-table-closer toggleOpened" data-dojo-attach-point\x3d"tableCloseButton" href\x3d"JavaScript:void(0);" title\x3d"Hide Table"\x3e\x3c/a\x3e\x3c/div\x3e \r\n \x3cdiv data-dojo-attach-point\x3d "_menuNode" class\x3d"esri-feature-table-menu-item esri-feature-table-menu-options"\x3e\r\n \x3cdiv id\x3d"${gridMenuNodeId}"\x3e\x3c/div\x3e\r\n \x3c/div\x3e\r\n \x3c/div\x3e\r\n \x3cdiv id\x3d "${gridContentPaneId}" class\x3d"esri-feature-table-content-pane" data-dojo-attach-point\x3d "_gridContentPane" data-dojo-type\x3d"dijit/layout/ContentPane" data-dojo-props\x3d"region: \'center\'"\x3e\r\n \x3cdiv id\x3d"${gridId}" class\x3d"esri-feature-table-grid" data-dojo-attach-point\x3d"_gridNode"\x3e\x3c/div\x3e\r\n \x3c/div\x3e\r\n \x3c/div\x3e\r\n\x3c/div\x3e'
}
});
define("esri/dijit/FeatureTable", "dojo/aspect dojo/on dojo/Deferred dojo/DeferredList dojo/Evented dojo/has dojo/date/locale dojo/promise/all dojo/query dojo/number dojo/string dojo/dom-construct dojo/dom-class dojo/dom-style dojo/_base/declare dojo/_base/lang dojo/_base/array dojo/text!../dijit/FeatureTable/templates/FeatureTable.html dojo/i18n!../nls/jsapi dojo/store/Cache dojo/store/Memory dojo/store/Observable dojo/fx/Toggler dijit/_WidgetBase dijit/_OnDijitClickMixin dijit/_TemplatedMixin dijit/_WidgetsInTemplateMixin dijit/Dialog dijit/Menu dijit/MenuItem dijit/form/DropDownButton dijit/form/TimeTextBox dijit/form/DateTextBox dijit/form/NumberTextBox dijit/form/Button dijit/form/Select dgrid/OnDemandGrid dgrid/Selection dgrid/selector dgrid/Keyboard dgrid/editor dgrid/extensions/Pagination dgrid/extensions/DijitRegistry dgrid/extensions/ColumnHider dgrid/extensions/ColumnResizer ../kernel ../lang ../config ../geometry/Extent ../layers/FeatureLayer ../tasks/query ../tasks/StatisticDefinition ../tasks/QueryTask ../dijit/FeatureLayerQueryStore dijit/layout/BorderContainer dijit/layout/ContentPane dojo/query!css2 dojo/domReady!".split(" "), function(I, k, A, V, B, W, X, Y, Z, v, r, h, s, $, D, d, n, aa, m, ba, J, ca, da, ea, fa, ga, ha, ia, K, E, ja, ka, L, F, M, G, N, O, P, Q, C, la, R, S, T, ma, w, H, U, na, x, oa, pa, z, qa, ra) {
B = D([ea, fa, ga, ha, B], {
baseClass: "esri-feature-table",
loaded: !1,
templateString: aa,
widgetsInTemplate: !0,
i18n: m,
dataStore: null ,
featureCount: 0,
columns: [],
idProperty: "id",
grid: null ,
gridMenu: null ,
gridMenuAnchor: null ,
css: {
featureTableColumnHeader: "esri-feature-table-column-header",
featureTableColumnHeaderTitle: "esri-feature-table-column-header-title",
featureTableColumnHeaderType: "esri-feature-table-column-header-type",
collapsed: "collapsed",
expando: "expando",
headerGear: "esri-feature-table-gear",
settingsIcon: "esri-icon-settings",
lockedIcon: "esri-icon-locked",
menuItem: "esri-feature-table-menu-item",
dialog: "esri-feature-table-dialog"
},
featureLayer: null ,
map: null ,
layerInfo: {
idArray: [],
fieldInfos: []
},
fieldInfos: [],
gridOptions: {},
dateOptions: {},
selectedRows: [],
selectedRowIds: [],
hiddenFields: [],
outFields: ["*"],
editable: !1,
syncSelection: !0,
zoomToSelection: !0,
showDataTypes: !1,
showGridHeader: !0,
showGridMenu: !0,
menuFunctions: [],
_defaultDateOptions: {
timeEnabled: !1,
timePattern: null ,
datePattern: null
},
_defaultGridOptions: {
noDataMessage: "No Data",
allowSelectAll: !1,
cellNavigation: !1,
selectionMode: "extended",
pagination: !1,
allowTextSelection: !1,
pageSizeOptions: [10, 25, 50]
},
_queryStore: null ,
_memoryStore: null ,
_featureSet: null ,
_orderByFields: null ,
_editorTrackingInfos: {},
_userIds: {},
_featureSelectedCount: 0,
_filteredRowIds: [],
_gridQuery: !1,
_activeEditors: [],
_rollbackInfos: [],
_batchCount: 0,
_defaultBatchCount: 1E3,
_defaultFeatureCount: 2E3,
_toggler: null ,
_expandedNodes: [],
_nestedGrids: [],
_i18nStrings: {
gridHeader: m.widgets.FeatureTable.gridHeader,
loadingData: m.widgets.FeatureTable.loadingData,
untitled: m.widgets.FeatureTable.untitled,
dataError: m.widgets.FeatureTable.dataError,
sortAsc: m.widgets.FeatureTable.sortAsc,
sortDesc: m.widgets.FeatureTable.sortDesc,
statistics: m.widgets.FeatureTable.statistics,
close: m.widgets.FeatureTable.close,
defaultSort: m.widgets.FeatureTable.defaultSort,
showSelected: m.widgets.FeatureTable.showSelected,
clearSelection: m.widgets.FeatureTable.clearSelection,
toggleColumns: m.widgets.FeatureTable.toggleColumns,
add: m.widgets.FeatureTable.add,
show: m.widgets.FeatureTable.show,
hide: m.widgets.FeatureTable.hide,
attachments: m.widgets.FeatureTable.attachments,
owners: m.widgets.FeatureTable.owners,
parenValue: m.widgets.FeatureTable.parenValue,
date: m.widgets.FeatureTable.date,
number: m.widgets.FeatureTable.number,
string: m.widgets.FeatureTable.string
},
constructor: function(a, c) {
c && this.set({
gridId: c + "_grid",
gridBorderContainerId: c + "_gridBorderContainer",
gridHeaderId: c + "_gridHeaderNode",
gridContentPaneId: c + "_gridContentPane",
gridMenuNodeId: c + "_menuNode"
})
},
postMixInProperties: function() {
this.inherited(arguments);
this.set("gridOptions", d.mixin(this._defaultGridOptions, this.gridOptions));
this.set("dateOptions", d.mixin(this._defaultDateOptions, this.dateOptions));
this._GridDefinition = this._generateGridDefinition()
},
postCreate: function() {
this.inherited(arguments);
this._listenerHandles = []
},
startup: function() {
this.inherited(arguments);
var a = this.get("featureLayer");
a && a.loadError ? this._showLoadError(a.loadError.message) : this.domNode && a.loaded ? this._init() : this.own(k(a, "load", d.hitch(this, function() {
this._init()
})), k(a, "error", d.hitch(this, function() {
a.loadError ? this._showLoadError(a.loadError.message) : this._showLoadError("")
})))
},
refresh: function() {
this.grid.refresh()
},
destroy: function() {
this.inherited(arguments);
n.forEach(this._listenerHandles, function(a) {
a.remove()
});
this.gridMenu && this.gridMenu.destroy();
this.statisticsDialog && this.statisticsDialog.destroy();
this.columnMenu && this.columnMenu.destroyRecursive();
this.grid && this.grid._destroyColumns();
delete this.columns;
delete this.layerInfo
},
resize: function() {
this._resize()
},
selectRows: function(a) {
this._closeEditors();
var c = [], b = [], e;
this.grid.clearSelection();
a[0] && "esri.Graphic" === a[0].declaredClass && (n.forEach(a, function(a) {
b.push(a.attributes[this.idProperty])
}, this),
a = b);
if (1 === a.length) {
e = a[0];
a = this.dataStore.get(a);
var l = this.dataStore.data.indexOf(a);
this.grid.select(e);
this._updateGridSelection().then(d.hitch(this, function() {
this._updateGridHeaderText();
this.grid.scrollTo({
x: 0,
y: this.grid.rowHeight * l
});
this.grid.row(e).element && this.grid.row(e).element.scrollIntoView()
}))
} else
n.forEach(a, function(a) {
c.push(this.dataStore.get(a))
}, this),
this._updateGridSelection().then(d.hitch(this, function() {
this._updateGridHeaderText()
}))
},
filterSelectedRecords: function(a) {
a ? this._showSelectedRecords() : (this.grid.set("query", {}),
this.set("_gridQuery", !1))
},
clearSelection: function() {
this._clearSelection()
},
getRowDataById: function(a) {
return this.grid.row(a).data
},
getFeatureDataById: function(a) {
var c = new x;
c.objectIds = [a];
c.outFields = ["*"];
return this.featureLayer.queryFeatures(c, d.hitch(this, function(a) {
return a.features[0]
}))
},
_init: function() {
this.set("idProperty", this.featureLayer.objectIdField);
this._getLayerInfo();
this._getEditingInfo();
var a = w.isDefined(this.featureLayer.maxRecordCount) ? this.featureLayer.maxRecordCount : 1E3;
this._batchCount = Math.min(a, this._defaultBatchCount);
this.grid = this._generateGrid();
this.grid.startup();
this.grid.resize();
this._listenerHandles.push(this._gridSelectListener(), this._gridDeselectListener(), this._gridDataChangeListener(), this._gridRefreshListener(), this._gridColumnStateChangeListener(), this._gridColumnResizeListener(), this._gridErrorListener(), this._gridSortListener(), this._gridFilterListener(), this._gridEditorShowListener(), this._gridEditorHideListener());
this.showGridMenu && this._createTableMenu();
this.showGridHeader || $.set(this._gridHeaderNode.domNode, "display", "none");
this._toggler = this._createTableToggle();
this._listenerHandles.push(this._tableToggleClickCallback(), this._columnClickCallback(), this._layerClickCallback(), this._applyEditsListener());
this.set("loaded", !0);
this.emit("load", this.loaded);
this.grid.set("noDataMessage", "");
this._gridTitleNode.innerHTML = this._i18nStrings.loadingData;
this._resize();
this._toggleLoadingIndicator(!0);
this._createStoreFromDataQuery()
},
_generateGridDefinition: function() {
return this.gridOptions.pagination ? D([R, N, O, C, P, Q, S, T, la]) : D([R, N, O, C, P, Q, S, T])
},
_generateGrid: function() {
var a = this
, c = this.get("gridOptions")
, b = this.get("columns")
, e = new (this._generateGridDefinition())({
columns: b,
sort: this.get("idProperty"),
noDataMessage: "",
selectionMode: c.selectionMode,
allowSelectAll: c.allowSelectAll,
allowTextSelection: c.allowTextSelection,
cellNavigation: c.cellNavigation,
keepScrollPosition: !0,
pageSizeOptions: c.pageSizeOptions,
minRowsPerPage: this.get("_batchCount"),
maxRowsPerPage: this.get("_batchCount"),
queryRowsOverlap: 0,
pagingDelay: 1E3,
renderRow: function(b) {
return a._renderExpandoRow(b, this)
}
},this.get("gridId"));
I.before(e, "removeRow", d.hitch(this, function(a) {
n.forEach(b.length, function(b, c) {
var d = e.cell(a, c).element;
(d = (d.contents || d).widget) && d.destroyRecursive()
}, this)
}));
I.after(e, "renderHeader", d.hitch(this, function() {
e._sortListener.remove()
}));
return e
},
_renderExpandoRow: function(a, c) {
var b = h.create("div", {
className: "collapsed"
});
b.appendChild(this._GridDefinition.prototype.renderRow.apply(c, arguments));
h.create("div", {
className: "expando"
}, b);
return b
},
_createStoreFromDataQuery: function() {
this.get("dataStore") && (this._toggleLoadingIndicator(!0),
this._gridTitleNode.innerHTML = this._i18nStrings.loadingData,
this.grid.set({
store: null ,
noDataMessage: ""
}),
this.set("dataStore", null ));
this._getFeatureCount().then(d.hitch(this, this._queryFeatureLayerSetup))
},
_getFeatureCount: function() {
var a = new x;
a.returnGeometry = !1;
a.returnIdsOnly = !1;
a.where = "1\x3d1";
H.defaults.io.timeout = 1E4;
return this.featureLayer.queryCount(a).then(d.hitch(this, function(a) {
H.defaults.io.timeout = 6E4;
this.set("featureCount", a);
return a
}), d.hitch(this, function() {
H.defaults.io.timeout = 6E4;
this.set("featureCount", this.layerInfo.isFeatureCollection ? this.featureLayer.graphics.length : this._defaultFeatureCount);
return this.featureCount
}))
},
_getAllIds: function() {
var a = new A
, c = this.get("featureLayer")
, b = new x;
b.returnGeometry = !1;
b.outFields = [this.idProperty];
b.where = "1\x3d1";
b.returnIdsOnly = !0;
c.queryIds(b).then(function(b) {
a.resolve(b)
}, function(b) {
a.reject(b)
});
return a
},
_queryFeatureLayer: function(a) {
var c = new A
, b = this.get("featureLayer")
, e = new x;
e.where = "1\x3d1";
e.returnGeometry = !1;
e.objectIds = a;
b.queryFeatures(e, function(a) {
c.resolve(a)
});
return c
},
_queryFeatureLayerSetup: function() {
var a = this.get("featureLayer");
this.layerInfo.isFeatureCollection ? this._queryFeatureCollection() : this._queryFeatureLayer().then(d.hitch(this, function(c) {
this._updateFieldInfos(c.fields);
this._generateColumnsFromFieldInfos();
this.grid.set("columns", this.get("columns"));
this._updateGridHeaderText();
if (c.exceededTransferLimit)
if (a.advancedQueryCapabilities && !a.advancedQueryCapabilities.supportsPagination) {
if (this.layerInfo.idArray && 0 < this.layerInfo.idArray.length) {
this._generateCacheStore(this.layerInfo.idArray);
this.grid.set("store", this.dataStore);
return
}
this._getAllIds().then(d.hitch(this, function(a) {
this.layerInfo.idArray = a;
this._generateCacheStore(a);
this.grid.set("store", this.dataStore)
}), function(a) {
this._showLoadError(a.message)
})
} else
this._generateCacheStore();
else
this._generateMemoryStore(c.features);
this.grid.set("store", this.dataStore)
}), d.hitch(this, function(a) {
this._showLoadError(a.message);
this.grid.set("noDataMessage", this.gridOptions.noDataMessage)
}))
},
_queryFeatureCollection: function() {
this.grid.set("noDataMessage", this.gridOptions.noDataMessage);
this._updateFieldInfos(this.featureLayer.fields);
this._generateColumnsFromFieldInfos();
this.grid.set("columns", this.get("columns"));
this._updateGridHeaderText();
this._generateMemoryStore(this.featureLayer.graphics);
this.layerInfo.features = this.featureLayer.graphics;
this.grid.set("store", this.dataStore);
this._toggleLoadingIndicator(!1)
},
_generateCacheStore: function(a) {
var c = this.get("featureLayer"), b;
a = new z({
layer: c,
objectIds: a,
totalCount: this.featureCount,
batchCount: this._batchCount,
where: "1\x3d1",
orderByFields: this._orderByFields
});
c = new J;
b = new ba(a,c,{});
this.set({
_queryStore: a,
_memoryStore: c,
dataStore: b
});
this.grid.set("noDataMessage", this.gridOptions.noDataMessage);
this._toggleLoadingIndicator(!1)
},
_generateMemoryStore: function(a) {
var c = [];
n.forEach(a, function(a) {
c.push(a.attributes)
}, this);
this.dataStore = new ca(new J({
data: c,
idProperty: this.get("idProperty")
}));
this.grid.set("noDataMessage", this.gridOptions.noDataMessage);
this._toggleLoadingIndicator(!1)
},
_getAllDataFromCache: function() {
var a = this.get("featureCount"), c = this.featureLayer.maxRecordCount, a = Math.ceil(a / c), b = [], e, l;
for (l = 0; l < a; l++)
e = c * l,
b.push(this._queryCacheStore(c, e));
return new V(b)
},
_queryCacheStore: function(a, c) {
var b = new A;
this.dataStore.query(null , {
sort: [{
attribute: this.idProperty,
descending: !0
}],
count: a,
start: c
}).then(function(a) {
b.resolve(a)
});
return b
},
_getLayerInfo: function() {
var a = {}
, c = this.featureLayer
, b = c.id || c.layerId;
c.credential && (this._userIds[b] = this.featureLayer.credential.userId);
a.userId && (this._userIds[b] = a.userId);
a.isFeatureCollection = c._collection && !0 === c._collection || null === c.url && null === c._url ? !0 : !1;
a.idProperty = this.get("idProperty");
a.layerId = b;
a.editable = c.isEditable();
a.editCapabilities = {};
a.typeIdField = c.typeIdField;
a.types = c.types;
a.fieldInfos = [];
a.hasAttachments = c.hasAttachments;
this.set("layerInfo", d.clone(a))
},
_getEditingInfo: function() {
this.featureLayer.getEditCapabilities && (this.layerInfo.editCapabilities = this.featureLayer.getEditCapabilities());
var a = [];
this.featureLayer.editFieldsInfo && (this.featureLayer.editFieldsInfo.creatorField && a.push(this.featureLayer.editFieldsInfo.creatorField),
this.featureLayer.editFieldsInfo.creationDateField && a.push(this.featureLayer.editFieldsInfo.creationDateField),
this.featureLayer.editFieldsInfo.editorField && a.push(this.featureLayer.editFieldsInfo.editorField),
this.featureLayer.editFieldsInfo.editDateField && a.push(this.featureLayer.editFieldsInfo.editDateField));
this._editorTrackingInfos[this.featureLayer.id] = a
},
_generateColumnOrder: function(a) {
var c = []
, b = this.outFields;
"*" !== b[0] ? (-1 === n.indexOf(b, this.idProperty) && c.push(this._findFirst(a, "name", this.idProperty)),
n.forEach(b, function(b) {
var l = this._findFirst(a, "name", b) || null ;
l && (b.name !== this.idProperty && -1 === n.indexOf(c, l)) && c.push(l)
}, this),
n.forEach(a, function(a) {
-1 === n.indexOf(c, a) && c.push(a)
}, this)) : c = d.clone(a);
return c
},
_updateFieldInfos: function(a) {
a = this._generateColumnOrder(a);
n.forEach(a, function(a, b) {
var e, l, f, g, y = !1, u = this._findFirst(this.featureLayer.fields, "name", a.name) || {}, p = this._findFirst(this.fieldInfos, "name", a.name) || null ;
e = p && p.alias ? p.alias : u.alias;
f = u.domain || !1;
l = this.layerInfo.typeIdField && a.name === this.layerInfo.typeIdField || !1;
this.layerInfo && this.layerInfo.types && n.forEach(this.layerInfo.types, function(b) {
b.domains && b.domains[a.name] && (y = !0)
}, this);
g = -1 !== n.indexOf(this.hiddenFields, a.name) || "esriFieldTypeOID" === a.type || "esriFieldTypeGlobalID" === a.type || -1 !== n.indexOf(this._editorTrackingInfos[this.featureLayer.id], a.name) || p && !1 === p.visible || "*" !== this.outFields[0] && -1 === n.indexOf(this.outFields, a.name);
this.layerInfo.fieldInfos[b] = d.clone({
idx: b,
name: a.name,
alias: e,
length: a.length || null ,
type: a.type,
hidden: g,
editable: this.editable && a.name !== this.idProperty && this.layerInfo.editable ? u && "undefined" !== typeof u.editable ? p && "undefined" !== typeof p.editable && !1 !== u.editable ? p.editable || !1 : u.editable : !1 : !1,
nullable: u.nullable || !1,
domain: f,
typeId: l,
subtypeDomain: y,
format: p && p.format ? p.format : null ,
dateOptions: p && p.dateOptions ? p.dateOptions : null
})
}, this)
},
_generateColumnsFromFieldInfos: function() {
var a = [];
n.forEach(this.layerInfo.fieldInfos, function(c, b) {
var e = this.layerInfo.fieldInfos[b];
"esriFieldTypeDate" === c.type ? c.editable ? a.push(this._generateDateTimeEditorColumn(c, e)) : a.push(this._generateDateTimeColumn(c, e)) : c.domain ? c.editable ? a.push(this._generateDomainEditorColumn(c, e)) : a.push(this._generateDomainColumn(c, e)) : c.typeId ? c.editable ? a.push(this._generateTypeEditorColumn(c, e)) : a.push(this._generateTypeColumn(c, e)) : c.subtypeDomain ? c.editable ? a.push(this._generateSubtypeDomainEditorColumn(c, e)) : a.push(this._generateSubtypeDomainColumn(c, e)) : "esriFieldTypeInteger" === c.type || "esriFieldTypeSingle" === c.type || "esriFieldTypeDouble" === c.type || "esriFieldTypeSmallInteger" === c.type ? c.editable ? a.push(this._generateNumberEditorColumn(c, e)) : a.push(this._generateNumberColumn(c, e)) : "esriFieldTypeGUID" === c.type || ("esriFieldTypeRaster" === c.type || "esriFieldTypeBlob" === c.type || "esriFieldTypeGeometry" === c.type || "esriFieldTypeXML" === c.type) || (c.editable ? a.push(this._generateStringEditorColumn(c, e)) : a.push(this._generateStringColumn(c, e)))
}, this);
this.set("columns", a)
},
_generateDomainColumn: function(a, c) {
return {
label: a.alias,
field: a.name,
type: a.type,
hidden: a.hidden,
get: d.hitch(this, function(b) {
b = this._findFirst(c.domain.codedValues, "code", b[a.name]);
return null !== b ? b.name : null
}),
renderHeaderCell: d.hitch(this, function(b) {
return this._getColumnHeaderCell(b, a)
})
}
},
_generateDomainEditorColumn: function(a, c) {
return {
label: a.alias,
field: a.name,
type: a.type,
hidden: a.hidden,
get: d.hitch(this, function(b) {
var e;
a.domain.codedValues ? (b = this._findFirst(c.domain.codedValues, "code", b[a.name]),
e = null !== b ? b.name : null ) : "range" === a.domain.type && (e = b[a.name]);
return e
}),
renderCell: d.hitch(this, function(b, e, l) {
var f = h.create("div", {
innerHTML: e
}, l)
, g = [];
f.innerHTML = e;
if (a.domain.codedValues)
n.forEach(c.domain.codedValues, function(e) {
b[a.name] === e.code ? g.push({
label: e.name,
value: e.code,
selected: !0
}) : g.push({
label: e.name,
value: e.code
})
}),
(null === b[a.name] || " " === b[a.name] || "" === b[a.name]) && a.nullable ? g.push({
label: "- empty -",
value: "ft_null",
selected: !0
}) : (null === b[a.name] || " " === b[a.name] || "" === b[a.name]) && !a.nullable ? g.push({
label: "- empty -",
value: "ft_null",
selected: !0,
disabled: !0
}) : a.nullable && g.push({
label: "- empty -",
value: "ft_null"
}),
k(l, "dblclick", d.hitch(this, function() {
this._closeEditors();
f.innerHTML = "";
var e = new G({
options: g,
style: {
width: "100%"
}
});
e.placeAt(f);
this.emit("editor-show", {
cell: l,
editor: e,
grid: this.grid
});
k(e, "blur", d.hitch(this, function() {
var e = this._findFirst(c.domain.codedValues, "code", b[a.name]);
f.innerHTML = e ? e.name : null
}));
k(e, "keydown", function(a) {
13 === a.keyCode && e.focusNode.blur()
});
k(e, "change", d.hitch(this, function(d) {
var g = {
fieldName: a.name,
oldValue: b[a.name],
rowId: b[this.idProperty],
rowObject: b
};
"ft_null" === d && (d = null );
b[a.name] = d;
d = this._findFirst(c.domain.codedValues, "code", d);
f.innerHTML = d ? d.name : null ;
e.destroy();
this._applyEditsByRow(b, g);
this.emit("editor-hide", {
cell: l,
editor: e,
grid: this.grid
})
}));
this._activeEditors.push({
id: b[this.idProperty],
widget: e
})
}));
else if ("range" === a.domain.type) {
var y = a.domain.minValue
, u = a.domain.maxValue;
k(l, "dblclick", d.hitch(this, function() {
this._closeEditors();
f.innerHTML = "";
var e = new F({
value: b[a.name],
required: !a.nullable,
constraints: {
min: y,
max: u
}
});
e.placeAt(f);
e.focus();
e.textbox.select();
this.emit("editor-show", {
cell: l,
editor: e,
grid: this.grid
});
k(e, "blur", d.hitch(this, function() {
f.innerHTML = b[a.name]
}));
k(e, "keydown", function(a) {
13 === a.keyCode && e.isValid() && e.focusNode.blur()
});
k(e, "change", d.hitch(this, function(c) {
var d = {
fieldName: a.name,
oldValue: b[a.name],
rowId: b[this.idProperty],
rowObject: b
};
e.isValid() ? (b[a.name] = c,
f.innerHTML = c,
e.destroy(),
this._applyEditsByRow(b, d)) : (f.innerHTML = b[a.name],
e.destroy(),
this.emit("editor-hide", {
cell: l,
editor: e,
grid: this.grid
}))
}));
this._activeEditors.push({
id: b[this.idProperty],
widget: e
})
}))
} else
this.emit("error", "Domain type is not supported.")
}),
renderHeaderCell: d.hitch(this, function(b) {
return this._getColumnHeaderCell(b, a)
})
}
},
_generateTypeColumn: function(a, c) {
return {
label: a.alias,
field: a.name,
type: a.type,
hidden: a.hidden,
get: d.hitch(this, function(b) {
b = this._findFirst(this.layerInfo.types, "id", b[a.name]);
return null !== b ? b.name : null
}),
renderHeaderCell: d.hitch(this, function(b) {
return this._getColumnHeaderCell(b, a)
})
}
},
_generateTypeEditorColumn: function(a, c) {
return {
label: a.alias,
field: a.name,
type: a.type,
hidden: a.hidden,
get: d.hitch(this, function(b) {
b = this._findFirst(this.layerInfo.types, "id", b[a.name]);
return null !== b ? b.name : null
}),
renderCell: d.hitch(this, function(b, e, c) {
var f = h.create("div", {
innerHTML: e
}, c)
, g = [];
f.innerHTML = e;
n.forEach(this.layerInfo.types, function(e) {
b[a.name] === e.id ? g.push({
label: e.name,
value: e.id,
selected: !0
}) : g.push({
label: e.name,
value: e.id
})
}, this);
(null === b[a.name] || " " === b[a.name] || "" === b[a.name]) && a.nullable ? g.push({
label: "- empty -",
value: "ft_null",
selected: !0
}) : (null === b[a.name] || " " === b[a.name] || "" === b[a.name]) && !a.nullable ? g.push({
label: "- empty -",
value: "ft_null",
selected: !0,
disabled: !0
}) : a.nullable && g.push({
label: "- empty -",
value: "ft_null"
});
k(c, "dblclick", d.hitch(this, function() {
this._closeEditors();
f.innerHTML = "";
var e = new G({
options: g,
style: {
width: "100%"
}
});
e.placeAt(f);
this.emit("editor-show", {
cell: c,
editor: e,
grid: this.grid
});
k(e, "blur", d.hitch(this, function() {
var e = this._findFirst(this.layerInfo.types, "id", b[a.name]);
f.innerHTML = e ? e.name : null
}));
k(e, "keydown", function(a) {
13 === a.keyCode && e.focusNode.blur()
});
k(e, "change", d.hitch(this, function(d) {
var g = {
fieldName: a.name,
oldValue: b[a.name],
rowId: b[this.idProperty],
rowObject: b
};
"ft_null" === d && (d = null );
b[a.name] = d;
d = this._findFirst(this.layerInfo.types, "id", d);
f.innerHTML = d ? d.name : null ;
e.destroy();
this._applyEditsByRow(b, g);
this.emit("editor-hide", {
cell: c,
editor: e,
grid: this.grid
})
}));
this._activeEditors.push({
id: b[this.idProperty],
widget: e
})
}))
}),
renderHeaderCell: d.hitch(this, function(b) {
return this._getColumnHeaderCell(b, a)
})
}
},
_generateSubtypeDomainColumn: function(a, c) {
return {
label: a.alias,
field: a.name,
type: a.type,
hidden: a.hidden,
get: d.hitch(this, function(b) {
var e, c = this._findFirst(this.layerInfo.types, "id", b[this.layerInfo.typeIdField]);
c && (c.domains && c.domains[a.name] && c.domains[a.name].codedValues) && (e = this._findFirst(c.domains[a.name].codedValues, "code", b[a.name]));
return e ? e.name : b[a.name]
}),
renderHeaderCell: d.hitch(this, function(b) {
return this._getColumnHeaderCell(b, a)
})
}
},
_generateSubtypeDomainEditorColumn: function(a, c) {
var b = {
label: a.alias,
field: a.name,
type: a.type,
hidden: a.hidden,
editOn: "dblclick",
editor: "text",
get: d.hitch(this, function(e) {
var b, c = this._findFirst(this.layerInfo.types, "id", e[this.layerInfo.typeIdField]);
c && (c.domains && c.domains[a.name] && c.domains[a.name].codedValues) && (b = this._findFirst(c.domains[a.name].codedValues, "code", e[a.name]));
return b ? b.name : e[a.name]
}),
renderCell: d.hitch(this, function(e, b, c) {
var g = h.create("div", {
innerHTML: b
}, c)
, y = !1;
g.innerHTML = b;
k(c, "dblclick", d.hitch(this, function() {
this._closeEditors();
var b = this._findFirst(this.layerInfo.types, "id", e[this.layerInfo.typeIdField]), l, h, t = [];
if (b.domains[a.name]) {
l = b.domains[a.name].codedValues;
h = this._findFirst(l, "code", e[a.name]);
n.forEach(l, function(b) {
e[a.name] === b.code ? t.push({
label: b.name,
value: b.code,
selected: !0
}) : t.push({
label: b.name,
value: b.code
});
b.code === h && (y = !0)
});
(null === e[a.name] || " " === e[a.name] || "" === e[a.name]) && a.nullable ? t.push({
label: "- empty -",
value: "ft_null",
selected: !0
}) : (null === e[a.name] || " " === e[a.name] || "" === e[a.name]) && !a.nullable ? t.push({
label: "- empty -",
value: "ft_null",
selected: !0,
disabled: !0
}) : a.nullable && t.push({
label: "- empty -",
value: "ft_null"
});
!y && (!h && null !== e[a.name]) && t.push({
label: e[a.name],
value: "N/A",
selected: !0,
disabled: !0
});
g.innerHTML = "";
var m = new G({
options: t,
style: {
width: "100%"
}
});
m.placeAt(g);
this.emit("editor-show", {
cell: c,
editor: m,
grid: this.grid
});
k(m, "blur", d.hitch(this, function() {
var b = this._findFirst(l, "code", e[a.name]);
g.innerHTML = b ? b.name : e[a.name]
}));
k(m, "keydown", function(a) {
13 === a.keyCode && m.focusNode.blur()
});
k(m, "change", d.hitch(this, function(b) {
var d = {
fieldName: a.name,
oldValue: e[a.name],
rowId: e[this.idProperty],
rowObject: e
};
"ft_null" === b && (b = null );
e[a.name] = b;
b = this._findFirst(l, "code", b);
g.innerHTML = b ? b.name : null ;
m.destroy();
this._applyEditsByRow(e, d);
this.emit("editor-hide", {
cell: c,
editor: m,
grid: this.grid
})
}));
this._activeEditors.push({
id: e[this.idProperty],
widget: m
})
} else {
g.innerHTML = "";
var q = new F({
value: e[a.name],
required: !a.nullable
});
q.placeAt(g);
q.focus();
q.textbox.select();
this.emit("editor-show", {
cell: c,
editor: q,
grid: this.grid
});
k(q, "blur", d.hitch(this, function() {
g.innerHTML = e[a.name]
}));
k(q, "keydown", function(a) {
13 === a.keyCode && q.isValid() && q.focusNode.blur()
});
k(q, "change", d.hitch(this, function(b) {
var d = {
fieldName: a.name,
oldValue: e[a.name],
rowId: e[this.idProperty],
rowObject: e
};
q.isValid() ? (e[a.name] = b,
g.innerHTML = b,
q.destroy(),
this._applyEditsByRow(e, d)) : (g.innerHTML = e[a.name],
q.destroy());
this.emit("editor-hide", {
cell: c,
editor: q,
grid: this.grid
})
}));
this._activeEditors.push({
id: e[this.idProperty],
widget: q
})
}
}));
return b
}),
renderHeaderCell: d.hitch(this, function(b) {
return this._getColumnHeaderCell(b, a)
})
};
b.formatter = a.format && a.format.embeddedHTML ? d.hitch(this, function(a) {
return a ? a : null
}) : a.format && a.format.template ? d.hitch(this, function(b) {
var c;
b && (c = r.substitute(a.format.template, {
value: b
}));
return c || null
}) : a.format && !1 === a.format.link ? d.hitch(this, function(a) {
return a
}) : d.hitch(this, function(a) {
return this._generateLinkFromString(a)
});
return b
},
_generateStringColumn: function(a, c) {
var b = {
label: a.alias,
field: a.name,
type: a.type,
hidden: a.hidden,
renderHeaderCell: d.hitch(this, function(b) {
return this._getColumnHeaderCell(b, a)
})
};
b.formatter = a.format && a.format.embeddedHTML ? d.hitch(this, function(a) {
return a ? a : null
}) : a.format && a.format.template ? d.hitch(this, function(b) {
var c;
b && (c = r.substitute(a.format.template, {
value: b
}));
return c || null
}) : a.format && !1 === a.format.link ? d.hitch(this, function(a) {
return a
}) : d.hitch(this, function(a) {
return this._generateLinkFromString(a)
});
return b
},
_generateStringEditorColumn: function(a, c) {
var b = new C({
label: a.alias,
field: a.name,
type: a.type,
hidden: a.hidden,
editorArgs: {
required: !a.nullable
},
editOn: "dblclick",
editor: "text",
renderHeaderCell: d.hitch(this, function(b) {
return this._getColumnHeaderCell(b, a)
})
});
b.formatter = a.format && a.format.embeddedHTML ? d.hitch(this, function(a) {
return a ? a : null
}) : a.format && a.format.template ? d.hitch(this, function(b) {
var c;
b && (c = r.substitute(a.format.template, {
value: b
}));
return c || null
}) : a.format && !1 === a.format.link ? d.hitch(this, function(a) {
return a
}) : d.hitch(this, function(a) {
return this._generateLinkFromString(a)
});
return b
},
_generateNumberColumn: function(a, c) {
var b = {
label: a.alias,
field: a.name,
type: a.type,
hidden: a.hidden,
renderHeaderCell: d.hitch(this, function(b) {
return this._getColumnHeaderCell(b, a)
})
};
a.format && a.format.template && (b.formatter = d.hitch(this, function(b) {
var c;
b && (c = r.substitute(a.format.template, {
value: b
}));
return c || null
}));
return b
},
_generateNumberEditorColumn: function(a, c) {
var b = {
label: a.alias,
field: a.name,
type: a.type,
hidden: a.hidden,
renderHeaderCell: d.hitch(this, function(b) {
return this._getColumnHeaderCell(b, a)
}),
renderCell: d.hitch(this, function(b, c, f) {
var g = h.create("div", {
innerHTML: c
}, f)
, m = null
, n = {};
"esriFieldTypeInteger" === a.type && (n.places = 0);
m = a.format && a.format.template && null !== c ? r.substitute(a.format.template, {
value: c
}) : c;
g.innerHTML = m;
k(f, "dblclick", d.hitch(this, function() {
this._closeEditors();
g.innerHTML = "";
var c = new F({
value: b[a.name],
required: !a.nullable,
constraints: n
});
c.placeAt(g);
c.focus();
c.textbox.select();
this.emit("editor-show", {
cell: f,
editor: c,
grid: this.grid
});
k(c, "blur", d.hitch(this, function() {
var c = b[a.name]
, d = null
, d = a.format && a.format.template && null !== c ? r.substitute(a.format.template, {
value: c
}) : c;
g.innerHTML = d
}));
k(c, "keydown", function(a) {
13 === a.keyCode && c.isValid() && c.focusNode.blur()
});
k(c, "change", d.hitch(this, function(d) {
var l = {
fieldName: a.name,
oldValue: b[a.name],
rowId: b[this.idProperty],
rowObject: b
}
, h = null ;
if ("" === d || isNaN(d))
d = null ;
c.isValid() ? (b[a.name] = d,
h = a.format && a.format.template && null !== d ? r.substitute(a.format.template, {
value: d
}) : d,
g.innerHTML = h,
c.destroy(),
this._applyEditsByRow(b, l)) : (h = a.format && a.format.template && null !== b[a.name] ? r.substitute(a.format.template, {
value: b[a.name]
}) : b[a.name],
g.innerHTML = h,
c.destroy(),
this.emit("editor-hide", {
cell: f,
editor: c,
grid: this.grid
}))
}));
this._activeEditors.push({
id: b[this.idProperty],
widget: c
})
}))
})
};
a.format && a.format.template && (b.formatter = d.hitch(this, function(b) {
var c;
b && (c = r.substitute(a.format.template, {
value: b
}));
return c || null
}));
return b
},
_generateDateTimeColumn: function(a, c) {
var b = {};
return b = {
label: a.alias,
field: a.name,
type: a.type,
hidden: a.hidden,
get: d.hitch(this, function(b) {
return "" === b[a.name] || null === b[a.name] ? null : this._generateDateFromLocale(new Date(b[a.name]), a)
}),
renderHeaderCell: d.hitch(this, function(b) {
return this._getColumnHeaderCell(b, a)
})
}
},
_generateDateTimeEditorColumn: function(a, c) {
return (a.dateOptions && void 0 !== a.dateOptions.timeEnabled ? a.dateOptions.timeEnabled : this.dateOptions.timeEnabled) ? {
label: a.alias,
field: a.name,
type: a.type,
hidden: a.hidden,
get: d.hitch(this, function(b) {
return "" === b[a.name] || null === b[a.name] ? null : this._generateDateFromLocale(new Date(b[a.name]), a)
}),
renderCell: d.hitch(this, function(b, c, l) {
var f, g;
c && h.create("div", {
innerHTML: c
}, l);
k(l, "dblclick", d.hitch(this, function() {
var k, m;
this._closeEditors();
f = new L({
value: new Date(b[a.name]),
constraints: {
datePattern: a.dateOptions && a.dateOptions.datePattern ? a.dateOptions.datePattern : this.dateOptions.datePattern
}
});
f.on("change", d.hitch(this, function(c) {
var e = {
fieldName: a.name,
oldValue: b[a.name],
rowId: b[this.idProperty],
rowObject: b
}
, d = g.value;
f.isValid() ? (null === c || "" === c ? (g.setValue(null ),
b[a.name] = null ) : (null === d && (d = new Date(0,0),
g.setValue(d)),
c = this._getCombinedDateTime(c, d).getTime(),
b[a.name] = c),
this._applyEditsByRow(b, e)) : f.setValue(null )
}));
g = new ka({
value: new Date(b[a.name]),
constraints: {
timePattern: a.dateOptions && a.dateOptions.timePattern ? a.dateOptions.timePattern : this.dateOptions.timePattern
}
});
g.on("change", d.hitch(this, function(c) {
var e = {
fieldName: a.name,
oldValue: b[a.name],
rowId: b[this.idProperty],
rowObject: b
}
, d = f.value;
g.isValid() ? null === c || "" === c ? (f.setValue(null ),
b[a.name] = null ) : (null === d && (d = new Date(0,0),
f.setValue(d)),
c = this._getCombinedDateTime(d, c).getTime(),
b[a.name] = c,
this._applyEditsByRow(b, e)) : g.setValue(null )
}));
l.innerHTML = "";
k = h.create("div", {
style: {
"float": "left",
display: "inline",
width: "90%"
}
}, l);
m = h.create("div", {
style: {
"float": "right",
display: "inline",
width: "10%",
"margin-top": "5px"
}
}, l);
f.placeAt(k);
g.placeAt(k);
(new M({
iconClass: "dijitIconSave",
showLabel: !1,
onClick: d.hitch(this, function() {
var d = {
fieldName: a.name,
oldValue: b[a.name],
rowId: b[this.idProperty],
rowObject: b
}
, h = f.value
, k = g.value;
g.isValid() && f.isValid() ? (h && k ? (h = this._getCombinedDateTime(h, k).getTime(),
l.innerHTML = this._generateDateFromLocale(new Date(h), a)) : (h = null ,
l.innerHTML = ""),
b[a.name] = h,
this._applyEditsByRow(b, d)) : l.innerHTML = c
})
},h.create("div", null , m))).startup();
f.focus();
f.textbox.select()
}))
}),
renderHeaderCell: d.hitch(this, function(b) {
return this._getColumnHeaderCell(b, a)
})
} : new C({
label: a.alias,
field: a.name,
type: a.type,
editorArgs: {
required: !a.nullable,
constraints: {
datePattern: a.dateOptions && a.dateOptions.datePattern ? a.dateOptions.datePattern : this.dateOptions.datePattern
}
},
editOn: "dblclick",
hidden: a.hidden,
formatter: d.hitch(this, function(b) {
return b ? this._generateDateFromLocale(b, a) : null
}),
get: d.hitch(this, function(b) {
return "" === b[a.name] || null === b[a.name] ? null : new Date(b[a.name])
}),
renderHeaderCell: d.hitch(this, function(b) {
return this._getColumnHeaderCell(b, a)
})
},L)
},
_closeEditors: function() {
n.forEach(this._activeEditors, function(a) {
a.widget.onBlur()
});
this.set("_activeEditors", [])
},
_getColumnHeaderCell: function(a, c) {
var b = h.create("div", {
className: this.css.featureTableColumnHeader
});
h.create("div", {
innerHTML: c.alias,
className: this.css.featureTableColumnHeaderTitle
}, b);
!c.editable && (this.editable && this.layerInfo.editable) && h.create("span", {
className: this.css.headerGear + " " + this.css.lockedIcon
}, b);
h.create("div", {
style: {
clear: "both"
}
}, b);
this.showDataTypes && h.create("div", {
innerHTML: c.type,
className: this.css.featureTableColumnHeaderType
}, b);
return b
},
_selectFeaturesFromIds: function(a) {
if (a || 0 !== this.selectedRowIds.length) {
var c = new x;
c.returnGeometry = !!this.map;
c.objectIds = a || this.selectedRowIds;
c.where = "1\x3d1";
return this.featureLayer.selectFeatures(c, na.SELECTION_NEW)
}
},
_updateGridSelection: function() {
var a = this.grid.selection, c = new A, b = [], e = [], d, f;
for (d in a)
a.hasOwnProperty(d) && (f = parseInt(d, 10),
e.push(f),
b.push(this.grid.row(f).data));
this.set({
selectedRows: b,
selectedRowIds: e,
_featureSelectedCount: e.length
});
c.resolve();
return c
},
_showExpandoCallback: function(a, c, b, e, d) {
c = c.element;
var f = s.contains(c, "collapsed")
, g = Z(".expando", c)[0]
, h = this._expandedNodes[0] ? a === this._expandedNodes[0].grid : !1;
d = this._expandedNodes[0] ? s.contains(this._expandedNodes[0].textSpan, d) : !1;
this._expandedNodes[0] && this._expandedNodes[0].rowNode === c && d ? (e.innerHTML = this._i18nStrings.hide,
this._expandedNodes[0].textSpan.innerHTML = this._i18nStrings.show,
this._expandedNodes = [{
grid: a,
rowNode: c,
textDiv: b,
textSpan: e
}]) : !h && this._expandedNodes[0] ? s.toggle(c, "collapsed", !f) : (n.forEach(this._expandedNodes, function(a) {
s.add(a.rowNode, "collapsed");
a.textSpan.innerHTML = this._i18nStrings.show
}, this),
s.toggle(c, "collapsed", !f),
this._expandedNodes = f ? [{
grid: a,
rowNode: c,
textDiv: b,
textSpan: e
}] : [],
e.innerHTML = f ? this._i18nStrings.hide : this._i18nStrings.show);
return g
},
_applyEdits: function(a, c) {
a = a || [];
if (!(0 >= a.length)) {
var b = [];
n.forEach(a, function(a) {
a.layer && b.push(a.layer.applyEdits(a.adds, a.updates, a.deletes))
});
0 < b.length ? Y(b).then(d.hitch(this, function() {
c && c()
})) : this._toggleLoadingIndicator(!1)
}
},
_applyEditsByRow: function(a, c) {
c && this._rollbackInfos.push({
id: c.rowId,
data: c
});
this.getFeatureDataById(a[this.idProperty]).then(d.hitch(this, function(b) {
this._toggleLoadingIndicator(!0);
b = b.features[0];
b.attributes = a;
this._applyEdits([{
layer: this.featureLayer,
updates: [b]
}], null )
}))
},
_applyEditsListener: function() {
return k(this.featureLayer, "edits-complete", d.hitch(this, function(a) {
this.emit("edits-complete", a);
a = a.updates || [];
var c = this._rollbackInfos, b, e, d, f;
a && a.length && n.forEach(a, function(a) {
b = this._findFirst(c, "id", a.objectId);
e = b.data;
a.success || (a.error ? this.emit("error", a.error) : this.emit("error", "Update failed."),
e ? (d = this.grid.row(e.rowId),
f = d.data,
f[this.idProperty] === a.objectId ? (f[e.fieldName] = e.oldValue,
this.grid.updateDirty(e.rowId, e.fieldName, e.oldValue),
this.grid.refresh()) : this.emit("error", "Couldn't rollback value.")) : this.emit("error", "Couldn't rollback value."));
this._rollbackInfos.splice(n.indexOf(this._rollbackInfos, b), 1);
this._toggleLoadingIndicator(!1)
}, this);
this.layerInfo.isFeatureCollection && this._createStoreFromDataQuery();
this._toggleLoadingIndicator(!1)
}))
},
_layerClickCallback: function() {
return k(this.featureLayer, "click", d.hitch(this, function(a) {
if (this.syncSelection && a.graphic && a.graphic.attributes && a.graphic.attributes[this.idProperty]) {
this.grid.clearSelection();
this.featureLayer.clearSelection();
var c = a.graphic.attributes[this.idProperty];
this._selectFeaturesFromIds([c]).then(d.hitch(this, function(a) {
if (a.length) {
if (this.map && this.zoomToSelection) {
var e = this._calcGraphicsExtent(a);
e ? (e = e.getCenter(),
this.map.centerAndZoom(e, 12).then(function() {
n.forEach(a, function(a) {
a.getDojoShape() && a.getDojoShape().moveToFront()
})
})) : this.emit("error", "Could not generate valid extent.")
}
var e = this.dataStore.get(c)
, l = this.dataStore.data.indexOf(e);
("undefined" === typeof e || -1 === l) && this.emit("error", "Could not load the row. Selection failed.");
this.grid.select(c);
this._updateGridSelection().then(d.hitch(this, function() {
this._updateGridHeaderText();
k.once(this.grid, "scroll", d.hitch(this, function() {
this.grid.row(c).element && this.grid.row(c).element.scrollIntoView()
}));
this.grid.scrollTo({
x: 0,
y: this.grid.rowHeight * l
})
}))
}
}), function(a) {
this.emit("error", "Could not select features.")
})
}
}))
},
_gridRefreshListener: function() {
return k(this.grid, "dgrid-refresh-complete", d.hitch(this, function(a) {
this.grid.columns[0] && this.emit("refresh", a)
}))
},
_gridDataChangeListener: function() {
return k(this.grid, "dgrid-datachange", d.hitch(this, function(a) {
var c = a.cell.column.field
, b = a.value
, e = parseInt(a.rowId, 10)
, l = this.grid.row(e).data
, f = this._findFirst(this.layerInfo.fieldInfos, "name", c)
, g = {
oldValue: a.oldValue,
fieldName: c,
rowId: e,
rowObject: l
};
this.emit("data-change", a);
"" === b && (b = null );
if (("esriFieldTypeInteger" === f.type || "esriFieldTypeSmallInteger" === f.type) && null !== b)
b = parseInt(b, 10);
if (("esriFieldTypeDouble" === f.type || "esriFieldTypeSingle" === f.type) && null !== b)
b = parseFloat(b);
b && b.getTime && b.getTime() ? l[c] = b.getTime() : l[c] = b;
this._updateGridSelection().then(d.hitch(this, function() {
this._updateGridHeaderText();
this._applyEditsByRow(l, g)
}))
}))
},
_gridSelectListener: function() {
return k(this.grid, "dgrid-select", d.hitch(this, function(a) {
this._activeEditors[0] && this._activeEditors[0].id && a.rows[0] && Number(a.rows[0].id) !== Number(this._activeEditors[0].id) && this._closeEditors();
this.emit("row-select", a.rows);
this._updateGridSelection().then(d.hitch(this, function() {
this._updateGridHeaderText();
this.map && this.syncSelection && this._selectFeaturesFromIds().then(d.hitch(this, function(a) {
if (this.zoomToSelection) {
var b = this._calcGraphicsExtent(a);
b ? (b = b.getCenter(),
this.map.centerAt(b).then(function() {
n.forEach(a, function(a) {
a.getDojoShape() && a.getDojoShape().moveToFront()
})
})) : this.emit("error", "Could not generate valid extent.")
}
}), function(a) {
this.emit("error", "Could not select features")
})
}))
}))
},
_gridDeselectListener: function() {
return k(this.grid, "dgrid-deselect", d.hitch(this, function(a) {
this.emit("row-deselect", a.rows);
this._updateGridSelection().then(d.hitch(this, function() {
this._updateGridHeaderText();
this._selectFeaturesFromIds()
}))
}))
},
_gridColumnStateChangeListener: function() {
return k(this.grid, "dgrid-columnstatechange", d.hitch(this, function(a) {
this.emit("column-state-change", a)
}))
},
_gridColumnResizeListener: function() {
return k(this.grid, "dgrid-columnresize", d.hitch(this, function(a) {
this.emit("column-resize", a)
}))
},
_gridErrorListener: function() {
return k(this.grid, "dgrid-error", d.hitch(this, function(a) {
this.emit("error", a)
}))
},
_gridSortListener: function() {
return k(this.grid, "dgrid-sort", d.hitch(this, function(a) {
this.emit("sort", a)
}))
},
_gridFilterListener: function() {
return k(this.grid, "dgrid-filter", d.hitch(this, function(a) {
this.emit("filter", a)
}))
},
_gridEditorShowListener: function() {
return k(this.grid, "dgrid-editor-show", d.hitch(this, function(a) {
this.emit("editor-show", a)
}))
},
_gridEditorHideListener: function() {
return k(this.grid, "dgrid-editor-hide", d.hitch(this, function(a) {
this.emit("editor-hide", a)
}))
},
_columnClickCallback: function() {
return this.grid.on(".dgrid-header .dgrid-cell:click", d.hitch(this, this._showColumnMenu))
},
_tableToggleClickCallback: function() {
return k(this.tableCloseButton, "click", d.hitch(this, function() {
this._toggleOpened ? (s.remove(this.tableCloseButton, "toggleOpened"),
s.add(this.tableCloseButton, "toggleClosed"),
this._toggler.hide(),
this._gridContentPane.domNode.style.display = "none") : (s.remove(this.tableCloseButton, "toggleClosed"),
s.add(this.tableCloseButton, "toggleOpened"),
this._toggler.show(),
this._gridContentPane.domNode.style.display = "block");
this._resize();
this._toggleOpened = !this._toggleOpened
}))
},
_resize: function() {
this._gridBorderContainer.resize();
this._gridHeaderNode.resize();
this._gridContentPane.resize();
this.grid && this.grid.resize()
},
_updateGridHeaderText: function() {
this._gridTitleNode.innerHTML = r.substitute(this._i18nStrings.gridHeader, {
gridTitle: this.featureLayer.name || this._i18nStrings.untitled,
featureCount: this.featureCount,
featureSelectedCount: this._featureSelectedCount
})
},
_createTableToggle: function() {
var a = new da({
node: this.gridContentPaneId
});
this._toggleOpened = !0;
return a
},
_toggleLoadingIndicator: function(a) {
this._gridLoadingIndicatorNode.style.display = a ? "block" : "none"
},
_showLoadError: function() {
this._toggleLoadingIndicator(!1);
this._gridTitleNode.innerHTML = this._i18nStrings.dataError
},
_showInfoWindow: function() {},
_hideInfoWindow: function() {},
_showColumnMenu: function(a) {
var c = this.grid.cell(a)
, b = c.column;
if (b) {
var e = this.get("columnMenu"), l = b.id, f = this.columns[l], b = this.layerInfo.fieldInfos[l], g = b.type, h, m;
e && this.set({
_oldColumnMenu: e,
columnMenu: null
});
var p = new K({});
if (!1 !== f.sortable) {
if (this.featureCount > this.featureLayer.maxRecordCount && !this.featureLayer.advancedQueryCapabilities.supportsPagination)
return;
e = [this._i18nStrings.sortAsc, this._i18nStrings.sortDesc];
h = ["iconSortAscending", "iconSortDescending"];
m = [this._sortAscending, this._sortDescending];
n.forEach(e, function(a, b) {
var c = new E({
label: a,
iconClass: h[b],
baseClass: this.css.menuItem,
onClick: d.hitch(this, m[b], l)
});
p.addChild(c)
}, this)
}
if (this.featureLayer.supportsStatistics && (b && !b.domain) && ("esriFieldTypeDouble" === g || "esriFieldTypeSingle" === g || "esriFieldTypeInteger" === g || "esriFieldTypeSmallInteger" === g))
e = new E({
label: this._i18nStrings.statistics,
iconClass: "iconTableStatistics",
baseClass: this.css.menuItem,
onClick: d.hitch(this, this._getColumnStats, l)
}),
p.addChild(e);
p.startup();
p._openMyself({
target: a.target,
delegatedTarget: c,
iframe: null ,
coords: {
x: a.pageX,
y: a.pageY
}
});
k(p, "close", d.hitch(this, function() {
this._oldColumnMenu && (this._oldColumnMenu.destroyRecursive(),
this._oldColumnMenu = null )
}));
this.set("columnMenu", p)
}
},
_sortAscending: function(a) {
this.dataStore instanceof z && (this.set("_orderByFields", [this.columns[a].field + " ASC"]),
this._createStoreFromDataQuery());
this.grid.set("sort", [{
attribute: this.columns[a].field,
descending: !1
}]);
this.emit("sort", {
field: this.columns[a].field,
descending: !1
})
},
_sortDescending: function(a) {
this.dataStore instanceof z && (this.set("_orderByFields", [this.columns[a].field + " DESC"]),
this._createStoreFromDataQuery());
this.grid.set("sort", [{
attribute: this.columns[a].field,
descending: !0
}]);
this.emit("sort", {
field: this.columns[a].field,
descending: !0
})
},
_getColumnStats: function(a) {
var c = this.columns[a].field;
a = [];
var b = "countField sumField minField maxField avgField stddevField".split(" "), e;
e = new x;
e.outFields = [c];
e.outStatistics = [];
e.where = "1\x3d1";
n.forEach("count sum min max avg stddev".split(" "), function(a, d) {
var g = new oa;
g.statisticType = a;
g.onStatisticField = c;
g.outStatisticFieldName = b[d];
g.displayFieldName = c;
e.outStatistics.push(g)
}, this);
0 < this._filteredRowIds.length && (a = this._filteredRowIds);
e.where && 0 < a.length && (e.where = "(" + e.where + ") AND (" + this.idProperty + " IN (" + a.toString() + "))");
(new pa(this.featureLayer.url)).execute(e).then(d.hitch(this, function(a) {
a.features && a.features.length && this._showStatisticsDialog(a, c)
}), function(a) {
this.emit("error", "Could not get statistics.")
})
},
_showStatisticsDialog: function(a, c) {
var b = a.features[0].attributes, e = {}, d = {
pattern: "#,###,###,##0.########"
}, f = "Number of Values;Sum of Values;Minimum;Maximum;Average;Standard Deviation".split(";"), g, k, m, n, r, t, s;
this.statisticsDialog && this.statisticsDialog.destroy();
g = h.create("div", {
className: "esriAGOTableStatistics",
innerHTML: ""
});
h.create("div", {
className: "header",
innerHTML: "Field: " + c
}, g);
h.create("div", {
className: "hzLine",
innerHTML: ""
}, g);
k = h.create("table", {
className: "attrTable",
innerHTML: "",
style: {
cellpadding: 0,
cellspacing: 0
}
}, g);
for (m in b)
b.hasOwnProperty(m) && (e[m.toLowerCase()] = b[m]);
n = w.isDefined(e.countfield) ? v.format(e.countfield, d) : "";
s = w.isDefined(e.sumfield) ? v.format(e.sumfield, d) : "";
t = w.isDefined(e.minfield) ? v.format(e.minfield, d) : "";
r = w.isDefined(e.maxfield) ? v.format(e.maxfield, d) : "";
m = w.isDefined(e.avgfield) ? v.format(v.round(e.avgfield, this._roundPos(e.avgfield)), d) : "";
e = w.isDefined(e.stddevfield) ? v.format(v.round(e.stddevfield, this._roundPos(e.stddevfield)), d) : "";
k = h.create("tbody", {}, k);
d = h.create("tr", {
valign: "top"
}, k);
h.create("td", {
"class": "attrName",
innerHTML: f[0]
}, d);
h.create("td", {
"class": "attrValue",
innerHTML: n
}, d);
d = h.create("tr", {
valign: "top"
}, k);
h.create("td", {
"class": "attrName",
innerHTML: f[1]
}, d);
h.create("td", {
"class": "attrValue",
innerHTML: s
}, d);
d = h.create("tr", {
valign: "top"
}, k);
h.create("td", {
"class": "attrName",
innerHTML: f[2]
}, d);
h.create("td", {
"class": "attrValue",
innerHTML: t
}, d);
d = h.create("tr", {
valign: "top"
}, k);
h.create("td", {
"class": "attrName",
innerHTML: f[3]
}, d);
h.create("td", {
"class": "attrValue",
innerHTML: r
}, d);
d = h.create("tr", {
valign: "top"
}, k);
h.create("td", {
"class": "attrName",
innerHTML: f[4]
}, d);
h.create("td", {
"class": "attrValue",
innerHTML: m
}, d);
d = h.create("tr", {
valign: "top"
}, k);
h.create("td", {
"class": "attrName",
innerHTML: f[5]
}, d);
h.create("td", {
"class": "attrValue",
innerHTML: e
}, d);
h.create("div", {
className: "break",
innerHTML: ""
}, g);
this.statisticsDialog = new ia({
title: this._i18nStrings.statistics,
content: g,
baseClass: this.css.dialog
});
var f = h.create("button", {
type: "button"
}, this.statisticsDialog.containerNode)
, q = this;
this._closeButton = new M({
label: this._i18nStrings.close,
baseClass: "primary dijitButton",
onClick: function() {
var a = q.statisticsDialog;
a.hide().then(function() {
a.destroyRecursive()
})
}
},f);
this.statisticsDialog.show();
this.emit("show-statistics", {
dialog: this.statisticsDialog,
statistics: b
})
},
_createTableMenu: function() {
this.gridMenu = new K({});
var a = [this._i18nStrings.defaultSort, this._i18nStrings.showSelected, this._i18nStrings.clearSelection, this._i18nStrings.toggleColumns]
, c = [this._defaultSortOrder, this._showSelectedRecords, this._clearSelection, this._showHideColumns];
this.map && this.syncSelection && (a.push("Center on Selection"),
c.push(this._centerOnSelection));
0 < this.menuFunctions.length && n.forEach(this.menuFunctions, function(b) {
a.push(b.label);
c.push(b.callback)
}, this);
n.forEach(a, function(a, e) {
var l = new E({
label: a,
baseClass: this.css.menuItem,
onClick: d.hitch(this, c[e])
});
this.gridMenu.addChild(l)
}, this);
this.gridMenuAnchor = new ja({
label: m.widgets.geocodeMatch.match.tableOptionsLabel,
dropDown: this.gridMenu
},this.gridMenuNodeId);
this.gridMenu.startup()
},
_defaultSortOrder: function() {
this.dataStore instanceof z && (this.set("_orderByFields", null ),
this._createStoreFromDataQuery());
this.grid.set("sort", [{
attribute: this.idProperty,
descending: !1
}]);
this.emit("sort", {
field: this.idProperty,
descending: !1
})
},
_filterRows: function() {},
_showSelectedRecords: function() {
var a = this.selectedRowIds;
this.set("_filteredRowIds", a);
a && 0 < a.length && (this.dataStore instanceof z ? this.emit("error", "Unable to show current selection.") : (this.grid.set("query", d.hitch(this, function(c) {
return -1 !== a.indexOf(c[this.idProperty]) ? !0 : !1
})),
this._gridQuery = !0),
this.emit("filter", a))
},
_centerOnSelection: function() {
var a = this.selectedRowIds
, c = new x;
c.objectIds = a;
c.outFields = ["*"];
0 < this.selectedRows.length && 0 < this.selectedRowIds.length && this.featureLayer.queryFeatures(c, d.hitch(this, function(a) {
this.map.setExtent(this._calcGraphicsExtent(a.features))
}))
},
_clearSelection: function() {
this.set("_filteredRowIds", []);
this._gridQuery && (this.grid.set("query", {}),
this.set("_gridQuery", !1));
this.grid.clearSelection();
this._updateGridSelection().then(d.hitch(this, function() {
this._updateGridHeaderText();
this.featureLayer.clearSelection()
}));
this.emit("filter", {})
},
_showHideColumns: function() {
this.grid._toggleColumnHiderMenu()
},
_exportToCSV: function() {},
_roundPos: function(a) {
return 1E3 <= a ? 0 : 10 <= a ? 2 : 0 <= a ? 4 : 6
},
_generateLinkFromString: function(a) {
if (a && "string" === typeof a) {
var c = a.indexOf("http:");
-1 === c && (c = a.indexOf("https:"));
if (-1 < c && -1 === a.indexOf("href\x3d")) {
var b = a.indexOf(" ", c);
-1 === b && (b = a.length);
var e = a.substring(c, b);
a = a.substring(0, c) + "\x3ca href\x3d'" + e + "' target\x3d'_blank'\x3e" + e + "\x3c/a\x3e" + a.substring(b, a.length)
}
}
return a || null
},
_calcGraphicsExtent: function(a) {
var c = a[0].geometry;
if (null === c && 1 === a.length)
return null ;
for (var b = a.length - 1; 0 <= b; b--)
null === a[b].geometry && a.splice(b, 1);
var c = a[0].geometry, b = c.getExtent(), e, d, f = a.length;
null === b && (b = new U(c.x,c.y,c.x,c.y,c.spatialReference));
for (d = 1; d < f; d += 1)
c = a[d].geometry,
e = c.getExtent(),
null === e && (e = new U(c.x,c.y,c.x,c.y,c.spatialReference)),
b = b.union(e);
return b
},
_generateDateFromLocale: function(a, c) {
var b = !1
, e = !1
, d = {}
, f = c && c.dateOptions ? c.dateOptions : !1;
f ? ("undefined" !== typeof f.datePattern && !1 !== f.datePattern ? (d.datePattern = f.datePattern || this.dateOptions.datePattern,
b = !0) : this.dateOptions && null !== this.dateOptions.datePattern && (d.datePattern = this.dateOptions.datePattern,
b = !1 === f.datePattern ? !1 : !0),
f.timeEnabled || this.dateOptions.timeEnabled ? (d.timePattern = f.timePattern || this.dateOptions.timePattern,
e = "undefined" !== typeof f.timeEnabled ? f.timeEnabled : this.dateOptions.timeEnabled) : this.dateOptions && ("undefined" !== typeof this.dateOptions.timeEnabled && null !== this.dateOptions.timePattern) && (d.timePattern = this.dateOptions.timePattern,
e = this.dateOptions.timeEnabled)) : (this.dateOptions && null !== this.dateOptions.datePattern && (d.datePattern = this.dateOptions.datePattern,
b = !0),
this.dateOptions && ("undefined" !== typeof this.dateOptions.timeEnabled && null !== this.dateOptions.timePattern) && (d.timePattern = this.dateOptions.timePattern,
e = this.dateOptions.timeEnabled));
b && e ? d.selector = "date and time" : b && !e ? d.selector = "date" : !b && e ? d.selector = "time" : d.selecter = "date";
return X.format(new Date(a), d)
},
_getCombinedDateTime: function(a, c) {
return new Date(a.getFullYear(),a.getMonth(),a.getDate(),c.getHours(),c.getMinutes(),c.getSeconds())
},
_findFirst: function(a, c, b) {
return (a = n.filter(a, function(a) {
return a.hasOwnProperty(c) && a[c] === b
})) && a.length ? a[0] : null
}
});
W("extend-esri") && d.setObject("dijit.FeatureTable", B, ma);
return B
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment