2012-07-17 22:22:38 +00:00
|
|
|
|
// js/modules/controls.js
|
|
|
|
|
// Module reference argument, assigned at the bottom
|
|
|
|
|
// every device gets its model from the base and is rendered into seperate viewbases
|
|
|
|
|
|
2012-07-19 14:25:01 +00:00
|
|
|
|
(function (Device) {
|
|
|
|
|
|
2012-07-17 22:22:38 +00:00
|
|
|
|
// Dependencies
|
2012-07-19 21:45:22 +00:00
|
|
|
|
var Position = app.module("position"),
|
|
|
|
|
Option = app.module("option"),
|
|
|
|
|
Util = app.module("util"),
|
|
|
|
|
Switch = app.module("switch");
|
2012-07-17 22:22:38 +00:00
|
|
|
|
|
|
|
|
|
Device.Model = Backbone.Model.extend({
|
|
|
|
|
defaults: {
|
2012-07-19 14:25:01 +00:00
|
|
|
|
deviceId: 0,
|
|
|
|
|
pos: Position.Model,
|
|
|
|
|
type: ''
|
2012-07-17 22:22:38 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2012-07-19 14:25:01 +00:00
|
|
|
|
Device.List = Backbone.Collection.extend({
|
|
|
|
|
model: Device.Model
|
2012-07-17 22:22:38 +00:00
|
|
|
|
});
|
|
|
|
|
|
2012-07-19 14:25:01 +00:00
|
|
|
|
Device.View = Backbone.View.extend({
|
|
|
|
|
initialize: function () {
|
|
|
|
|
this.$el.addClass('device');
|
|
|
|
|
this.pos = new Position.Model(this.model.get('pos'));
|
|
|
|
|
this.type = this.model.get('type');
|
2012-07-19 21:45:22 +00:00
|
|
|
|
this.template = Handlebars.compile(Util.getTemplate(this.type));
|
|
|
|
|
//this.childControl = new Switch.View({ model: new Option.List(this.model.get('options')) });
|
2012-07-19 14:25:01 +00:00
|
|
|
|
},
|
|
|
|
|
render: function () {
|
|
|
|
|
this.$el.attr('style', 'left:' + this.pos.get('x') + 'px;top:' + this.pos.get('y') + 'px');
|
|
|
|
|
this.$el.html(this.template(this.model.toJSON()));
|
|
|
|
|
return this;
|
|
|
|
|
},
|
2012-07-19 21:45:22 +00:00
|
|
|
|
events: {
|
|
|
|
|
"click .switch": "toggleSwitch",
|
|
|
|
|
"change input.color": "updateColor"
|
|
|
|
|
},
|
|
|
|
|
updateColor: function() {
|
|
|
|
|
$('.cpicker', this.$el).attr('style','background-color:#' + $('input.color', this.$el).val());
|
|
|
|
|
},
|
|
|
|
|
toggleSwitch: function () {
|
|
|
|
|
var status = this.model.get('options')[0].status;
|
|
|
|
|
status = (status == "off" ? "on" : "off");
|
|
|
|
|
this.model.get('options')[0].status = status;
|
|
|
|
|
this.model.trigger("change:options");
|
|
|
|
|
this.render();
|
|
|
|
|
}
|
2012-07-19 14:25:01 +00:00
|
|
|
|
});
|
2012-07-17 22:22:38 +00:00
|
|
|
|
|
2012-07-19 14:25:01 +00:00
|
|
|
|
})(app.module("device"));
|