bunti-node/js/modules/room.js

46 lines
1.3 KiB
JavaScript
Raw Permalink Normal View History

// 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");
// The basic person model
Room.Model = Backbone.Model.extend({
defaults: {
roomId: null,
title: 'undefined',
devices: Device.List
}
});
Room.List = Backbone.Collection.extend({
model: Room.Model
});
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);
}
});
})(app.module("room"));