annotate src/DML/MainVisBundle/Resources/assets/marionette/modules/MainRegionModule/MainRegionModule.20-ConfigGridCellsView.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.ConfigGridCellsView = MainRegionModule.ConfigGridChildView.extend({
Daniel@0 6
Daniel@0 7 options: {
Daniel@0 8 state: null,
Daniel@0 9 configGrid: null,
Daniel@0 10 parentConfigGridView: null,
Daniel@0 11 scrollAnimationMinSpeed: 100,
Daniel@0 12 scrollAnimationBaseSpeed: 400,
Daniel@0 13 scrollAnimationBaseDistance: 500,
Daniel@0 14 desiredPaddingAroundVisInstanceOnScroll: {
Daniel@0 15 left: 35,
Daniel@0 16 top: 20,
Daniel@0 17 right: 35,
Daniel@0 18 bottom: 33,
Daniel@0 19 },
Daniel@0 20 enableFixedHeaders: true, // headers become fixed when scrolling
Daniel@0 21 },
Daniel@0 22
Daniel@0 23 _logger: null,
Daniel@0 24
Daniel@0 25 _$entityHeadersContainer: null,
Daniel@0 26 _$entityHeadersBlind: null,
Daniel@0 27 _$viewHeadersContainer: null,
Daniel@0 28 _$viewHeadersBlind: null,
Daniel@0 29 _$visInstancesContainer: null,
Daniel@0 30 _$cornerBlind: null,
Daniel@0 31 _$fixedContainer: null,
Daniel@0 32
Daniel@0 33 _$entityAdder: null,
Daniel@0 34 _$viewAdder: null,
Daniel@0 35
Daniel@0 36 _distanceBetweenEntities: 10,
Daniel@0 37 _distanceBetweenViews: 10,
Daniel@0 38 _viewHeaderHeight: 0,
Daniel@0 39 _entityAdderWidth: 0,
Daniel@0 40 _viewAdderHeight: 0,
Daniel@0 41 _cachedMinSpaceWidth: 0,
Daniel@0 42 _cachedMinSpaceHeight: 0,
Daniel@0 43 _spacePadding: null, // top, right, bottom, left, h = l + r, v = t + b
Daniel@0 44 _scrollLeftBeforeLatestSelectionUpdate: 0,
Daniel@0 45 _scrollTopBeforeLatestSelectionUpdate: 0,
Daniel@0 46
Daniel@0 47 _ignoreXOnNextScroll: false,
Daniel@0 48 _ignoreYOnNextScroll: false,
Daniel@0 49 _latestChangeWasAReset: false,
Daniel@0 50
Daniel@0 51 _cachedScrollPosGridHash: null,
Daniel@0 52 _cachedScrollPosSelection: null,
Daniel@0 53 _cachedScrollPosX: null,
Daniel@0 54 _cachedScrollPosY: null,
Daniel@0 55
Daniel@0 56 _cachedSelectedEntityConfigClientId: null, // string
Daniel@0 57 _cachedSelectedViewConfigClientId: null, // string
Daniel@0 58
Daniel@0 59 _cachedEntityHeaderViewsByClientId: {}, // string: Backbone view
Daniel@0 60 _cachedViewHeaderViewsByClientId: {}, // string: Backbone view
Daniel@0 61 _cachedVisInstanceViewsByClientIdPair: {}, // string: Backbone view
Daniel@0 62
Daniel@0 63 _cachedEntityConfigClientIds: null, // [string] (keys of _cachedEntityHeaderViewsByClientId)
Daniel@0 64 _cachedViewConfigClientIds: null, // [string] (keys of _cachedViewHeaderViewsByClientId)
Daniel@0 65
Daniel@0 66 _cachedEntityWidth: null,
Daniel@0 67 _cachedViewContentHeights: null,
Daniel@0 68
Daniel@0 69 initialize: function(options) {
Daniel@0 70 var _this = this;
Daniel@0 71
Daniel@0 72 _this._logger = Logger.get("ConfigGridCellsView");
Daniel@0 73 //_this._logger.setLevel(Logger.DEBUG);
Daniel@0 74
Daniel@0 75 _this.options = _.defaults(options || {}, this.options);
Daniel@0 76 if (_this.options.enableFixedHeaders === null) {
Daniel@0 77 _this.options.enableFixedHeaders = (navigator.userAgent.indexOf("afari") >= 0 && navigator.userAgent.indexOf("Chrom") == -1) || navigator.userAgent.indexOf("MSIE") >= 0 || navigator.userAgent.indexOf("MATM") >= 0 || navigator.userAgent.indexOf("Trident") >= 0;
Daniel@0 78 }
Daniel@0 79
Daniel@0 80 var configGridType = _this.options.configGrid.getType();
Daniel@0 81
Daniel@0 82 _this.$el.empty();
Daniel@0 83
Daniel@0 84 _this._$entityHeadersContainer = $.bem.generateElement("config-grid-cells", "entity-headers-container");
Daniel@0 85 _this._$entityHeadersBlind = $.bem.generateElement("config-grid-cells", "entity-headers-blind");
Daniel@0 86 _this._$entityHeadersContainer.append(_this._$entityHeadersBlind);
Daniel@0 87
Daniel@0 88 _this._$viewHeadersContainer = $.bem.generateElement("config-grid-cells", "view-headers-container");
Daniel@0 89 _this._$viewHeadersBlind = $.bem.generateElement("config-grid-cells", "view-headers-blind");
Daniel@0 90 _this._$viewAdder = $.bem.generateElement("config-grid-cells", "view-header", ["kind_adder"]);
Daniel@0 91 _this._$viewHeadersContainer.append(_this._$viewHeadersBlind, _this._$viewAdder);
Daniel@0 92
Daniel@0 93 _this._$visInstancesContainer = $.bem.generateElement("config-grid-cells", "vis-instances-container");
Daniel@0 94
Daniel@0 95 _this._$cornerBlind = $.bem.generateElement("config-grid-cells", "corner-blind");
Daniel@0 96
Daniel@0 97 _this._$space = $.bem.generateElement("config-grid-cells", "space");
Daniel@0 98
Daniel@0 99 _this._$containerOfScrollable = $.bem.generateElement("config-grid-cells", "container", ["position_scrollable"]);
Daniel@0 100 _this._$containerOfFixed = $.bem.generateElement("config-grid-cells", "container", ["position_fixed"]);
Daniel@0 101
Daniel@0 102 // Entity and collection adders
Daniel@0 103 if (configGridType == "collection") {
Daniel@0 104 _this._$entityAdder = $.bem.generateElement("config-grid-cells", "entity-header", ["kind_adder"]);
Daniel@0 105 var $entityAdderBackground = $.bem.generateElement("config-grid-cells", "entity-header-background");
Daniel@0 106 var $entityAdderLabel = $.bem.generateElement("config-grid-cells", "entity-header-label");
Daniel@0 107 $entityAdderLabel.html(Backbone.Marionette.TemplateCache.get("#config-grid_collection__entity-adder-label"));
Daniel@0 108 _this._$entityAdder.append($entityAdderBackground, $entityAdderLabel);
Daniel@0 109 _this._$entityHeadersContainer.append(_this._$entityAdder);
Daniel@0 110 _this._$entityAdder.click(function() {
Daniel@0 111 _this.options.configGrid.addEntityAndSelectIt(new App.ContextModule.Config());
Daniel@0 112 });
Daniel@0 113 } else {
Daniel@0 114 _this._$entityAdder = $();
Daniel@0 115 }
Daniel@0 116 _this._$viewAdder = $.bem.generateElement("config-grid-cells", "view-header", ["kind_adder"]);
Daniel@0 117 var $viewAdderBackground = $.bem.generateElement("config-grid-cells", "view-header-background");
Daniel@0 118 var $viewAdderLabel = $.bem.generateElement("config-grid-cells", "view-header-label");
Daniel@0 119 $viewAdderLabel.html(Backbone.Marionette.TemplateCache.get("#config-grid__view-adder-label"));
Daniel@0 120 _this._$viewAdder.append($viewAdderBackground, $viewAdderLabel);
Daniel@0 121 _this._$viewHeadersContainer.append(_this._$viewAdder);
Daniel@0 122 _this._$viewAdder.click(function() {
Daniel@0 123 _this.options.configGrid.addViewAndSelectIt(new App.ContextModule.Config());
Daniel@0 124 });
Daniel@0 125
Daniel@0 126 _this._$entityHeadersContainer.append();
Daniel@0 127 _this._$viewHeadersContainer.append();
Daniel@0 128 _this._$space.append(
Daniel@0 129 _this._$visInstancesContainer,
Daniel@0 130 _this._$entityHeadersContainer,
Daniel@0 131 _this._$viewHeadersContainer,
Daniel@0 132 _this._$cornerBlind
Daniel@0 133 );
Daniel@0 134
Daniel@0 135 _this._$containerOfScrollable.append(_this._$space);
Daniel@0 136 _this.$el.append(_this._$containerOfScrollable, _this._$containerOfFixed);
Daniel@0 137
Daniel@0 138 // extract some size- and position-related constants
Daniel@0 139 _this._viewHeaderHeight = _this._$viewAdder.height();
Daniel@0 140 _this._entityAdderWidth = _this._$entityAdder.width();
Daniel@0 141 _this._viewAdderHeight = _this._viewHeaderHeight;
Daniel@0 142 if (!_this._entityAdderWidth) {
Daniel@0 143 _this._entityAdderWidth = -_this._distanceBetweenEntities;
Daniel@0 144 }
Daniel@0 145
Daniel@0 146 // When defining space padding, it is sometimes necessary to wait a bit
Daniel@0 147 // A grid that is on the "back side of the card" may sometimes become blank when scrolling otherwise
Daniel@0 148 _this._spacePadding = {};
Daniel@0 149 var interval;
Daniel@0 150 var setSpaceInterval = function() {
Daniel@0 151 if (_this._$space.css("padding-top")) {
Daniel@0 152 _this._spacePadding.top = parseInt(_this._$space.css("padding-top"), 10);
Daniel@0 153 _this._spacePadding.right = parseInt(_this._$space.css("padding-right"), 10);
Daniel@0 154 _this._spacePadding.bottom = parseInt(_this._$space.css("padding-bottom"), 10);
Daniel@0 155 _this._spacePadding.left = parseInt(_this._$space.css("padding-left"), 10);
Daniel@0 156 _this._spacePadding.h = _this._spacePadding.left + _this._spacePadding.right;
Daniel@0 157 _this._spacePadding.v = _this._spacePadding.top + _this._spacePadding.bottom;
Daniel@0 158 //_this._toggleFixedHeadersIfNeeded(false);
Daniel@0 159 _this._updateDemensionsForContainerOfFixed();
Daniel@0 160 clearInterval(interval);
Daniel@0 161 }
Daniel@0 162 };
Daniel@0 163 if (_this._$space.css("padding-top")) {
Daniel@0 164 setSpaceInterval();
Daniel@0 165 } else {
Daniel@0 166 interval = setInterval(setSpaceInterval, 50);
Daniel@0 167 }
Daniel@0 168
Daniel@0 169 // subscribe to events
Daniel@0 170 _this.listenTo(_this.options.configGrid, "change", _this.renderIfParentConfigGridIsVisible);
Daniel@0 171
Daniel@0 172 var isSafari = navigator.userAgent.indexOf("afari") >= 0;
Daniel@0 173 var isChrome = navigator.userAgent.indexOf("rome") >= 0;
Daniel@0 174 var isScrolling = false;
Daniel@0 175 if (_this.options.enableFixedHeaders) {
Daniel@0 176 _this._$containerOfScrollable.mousewheel(_.debounce(function(event) {
Daniel@0 177 _this._toggleFixedHeadersIfNeeded(true);
Daniel@0 178
Daniel@0 179 var visInstanceViews = _.values(_this._cachedVisInstanceViewsByClientIdPair);
Daniel@0 180 for (var i = visInstanceViews.length - 1; i >= 0; --i) {
Daniel@0 181 visInstanceViews[i].cancelPointerHighlights();
Daniel@0 182 }
Daniel@0 183
Daniel@0 184 App.TooltipModule.update();
Daniel@0 185 if (isSafari || isChrome) {
Daniel@0 186 _this._$containerOfScrollable.scrollLeft(_this._$containerOfScrollable.scrollLeft() + event.deltaX);
Daniel@0 187 _this._$containerOfScrollable.scrollTop (_this._$containerOfScrollable.scrollTop() - event.deltaY);
Daniel@0 188 event.preventDefault();
Daniel@0 189 }
Daniel@0 190 }, 50, true));
Daniel@0 191 _this._$containerOfScrollable.mousewheel(_.debounce(function(event) {
Daniel@0 192 if (!isScrolling) {
Daniel@0 193 _this._toggleFixedHeadersIfNeeded(false);
Daniel@0 194 }
Daniel@0 195 }, 200));
Daniel@0 196 }
Daniel@0 197
Daniel@0 198 _this._$containerOfScrollable.scroll(function(event) {
Daniel@0 199 if (!isScrolling) {
Daniel@0 200 isScrolling = true;
Daniel@0 201 }
Daniel@0 202 _this._toggleFixedHeadersIfNeeded(true);
Daniel@0 203 });
Daniel@0 204
Daniel@0 205 _this._$containerOfScrollable.scroll(_.debounce(function(event) {
Daniel@0 206 _this._toggleFixedHeadersIfNeeded(false);
Daniel@0 207 _this._reviseSpaceSize();
Daniel@0 208 isScrolling = false;
Daniel@0 209 _this._updateCachedScroll();
Daniel@0 210 }, 200));
Daniel@0 211
Daniel@0 212 $(window).resize(_.throttle(function() {
Daniel@0 213 _this._reviseSpaceSize();
Daniel@0 214 _this._updateDemensionsForContainerOfFixed();
Daniel@0 215 }, 100));
Daniel@0 216 _this._toggleFixedHeadersIfNeeded(false);
Daniel@0 217 _this._updateDemensionsForContainerOfFixed();
Daniel@0 218
Daniel@0 219 // Restore and save precise scroll position of the currently selected entity and view
Daniel@0 220 _this._cachedScrollPosGridHash = App.DataModule.Storage.getStrCache(MainRegionModule, _.str.sprintf("scroll-pos-grid-hash_%s", configGridType));
Daniel@0 221 _this._cachedScrollPosSelection = App.DataModule.Storage.getStrCache(MainRegionModule, _.str.sprintf("scroll-pos-selection_%s", configGridType));
Daniel@0 222 _this._cachedScrollPosX = 1 * App.DataModule.Storage.getStrCache(MainRegionModule, _.str.sprintf("scroll-pos-x_%s", configGridType));
Daniel@0 223 _this._cachedScrollPosY = 1 * App.DataModule.Storage.getStrCache(MainRegionModule, _.str.sprintf("scroll-pos-y_%s", configGridType));
Daniel@0 224
Daniel@0 225 $(window).unload(function() {
Daniel@0 226 App.DataModule.Storage.setStrCache(MainRegionModule, _.str.sprintf("scroll-pos-grid-hash_%s", configGridType), _this._cachedScrollPosGridHash);
Daniel@0 227 App.DataModule.Storage.setStrCache(MainRegionModule, _.str.sprintf("scroll-pos-selection_%s", configGridType), _this._cachedScrollPosSelection);
Daniel@0 228 App.DataModule.Storage.setStrCache(MainRegionModule, _.str.sprintf("scroll-pos-x_%s", configGridType), "" + _this._cachedScrollPosX);
Daniel@0 229 App.DataModule.Storage.setStrCache(MainRegionModule, _.str.sprintf("scroll-pos-y_%s", configGridType), "" + _this._cachedScrollPosY);
Daniel@0 230 });
Daniel@0 231
Daniel@0 232 },
Daniel@0 233
Daniel@0 234 render: function (deep, instant) {
Daniel@0 235 var _this = this;
Daniel@0 236
Daniel@0 237 _this._updateLayout(deep, instant);
Daniel@0 238 _this._updateSelection(deep, instant);
Daniel@0 239 if (deep) {
Daniel@0 240 _this._reviseSpaceSize();
Daniel@0 241 _this._updateDemensionsForContainerOfFixed();
Daniel@0 242 }
Daniel@0 243 _this._adjustToScrollPos(deep, instant);
Daniel@0 244 _this.scrollAccordingToSelection(deep, instant);
Daniel@0 245
Daniel@0 246 if (deep) {
Daniel@0 247 var entityHeaderViews = _.values(_this._cachedEntityHeaderViewsByClientId);
Daniel@0 248 for (var i = entityHeaderViews.length - 1; i >= 0; --i) {
Daniel@0 249 entityHeaderViews[i].render(deep, instant);
Daniel@0 250 }
Daniel@0 251
Daniel@0 252 var viewHeaderViews = _.values(_this._cachedViewHeaderViewsByClientId);
Daniel@0 253 for (var i = viewHeaderViews.length - 1; i >= 0; --i) {
Daniel@0 254 viewHeaderViews[i].render(deep, instant);
Daniel@0 255 }
Daniel@0 256
Daniel@0 257 var visInstanceViews = _.values(_this._cachedVisInstanceViewsByClientIdPair);
Daniel@0 258 for (var i = visInstanceViews.length - 1; i >= 0; --i) {
Daniel@0 259 visInstanceViews[i].render(deep, instant);
Daniel@0 260 }
Daniel@0 261 };
Daniel@0 262 },
Daniel@0 263
Daniel@0 264 getEntityWidth: function() {
Daniel@0 265 var _this = this;
Daniel@0 266 return (_this.options.configGrid.get("entityWidth") || App.options.defaultEntityWidth) * 1;
Daniel@0 267 },
Daniel@0 268
Daniel@0 269 _updateLayout: function(deep, instant) {
Daniel@0 270 var _this = this;
Daniel@0 271
Daniel@0 272 // Check if entities of views have changed
Daniel@0 273 var entityListHasChanged = false;
Daniel@0 274 var viewListHasChanged = false;
Daniel@0 275 var newEntityConfigs = _this.options.configGrid.get("entityConfigs");
Daniel@0 276 var newViewConfigs = _this.options.configGrid.get("viewConfigs");
Daniel@0 277 var newEntityConfigClientIds = _.pluck(newEntityConfigs.models, "cid");
Daniel@0 278 var newViewConfigClientIds = _.pluck(newViewConfigs.models, "cid");
Daniel@0 279
Daniel@0 280 _this._scrollLeftBeforeLatestLayoutUpdate = _this.$el.scrollLeft();
Daniel@0 281 _this._scrollTopBeforeLatestLayoutUpdate = _this.$el.scrollTop();
Daniel@0 282
Daniel@0 283 if (_this._cachedEntityConfigClientIds === null) {
Daniel@0 284 entityListHasChanged = true;
Daniel@0 285 viewListHasChanged = true;
Daniel@0 286 _this._cachedEntityConfigClientIds = [];
Daniel@0 287 _this._cachedViewConfigClientIds = [];
Daniel@0 288 }
Daniel@0 289
Daniel@0 290 var createdEntityConfigClientIds = _.difference(newEntityConfigClientIds, _this._cachedEntityConfigClientIds);
Daniel@0 291 var createdViewConfigClientIds = _.difference(newViewConfigClientIds, _this._cachedViewConfigClientIds);
Daniel@0 292 var removedEntityConfigClientIds = _.difference(_this._cachedEntityConfigClientIds, newEntityConfigClientIds);
Daniel@0 293 var removedViewConfigClientIds = _.difference(_this._cachedViewConfigClientIds, newViewConfigClientIds);
Daniel@0 294
Daniel@0 295 _this._latestChangeWasAReset = false;
Daniel@0 296
Daniel@0 297 if (createdEntityConfigClientIds.length + removedEntityConfigClientIds.length == 1) {
Daniel@0 298 _this._ignoreYOnNextScroll = true;
Daniel@0 299 }
Daniel@0 300 if (createdViewConfigClientIds.length + removedViewConfigClientIds.length == 1) {
Daniel@0 301 _this._ignoreXOnNextScroll = true;
Daniel@0 302 }
Daniel@0 303
Daniel@0 304 if (!_.isEqual(newEntityConfigClientIds, _this._cachedEntityConfigClientIds)) {
Daniel@0 305 entityListHasChanged = true;
Daniel@0 306 }
Daniel@0 307 if (!_.isEqual(newViewConfigClientIds, _this._cachedViewConfigClientIds)) {
Daniel@0 308 viewListHasChanged = true;
Daniel@0 309 }
Daniel@0 310
Daniel@0 311 if ((entityListHasChanged && createdEntityConfigClientIds.length + removedEntityConfigClientIds.length > 1)
Daniel@0 312 || (viewListHasChanged && createdViewConfigClientIds.length + removedViewConfigClientIds.length > 1)) {
Daniel@0 313 _this._latestChangeWasAReset = true;
Daniel@0 314 _this._ignoreXOnNextScroll = false;
Daniel@0 315 _this._ignoreYOnNextScroll = false;
Daniel@0 316 }
Daniel@0 317
Daniel@0 318
Daniel@0 319 var newEntityHeaderViewsByClientId = _this._cachedEntityHeaderViewsByClientId;
Daniel@0 320 var newViewHeaderViewsByClientId = _this._cachedViewHeaderViewsByClientId;
Daniel@0 321 var newVisInstanceViewsByClientIdPair = _this._cachedVisInstanceViewsByClientIdPair;
Daniel@0 322 var viewHeaderViewsToRender = [];
Daniel@0 323 var entityHeaderViewsToRender = [];
Daniel@0 324 var visInstanceViewsToRender = [];
Daniel@0 325
Daniel@0 326 // Replacement of entity headers if needed
Daniel@0 327 if (entityListHasChanged) {
Daniel@0 328 newEntityHeaderViewsByClientId = {};
Daniel@0 329 for (var i = 0; i < newEntityConfigClientIds.length; i++) {
Daniel@0 330 var currentEntityClientId = newEntityConfigClientIds[i];
Daniel@0 331
Daniel@0 332 // Look for an existing entity header view
Daniel@0 333 var entityHeaderView = _this._cachedEntityHeaderViewsByClientId[currentEntityClientId];
Daniel@0 334
Daniel@0 335 // Create a new entity header if it does not exist
Daniel@0 336 if (!entityHeaderView) {
Daniel@0 337 _this._logger.debug("generate entity header ", currentEntityClientId);
Daniel@0 338 entityHeaderView = _this._generateEntityHeaderView(newEntityConfigs.get(currentEntityClientId));
Daniel@0 339 entityHeaderViewsToRender.push(entityHeaderView);
Daniel@0 340 _this._$entityHeadersContainer.append(entityHeaderView.el);
Daniel@0 341 }
Daniel@0 342 newEntityHeaderViewsByClientId[currentEntityClientId] = entityHeaderView;
Daniel@0 343 }
Daniel@0 344
Daniel@0 345 // Remove entity header views that are no longer needed
Daniel@0 346 // The order of the views does not matter as the right layout is achieved with absolute positioning
Daniel@0 347 for (var i = removedEntityConfigClientIds.length - 1; i >= 0; --i) {
Daniel@0 348 _this._cachedEntityHeaderViewsByClientId[removedEntityConfigClientIds[i]].remove();
Daniel@0 349 App.dynamicDerivedConfigDataProvider.retire(removedEntityConfigClientIds[i]);
Daniel@0 350 }
Daniel@0 351 } else {
Daniel@0 352 newEntityHeaderViewsByClientId = _this._cachedEntityHeaderViewsByClientId;
Daniel@0 353 }
Daniel@0 354
Daniel@0 355 // Replacement of view headers if needed
Daniel@0 356 if (viewListHasChanged) {
Daniel@0 357 newViewHeaderViewsByClientId = {};
Daniel@0 358 for (var i = 0; i < newViewConfigClientIds.length; i++) {
Daniel@0 359 var currentViewClientId = newViewConfigClientIds[i];
Daniel@0 360
Daniel@0 361 // Look for an existing entity header
Daniel@0 362 var viewHeaderView = _this._cachedViewHeaderViewsByClientId[currentViewClientId];
Daniel@0 363
Daniel@0 364 // Create a new view header if it does not exist
Daniel@0 365 if (!viewHeaderView) {
Daniel@0 366 _this._logger.debug("generate view header ", currentViewClientId);
Daniel@0 367 viewHeaderView = _this._generateViewHeaderView(newViewConfigs.get(currentViewClientId));
Daniel@0 368 viewHeaderViewsToRender.push(viewHeaderView);
Daniel@0 369 _this._$viewHeadersContainer.append(viewHeaderView.el);
Daniel@0 370 }
Daniel@0 371 newViewHeaderViewsByClientId[currentViewClientId] = viewHeaderView;
Daniel@0 372 }
Daniel@0 373
Daniel@0 374 // Remove entity header views that are no longer needed
Daniel@0 375 // The order of the views does not matter as the right layout is achieved with absolute positioning
Daniel@0 376 for (var i = removedViewConfigClientIds.length - 1; i >= 0; --i) {
Daniel@0 377 _this._cachedViewHeaderViewsByClientId[removedViewConfigClientIds[i]].remove();
Daniel@0 378 App.dynamicDerivedConfigDataProvider.retire(removedViewConfigClientIds[i]);
Daniel@0 379 }
Daniel@0 380 } else {
Daniel@0 381 newViewHeaderViewsByClientId = _this._cachedViewHeaderViewsByClientId;
Daniel@0 382 }
Daniel@0 383
Daniel@0 384 // Replacement of vis instances
Daniel@0 385 if (viewListHasChanged || entityListHasChanged) {
Daniel@0 386 newVisInstanceViewsByClientIdPair = {};
Daniel@0 387 for (var i = 0; i < newEntityConfigClientIds.length; i++) {
Daniel@0 388 var currentEntityClientId = newEntityConfigClientIds[i];
Daniel@0 389
Daniel@0 390 for (var j = 0; j < newViewConfigClientIds.length; j++) {
Daniel@0 391 var currentViewClientId = newViewConfigClientIds[j];
Daniel@0 392 var currentClientIdPair = currentEntityClientId + currentViewClientId;
Daniel@0 393
Daniel@0 394 // Look for an existing vis instance view
Daniel@0 395 var visInstanceView = _this._cachedVisInstanceViewsByClientIdPair[currentClientIdPair];
Daniel@0 396
Daniel@0 397 // Create a new vis instance view if it does not exist
Daniel@0 398 if (!visInstanceView) {
Daniel@0 399 _this._logger.debug("generate vis instance", currentEntityClientId, currentViewClientId);
Daniel@0 400 visInstanceView = _this._generateVisInstanceView(newEntityConfigs.get(currentEntityClientId), newViewConfigs.get(currentViewClientId));
Daniel@0 401 visInstanceViewsToRender.push(visInstanceView);
Daniel@0 402 _this._$visInstancesContainer.append(visInstanceView.el);
Daniel@0 403 }
Daniel@0 404 newVisInstanceViewsByClientIdPair[currentClientIdPair] = visInstanceView;
Daniel@0 405 }
Daniel@0 406 }
Daniel@0 407
Daniel@0 408 // Add new vis instances and remove those that are no longer needed
Daniel@0 409 // The order does not matter as the right layout is achieved with absolute positioning
Daniel@0 410 for (var i = this._cachedEntityConfigClientIds.length - 1; i >= 0; --i) {
Daniel@0 411 for (var j = removedViewConfigClientIds.length - 1; j >= 0; --j) {
Daniel@0 412 var visInstanceToRemove = _this._cachedVisInstanceViewsByClientIdPair[this._cachedEntityConfigClientIds[i] + removedViewConfigClientIds[j]];
Daniel@0 413 visInstanceToRemove.remove();
Daniel@0 414 }
Daniel@0 415 }
Daniel@0 416 for (var i = removedEntityConfigClientIds.length - 1; i >= 0; --i) {
Daniel@0 417 for (var j = this._cachedViewConfigClientIds.length - 1; j >= 0; --j) {
Daniel@0 418 var visInstanceToRemove = _this._cachedVisInstanceViewsByClientIdPair[removedEntityConfigClientIds[i] + this._cachedViewConfigClientIds[j]];
Daniel@0 419 if (visInstanceToRemove) {
Daniel@0 420 visInstanceToRemove.remove();
Daniel@0 421 }
Daniel@0 422 }
Daniel@0 423 }
Daniel@0 424 }
Daniel@0 425
Daniel@0 426 // view heights
Daniel@0 427 var viewHeightsHaveChanged = false;
Daniel@0 428 var entityWidthHasChanged = false;
Daniel@0 429
Daniel@0 430 var entityWidth = _this.getEntityWidth();
Daniel@0 431 var viewContentHeights = [];
Daniel@0 432 for (var row = 0; row < newViewConfigClientIds.length; row++) {
Daniel@0 433 var currentViewConfigClientId = newViewConfigClientIds[row];
Daniel@0 434 var viewConfig = newViewConfigs.get(currentViewConfigClientId);
Daniel@0 435 var viewContentHeight = App.RepresentationModule.getMasterForConfig(viewConfig).calculateVisInstanceContentHeight(viewConfig, entityWidth);
Daniel@0 436 viewContentHeights.push(viewContentHeight);
Daniel@0 437 }
Daniel@0 438
Daniel@0 439 if (entityWidth !== _this._cachedEntityWidth) {
Daniel@0 440 entityWidthHasChanged = true;
Daniel@0 441 _this._cachedEntityWidth = entityWidth;
Daniel@0 442 }
Daniel@0 443 if (!_.isEqual(viewContentHeights, _this._cachedViewContentHeights)) {
Daniel@0 444 viewHeightsHaveChanged = true;
Daniel@0 445 _this._cachedViewContentHeights = viewContentHeights;
Daniel@0 446 }
Daniel@0 447
Daniel@0 448 // Set up positions and sizes for entities and views
Daniel@0 449 if (viewListHasChanged || entityListHasChanged || entityWidthHasChanged || viewHeightsHaveChanged) {
Daniel@0 450 var newEntityDimensions = []; //entityId, x, width
Daniel@0 451 var newViewDimensions = []; //viewId, y, height
Daniel@0 452 var x = 0;
Daniel@0 453 var configGridType = _this.options.configGrid.getType();
Daniel@0 454 for (var col = 0; col < newEntityConfigClientIds.length; col++) {
Daniel@0 455 var currentEntityConfigClientId = newEntityConfigClientIds[col];
Daniel@0 456 newEntityDimensions.push([currentEntityConfigClientId, x, entityWidth]);
Daniel@0 457 x += entityWidth + _this._distanceBetweenEntities;
Daniel@0 458 }
Daniel@0 459 var y = 0;
Daniel@0 460 var viewHeaderHeight = _this._viewHeaderHeight;
Daniel@0 461 for (var row = 0; row < newViewConfigClientIds.length; row++) {
Daniel@0 462 var currentViewConfigClientId = newViewConfigClientIds[row];
Daniel@0 463 newViewDimensions.push([currentViewConfigClientId, y, _this._cachedViewContentHeights[row]]);
Daniel@0 464 y += viewHeaderHeight + _this._cachedViewContentHeights[row] + _this._distanceBetweenViews;
Daniel@0 465 }
Daniel@0 466
Daniel@0 467 // Reposition and resize view headers
Daniel@0 468 for (var row = newViewDimensions.length - 1; row >= 0; --row) {
Daniel@0 469 var currentViewDimensions = newViewDimensions[row];
Daniel@0 470 var viewHeaderView = newViewHeaderViewsByClientId[currentViewDimensions[0]];
Daniel@0 471 viewHeaderView.$el.css("top", currentViewDimensions[1])
Daniel@0 472 .attr("data-top", currentViewDimensions[1])
Daniel@0 473 .attr("data-total-height", currentViewDimensions[2] + _this._viewHeaderHeight);
Daniel@0 474 viewHeaderView.setSize(currentViewDimensions[2]);
Daniel@0 475 }
Daniel@0 476 for (var col = newEntityDimensions.length - 1; col >= 0; --col) {
Daniel@0 477 var currentEntityDimensions = newEntityDimensions[col];
Daniel@0 478
Daniel@0 479 // Reposition and resize entity headers
Daniel@0 480 var entityHeaderView = newEntityHeaderViewsByClientId[currentEntityDimensions[0]];
Daniel@0 481 entityHeaderView.$el.css("left", currentEntityDimensions[1])
Daniel@0 482 .attr("data-left", currentEntityDimensions[1])
Daniel@0 483 .attr("data-width", currentEntityDimensions[2]);
Daniel@0 484 entityHeaderView.setSize(currentEntityDimensions[2]);
Daniel@0 485
Daniel@0 486 for (var row = newViewDimensions.length - 1; row >= 0; --row) {
Daniel@0 487 var currentViewDimensions = newViewDimensions[row];
Daniel@0 488
Daniel@0 489 // Reposition and resize vis instances
Daniel@0 490 var visInstanceView = newVisInstanceViewsByClientIdPair[currentEntityDimensions[0] + currentViewDimensions[0]];
Daniel@0 491 visInstanceView.$el.css({
Daniel@0 492 "left": currentEntityDimensions[1],
Daniel@0 493 "top": currentViewDimensions[1] + viewHeaderHeight
Daniel@0 494 });
Daniel@0 495 visInstanceView.setSize(currentEntityDimensions[2], currentViewDimensions[2]);
Daniel@0 496 }
Daniel@0 497 }
Daniel@0 498
Daniel@0 499 // Reposition entity and view adders
Daniel@0 500 var needToResizeSpace = false;
Daniel@0 501 if (x != _this._$entityAdder.css("left")) {
Daniel@0 502 _this._$entityAdder.css("left", x);
Daniel@0 503 needToResizeSpace = true;
Daniel@0 504 }
Daniel@0 505 if (y != _this._$viewAdder.css("top")) {
Daniel@0 506 _this._$viewAdder.css("top", y);
Daniel@0 507 needToResizeSpace = true;
Daniel@0 508 }
Daniel@0 509
Daniel@0 510 // Resize the space
Daniel@0 511 if (needToResizeSpace) {
Daniel@0 512 _this._cachedMinSpaceWidth = x + _this._entityAdderWidth;
Daniel@0 513 _this._cachedMinSpaceHeight = y + _this._viewAdderHeight;
Daniel@0 514 _this._reviseSpaceSize(!_this._latestChangeWasAReset);
Daniel@0 515 }
Daniel@0 516 }
Daniel@0 517
Daniel@0 518 // Update cached view data
Daniel@0 519 if (entityListHasChanged) {
Daniel@0 520 _this._cachedEntityHeaderViewsByClientId = newEntityHeaderViewsByClientId;
Daniel@0 521 _this._cachedEntityConfigClientIds = newEntityConfigClientIds;
Daniel@0 522 }
Daniel@0 523 if (viewListHasChanged) {
Daniel@0 524 _this._cachedViewHeaderViewsByClientId = newViewHeaderViewsByClientId;
Daniel@0 525 _this._cachedViewConfigClientIds = newViewConfigClientIds;
Daniel@0 526 }
Daniel@0 527 if (viewListHasChanged || entityListHasChanged) {
Daniel@0 528 _this._cachedVisInstanceViewsByClientIdPair = newVisInstanceViewsByClientIdPair;
Daniel@0 529 }
Daniel@0 530
Daniel@0 531 // Render new vis instances and those that have changed their dimensions
Daniel@0 532 // If deep rendering takes place, all view instances will be rendered later
Daniel@0 533
Daniel@0 534 if (!deep && entityHeaderViewsToRender) {
Daniel@0 535 for (var i = entityHeaderViewsToRender.length - 1; i >= 0; --i) {
Daniel@0 536 entityHeaderViewsToRender[i].render();
Daniel@0 537 }
Daniel@0 538 }
Daniel@0 539 if (!deep && viewHeaderViewsToRender) {
Daniel@0 540 for (var i = viewHeaderViewsToRender.length - 1; i >= 0; --i) {
Daniel@0 541 viewHeaderViewsToRender[i].render();
Daniel@0 542 }
Daniel@0 543 }
Daniel@0 544 if (!deep && visInstanceViewsToRender) {
Daniel@0 545 for (var i = visInstanceViewsToRender.length - 1; i >= 0; --i) {
Daniel@0 546 visInstanceViewsToRender[i].render();
Daniel@0 547 }
Daniel@0 548 }
Daniel@0 549
Daniel@0 550 // Destroy detached vis instances
Daniel@0 551 if (viewListHasChanged || entityListHasChanged) {
Daniel@0 552 var destroyedVisInstanceViews = _.difference(_.values(this._cachedVisInstanceViewsByClientIdPair), _.values(newVisInstanceViewsByClientIdPair));
Daniel@0 553 for (var i = destroyedVisInstanceViews.length - 1; i >= 0; --i) {
Daniel@0 554 destroyedVisInstanceViews[i].remove();
Daniel@0 555 }
Daniel@0 556 }
Daniel@0 557 },
Daniel@0 558
Daniel@0 559 _updateSelection: function(deep, instant) {
Daniel@0 560 var _this = this;
Daniel@0 561
Daniel@0 562 var selectedEntityConfig = _this.options.configGrid.getSelectedEntityConfig();
Daniel@0 563 var selectedViewConfig = _this.options.configGrid.getSelectedViewConfig();
Daniel@0 564 var selectedEntityConfigClientId = selectedEntityConfig ? selectedEntityConfig.getClientId() : null;
Daniel@0 565 var selectedViewConfigClientId = selectedViewConfig ? selectedViewConfig.getClientId() : null;
Daniel@0 566
Daniel@0 567 if (_this._cachedSelectedEntityConfigClientId !== selectedEntityConfigClientId) {
Daniel@0 568 _this._cachedSelectedEntityConfigClientId = selectedEntityConfigClientId;
Daniel@0 569 }
Daniel@0 570 if (_this._cachedSelectedViewConfigClientId !== selectedViewConfigClientId) {
Daniel@0 571 _this._cachedSelectedViewConfigClientId = selectedViewConfigClientId;
Daniel@0 572 }
Daniel@0 573 //
Daniel@0 574 // // entity headers
Daniel@0 575 // var selectionChanged = false;
Daniel@0 576 // selectionChanged = true;
Daniel@0 577 // if (_this._cachedSelectedEntityConfigClientId) {
Daniel@0 578 // $(_this._cachedEntityHeaderViewsByClientId[_this._cachedSelectedEntityConfigClientId])
Daniel@0 579 // .toggleSelected(false);
Daniel@0 580 // }
Daniel@0 581 // if (newSelectedEntityConfigClientId) {
Daniel@0 582 // $(_this._cachedEntityHeaderViewsByClientId[newSelectedEntityConfigClientId])
Daniel@0 583 // .toggleSelected(true);
Daniel@0 584 // }
Daniel@0 585 // _this._cachedSelectedEntityConfigClientId = newSelectedEntityConfigClientId;
Daniel@0 586 // };
Daniel@0 587 //
Daniel@0 588 // // view headers
Daniel@0 589 // if (_this._cachedSelectedViewConfigClientId !== newSelectedViewConfigClientId) {
Daniel@0 590 // selectionChanged = true;
Daniel@0 591 // if (_this._cachedSelectedViewConfigClientId) {
Daniel@0 592 // $(_this._cachedViewHeaderViewsByClientId[_this._cachedSelectedViewConfigClientId])
Daniel@0 593 // .toggleSelected(false);
Daniel@0 594 // }
Daniel@0 595 // if (newSelectedViewConfigClientId) {
Daniel@0 596 // $(_this._cachedViewHeaderViewsByClientId[newSelectedViewConfigClientId])
Daniel@0 597 // .toggleSelected(true);
Daniel@0 598 // }
Daniel@0 599 // _this._cachedSelectedViewConfigClientId = newSelectedViewConfigClientId;
Daniel@0 600 // };
Daniel@0 601 },
Daniel@0 602
Daniel@0 603 scrollAccordingToSelection: function(deep, instant) {
Daniel@0 604 var _this = this;
Daniel@0 605
Daniel@0 606 return;
Daniel@0 607 var entityConfigClientId = _this._cachedSelectedEntityConfigClientId;
Daniel@0 608 var viewConfigClientId = _this._cachedSelectedViewConfigClientId;
Daniel@0 609
Daniel@0 610 var dimensions = {
Daniel@0 611 left: 0,
Daniel@0 612 top: 0,
Daniel@0 613 width: 0,
Daniel@0 614 height: 0
Daniel@0 615 };
Daniel@0 616
Daniel@0 617 if (entityConfigClientId) {
Daniel@0 618 dimensions.left = parseInt(_this._cachedEntityHeaderViewsByClientId[entityConfigClientId].el.getAttribute("data-left"), 10);
Daniel@0 619 dimensions.width = parseInt(_this._cachedEntityHeaderViewsByClientId[entityConfigClientId].el.getAttribute("data-width"), 10);
Daniel@0 620 }
Daniel@0 621 if (viewConfigClientId) {
Daniel@0 622 dimensions.top = parseInt(_this._cachedViewHeaderViewsByClientId[viewConfigClientId].el.getAttribute("data-top"), 10);
Daniel@0 623 dimensions.height = parseInt(_this._cachedViewHeaderViewsByClientId[viewConfigClientId].el.getAttribute("data-total-height"), 10);
Daniel@0 624 }
Daniel@0 625 var desiredPaddingAroundVisInstanceOnScroll = _this.options.desiredPaddingAroundVisInstanceOnScroll;
Daniel@0 626 var spacePadding = _this._spacePadding;
Daniel@0 627
Daniel@0 628 var targetScrollRange = {
Daniel@0 629 leftMax: dimensions.left - desiredPaddingAroundVisInstanceOnScroll.left,
Daniel@0 630 topMax: dimensions.top - desiredPaddingAroundVisInstanceOnScroll.top - _this._viewHeaderHeight,
Daniel@0 631 leftMin: dimensions.left + desiredPaddingAroundVisInstanceOnScroll.right + dimensions.width - _this._$containerOfScrollable[0].clientWidth + spacePadding.left,
Daniel@0 632 topMin: dimensions.top + desiredPaddingAroundVisInstanceOnScroll.bottom + dimensions.height - _this._$containerOfScrollable[0].clientHeight + spacePadding.top
Daniel@0 633 };
Daniel@0 634
Daniel@0 635 var currentScroll = {
Daniel@0 636 left: (_this._scrollLeftBeforeLatestLayoutUpdate == null ? _this._$containerOfScrollable.scrollLeft() : _this._scrollLeftBeforeLatestLayoutUpdate),
Daniel@0 637 top: (_this._scrollTopBeforeLatestLayoutUpdate == null ? _this._$containerOfScrollable.scrollTop() : _this._scrollTopBeforeLatestLayoutUpdate)
Daniel@0 638 };
Daniel@0 639
Daniel@0 640 var targetScrollLeft = currentScroll.left;
Daniel@0 641 var targetScrollTop = currentScroll.top;
Daniel@0 642
Daniel@0 643 if (_this._latestChangeWasAReset) {
Daniel@0 644 _this._cachedScrollPosSelection = null;
Daniel@0 645 targetScrollLeft = 0;
Daniel@0 646 targetScrollTop = 0;
Daniel@0 647 }
Daniel@0 648
Daniel@0 649 var currentGridHash = _this.getEntityWidth() + "~" + _this._cachedEntityConfigClientIds.join("|") + "~" + _this._cachedViewConfigClientIds.join("|");
Daniel@0 650 //_this._logger.debug("scrollAccordingToSelection[1]:", _this._cachedScrollPosGridHash === currentGridHash, _this._cachedScrollPosGridHash, currentGridHash);
Daniel@0 651 //_this._logger.debug("scrollAccordingToSelection[2]:", _this._cachedScrollPosSelection === "" + entityConfigClientId + viewConfigClientId, _this._cachedScrollPosSelection, "" + entityConfigClientId + viewConfigClientId);
Daniel@0 652 if (_this._cachedScrollPosGridHash === currentGridHash
Daniel@0 653 && _this._cachedScrollPosSelection === "" + entityConfigClientId + viewConfigClientId) {
Daniel@0 654 targetScrollLeft = _this._cachedScrollPosX;
Daniel@0 655 targetScrollTop = _this._cachedScrollPosY;
Daniel@0 656 _this._cachedScrollPosSelection = "";
Daniel@0 657 } else {
Daniel@0 658 if (!_this._ignoreXOnNextScroll) {
Daniel@0 659 if (targetScrollLeft < targetScrollRange.leftMin) {
Daniel@0 660 targetScrollLeft = targetScrollRange.leftMin;
Daniel@0 661 }
Daniel@0 662 if (targetScrollLeft > targetScrollRange.leftMax) {
Daniel@0 663 targetScrollLeft = targetScrollRange.leftMax;
Daniel@0 664 }
Daniel@0 665 }
Daniel@0 666 if (!_this._ignoreYOnNextScroll) {
Daniel@0 667 if (targetScrollTop < targetScrollRange.topMin) {
Daniel@0 668 targetScrollTop = targetScrollRange.topMin;
Daniel@0 669 }
Daniel@0 670 if (targetScrollTop > targetScrollRange.topMax) {
Daniel@0 671 targetScrollTop = targetScrollRange.topMax;
Daniel@0 672 }
Daniel@0 673 }
Daniel@0 674 if (targetScrollLeft < 0) {
Daniel@0 675 targetScrollLeft = 0;
Daniel@0 676 }
Daniel@0 677 if (targetScrollTop < 0) {
Daniel@0 678 targetScrollTop = 0;
Daniel@0 679 }
Daniel@0 680 }
Daniel@0 681
Daniel@0 682 var scrollDiffX = targetScrollLeft - currentScroll.left;
Daniel@0 683 var scrollDiffY = targetScrollTop - currentScroll.top;
Daniel@0 684
Daniel@0 685 if (!entityConfigClientId && !viewConfigClientId && !_this._latestChangeWasAReset) {
Daniel@0 686 _this._updateCachedScroll();
Daniel@0 687 } else if (instant || _this._latestChangeWasAReset) {
Daniel@0 688 _this._$containerOfScrollable.stop(true, true);
Daniel@0 689 _this._$containerOfScrollable.scrollLeft(targetScrollLeft);
Daniel@0 690 _this._$containerOfScrollable.scrollTop (targetScrollTop);
Daniel@0 691 _this._updateCachedScroll();
Daniel@0 692 _this._reviseSpaceSize();
Daniel@0 693 } else {
Daniel@0 694 _this._$containerOfScrollable.stop(true, false);
Daniel@0 695 if (_this._scrollLeftBeforeLatestLayoutUpdate !== null) {
Daniel@0 696 _this._$containerOfScrollable.scrollLeft(_this._scrollLeftBeforeLatestLayoutUpdate);
Daniel@0 697 _this._$containerOfScrollable.scrollTop (_this. _scrollTopBeforeLatestLayoutUpdate);
Daniel@0 698 }
Daniel@0 699 _this._$containerOfScrollable.animate(
Daniel@0 700 {"scrollLeft": targetScrollLeft, "scrollTop": targetScrollTop},
Daniel@0 701 _this.options.scrollAnimationMinSpeed + Math.min(Math.max(Math.abs(scrollDiffX), Math.abs(scrollDiffY)), _this.options.scrollAnimationBaseDistance) / _this.options.scrollAnimationBaseDistance * _this.options.scrollAnimationBaseSpeed,
Daniel@0 702 function() {
Daniel@0 703 _this._reviseSpaceSize();
Daniel@0 704 });
Daniel@0 705 }
Daniel@0 706 _this._ignoreXOnNextScroll = false;
Daniel@0 707 _this._ignoreYOnNextScroll = false;
Daniel@0 708 },
Daniel@0 709
Daniel@0 710 /**
Daniel@0 711 * Returns the positions of the currently selected items
Daniel@0 712 * relative to the top-left corner of the top-left view
Daniel@0 713 */
Daniel@0 714 getPositionsOfSelectedHeaders: function() {
Daniel@0 715 var _this = this;
Daniel@0 716
Daniel@0 717 var result = [];
Daniel@0 718
Daniel@0 719 var selectedEntityHeaderView = _this._cachedEntityHeaderViewsByClientId[_this._cachedSelectedEntityConfigClientId];
Daniel@0 720 var selectedViewHeaderView = _this._cachedViewHeaderViewsByClientId [_this._cachedSelectedViewConfigClientId];
Daniel@0 721
Daniel@0 722 if (selectedEntityHeaderView) {
Daniel@0 723 var $selectedEntityHeader = selectedEntityHeaderView.$el;
Daniel@0 724 result.push(parseInt($selectedEntityHeader.css("left"), 10) - _this._$containerOfScrollable.scrollLeft(), parseInt($selectedEntityHeader[0].style.width, 10));
Daniel@0 725 } else {
Daniel@0 726 result.push(null, null);
Daniel@0 727 }
Daniel@0 728
Daniel@0 729 if (selectedViewHeaderView) {
Daniel@0 730 var $selectedViewHeader = selectedViewHeaderView.$el;
Daniel@0 731 result.push(parseInt($selectedViewHeader.css("top"), 10) - _this._$containerOfScrollable.scrollTop(), _this._viewHeaderHeight);
Daniel@0 732 } else {
Daniel@0 733 result.push(null, null);
Daniel@0 734 }
Daniel@0 735
Daniel@0 736 return result;
Daniel@0 737 },
Daniel@0 738
Daniel@0 739 _updateCachedScroll: function() {
Daniel@0 740 var _this = this;
Daniel@0 741
Daniel@0 742 _this._cachedScrollPosGridHash = _this.getEntityWidth() + "~" + _this._cachedEntityConfigClientIds.join("|") + "~" + _this._cachedViewConfigClientIds.join("|");
Daniel@0 743 _this._cachedScrollPosSelection = "" + _this._cachedSelectedEntityConfigClientId + _this._cachedSelectedViewConfigClientId;
Daniel@0 744 _this._cachedScrollPosX = _this._$containerOfScrollable.scrollLeft();
Daniel@0 745 _this._cachedScrollPosY = _this._$containerOfScrollable.scrollTop();
Daniel@0 746
Daniel@0 747 //_this._logger.debug(_.str.sprintf("ConfigGridCellsView[%s]._updateCachedScroll()", _this.options.configGrid.getType()), _this._cachedScrollPosGridHash, _this._cachedScrollPosSelection, _this._cachedScrollPosX, _this._cachedScrollPosY);
Daniel@0 748 },
Daniel@0 749
Daniel@0 750 _toggleFixedHeadersIfNeeded: function(trueOrFalse) {
Daniel@0 751 //trueOrFalse = true;
Daniel@0 752 var _this = this;
Daniel@0 753 if (_this.options.enableFixedHeaders && trueOrFalse == true) {
Daniel@0 754 //_this._logger.debug("_toggleFixedHeadersIfNeeded(true)");
Daniel@0 755 if (!_this._$containerOfFixed[0].childNodes.length) {
Daniel@0 756 _this._$containerOfFixed.append(_this._$visInstancesContainer, _this._$entityHeadersContainer, _this._$viewHeadersContainer, _this._$cornerBlind);
Daniel@0 757 //_this._$containerOfFixed.append(_this._$entityHeadersContainer, _this._$viewHeadersContainer, _this._$cornerBlind);
Daniel@0 758 _this._$cornerBlind.css({"transform": "translate(0px, 0px)"});
Daniel@0 759 _this._$containerOfFixed.show();
Daniel@0 760 }
Daniel@0 761 } else {
Daniel@0 762 //_this._logger.debug("_toggleFixedHeadersIfNeeded(false)");
Daniel@0 763 _this._$containerOfFixed.hide();
Daniel@0 764 _this._$space.append(_this._$visInstancesContainer, _this._$entityHeadersContainer, _this._$viewHeadersContainer, _this._$cornerBlind);
Daniel@0 765 //_this._$space.append(_this._$entityHeadersContainer, _this._$viewHeadersContainer, _this._$cornerBlind);
Daniel@0 766 _this._$entityHeadersBlind.css({"transform": "translate(0px, 0px)"});
Daniel@0 767 _this._$visInstancesContainer.css({"transform": "translate(0px, 0px)"});
Daniel@0 768
Daniel@0 769 }
Daniel@0 770 _this._adjustToScrollPos();
Daniel@0 771 },
Daniel@0 772
Daniel@0 773 _adjustToScrollPos: function() {
Daniel@0 774 var _this = this;
Daniel@0 775 if (_this._scrollLeftBeforeLatestLayoutUpdate !== null) {
Daniel@0 776 _this._scrollLeftBeforeLatestLayoutUpdate = null;
Daniel@0 777 _this._scrollTopBeforeLatestLayoutUpdate = null;
Daniel@0 778 }
Daniel@0 779
Daniel@0 780 var scrollLeft = _this._$containerOfScrollable.scrollLeft();
Daniel@0 781 var scrollTop = _this._$containerOfScrollable.scrollTop();
Daniel@0 782 if (_this._$containerOfFixed[0].childNodes.length) {
Daniel@0 783 _this._$entityHeadersContainer.css({"transform": "translate(" + (-scrollLeft) + "px, 0px)"});
Daniel@0 784 _this._$entityHeadersBlind.css({"transform": "translate(" + scrollLeft + "px, 0px)"});
Daniel@0 785 _this._$visInstancesContainer.css({"transform": "translate(" + (-scrollLeft) + "px, " + (-scrollTop) + "px)"});
Daniel@0 786 _this._$viewHeadersContainer.css({"transform": "translate(0px, " + (-scrollTop) + "px)"});
Daniel@0 787 } else {
Daniel@0 788 _this._$entityHeadersContainer.css({"transform": "translate(0, " + scrollTop + "px)"});
Daniel@0 789 _this._$viewHeadersContainer.css({"transform": "translate(" + scrollLeft + "px, 0)"});
Daniel@0 790 _this._$cornerBlind.css({"transform": "translate(" + scrollLeft + "px, " + scrollTop + "px)"});
Daniel@0 791 }
Daniel@0 792
Daniel@0 793 _this._reportPositionsOfSelectedHeaders();
Daniel@0 794 },
Daniel@0 795
Daniel@0 796 _reportPositionsOfSelectedHeaders: function() {
Daniel@0 797 var _this = this;
Daniel@0 798
Daniel@0 799 var positionsOfSelectedHeaders = _this.getPositionsOfSelectedHeaders();
Daniel@0 800 _this.trigger("change-positions-of-selected-headers", positionsOfSelectedHeaders[0], positionsOfSelectedHeaders[1], positionsOfSelectedHeaders[2], positionsOfSelectedHeaders[3]);
Daniel@0 801 },
Daniel@0 802
Daniel@0 803
Daniel@0 804 _reviseSpaceSize: function(increaseOnly) {
Daniel@0 805 var _this = this;
Daniel@0 806
Daniel@0 807 var elInnerWidth = _this._$containerOfScrollable[0].clientWidth;
Daniel@0 808 var elInnerHeight = _this._$containerOfScrollable[0].clientHeight;
Daniel@0 809 var elScrollLeft = _this._$containerOfScrollable.scrollLeft();
Daniel@0 810 var elScrollTop = _this._$containerOfScrollable.scrollTop();
Daniel@0 811 var spaceWidth = _this._cachedMinSpaceWidth;
Daniel@0 812 var spaceHeight = _this._cachedMinSpaceHeight;
Daniel@0 813
Daniel@0 814 var missingWidth = elScrollLeft + elInnerWidth - _this._spacePadding.h - spaceWidth;
Daniel@0 815 var missingHeight = elScrollTop + elInnerHeight - _this._spacePadding.v - spaceHeight;
Daniel@0 816
Daniel@0 817 spaceWidth += Math.max(0, missingWidth);
Daniel@0 818 spaceHeight += Math.max(0, missingHeight);
Daniel@0 819
Daniel@0 820 if (!increaseOnly || (spaceWidth >= _this._$space.width() && spaceHeight >= _this._$space.height())) {
Daniel@0 821 _this._$space.css({
Daniel@0 822 "width": spaceWidth,
Daniel@0 823 "height": spaceHeight
Daniel@0 824 });
Daniel@0 825 _this._$viewHeadersBlind.height(spaceHeight);
Daniel@0 826 }
Daniel@0 827 },
Daniel@0 828
Daniel@0 829 _updateDemensionsForContainerOfFixed: function() {
Daniel@0 830 var _this = this;
Daniel@0 831 _this._$containerOfFixed.width(_this._$containerOfScrollable[0].clientWidth);
Daniel@0 832 _this._$containerOfFixed.height(_this._$containerOfScrollable[0].clientHeight);
Daniel@0 833 },
Daniel@0 834
Daniel@0 835 _generateEntityHeaderView: function(entityConfig) {
Daniel@0 836 var _this = this;
Daniel@0 837
Daniel@0 838 var $el = $.bem.generateElement("config-grid-cells", "entity-header");
Daniel@0 839
Daniel@0 840 var result = new App.MainRegionModule.ConfigHeaderView({
Daniel@0 841 dimension: "entity",
Daniel@0 842 el: $el,
Daniel@0 843 state: _this.options.state,
Daniel@0 844 configGrid: _this.options.configGrid,
Daniel@0 845 config: entityConfig,
Daniel@0 846 parentConfigGridView: _this.options.parentConfigGridView
Daniel@0 847 });
Daniel@0 848
Daniel@0 849 result.$el.dblclick(function() {
Daniel@0 850 if (entityConfig.getParameterValue("kind")) {
Daniel@0 851 return;
Daniel@0 852 }
Daniel@0 853 if (_this.options.configGrid.getSelectedEntityConfig() == entityConfig) {
Daniel@0 854 _this.options.configGrid.addEntityAndSelectIt(new App.ContextModule.Config({
Daniel@0 855 parameters: {
Daniel@0 856 "kind": "pair",
Daniel@0 857 "comparisonMode": "superposition"
Daniel@0 858 }
Daniel@0 859 }), _this.options.configGrid.getNextEntityNeighbour(entityConfig)) ;
Daniel@0 860 }
Daniel@0 861 });
Daniel@0 862
Daniel@0 863 return result;
Daniel@0 864 },
Daniel@0 865
Daniel@0 866 _generateViewHeaderView: function(viewConfig) {
Daniel@0 867 var _this = this;
Daniel@0 868
Daniel@0 869 var $el = $.bem.generateElement("config-grid-cells", "view-header");
Daniel@0 870
Daniel@0 871 var result = new App.MainRegionModule.ConfigHeaderView({
Daniel@0 872 dimension: "view",
Daniel@0 873 el: $el,
Daniel@0 874 state: _this.options.state,
Daniel@0 875 configGrid: _this.options.configGrid,
Daniel@0 876 config: viewConfig,
Daniel@0 877 parentConfigGridView: _this.options.parentConfigGridView
Daniel@0 878 });
Daniel@0 879
Daniel@0 880 return result;
Daniel@0 881 },
Daniel@0 882
Daniel@0 883 _generateVisInstanceView: function(entityConfig, viewConfig) {
Daniel@0 884 var _this = this;
Daniel@0 885
Daniel@0 886 var $el = $.bem.generateElement("config-grid-cells", "vis-instance").addClass("vis-instance");
Daniel@0 887
Daniel@0 888 var result = new App.MainRegionModule.VisInstanceView({
Daniel@0 889 el: $el,
Daniel@0 890 state: _this.options.state,
Daniel@0 891 configGrid: _this.options.configGrid,
Daniel@0 892 entityConfig: entityConfig,
Daniel@0 893 viewConfig: viewConfig,
Daniel@0 894 parentConfigGridView: _this.options.parentConfigGridView
Daniel@0 895 });
Daniel@0 896
Daniel@0 897 return result;
Daniel@0 898 }
Daniel@0 899 });
Daniel@0 900 }, Logger);