Skip to content

Instantly share code, notes, and snippets.

@green3g
Created October 11, 2016 13:15
Show Gist options
  • Save green3g/b38e7303e8ee2c0cc2465341f950f7c7 to your computer and use it in GitHub Desktop.
Save green3g/b38e7303e8ee2c0cc2465341f950f7c7 to your computer and use it in GitHub Desktop.
A pretty interesting example of adding custom buttons to tmcgee's search widget
define([
'dojo/_base/lang',
'dojo/topic',
'tmcgee/Search',
'dijit/form/Button',
'./auth_util'
], function (lang, topic, Search, Button, Auth) {
var workorderButton = {
include: Auth.hasOneRole(['workorders_create', 'admin']),
layerMap: {
'Storm Pipe': 'storm_pipe',
'Storm Structures': 'storm_struc',
'Sanitary Pipe': 'san_pipe',
'Sanitary Structures': 'san_struc',
'Sanitary Service': 'san_service',
'Water Structures': 'water_struc',
'Water Pipes': 'water_pipe',
'Wells and Reservoirs': 'water_well_res',
'Water Serivce Lines': 'water_service',
'Curb Stops': 'water_curbstop',
'Parcels': 'city_parcel'
},
label: '<i class="fa fa-wrench"></i> Create Workorder',
onClick: function () {
var tableName = this.layerMap[this.tab.title];
var idField = this.workorderLayers.filter(function (l) {
return l.tablename === tableName;
})[0].id_field;
window.location.hash = window.can.route.url({
view: 'all_wo',
page: 'add',
featureType: tableName,
featureIds: this.tab.grid.store.data.map(function (row) {
return row[idField];
})
}, true);
}
};
return {
// layerControlLayerInfos: true,
map: true,
layers: [{
title: 'Storm Pipe',
name: 'Storm Pipe',
topicID: 'storm_pipe',
queryParameters: {
type: 'spatial',
layerID: 'assets',
sublayerID: 11
},
buttons: [workorderButton],
attributeSearches: []
}, {
title: 'Curb Stops',
name: 'Curb Stop (Tap Cards)',
topicID: 'curbStop',
queryParameters: {
type: 'spatial',
layerID: 'assets',
sublayerID: 26
},
attributeSearches: [],
buttons: [{
label: '<i class="fa fa-file-text-o"></i> Tapcard Report',
onClick: function () {
window.open('/utilities/tap_report/tap/' +
this.tab.grid.store.data.map(function (row) {
return row['gis.DBO.water_curbstop.cid'];
}).join('+'));
}
}]
}, {
title: 'Parcels',
topicID: 'parcels',
name: 'Parcels',
queryParameters: {
type: 'spatial',
layerID: 'assets',
sublayerID: 1
},
attributeSearches: [],
buttons: [{
label: '<i class="fa fa-file-text-o"></i> Tapcard Report',
onClick: function () {
window.open('/utilities/tap_report/parcel/' +
this.tab.grid.store.data.map(function (row) {
return row.PARCELID;
}).join('+'));
}
}]
}],
tabsWithButtons: {},
startup: function () {
Search.prototype.startup.apply(this, arguments);
//subscribe a topic to modify the attributes container add tab
topic.subscribe('attributesContainer/tableAdded', lang.hitch(this, function (tab) {
if (this.tabsWithButtons[tab.title]) {
return;
}
this.layers.forEach(lang.hitch(this, function (l) {
if (l.title === tab.title && l.buttons) {
l.buttons.forEach(lang.hitch(this, function (b) {
// only include if the buttons include property is not false
if (b.include !== false) {
this.addButton(tab, b);
}
}));
}
}));
}));
},
addButton: function (tab, options) {
tab.attributesTableToolbarDijit.addChild(new Button(lang.mixin(options, {
tab: tab
})));
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment