X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/3bf45c83c84f9e7a1c5f2dafd64d812c987037e5..de93104a2513acc5a378496c6bf6ab7ed0d45d60:/project/static/js/views/panel_container.js diff --git a/project/static/js/views/panel_container.js b/project/static/js/views/panel_container.js index 66683dd2..6dbddd98 100644 --- a/project/static/js/views/panel_container.js +++ b/project/static/js/views/panel_container.js @@ -1,28 +1,48 @@ -/*globals Class render_template panels*/ +/*globals View render_template panels*/ -var PanelContainerView = Class.extend({ +var PanelContainerView = View.extend({ + _className: 'PanelContainerView', element: null, + model: null, template: 'panel-container-view-template', contentView: null, - init: function(element, template) { - this.element = $(element); - this.template = template || this.template; - - this.element.html(render_template(this.template, {panels: panels})); - $('select', this.element.get(0)).bind('change.panel-container-view', this.selectChanged.bind(this)); + init: function(element, model, template) { + this._super(element, model, template); + + $('.panel-main-toolbar select', this.element.get(0)).bind('change.panel-container-view', this.selectChanged.bind(this)); + $('.panel-main-toolbar .refresh', this.element.get(0)) + .bind('click.panel-container-view', this.refreshButtonClicked.bind(this)) + .attr('disabled', 'disabled'); }, selectChanged: function(event) { - var view = panels[$('select', this.element.get(0)).val()]; - var klass = view.klass; - console.log(view, klass); - this.contentView = new klass($('.content-view', this.element.get(0))); - console.log(this.contentView); + var value = $('select', this.element.get(0)).val(); + var klass = panels[value]; + + if (this.contentView) { + this.contentView.dispose(); + this.contentView = null; + } + + if( value != 'empty') { + this.contentView = new klass($('.content-view', + this.element.get(0)), this.model.contentModels[value], this); + $('.panel-main-toolbar .refresh', this.element.get(0)).attr('disabled', null); + } + }, + + refreshButtonClicked: function(event) { + if (this.contentView) { + console.log('refreshButtonClicked'); + this.contentView.reload(); + } }, dispose: function() { - $('select', this.element.get(0)).unbind('change.panel-container-view'); + $('.panel-main-toolbar .refresh', this.element.get(0)).unbind('click.panel-container-view'); + $('.panel-main-toolbar select', this.element.get(0)).unbind('change.panel-container-view'); + this._super(); } });