Skip to content

Instantly share code, notes, and snippets.

@dima117
Forked from GorosVi/wi.js
Last active September 23, 2015 19:59
Show Gist options
  • Save dima117/998302e094cb64b959a4 to your computer and use it in GitHub Desktop.
Save dima117/998302e094cb64b959a4 to your computer and use it in GitHub Desktop.
Widget test
define(['lib'], function (lib) {
var PresetWidgetView = lib.marionette.ItemView.extend({
template: lib.handlebars.compile(
'{{displayName}}' +
'<div class="btn-group-justified nooui-btngroup">' +
'<a href="#" class="btn btn-default nooui-button js-btn-on"> On </a>' +
'<a href="#" class="btn btn-default nooui-button js-btn-off"> Off </a>' +
'</div>'),
className: 'nooui-widget',
triggers: {
"click .js-btn-on": "switch:on",
"click .js-btn-off": "switch:off"
}
});
var createSender = function(channel, cmd) {
return function() {
return lib.$.getJSON('/api/noolite', { ch: channel, cmd: cmd });
}
};
return {
show: function (model, region) {
var view = new PresetWidgetView({ model: model });
var channel = model.get('data').channel;
view.on("switch:on", createSender(channel, 2));
view.on("switch:off", createSender(channel, 6));
region.show(view);
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment