Skip to content

Commit

Permalink
adds default formatters where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
green3g committed Oct 10, 2016
1 parent 86064a2 commit b16f887
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
23 changes: 19 additions & 4 deletions viewer/js/gis/dijit/Identify.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ define([
'esri/TimeExtent',
'dojo/text!./Identify/templates/Identify.html',
'dojo/i18n!./Identify/nls/resource',
'./Identify/Formatters',

'dijit/form/Form',
'dijit/form/FilteringSelect',
'xstyle/css!./Identify/css/Identify.css'
], function (declare, _WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin, MenuItem, lang, array, all, topic, query, domStyle, domClass, Moveable, Memory, IdentifyTask, IdentifyParameters, PopupTemplate, FeatureLayer, TimeExtent, IdentifyTemplate, i18n) {
], function (declare, _WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin, MenuItem, lang, array, all, topic, query, domStyle, domClass, Moveable, Memory, IdentifyTask, IdentifyParameters, PopupTemplate, FeatureLayer, TimeExtent, IdentifyTemplate, i18n, Formatters) {

return declare([_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin], {
widgetsInTemplate: true,
Expand All @@ -47,6 +48,19 @@ define([
'shape_len', 'shape.stlength()',
'shape.area', 'shape_area', 'shape.starea()'
],
/**
* field type mappings to their default formatter functions
* overriding this object will globally replace the default
* formatter function for the field type
* @type {Object<Function>}
*/
defaultFormatters: {
'esriFieldTypeSmallInteger': Formatters.formatInt,
'esriFieldTypeInteger': Formatters.formatInt,
'esriFieldTypeSingle': Formatters.formatFloat,
'esriFieldTypeDouble': Formatters.formatFloat,
'esriFieldTypeDate': Formatters.formatDate
},

postCreate: function () {
this.inherited(arguments);
Expand Down Expand Up @@ -419,19 +433,20 @@ define([
this.addDefaultFieldInfo(fieldInfos, {
fieldName: foundField[0].name,
label: foundField[0].alias,
visible: true
visible: true,
formatter: typeof this.defaultFormatters[foundField[0].type] !== 'undefined' ? this.defaultFormatters[foundField[0].type] : undefined
});
}
}));

// from the fields layer
} else if (layer.fields) {

array.forEach(layer.fields, lang.hitch(this, function (field) {
this.addDefaultFieldInfo(fieldInfos, {
fieldName: field.name,
label: field.alias,
visible: true
visible: true,
formatter: typeof this.defaultFormatters[field.type] !== 'undefined' ? this.defaultFormatters[field.type] : undefined
});
}));
}
Expand Down
21 changes: 21 additions & 0 deletions viewer/js/gis/dijit/Identify/Formatters.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
define([
'dojo/number',
'dojo/date/locale'
], function (number, locale) {
return {
formatInt: function (value) {
return number.format(value);
},
formatFloat: function (value) {
return number.format(value, {
places: 3
});
},
formatDate: function (value) {
var date = new Date(value);
return locale.format(date, {
formatLength: 'short'
});
}
};
});

0 comments on commit b16f887

Please sign in to comment.