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.ConfigHeaderView = MainRegionModule.ConfigGridChildView.extend({
|
Daniel@0
|
6
|
Daniel@0
|
7 options: {
|
Daniel@0
|
8 dimension: null,
|
Daniel@0
|
9 parentState: null,
|
Daniel@0
|
10 configGrid: null,
|
Daniel@0
|
11 config: null,
|
Daniel@0
|
12 parentConfigGridView: null,
|
Daniel@0
|
13 },
|
Daniel@0
|
14
|
Daniel@0
|
15 _dimensionIsEntity: false,
|
Daniel@0
|
16 _dimensionIsView: false,
|
Daniel@0
|
17
|
Daniel@0
|
18 initialize: function(options) {
|
Daniel@0
|
19 var _this = this;
|
Daniel@0
|
20
|
Daniel@0
|
21 _this.options = _.defaults(options || {}, _this.options);
|
Daniel@0
|
22
|
Daniel@0
|
23 _this._cachedConfigGridType = options.configGrid.getType();
|
Daniel@0
|
24 _this._cachedKind = "-";
|
Daniel@0
|
25 _this._cachedMaster = null;
|
Daniel@0
|
26
|
Daniel@0
|
27 _this.$el.disableSelection();
|
Daniel@0
|
28
|
Daniel@0
|
29 _this.dynamicDerivedConfigData = null;
|
Daniel@0
|
30
|
Daniel@0
|
31 if (_this.options.dimension === "entity") {
|
Daniel@0
|
32 _this._dimensionIsEntity = true;
|
Daniel@0
|
33 } else {
|
Daniel@0
|
34 _this._dimensionIsView = true;
|
Daniel@0
|
35 }
|
Daniel@0
|
36
|
Daniel@0
|
37 // _this._debouncedRenderIfParentConfigGridIsVisible = _.debounce(function() {
|
Daniel@0
|
38 // _this.renderIfParentConfigGridIsVisible();
|
Daniel@0
|
39 // }, 50);
|
Daniel@0
|
40 _this._debouncedRenderIfParentConfigGridIsVisible = _this.renderIfParentConfigGridIsVisible;
|
Daniel@0
|
41
|
Daniel@0
|
42 _this.listenTo(_this.options.configGrid, "change_selection", _this._debouncedRenderIfParentConfigGridIsVisible);
|
Daniel@0
|
43 _this.listenTo(_this.options.configGrid, "change_layout", _this._debouncedRenderIfParentConfigGridIsVisible);
|
Daniel@0
|
44 _this.listenTo(_this.options.config, "change:parametersOrPlannedParameterUpdates", _this._debouncedRenderIfParentConfigGridIsVisible);
|
Daniel@0
|
45
|
Daniel@0
|
46 _this._$background = $.bem.generateElement("config-grid-cells", _this._dimensionIsEntity ? "entity-header-background" : "view-header-background");
|
Daniel@0
|
47 _this.$el.append(_this._$background);
|
Daniel@0
|
48
|
Daniel@0
|
49 _this.$el.click(function(event) {
|
Daniel@0
|
50 if (_this._dimensionIsEntity) {
|
Daniel@0
|
51 _this.options.parentConfigGridView.ignoreAxisOnNextScroll(false, true);
|
Daniel@0
|
52 } else {
|
Daniel@0
|
53 _this.options.parentConfigGridView.ignoreAxisOnNextScroll(true, false);
|
Daniel@0
|
54 }
|
Daniel@0
|
55 if (_this._cachedSelected) {
|
Daniel@0
|
56 _this.options.parentConfigGridView.scrollAccordingToSelection();
|
Daniel@0
|
57 } else {
|
Daniel@0
|
58 _this.options.configGrid.set(_this._dimensionIsEntity ? "selectedEntityConfigClientId" : "selectedViewConfigClientId", _this.options.config.getClientId());
|
Daniel@0
|
59 }
|
Daniel@0
|
60 event.stopPropagation();
|
Daniel@0
|
61 event.preventDefault();
|
Daniel@0
|
62 });
|
Daniel@0
|
63
|
Daniel@0
|
64 _this._cachedSelected = false;
|
Daniel@0
|
65 _this._cachedHashForParameters = null;
|
Daniel@0
|
66 },
|
Daniel@0
|
67
|
Daniel@0
|
68 setSize: function (widthOrHeight) {
|
Daniel@0
|
69 var _this = this;
|
Daniel@0
|
70
|
Daniel@0
|
71 var $el = _this.$el;
|
Daniel@0
|
72 var changed = false;
|
Daniel@0
|
73 if (_this._dimensionIsEntity) {
|
Daniel@0
|
74 if (widthOrHeight != $el.width()) {
|
Daniel@0
|
75 $el.width(widthOrHeight);
|
Daniel@0
|
76 changed = true;
|
Daniel@0
|
77 }
|
Daniel@0
|
78 } else {
|
Daniel@0
|
79 return;
|
Daniel@0
|
80 if (widthOrHeight != $el.height()) {
|
Daniel@0
|
81 $el.height(widthOrHeight);
|
Daniel@0
|
82 changed = true;
|
Daniel@0
|
83 }
|
Daniel@0
|
84 }
|
Daniel@0
|
85
|
Daniel@0
|
86 if (changed) {
|
Daniel@0
|
87 _this._debouncedRenderIfParentConfigGridIsVisible();
|
Daniel@0
|
88 }
|
Daniel@0
|
89 },
|
Daniel@0
|
90
|
Daniel@0
|
91 render: function (deep, instant) {
|
Daniel@0
|
92 var _this = this;
|
Daniel@0
|
93
|
Daniel@0
|
94 // do not render if config has just been removed from the grid,
|
Daniel@0
|
95 // but the view has not been destroyed yet
|
Daniel@0
|
96 if (!_this.options.config.getConfigGridType()) {
|
Daniel@0
|
97 return;
|
Daniel@0
|
98 }
|
Daniel@0
|
99
|
Daniel@0
|
100 // modifier: selected or not
|
Daniel@0
|
101 var newSelected = _this._dimensionIsEntity
|
Daniel@0
|
102 ? _this.options.configGrid.getSelectedEntityConfig() == _this.options.config
|
Daniel@0
|
103 : _this.options.configGrid.getSelectedViewConfig() == _this.options.config;
|
Daniel@0
|
104
|
Daniel@0
|
105 if (newSelected !== _this._cachedSelected) {
|
Daniel@0
|
106 if (newSelected) {
|
Daniel@0
|
107 _this.$el.addClass(_this._dimensionIsEntity ? "config-grid-cells__entity-header_selected" : "config-grid-cells__view-header_selected");
|
Daniel@0
|
108 } else {
|
Daniel@0
|
109 _this.$el.removeClass(_this._dimensionIsEntity ? "config-grid-cells__entity-header_selected" : "config-grid-cells__view-header_selected");
|
Daniel@0
|
110 }
|
Daniel@0
|
111 _this._cachedSelected = newSelected;
|
Daniel@0
|
112 };
|
Daniel@0
|
113
|
Daniel@0
|
114 // kind
|
Daniel@0
|
115 var newKind = _this.options.config.getParameterValue("kind");
|
Daniel@0
|
116 if (newKind !== _this._cachedKind) {
|
Daniel@0
|
117 _this._cachedKind = newKind;
|
Daniel@0
|
118 _this._cachedMaster = App.RepresentationModule.getMasterForConfig(_this.options.config);
|
Daniel@0
|
119
|
Daniel@0
|
120 // swap derived config data when the kind changes (i.e. the master changes)
|
Daniel@0
|
121 if (_this.dynamicDerivedConfigData) {
|
Daniel@0
|
122 _this.stopListening(_this.dynamicDerivedConfigData);
|
Daniel@0
|
123 }
|
Daniel@0
|
124 _this.dynamicDerivedConfigData = App.dynamicDerivedConfigDataProvider.get(_this.options.config);
|
Daniel@0
|
125 _this.listenTo(_this.dynamicDerivedConfigData, "change", _this._debouncedRenderIfParentConfigGridIsVisible);
|
Daniel@0
|
126
|
Daniel@0
|
127 _this.$el.setMod("config-grid-cells", "entity-header", "kind", newKind ? newKind : false);
|
Daniel@0
|
128 }
|
Daniel@0
|
129
|
Daniel@0
|
130 // content
|
Daniel@0
|
131 _this._cachedMaster.renderHeaderContent(this, instant);
|
Daniel@0
|
132 },
|
Daniel@0
|
133 });
|
Daniel@0
|
134 }, Logger); |