Mercurial > hg > dml-open-vis
comparison src/DML/MainVisBundle/Resources/assets/marionette/modules/RepresentationModule/RepresentationModule.20-Master._.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("RepresentationModule", function(RepresentationModule, App, Backbone, Marionette, $, _, Logger) { | |
4 | |
5 RepresentationModule.addInitializer(function(options){ | |
6 | |
7 /** | |
8 * Base structure and functionality of all masters of any dimension | |
9 * All masters inherit from the given object | |
10 */ | |
11 RepresentationModule.registerMaster({ | |
12 id: "_", | |
13 | |
14 options: { | |
15 }, | |
16 | |
17 defaultConfigParameterValues: { | |
18 kind: "", | |
19 }, | |
20 | |
21 initialize: function() { | |
22 }, | |
23 | |
24 | |
25 // ================================================================= | |
26 // housekeeping | |
27 | |
28 generateDynamicDerivedConfigData: function(config, configGrid) { | |
29 return new RepresentationModule.DynamicDerivedConfigData(); | |
30 }, | |
31 | |
32 | |
33 configGridParameterHasDefaultValue: function(config, parameterName) { | |
34 return this.getConfigParameterValueOrDefaultValue(config, parameterName) == this.defaultConfigParameterValues[parameterName]; | |
35 }, | |
36 | |
37 | |
38 getConfigParameterValueOrDefaultValue: function(config, parameterName, trimResult) { | |
39 var value = config.getParameterValue(parameterName); | |
40 if (!_.isUndefined(value)) { | |
41 return (trimResult && _.isString(value)) ? _.str.trim(value) : value; | |
42 } else { | |
43 return this.defaultConfigParameterValues[parameterName]; | |
44 } | |
45 }, | |
46 | |
47 | |
48 getConfigPlannedParameterValueOrDefaultValue: function(config, parameterName) { | |
49 var value = config.getPlannedParameterValue(parameterName); | |
50 if (!_.isUndefined(value)) { | |
51 return value; | |
52 } else { | |
53 return this.defaultConfigParameterValues[parameterName]; | |
54 } | |
55 }, | |
56 | |
57 getSupportedKind: function() { | |
58 if (this._cachedSupportedKind === undefined) { | |
59 this._cachedSupportedKind = this.id.split(".")[2]; | |
60 } | |
61 return this._cachedSupportedKind; | |
62 }, | |
63 | |
64 | |
65 planConfigParameterUpdateWithRespectToValueAndDefaultValue: function(config, parameterName, parameterValue) { | |
66 var defaultParameterValue = this.defaultConfigParameterValues[parameterName]; | |
67 var currentParameterValue = config.getParameterValue(parameterName); | |
68 var plannedParameterValue = parameterValue; | |
69 | |
70 if (currentParameterValue === undefined && plannedParameterValue === "" + defaultParameterValue) { | |
71 config.cancelPlannedParameterUpdate(parameterName); | |
72 } else { | |
73 config.planParameterUpdate(parameterName, plannedParameterValue); | |
74 } | |
75 }, | |
76 | |
77 | |
78 extractCleanedConfigParameterValuesFromPlannedParameterValues: function(config) { | |
79 var result = config.getPlannedParameterValues(); | |
80 | |
81 // make sure no redundant parameters are set | |
82 for (var key in result) { | |
83 if (result.hasOwnProperty(key)) { | |
84 if (this.defaultConfigParameterValues[key] === undefined) { | |
85 delete result[key]; | |
86 } | |
87 } | |
88 } | |
89 | |
90 // make sure all parameters are set to defaults if missing | |
91 for (var key in this.defaultConfigParameterValues) { | |
92 if (this.defaultConfigParameterValues.hasOwnProperty(key)) { | |
93 if (!result.hasOwnProperty(key)) { | |
94 result[key] = "" + this.defaultConfigParameterValues[key]; | |
95 } | |
96 } | |
97 } | |
98 | |
99 return result; | |
100 }, | |
101 | |
102 cleanConfigPlannedParameterValuesAndApplyThem: function(config) { | |
103 var newParameterValues = this.extractCleanedConfigParameterValuesFromPlannedParameterValues(config); | |
104 config.unserialize({ | |
105 parameters: newParameterValues, | |
106 plannedParameterUpdates: {}, | |
107 tempParameters: {} | |
108 }); | |
109 }, | |
110 | |
111 | |
112 // ================================================================= | |
113 // config grid panel | |
114 | |
115 | |
116 parseAutocompleteSuggestions: function(rawAutocompleteSuggestions) { | |
117 if (!_.isString(rawAutocompleteSuggestions) || !rawAutocompleteSuggestions) { | |
118 return null; | |
119 } | |
120 var rawAutocompleteAsArray = rawAutocompleteSuggestions.split(";"); | |
121 var result = {}; | |
122 _.each(rawAutocompleteAsArray, function(item) { | |
123 var parts = item.split("|"); | |
124 if (parts.length == 2) { | |
125 result[parts[0]] = parts[1]; | |
126 } else { | |
127 result[parts[0]] = parts[0]; | |
128 } | |
129 }); | |
130 return result; | |
131 }, | |
132 | |
133 | |
134 // ----------------------------------------------------------------- | |
135 // config grid panel - prepare | |
136 | |
137 prepareConfigGridPanelMainArea: function(configGridPanelView) { | |
138 | |
139 // text fields | |
140 var $textfields = configGridPanelView._$mainArea.find(".cgpma__textfield"); | |
141 configGridPanelView._$mainArea.data("$textfields", $textfields); | |
142 | |
143 var master = this; | |
144 | |
145 $textfields.each(function() { | |
146 var $textfield = $(this); | |
147 if (!$textfield.data("cgpma-textfield")) { | |
148 $textfield.textfield({ | |
149 autocompleteSuggestions: master.parseAutocompleteSuggestions($textfield.data("autocomplete-suggestions")), | |
150 autocompleteIsAdvisory: $textfield.data("autocomplete-is-advisory"), | |
151 autocompleteSort: $textfield.data("autocomplete-sort"), | |
152 autocompleteCSSClasses: "ui_config-grid-type_" + configGridPanelView._cachedConfigGridType | |
153 }); | |
154 } else { | |
155 $textfield.unbind("textfieldchangevalue"); | |
156 $textfield.unbind("textfieldapply"); | |
157 $textfield.unbind("textfielddiscard"); | |
158 } | |
159 $textfield.data("configGridPanelView", configGridPanelView); | |
160 $textfield.bind("textfieldchangevalue", master.__panelInputChangeValueHandler); | |
161 $textfield.bind("textfieldapply", master.__panelInputApplyHandler); | |
162 $textfield.bind("textfielddiscard", master.__panelInputDiscardHandler); | |
163 }); | |
164 | |
165 // tick boxes | |
166 var $tickboxes = configGridPanelView._$mainArea.find(".cgpma__tickbox"); | |
167 configGridPanelView._$mainArea.data("$tickboxes", $tickboxes); | |
168 | |
169 $tickboxes.each(function() { | |
170 var $tickbox = $(this); | |
171 if (!$tickbox.data("cgpma-tickbox")) { | |
172 $tickbox.tickbox(); | |
173 } | |
174 $tickbox.data("configGridPanelView", configGridPanelView); | |
175 $tickbox.bind("tickboxchangevalue", master.__panelInputChangeValueHandler); | |
176 }); | |
177 | |
178 // input blocks | |
179 var $inputBlocks = configGridPanelView._$mainArea.find(".cgpma__input-block"); | |
180 configGridPanelView._$mainArea.data("$inputBlocks", $inputBlocks); | |
181 $inputBlocks.each(function() { | |
182 var $inputBlock = $(this); | |
183 var inputBlockName = $inputBlock.data("name"); | |
184 if (!inputBlockName) { | |
185 var $firstElementWithParameterNameInsideInputBlock = $inputBlock.find("[data-parameter-name]").first(); | |
186 inputBlockName = $firstElementWithParameterNameInsideInputBlock.data("parameter-name"); | |
187 } | |
188 configGridPanelView._$mainArea.data("$inputBlock_" + inputBlockName, $inputBlock); | |
189 }); | |
190 | |
191 // initial population of the data | |
192 var $allInputs = $tickboxes.add($textfields); | |
193 configGridPanelView._$mainArea.data("$allInputs", $allInputs); | |
194 }, | |
195 | |
196 | |
197 __panelInputChangeValueHandler: function(event) { | |
198 var $this = $(this); | |
199 var parameterName = $this.data("parameter-name"); | |
200 if (!parameterName) { | |
201 return; | |
202 } | |
203 | |
204 var configGridPanelView = $this.data("configGridPanelView"); | |
205 var config = configGridPanelView._cachedConfig; | |
206 var master = configGridPanelView._masterBehindMainArea; | |
207 var value = undefined; | |
208 if ($this.data("cgpma-tickbox")) { | |
209 value = $this.tickbox("option", "value"); | |
210 } else { | |
211 value = $this.textfield("option", "value"); | |
212 } | |
213 master.planConfigParameterUpdateWithRespectToValueAndDefaultValue(config, parameterName, value); | |
214 }, | |
215 | |
216 __panelInputApplyHandler: function() { | |
217 var $this = $(this); | |
218 var configGridPanelView = $this.data("configGridPanelView"); | |
219 configGridPanelView._masterBehindMainArea.cleanConfigPlannedParameterValuesAndApplyThem(configGridPanelView._cachedConfig); | |
220 }, | |
221 | |
222 | |
223 __panelInputDiscardHandler: function() { | |
224 var $this = $(this); | |
225 var configGridPanelView = $this.data("configGridPanelView"); | |
226 configGridPanelView._cachedConfig.cancelPlannedParameterUpdates(); | |
227 }, | |
228 | |
229 | |
230 // ----------------------------------------------------------------- | |
231 // config grid panel - sync | |
232 | |
233 syncConfigGridPanelMainArea: function(configGridPanelView, instant) { | |
234 var $inputs = configGridPanelView._$mainArea.data("$allInputs"); | |
235 if ($inputs) { | |
236 var _this = this; | |
237 $inputs.each(function() { | |
238 var $input = $(this); | |
239 var parameterName = $input.attr("data-parameter-name"); | |
240 if (parameterName) { | |
241 var widgetType = "textfield"; | |
242 if ($input.data("cgpma-tickbox")) { | |
243 widgetType = "tickbox"; | |
244 } | |
245 $input[widgetType]("option", { | |
246 "value": "" + _this.getConfigPlannedParameterValueOrDefaultValue(configGridPanelView._cachedConfig, parameterName), | |
247 "baseValue": "" + _this.getConfigParameterValueOrDefaultValue(configGridPanelView._cachedConfig, parameterName), | |
248 }); | |
249 } | |
250 }); | |
251 } | |
252 }, | |
253 | |
254 | |
255 // ----------------------------------------------------------------- | |
256 // config grid panel - destroy | |
257 | |
258 destroyConfigGridPanelMainArea: function() { | |
259 }, | |
260 | |
261 | |
262 // =========================== | |
263 // config grid header | |
264 | |
265 renderHeaderContent: function(headerView, instant) { | |
266 var newHashRelatedToOwnData = this._generateHeaderContentHashRelatedToOwnData(headerView); | |
267 | |
268 if (newHashRelatedToOwnData !== headerView._cachedContentHashRelatedToOwnData) { | |
269 this._doRenderHeaderContentRelatedToOwnData(headerView, instant); | |
270 headerView._cachedContentHashRelatedToOwnData = newHashRelatedToOwnData; | |
271 } | |
272 | |
273 var newHash = this._generateHeaderContentHashRelatedToGridLayout(headerView); | |
274 if (newHash !== headerView._cachedContentHashRelatedToGridLayout) { | |
275 this._doRenderHeaderContentRelatedToGridLayout(headerView, instant); | |
276 headerView._cachedContentHashRelatedToGridLayout = newHash; | |
277 } | |
278 }, | |
279 | |
280 | |
281 _renderHeaderContentRelatedToGridLayout: function(headerView, instant) {}, | |
282 | |
283 | |
284 _generateHeaderContentHashRelatedToOwnData: function(headerView) { | |
285 return headerView.options.config.getHashForParameters() + (headerView.options.config.hasPlannedParameterUpdates() ? "1" : "0") + headerView.dynamicDerivedConfigData.getHash(); | |
286 }, | |
287 | |
288 | |
289 _generateHeaderContentHashRelatedToGridLayout: function(headerView) {} | |
290 }); | |
291 }); | |
292 }, Logger); |