2012-07-17 22:22:38 +00:00
|
|
|
|
// js/modules/room.js
|
|
|
|
|
// Module reference argument, assigned at the bottom
|
|
|
|
|
|
|
|
|
|
(function (Room) {
|
|
|
|
|
|
|
|
|
|
// Dependencies
|
2012-07-19 21:45:22 +00:00
|
|
|
|
var Util = app.module("util"),
|
|
|
|
|
Device = app.module("device");
|
2012-07-17 22:22:38 +00:00
|
|
|
|
|
|
|
|
|
// The basic person model
|
|
|
|
|
Room.Model = Backbone.Model.extend({
|
|
|
|
|
defaults: {
|
|
|
|
|
roomId: null,
|
|
|
|
|
title: 'undefined',
|
2012-07-19 14:25:01 +00:00
|
|
|
|
devices: Device.List
|
2012-07-17 22:22:38 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Room.List = Backbone.Collection.extend({
|
|
|
|
|
model: Room.Model
|
|
|
|
|
});
|
|
|
|
|
|
2012-07-19 14:25:01 +00:00
|
|
|
|
Room.View = Backbone.View.extend({
|
|
|
|
|
initialize: function () {
|
|
|
|
|
this.$el.attr('id', 'room' + this.model.get('roomId')).addClass('room');
|
|
|
|
|
this.template = Handlebars.compile(Util.getTemplate('room'));
|
|
|
|
|
this.devices = new Device.List(this.model.get('devices'));
|
|
|
|
|
},
|
|
|
|
|
render: function () {
|
|
|
|
|
this.$el.html(this.template(this.model.toJSON()));
|
|
|
|
|
_.each(this.devices.models, function (device) {
|
|
|
|
|
this.renderDevice(device);
|
|
|
|
|
}, this);
|
|
|
|
|
return this;
|
|
|
|
|
},
|
|
|
|
|
renderDevice: function (device) {
|
|
|
|
|
var deviceView = new Device.View({ model: device });
|
|
|
|
|
this.$el.append(deviceView.render().el);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2012-07-17 22:22:38 +00:00
|
|
|
|
})(app.module("room"));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|