Skip to content

Instantly share code, notes, and snippets.

@odoe
Created February 8, 2016 19:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save odoe/fe65f907c6d59b65c418 to your computer and use it in GitHub Desktop.
Save odoe/fe65f907c6d59b65c418 to your computer and use it in GitHub Desktop.
define([
'dojo/_base/declare',
'dijit/_WidgetBase',
'dijit/_TemplatedMixin',
'dojo/text!./templates/Widget.html'
], function(
declare,
_WidgetBase, _TemplatedMixin,
templateString
) {
function val(e) {
return e.target.value;
}
var Widget = _WidgetBase.createSubclass(_TemplatedMixin, {
templateString: templateString,
placeholder: 'Search camera id',
baseClass: 'camsearch',
onChange: function(e) {
var value = val(e);
var store = this.store;
store.map(function(x) {
x.visible = false;
return x;
}).filter(function(x) {
return x.CameraID === Number(value);
}).map(function(x) {
x.visible = true;
store.removeItem(x);
store.addItem(x);
});
},
onRefresh: function() {
this.inputNode.value = '';
var store = this.store;
store.map(function(x) {
x.visible = true;
return x;
}).filter(function(x) {
// trick to force a collection change event
return x.CameraID === Math.floor(Math.random() * 100) + 1000;
}).map(function(x) {
// this will trigger a Collection "change" event
store.removeItem(x);
store.addItem(x);
});
}
});
return Widget;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment