-
-
Save dima117/998302e094cb64b959a4 to your computer and use it in GitHub Desktop.
Widget test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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