Mercurial > hg > dml-open-vis
comparison src/DML/MainVisBundle/Resources/assets/marionette/modules/MainRegionModule/MainRegionModule.20-ConfigGridPanelView.js @ 0:493bcb69166c
added public content
author | Daniel Wolff |
---|---|
date | Tue, 09 Feb 2016 20:54:02 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:493bcb69166c |
---|---|
1 "use strict"; | |
2 | |
3 App.module("MainRegionModule", function (MainRegionModule, App, Backbone, Marionette, $, _, Logger) { | |
4 | |
5 MainRegionModule.ConfigGridPanelView = MainRegionModule.ConfigGridChildView.extend({ | |
6 | |
7 options: { | |
8 dimension: null, // entity | view | |
9 configGrid: null, | |
10 parentState: null, | |
11 parentConfigGridView: null | |
12 }, | |
13 | |
14 _cachedConfigGridType: null, | |
15 _cachedConfig: null, | |
16 _cachedBorderRadiusFixerSize: null, | |
17 | |
18 initialize: function(options) { | |
19 var _this = this; | |
20 _this.options = _.defaults(options || {}, this.options);; | |
21 | |
22 _this.listenTo(_this.options.configGrid, "change_selection", _this.renderIfParentConfigGridIsVisible); | |
23 | |
24 // Cached attributes | |
25 _this._cachedConfigGridType = this.options.configGrid.getType(); | |
26 | |
27 // Init border radius fixer (sits under the background and fills white space if the currently selected entity / view is near the corner) | |
28 _this._$borderRadiusFixer = $.bem.generateElement("config-grid-panel", "border-radius-fixer"); | |
29 _this._$borderRadiusFixerContainer = $.bem.generateElement("config-grid-panel", "border-radius-fixer-container"); | |
30 _this._$borderRadiusFixerContainer.append(_this._$borderRadiusFixer); | |
31 _this.$el.prepend(_this._$borderRadiusFixerContainer); | |
32 _this._cachedBorderRadiusFixerSize = _this._$borderRadiusFixerContainer.width(); | |
33 _this.updateRadiusFixer(null, null); | |
34 | |
35 // Init main area | |
36 _this._$mainAreaWrapper = $.bem.generateElement("config-grid-panel", "main-area-wrapper"); | |
37 _this._$mainArea = $.bem.generateElement("config-grid-panel", "main-area"); | |
38 _this._$mainArea.addClass("cgpma"); // this element is also a block | |
39 _this._$mainArea.appendTo(_this._$mainAreaWrapper); | |
40 _this._$mainAreaWrapper.appendTo(_this.$el); | |
41 | |
42 // Init commands | |
43 _this._$commands = _this.$(".config-grid-panel__commands"); | |
44 _this._$commandClone = _this.$(".config-grid-panel__command_action_clone"); | |
45 _this._$commandDelete = _this.$(".config-grid-panel__command_action_delete"); | |
46 _this._$commandApply = _this.$(".config-grid-panel__command_action_apply"); | |
47 _this._$commandDiscard = _this.$(".config-grid-panel__command_action_discard"); | |
48 | |
49 // Assign functions to the commands | |
50 _this._$commandClone.click(function() { | |
51 if (_this._cachedConfig && _this._$commandClone.hasClass("config-grid-panel__command_state_enabled")) { | |
52 var clonedConfig = _this._cachedConfig.clone(); | |
53 if (_this.options.dimension == "entity") { | |
54 _this.options.configGrid.addEntityAndSelectIt(clonedConfig, _this.options.configGrid.getNextEntityNeighbour(_this._cachedConfig)); | |
55 } else { | |
56 _this.options.configGrid.addViewAndSelectIt(clonedConfig, _this.options.configGrid.getNextViewNeighbour(_this._cachedConfig)); | |
57 } | |
58 } | |
59 }); | |
60 _this._$commandDelete.click(function() { | |
61 if (_this._cachedConfig && _this._$commandDelete.hasClass("config-grid-panel__command_state_enabled")) { | |
62 if (_this.options.dimension == "entity") { | |
63 _this.options.configGrid.removeEntityAndSelectNeighbour(_this._cachedConfig); | |
64 } else { | |
65 _this.options.configGrid.removeViewAndSelectNeighbour(_this._cachedConfig); | |
66 } | |
67 } | |
68 }); | |
69 | |
70 _this._$commandApply.click(function() { | |
71 if (_this._cachedConfig && _this._$commandApply.hasClass("config-grid-panel__command_state_enabled")) { | |
72 _this._masterBehindMainArea.cleanConfigPlannedParameterValuesAndApplyThem(_this._cachedConfig); | |
73 } | |
74 }); | |
75 | |
76 _this._$commandDiscard.click(function() { | |
77 if (_this._cachedConfig && _this._$commandDiscard.hasClass("config-grid-panel__command_state_enabled")) { | |
78 _this._cachedConfig.cancelPlannedParameterUpdates(); | |
79 } | |
80 }); | |
81 | |
82 _this._$commandClone .attr("title", " "); | |
83 _this._$commandDelete .attr("title", " "); | |
84 _this._$commandApply .attr("title", " "); | |
85 _this._$commandDiscard.attr("title", " "); | |
86 App.TooltipModule.convertTitlesToTooltips(_this.$el); | |
87 _this._updateTooltips(); | |
88 | |
89 _this._$commands.disableSelection(); | |
90 }, | |
91 | |
92 render: function (deep, instant) { | |
93 var _this = this; | |
94 | |
95 var selectedConfig = null; | |
96 if (_this.options.dimension == "entity") { | |
97 selectedConfig = _this.options.configGrid.getSelectedEntityConfig(); | |
98 } else { | |
99 selectedConfig = _this.options.configGrid.getSelectedViewConfig(); | |
100 } | |
101 | |
102 var configWasReplaced = false; | |
103 if (_this._cachedConfig != selectedConfig) { | |
104 | |
105 if (_this._cachedConfig) { | |
106 _this.stopListening(_this._cachedConfig, "change", _this.renderIfParentConfigGridIsVisible); | |
107 }; | |
108 | |
109 _this._cachedConfig = selectedConfig; | |
110 | |
111 if (_this._cachedConfig) { | |
112 _this.listenTo(_this._cachedConfig, "change", _this.renderIfParentConfigGridIsVisible); | |
113 }; | |
114 | |
115 configWasReplaced = true; | |
116 _this._updateTooltips(); | |
117 } | |
118 | |
119 var dynamicDerivedConfigData = App.dynamicDerivedConfigDataProvider.get(_this._cachedConfig); | |
120 if (_this._cachedDynamicDerivedConfigData != dynamicDerivedConfigData) { | |
121 if (_this._cachedDynamicDerivedConfigData) { | |
122 this.stopListening(_this._cachedDynamicDerivedConfigData, "change", _this.renderIfParentConfigGridIsVisible); | |
123 } | |
124 | |
125 _this._cachedDynamicDerivedConfigData = dynamicDerivedConfigData; | |
126 | |
127 if (_this._cachedDynamicDerivedConfigData) { | |
128 _this.listenTo(_this._cachedDynamicDerivedConfigData, "change", _this.renderIfParentConfigGridIsVisible); | |
129 }; | |
130 } | |
131 | |
132 _this._setupMainArea(deep, instant); | |
133 | |
134 var hashForData = null; | |
135 if (_this._cachedConfig) { | |
136 hashForData = _this._cachedConfig.getHash() | |
137 + _this._cachedDynamicDerivedConfigData.getHash(); | |
138 } | |
139 if (configWasReplaced || _this._cachedHashForData !== hashForData) { | |
140 _this._cachedHashForData = hashForData; | |
141 if (_this._masterBehindMainArea) { | |
142 _this._masterBehindMainArea.syncConfigGridPanelMainArea(_this, instant); | |
143 } | |
144 _this._renderApplyDiscardCommands(deep, instant); | |
145 } | |
146 | |
147 if (configWasReplaced || deep) { | |
148 _this._renderCloneDeleteCommands(deep, instant); | |
149 } | |
150 }, | |
151 | |
152 updateRadiusFixer: function(selectedConfigGridOffsetStart, selectedConfigGridSize) { | |
153 var _this = this; | |
154 var coordinate = selectedConfigGridOffsetStart; | |
155 var size = selectedConfigGridSize; | |
156 | |
157 if (_.isNumber(size) && !_.isNaN(size) && size > 0) { | |
158 if (coordinate + size <= 0) { | |
159 coordinate = null; | |
160 } | |
161 if (coordinate > _this._cachedBorderRadiusFixerSize) { | |
162 coordinate = null; | |
163 } else if (coordinate < 0) { | |
164 coordinate = 0; | |
165 } else if (coordinate + size > _this._cachedBorderRadiusFixerSize) { | |
166 size = _this._cachedBorderRadiusFixerSize - coordinate; | |
167 } | |
168 } else { | |
169 coordinate = null; | |
170 size = null; | |
171 } | |
172 if (coordinate !== null) { | |
173 if (_this.options.dimension == "entity") { | |
174 _this._$borderRadiusFixer.css({"left": coordinate, "width": size}); | |
175 } else { | |
176 _this._$borderRadiusFixer.css({"top": coordinate, "height": size}); | |
177 } | |
178 } else { | |
179 if (_this.options.dimension == "entity") { | |
180 _this._$borderRadiusFixer.css({"left": 0, "width": 0}); | |
181 } else { | |
182 _this._$borderRadiusFixer.css({"top": 0, "height": 0}); | |
183 } | |
184 } | |
185 }, | |
186 | |
187 _updateTooltips: function() { | |
188 var _this = this; | |
189 if (! this._cachedConfig) { | |
190 _this._$commandClone .attr("tooltip-title", ""); | |
191 _this._$commandDelete .attr("tooltip-title", ""); | |
192 _this._$commandApply .attr("tooltip-title", ""); | |
193 _this._$commandDiscard.attr("tooltip-title", ""); | |
194 } else { | |
195 var tooltipTemplate = null; | |
196 try { | |
197 tooltipTemplate = Marionette.TemplateCache.get("#config-grid-panel__command-titles_" + _this._cachedConfigGridType + "_" + this._cachedConfig.getDimension() + "_" + _.str.trim(this._cachedConfig.getParameterValue("kind"))); | |
198 } catch (e) { | |
199 tooltipTemplate = Marionette.TemplateCache.get("#config-grid-panel__command-titles_" + _this._cachedConfigGridType + "_" + this._cachedConfig.getDimension()); | |
200 } | |
201 var tooltips = tooltipTemplate().split("|"); | |
202 _this._$commandClone .attr("tooltip-title", tooltips[0]); | |
203 _this._$commandDelete .attr("tooltip-title", tooltips[1]); | |
204 _this._$commandApply .attr("tooltip-title", tooltips[2]); | |
205 _this._$commandDiscard.attr("tooltip-title", tooltips[3]); | |
206 } | |
207 }, | |
208 | |
209 _renderCloneDeleteCommands: function(deep, instant) { | |
210 var _this = this; | |
211 //var cloneEnabled = !!(_this._cachedConfig && !(_this.options.dimension == "entity" && _this._cachedConfigGridType == "recording")); | |
212 var cloneEnabled = !! _this._cachedConfig; | |
213 var deleteEnabled = !! _this._cachedConfig; | |
214 _this._$commandClone .toggleClass("config-grid-panel__command_state_enabled", cloneEnabled); | |
215 _this._$commandDelete.toggleClass("config-grid-panel__command_state_enabled", deleteEnabled); | |
216 }, | |
217 | |
218 _renderApplyDiscardCommands: function(deep, instant) { | |
219 var _this = this; | |
220 var enabled = !!(_this._cachedConfig && _this._cachedConfig.hasPlannedParameterUpdates()); | |
221 _this._$commandApply .toggleClass("config-grid-panel__command_state_enabled", enabled); | |
222 _this._$commandDiscard.toggleClass("config-grid-panel__command_state_enabled", enabled); | |
223 }, | |
224 | |
225 | |
226 | |
227 _setupMainArea: function(deep, instant) { | |
228 var _this = this; | |
229 | |
230 var master = null; | |
231 if (_this._cachedConfig) { | |
232 master = App.RepresentationModule.getMasterForConfig(_this._cachedConfig, true); | |
233 } | |
234 | |
235 var configHasChanged = _this._configBehindMainArea !== _this._cachedConfig; | |
236 var masterHasChanged = _this._masterBehindMainArea !== master; | |
237 | |
238 if (configHasChanged || masterHasChanged) { | |
239 if (_this._masterBehindMainArea) { | |
240 _this._masterBehindMainArea.destroyConfigGridPanelMainArea(this); | |
241 } | |
242 | |
243 if (!_this._cachedConfig) { | |
244 _this._configBehindMainArea = null; | |
245 _this._masterBehindMainArea = null; | |
246 _this._$mainArea.html(Backbone.Marionette.TemplateCache.get("#cgpma_" + _this._cachedConfigGridType + "_" + this.options.dimension + "__empty")); | |
247 } else { | |
248 | |
249 _this._configBehindMainArea = _this._cachedConfig; | |
250 _this._masterBehindMainArea = master; | |
251 | |
252 _this._$mainArea.empty(); | |
253 _this._$mainArea.removeData(); | |
254 | |
255 try { | |
256 _this._$mainArea.html(Backbone.Marionette.TemplateCache.get("#cgpma_" + _this._cachedConfigGridType + "_" + this.options.dimension + "_" + master.id.split(".")[2])); | |
257 } catch (e) { | |
258 _this._$mainArea.html(Backbone.Marionette.TemplateCache.get("#cgpma_" + _this._cachedConfigGridType + "_" + this.options.dimension + "__unknown")); | |
259 } | |
260 _this._masterBehindMainArea.prepareConfigGridPanelMainArea(_this); | |
261 } | |
262 | |
263 var masterKind = undefined; | |
264 if (_this._masterBehindMainArea) { | |
265 masterKind = _this._masterBehindMainArea.id.split(".")[2]; | |
266 } | |
267 this.$el.setMod("config-grid-panel", "master-kind", masterKind ? masterKind : false); | |
268 } | |
269 }, | |
270 }); | |
271 }, Logger); |