e4950ba87c62640c553f27ffbbf255487c061267
[redakcja.git] / project / static / js / views / panel_container.js
1 /*globals View render_template panels*/
2
3 var PanelContainerView = View.extend({
4   element: null,
5   model: null,
6   template: 'panel-container-view-template',
7   contentView: null,
8   
9   init: function(element, model, template) {
10     this.element = $(element);
11     this.model = model;
12     this.template = template || this.template;
13     
14     this.element.html(render_template(this.template, {panels: panels}));
15     $('select', this.element.get(0)).bind('change.panel-container-view', this.selectChanged.bind(this));
16   },
17   
18   selectChanged: function(event) {
19     var value = $('select', this.element.get(0)).val();
20     var klass = panels[value];
21     if (this.contentView) {
22       this.contentView.dispose();
23       this.contentView = null;
24     }
25     this.contentView = new klass($('.content-view', 
26       this.element.get(0)), this.model.contentModels[value]);
27   },
28   
29   dispose: function() {
30     $('select', this.element.get(0)).unbind('change.panel-container-view');
31     this._super();
32   }
33 });
34