Daniel@0: "use strict"; Daniel@0: Daniel@0: App.module("MainRegionModule", function (MainRegionModule, App, Backbone, Marionette, $, _, Logger) { Daniel@0: Daniel@0: MainRegionModule.VisInstanceView = MainRegionModule.ConfigGridChildView.extend({ Daniel@0: Daniel@0: options: { Daniel@0: state: null, Daniel@0: configGrid: null, Daniel@0: entityConfig: null, Daniel@0: viewConfig: null, Daniel@0: parentConfigGridView: null, Daniel@0: }, Daniel@0: Daniel@0: initialize: function(options) { Daniel@0: var _this = this; Daniel@0: _this.options = _.defaults(options || {}, _this.options);; Daniel@0: Daniel@0: _this._configGridType = _this.options.configGrid.getType(); Daniel@0: _this.$el.attr("data-entity-id", _this.options.entityConfig.getClientId()); Daniel@0: _this.$el.attr("data-view-id", _this.options.viewConfig.getClientId()); Daniel@0: Daniel@0: _this.$content = $.bem.generateElement("vis-instance", "content"); Daniel@0: _this.$cover = $.bem.generateElement("vis-instance", "cover"); Daniel@0: _this.$coverMessage = $.bem.generateElement("vis-instance", "cover-message"); Daniel@0: _this.$cover.append(_this.$coverMessage); Daniel@0: _this.$el.append(_this.$content, _this.$cover); Daniel@0: Daniel@0: _this._cachedEntityKind = "-"; Daniel@0: _this._cachedViewKind = "-"; Daniel@0: Daniel@0: _this.dynamicDerivedConfigDataForEntity = null; Daniel@0: _this.dynamicDerivedConfigDataForView = null; Daniel@0: _this.dynamicDerivedVisInstanceDataForBase = null; Daniel@0: _this.dynamicDerivedVisInstanceDataForOverlay = null; Daniel@0: _this.dynamicDerivedVisInstanceDataForTemp = null; Daniel@0: Daniel@0: _this._debouncedRenderIfParentConfigGridIsVisible = _.debounce(function() { Daniel@0: _this.renderIfParentConfigGridIsVisible(); Daniel@0: }, 50); Daniel@0: Daniel@0: //_this.listenTo(_this.options.configGrid, "change_selection", _this._debouncedRenderIfParentConfigGridIsVisible); Daniel@0: _this.listenTo(_this.options.entityConfig, "change:parameters", _this._debouncedRenderIfParentConfigGridIsVisible); Daniel@0: _this.listenTo(_this.options.viewConfig, "change:parameters", _this._debouncedRenderIfParentConfigGridIsVisible); Daniel@0: _this.listenTo(_this.options.entityConfig, "change:tempParameters", _this._debouncedRenderIfParentConfigGridIsVisible); Daniel@0: _this.listenTo(_this.options.viewConfig, "change:tempParameters", _this._debouncedRenderIfParentConfigGridIsVisible); Daniel@0: Daniel@0: // Make sure that the vis is in view after click Daniel@0: _this.$el.click(function() { Daniel@0: var entityClientId = _this.options.entityConfig.getClientId(); Daniel@0: var viewClientId = _this.options.viewConfig.getClientId(); Daniel@0: if (_this.options.configGrid.get("selectedEntityConfigClientId") !== entityClientId Daniel@0: || _this.options.configGrid.get("selectedViewConfigClientId") !== viewClientId Daniel@0: ) { Daniel@0: _this.options.configGrid.set({ Daniel@0: selectedEntityConfigClientId: entityClientId, Daniel@0: selectedViewConfigClientId: viewClientId Daniel@0: }); Daniel@0: } else { Daniel@0: _this.options.parentConfigGridView.scrollAccordingToSelection(); Daniel@0: } Daniel@0: }); Daniel@0: Daniel@0: }, Daniel@0: Daniel@0: remove: function() { Daniel@0: var _this = this; Daniel@0: Daniel@0: if (_this.dynamicDerivedVisInstanceDataForBase) { Daniel@0: _this.dynamicDerivedVisInstanceDataForBase.destroy(); Daniel@0: } Daniel@0: if (_this.dynamicDerivedVisInstanceDataForOverlay) { Daniel@0: _this.dynamicDerivedVisInstanceDataForOverlay.destroy(); Daniel@0: } Daniel@0: if (_this.dynamicDerivedVisInstanceDataForTemp) { Daniel@0: _this.dynamicDerivedVisInstanceDataForTemp.destroy(); Daniel@0: } Daniel@0: MainRegionModule.ConfigGridChildView.prototype.remove.apply(this, arguments); Daniel@0: }, Daniel@0: Daniel@0: setSize: function (width, height) { Daniel@0: var _this = this; Daniel@0: var $el = _this.$el; Daniel@0: var changed = false; Daniel@0: if (width != $el.width()) { Daniel@0: $el.width(width); Daniel@0: changed = true; Daniel@0: } Daniel@0: if (height != $el.height()) { Daniel@0: $el.height(height); Daniel@0: changed = true; Daniel@0: } Daniel@0: Daniel@0: if (changed) { Daniel@0: _this._cachedSizeHash = width + "|" + height; 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 view config or entity config has just been removed from the grid, Daniel@0: // but the view has not been destroyed yet Daniel@0: if (!this.options.entityConfig.getConfigGridType() || !this.options.viewConfig.getConfigGridType()) { Daniel@0: return; Daniel@0: } Daniel@0: Daniel@0: var newEntityKind = _.str.trim(_this.options.entityConfig.getParameterValue("kind")); Daniel@0: var newViewKind = _.str.trim(_this.options.viewConfig .getParameterValue("kind")); Daniel@0: var entityKindHasChanged = _this._cachedEntityKind !== newEntityKind; Daniel@0: var viewKindHasChanged = _this._cachedViewKind !== newViewKind; Daniel@0: Daniel@0: // reassign masters Daniel@0: if (entityKindHasChanged || viewKindHasChanged) { Daniel@0: _this._cachedEntityKind = newEntityKind; Daniel@0: _this._cachedViewKind = newViewKind; Daniel@0: Daniel@0: if (_this.cachedViewMaster) { Daniel@0: _this.stopListening(_this.cachedViewMaster); Daniel@0: } Daniel@0: Daniel@0: _this._cachedEntityMaster = App.RepresentationModule.getMasterForConfig(_this.options.entityConfig); Daniel@0: _this._cachedViewMaster = App.RepresentationModule.getMasterForConfig(_this.options.viewConfig); Daniel@0: _this.$content.empty(); Daniel@0: Daniel@0: _this.listenTo(_this._cachedViewMaster, "change:auxiliaryResourcesStatus", _this._debouncedRenderIfParentConfigGridIsVisible); Daniel@0: } Daniel@0: Daniel@0: // change dynamic derived config data Daniel@0: if (entityKindHasChanged) { Daniel@0: if (_this.dynamicDerivedConfigDataForEntity) { Daniel@0: _this.stopListening(_this.dynamicDerivedConfigDataForEntity); Daniel@0: } Daniel@0: _this.dynamicDerivedConfigDataForEntity = App.dynamicDerivedConfigDataProvider.get(_this.options.entityConfig); Daniel@0: _this.listenTo(_this.dynamicDerivedConfigDataForEntity, "change", _this._debouncedRenderIfParentConfigGridIsVisible); Daniel@0: } Daniel@0: Daniel@0: if (viewKindHasChanged) { Daniel@0: if (_this.dynamicDerivedConfigDataForView) { Daniel@0: _this.stopListening(_this.dynamicDerivedConfigDataForView); Daniel@0: } Daniel@0: _this.dynamicDerivedConfigDataForView = App.dynamicDerivedConfigDataProvider.get(_this.options.viewConfig); Daniel@0: _this.listenTo(_this.dynamicDerivedConfigDataForView, "change", _this._debouncedRenderIfParentConfigGridIsVisible); Daniel@0: } Daniel@0: Daniel@0: // change dynamic derived vis instance data Daniel@0: if (entityKindHasChanged || viewKindHasChanged) { Daniel@0: var dynamicDataTypes = ["Base", "Overlay", "Temp"]; Daniel@0: for (var i = 0; i < 3; i++) { Daniel@0: var propertyName = "dynamicDerivedVisInstanceDataFor" + dynamicDataTypes[i]; Daniel@0: var generatorFunctionName = "generateDynamicDerivedVisInstanceDataFor" + dynamicDataTypes[i]; Daniel@0: if (_this[propertyName]) { Daniel@0: _this.stopListening(_this[propertyName]); Daniel@0: _this[propertyName].destroy(); Daniel@0: } Daniel@0: _this[propertyName] = _this._cachedEntityMaster[generatorFunctionName](_this); Daniel@0: _this.listenTo(_this[propertyName], "change", _this._debouncedRenderIfParentConfigGridIsVisible); Daniel@0: } Daniel@0: } Daniel@0: Daniel@0: _this._cachedViewMaster.renderVisInstance(_this, deep, instant); Daniel@0: }, Daniel@0: Daniel@0: cancelPointerHighlights: function() { Daniel@0: var _this = this; Daniel@0: if (_this._cachedViewMaster) { Daniel@0: _this._cachedViewMaster.cancelVisInstancePointerHighlights(_this); Daniel@0: } Daniel@0: }, Daniel@0: }); Daniel@0: }, Logger);