annotate src/DML/MainVisBundle/Resources/assets/marionette/modules/MainRegionModule/MainRegionModule.33-VisInstanceView.js @ 1:f38015048f48 tip

Added GPL
author Daniel Wolff
date Sat, 13 Feb 2016 20:43:38 +0100
parents 493bcb69166c
children
rev   line source
Daniel@0 1 "use strict";
Daniel@0 2
Daniel@0 3 App.module("MainRegionModule", function (MainRegionModule, App, Backbone, Marionette, $, _, Logger) {
Daniel@0 4
Daniel@0 5 MainRegionModule.VisInstanceView = MainRegionModule.ConfigGridChildView.extend({
Daniel@0 6
Daniel@0 7 options: {
Daniel@0 8 state: null,
Daniel@0 9 configGrid: null,
Daniel@0 10 entityConfig: null,
Daniel@0 11 viewConfig: null,
Daniel@0 12 parentConfigGridView: null,
Daniel@0 13 },
Daniel@0 14
Daniel@0 15 initialize: function(options) {
Daniel@0 16 var _this = this;
Daniel@0 17 _this.options = _.defaults(options || {}, _this.options);;
Daniel@0 18
Daniel@0 19 _this._configGridType = _this.options.configGrid.getType();
Daniel@0 20 _this.$el.attr("data-entity-id", _this.options.entityConfig.getClientId());
Daniel@0 21 _this.$el.attr("data-view-id", _this.options.viewConfig.getClientId());
Daniel@0 22
Daniel@0 23 _this.$content = $.bem.generateElement("vis-instance", "content");
Daniel@0 24 _this.$cover = $.bem.generateElement("vis-instance", "cover");
Daniel@0 25 _this.$coverMessage = $.bem.generateElement("vis-instance", "cover-message");
Daniel@0 26 _this.$cover.append(_this.$coverMessage);
Daniel@0 27 _this.$el.append(_this.$content, _this.$cover);
Daniel@0 28
Daniel@0 29 _this._cachedEntityKind = "-";
Daniel@0 30 _this._cachedViewKind = "-";
Daniel@0 31
Daniel@0 32 _this.dynamicDerivedConfigDataForEntity = null;
Daniel@0 33 _this.dynamicDerivedConfigDataForView = null;
Daniel@0 34 _this.dynamicDerivedVisInstanceDataForBase = null;
Daniel@0 35 _this.dynamicDerivedVisInstanceDataForOverlay = null;
Daniel@0 36 _this.dynamicDerivedVisInstanceDataForTemp = null;
Daniel@0 37
Daniel@0 38 _this._debouncedRenderIfParentConfigGridIsVisible = _.debounce(function() {
Daniel@0 39 _this.renderIfParentConfigGridIsVisible();
Daniel@0 40 }, 50);
Daniel@0 41
Daniel@0 42 //_this.listenTo(_this.options.configGrid, "change_selection", _this._debouncedRenderIfParentConfigGridIsVisible);
Daniel@0 43 _this.listenTo(_this.options.entityConfig, "change:parameters", _this._debouncedRenderIfParentConfigGridIsVisible);
Daniel@0 44 _this.listenTo(_this.options.viewConfig, "change:parameters", _this._debouncedRenderIfParentConfigGridIsVisible);
Daniel@0 45 _this.listenTo(_this.options.entityConfig, "change:tempParameters", _this._debouncedRenderIfParentConfigGridIsVisible);
Daniel@0 46 _this.listenTo(_this.options.viewConfig, "change:tempParameters", _this._debouncedRenderIfParentConfigGridIsVisible);
Daniel@0 47
Daniel@0 48 // Make sure that the vis is in view after click
Daniel@0 49 _this.$el.click(function() {
Daniel@0 50 var entityClientId = _this.options.entityConfig.getClientId();
Daniel@0 51 var viewClientId = _this.options.viewConfig.getClientId();
Daniel@0 52 if (_this.options.configGrid.get("selectedEntityConfigClientId") !== entityClientId
Daniel@0 53 || _this.options.configGrid.get("selectedViewConfigClientId") !== viewClientId
Daniel@0 54 ) {
Daniel@0 55 _this.options.configGrid.set({
Daniel@0 56 selectedEntityConfigClientId: entityClientId,
Daniel@0 57 selectedViewConfigClientId: viewClientId
Daniel@0 58 });
Daniel@0 59 } else {
Daniel@0 60 _this.options.parentConfigGridView.scrollAccordingToSelection();
Daniel@0 61 }
Daniel@0 62 });
Daniel@0 63
Daniel@0 64 },
Daniel@0 65
Daniel@0 66 remove: function() {
Daniel@0 67 var _this = this;
Daniel@0 68
Daniel@0 69 if (_this.dynamicDerivedVisInstanceDataForBase) {
Daniel@0 70 _this.dynamicDerivedVisInstanceDataForBase.destroy();
Daniel@0 71 }
Daniel@0 72 if (_this.dynamicDerivedVisInstanceDataForOverlay) {
Daniel@0 73 _this.dynamicDerivedVisInstanceDataForOverlay.destroy();
Daniel@0 74 }
Daniel@0 75 if (_this.dynamicDerivedVisInstanceDataForTemp) {
Daniel@0 76 _this.dynamicDerivedVisInstanceDataForTemp.destroy();
Daniel@0 77 }
Daniel@0 78 MainRegionModule.ConfigGridChildView.prototype.remove.apply(this, arguments);
Daniel@0 79 },
Daniel@0 80
Daniel@0 81 setSize: function (width, height) {
Daniel@0 82 var _this = this;
Daniel@0 83 var $el = _this.$el;
Daniel@0 84 var changed = false;
Daniel@0 85 if (width != $el.width()) {
Daniel@0 86 $el.width(width);
Daniel@0 87 changed = true;
Daniel@0 88 }
Daniel@0 89 if (height != $el.height()) {
Daniel@0 90 $el.height(height);
Daniel@0 91 changed = true;
Daniel@0 92 }
Daniel@0 93
Daniel@0 94 if (changed) {
Daniel@0 95 _this._cachedSizeHash = width + "|" + height;
Daniel@0 96 _this._debouncedRenderIfParentConfigGridIsVisible();
Daniel@0 97 }
Daniel@0 98 },
Daniel@0 99
Daniel@0 100 render: function (deep, instant) {
Daniel@0 101 var _this = this;
Daniel@0 102
Daniel@0 103 // do not render if view config or entity config has just been removed from the grid,
Daniel@0 104 // but the view has not been destroyed yet
Daniel@0 105 if (!this.options.entityConfig.getConfigGridType() || !this.options.viewConfig.getConfigGridType()) {
Daniel@0 106 return;
Daniel@0 107 }
Daniel@0 108
Daniel@0 109 var newEntityKind = _.str.trim(_this.options.entityConfig.getParameterValue("kind"));
Daniel@0 110 var newViewKind = _.str.trim(_this.options.viewConfig .getParameterValue("kind"));
Daniel@0 111 var entityKindHasChanged = _this._cachedEntityKind !== newEntityKind;
Daniel@0 112 var viewKindHasChanged = _this._cachedViewKind !== newViewKind;
Daniel@0 113
Daniel@0 114 // reassign masters
Daniel@0 115 if (entityKindHasChanged || viewKindHasChanged) {
Daniel@0 116 _this._cachedEntityKind = newEntityKind;
Daniel@0 117 _this._cachedViewKind = newViewKind;
Daniel@0 118
Daniel@0 119 if (_this.cachedViewMaster) {
Daniel@0 120 _this.stopListening(_this.cachedViewMaster);
Daniel@0 121 }
Daniel@0 122
Daniel@0 123 _this._cachedEntityMaster = App.RepresentationModule.getMasterForConfig(_this.options.entityConfig);
Daniel@0 124 _this._cachedViewMaster = App.RepresentationModule.getMasterForConfig(_this.options.viewConfig);
Daniel@0 125 _this.$content.empty();
Daniel@0 126
Daniel@0 127 _this.listenTo(_this._cachedViewMaster, "change:auxiliaryResourcesStatus", _this._debouncedRenderIfParentConfigGridIsVisible);
Daniel@0 128 }
Daniel@0 129
Daniel@0 130 // change dynamic derived config data
Daniel@0 131 if (entityKindHasChanged) {
Daniel@0 132 if (_this.dynamicDerivedConfigDataForEntity) {
Daniel@0 133 _this.stopListening(_this.dynamicDerivedConfigDataForEntity);
Daniel@0 134 }
Daniel@0 135 _this.dynamicDerivedConfigDataForEntity = App.dynamicDerivedConfigDataProvider.get(_this.options.entityConfig);
Daniel@0 136 _this.listenTo(_this.dynamicDerivedConfigDataForEntity, "change", _this._debouncedRenderIfParentConfigGridIsVisible);
Daniel@0 137 }
Daniel@0 138
Daniel@0 139 if (viewKindHasChanged) {
Daniel@0 140 if (_this.dynamicDerivedConfigDataForView) {
Daniel@0 141 _this.stopListening(_this.dynamicDerivedConfigDataForView);
Daniel@0 142 }
Daniel@0 143 _this.dynamicDerivedConfigDataForView = App.dynamicDerivedConfigDataProvider.get(_this.options.viewConfig);
Daniel@0 144 _this.listenTo(_this.dynamicDerivedConfigDataForView, "change", _this._debouncedRenderIfParentConfigGridIsVisible);
Daniel@0 145 }
Daniel@0 146
Daniel@0 147 // change dynamic derived vis instance data
Daniel@0 148 if (entityKindHasChanged || viewKindHasChanged) {
Daniel@0 149 var dynamicDataTypes = ["Base", "Overlay", "Temp"];
Daniel@0 150 for (var i = 0; i < 3; i++) {
Daniel@0 151 var propertyName = "dynamicDerivedVisInstanceDataFor" + dynamicDataTypes[i];
Daniel@0 152 var generatorFunctionName = "generateDynamicDerivedVisInstanceDataFor" + dynamicDataTypes[i];
Daniel@0 153 if (_this[propertyName]) {
Daniel@0 154 _this.stopListening(_this[propertyName]);
Daniel@0 155 _this[propertyName].destroy();
Daniel@0 156 }
Daniel@0 157 _this[propertyName] = _this._cachedEntityMaster[generatorFunctionName](_this);
Daniel@0 158 _this.listenTo(_this[propertyName], "change", _this._debouncedRenderIfParentConfigGridIsVisible);
Daniel@0 159 }
Daniel@0 160 }
Daniel@0 161
Daniel@0 162 _this._cachedViewMaster.renderVisInstance(_this, deep, instant);
Daniel@0 163 },
Daniel@0 164
Daniel@0 165 cancelPointerHighlights: function() {
Daniel@0 166 var _this = this;
Daniel@0 167 if (_this._cachedViewMaster) {
Daniel@0 168 _this._cachedViewMaster.cancelVisInstancePointerHighlights(_this);
Daniel@0 169 }
Daniel@0 170 },
Daniel@0 171 });
Daniel@0 172 }, Logger);