Własna implementacja wzorca obserwator.
[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 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     this._super();
33   }
34 });
35