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