4823343942b90011a9c18f1c1e0e41998e82eee8
[redakcja.git] / project / static / js / views / panel_container.js
1 /*globals Class render_template panels*/
2
3 var PanelContainerView = Class.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 view = panels[$('select', this.element.get(0)).val()];
20     var klass = view.klass;
21     console.log(view, klass);
22     if (this.contentView) {
23       this.contentView.dispose();
24       this.contentView = null;
25     }
26     this.contentView = new klass($('.content-view', this.element.get(0)), this.model);
27     console.log(this.contentView);
28   },
29   
30   dispose: function() {
31     $('select', this.element.get(0)).unbind('change.panel-container-view');
32   }
33 });
34