Działający przycisk "Odśwież panel" (reload) :-)
[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     $('.panel-main-toolbar select', this.element.get(0)).bind('change.panel-container-view', this.selectChanged.bind(this));
14     $('.panel-main-toolbar .refresh', this.element.get(0))
15       .bind('click.panel-container-view', this.refreshButtonClicked.bind(this))
16       .attr('disabled', 'disabled');
17   },
18   
19   selectChanged: function(event) {
20     var value = $('select', this.element.get(0)).val();
21     var klass = panels[value];
22     if (this.contentView) {
23       this.contentView.dispose();
24       this.contentView = null;
25     }
26     this.contentView = new klass($('.content-view', 
27       this.element.get(0)), this.model.contentModels[value], this);
28     $('.panel-main-toolbar .refresh', this.element.get(0)).attr('disabled', null);
29   },
30   
31   refreshButtonClicked: function(event) {
32     if (this.contentView) {
33       console.log('refreshButtonClicked');
34       this.contentView.reload();
35     }
36   },
37   
38   dispose: function() {
39     $('.panel-main-toolbar .refresh', this.element.get(0)).unbind('click.panel-container-view');
40     $('.panel-main-toolbar select', this.element.get(0)).unbind('change.panel-container-view');
41     this._super();
42   }
43 });
44