Daniel@0: "use strict"; Daniel@0: Daniel@0: App.module("MainRegionModule", function (MainRegionModule, App, Backbone, Marionette, $, _, Logger) { Daniel@0: Daniel@0: MainRegionModule.ConfigHeaderView = MainRegionModule.ConfigGridChildView.extend({ Daniel@0: Daniel@0: options: { Daniel@0: dimension: null, Daniel@0: parentState: null, Daniel@0: configGrid: null, Daniel@0: config: null, Daniel@0: parentConfigGridView: null, Daniel@0: }, Daniel@0: Daniel@0: _dimensionIsEntity: false, Daniel@0: _dimensionIsView: false, Daniel@0: Daniel@0: initialize: function(options) { Daniel@0: var _this = this; Daniel@0: Daniel@0: _this.options = _.defaults(options || {}, _this.options); Daniel@0: Daniel@0: _this._cachedConfigGridType = options.configGrid.getType(); Daniel@0: _this._cachedKind = "-"; Daniel@0: _this._cachedMaster = null; Daniel@0: Daniel@0: _this.$el.disableSelection(); Daniel@0: Daniel@0: _this.dynamicDerivedConfigData = null; Daniel@0: Daniel@0: if (_this.options.dimension === "entity") { Daniel@0: _this._dimensionIsEntity = true; Daniel@0: } else { Daniel@0: _this._dimensionIsView = true; Daniel@0: } Daniel@0: Daniel@0: // _this._debouncedRenderIfParentConfigGridIsVisible = _.debounce(function() { Daniel@0: // _this.renderIfParentConfigGridIsVisible(); Daniel@0: // }, 50); Daniel@0: _this._debouncedRenderIfParentConfigGridIsVisible = _this.renderIfParentConfigGridIsVisible; Daniel@0: Daniel@0: _this.listenTo(_this.options.configGrid, "change_selection", _this._debouncedRenderIfParentConfigGridIsVisible); Daniel@0: _this.listenTo(_this.options.configGrid, "change_layout", _this._debouncedRenderIfParentConfigGridIsVisible); Daniel@0: _this.listenTo(_this.options.config, "change:parametersOrPlannedParameterUpdates", _this._debouncedRenderIfParentConfigGridIsVisible); Daniel@0: Daniel@0: _this._$background = $.bem.generateElement("config-grid-cells", _this._dimensionIsEntity ? "entity-header-background" : "view-header-background"); Daniel@0: _this.$el.append(_this._$background); Daniel@0: Daniel@0: _this.$el.click(function(event) { Daniel@0: if (_this._dimensionIsEntity) { Daniel@0: _this.options.parentConfigGridView.ignoreAxisOnNextScroll(false, true); Daniel@0: } else { Daniel@0: _this.options.parentConfigGridView.ignoreAxisOnNextScroll(true, false); Daniel@0: } Daniel@0: if (_this._cachedSelected) { Daniel@0: _this.options.parentConfigGridView.scrollAccordingToSelection(); Daniel@0: } else { Daniel@0: _this.options.configGrid.set(_this._dimensionIsEntity ? "selectedEntityConfigClientId" : "selectedViewConfigClientId", _this.options.config.getClientId()); Daniel@0: } Daniel@0: event.stopPropagation(); Daniel@0: event.preventDefault(); Daniel@0: }); Daniel@0: Daniel@0: _this._cachedSelected = false; Daniel@0: _this._cachedHashForParameters = null; Daniel@0: }, Daniel@0: Daniel@0: setSize: function (widthOrHeight) { Daniel@0: var _this = this; Daniel@0: Daniel@0: var $el = _this.$el; Daniel@0: var changed = false; Daniel@0: if (_this._dimensionIsEntity) { Daniel@0: if (widthOrHeight != $el.width()) { Daniel@0: $el.width(widthOrHeight); Daniel@0: changed = true; Daniel@0: } Daniel@0: } else { Daniel@0: return; Daniel@0: if (widthOrHeight != $el.height()) { Daniel@0: $el.height(widthOrHeight); Daniel@0: changed = true; Daniel@0: } Daniel@0: } Daniel@0: Daniel@0: if (changed) { Daniel@0: _this._debouncedRenderIfParentConfigGridIsVisible(); Daniel@0: } Daniel@0: }, Daniel@0: Daniel@0: render: function (deep, instant) { Daniel@0: var _this = this; Daniel@0: Daniel@0: // do not render if config has just been removed from the grid, Daniel@0: // but the view has not been destroyed yet Daniel@0: if (!_this.options.config.getConfigGridType()) { Daniel@0: return; Daniel@0: } Daniel@0: Daniel@0: // modifier: selected or not Daniel@0: var newSelected = _this._dimensionIsEntity Daniel@0: ? _this.options.configGrid.getSelectedEntityConfig() == _this.options.config Daniel@0: : _this.options.configGrid.getSelectedViewConfig() == _this.options.config; Daniel@0: Daniel@0: if (newSelected !== _this._cachedSelected) { Daniel@0: if (newSelected) { Daniel@0: _this.$el.addClass(_this._dimensionIsEntity ? "config-grid-cells__entity-header_selected" : "config-grid-cells__view-header_selected"); Daniel@0: } else { Daniel@0: _this.$el.removeClass(_this._dimensionIsEntity ? "config-grid-cells__entity-header_selected" : "config-grid-cells__view-header_selected"); Daniel@0: } Daniel@0: _this._cachedSelected = newSelected; Daniel@0: }; Daniel@0: Daniel@0: // kind Daniel@0: var newKind = _this.options.config.getParameterValue("kind"); Daniel@0: if (newKind !== _this._cachedKind) { Daniel@0: _this._cachedKind = newKind; Daniel@0: _this._cachedMaster = App.RepresentationModule.getMasterForConfig(_this.options.config); Daniel@0: Daniel@0: // swap derived config data when the kind changes (i.e. the master changes) Daniel@0: if (_this.dynamicDerivedConfigData) { Daniel@0: _this.stopListening(_this.dynamicDerivedConfigData); Daniel@0: } Daniel@0: _this.dynamicDerivedConfigData = App.dynamicDerivedConfigDataProvider.get(_this.options.config); Daniel@0: _this.listenTo(_this.dynamicDerivedConfigData, "change", _this._debouncedRenderIfParentConfigGridIsVisible); Daniel@0: Daniel@0: _this.$el.setMod("config-grid-cells", "entity-header", "kind", newKind ? newKind : false); Daniel@0: } Daniel@0: Daniel@0: // content Daniel@0: _this._cachedMaster.renderHeaderContent(this, instant); Daniel@0: }, Daniel@0: }); Daniel@0: }, Logger);