Daniel@0
|
1 "use strict";
|
Daniel@0
|
2
|
Daniel@0
|
3 App.module("RepresentationModule", function(RepresentationModule, App, Backbone, Marionette, $, _, Logger) {
|
Daniel@0
|
4
|
Daniel@0
|
5 RepresentationModule.addInitializer(function(options){
|
Daniel@0
|
6
|
Daniel@0
|
7 RepresentationModule.registerMaster({
|
Daniel@0
|
8 id: "entity.collection.default",
|
Daniel@0
|
9 inherit: "entity._default",
|
Daniel@0
|
10
|
Daniel@0
|
11 defaultConfigParameterValues: {
|
Daniel@0
|
12 "library": "",
|
Daniel@0
|
13 "year": "",
|
Daniel@0
|
14 "genre": "",
|
Daniel@0
|
15 "composer": "",
|
Daniel@0
|
16 "performer": "",
|
Daniel@0
|
17 "title": "",
|
Daniel@0
|
18 "place": "",
|
Daniel@0
|
19 "collection": ""
|
Daniel@0
|
20 },
|
Daniel@0
|
21
|
Daniel@0
|
22 options: {
|
Daniel@0
|
23 availableLibraries: ["bl", "charm", "ilm", "mazurka"],
|
Daniel@0
|
24 librarySeparator: ";",
|
Daniel@0
|
25 librarySeparatorAlternatives: /\,/g,
|
Daniel@0
|
26 presenceOfParameters: {
|
Daniel@0
|
27 "title": ["bl", "charm", "ilm", "mazurka"],
|
Daniel@0
|
28 "year": ["bl", "charm", "mazurka"], // in ILM there is a release date (160 000 / 250 000)
|
Daniel@0
|
29 "composer": ["bl", "charm", "mazurka"],
|
Daniel@0
|
30 "performer": ["bl", "charm", "mazurka"], // artist in ILM
|
Daniel@0
|
31 "collection": ["bl"], // (only for ethnographic, excludes composer)
|
Daniel@0
|
32 "genre": ["ilm"],
|
Daniel@0
|
33 "place": ["bl"],
|
Daniel@0
|
34 },
|
Daniel@0
|
35 },
|
Daniel@0
|
36
|
Daniel@0
|
37
|
Daniel@0
|
38 // =================================================================
|
Daniel@0
|
39 // housekeeping
|
Daniel@0
|
40
|
Daniel@0
|
41 extractCleanedConfigParameterValuesFromPlannedParameterValues: function(config) {
|
Daniel@0
|
42 // Parent master's behaviour
|
Daniel@0
|
43 var result = RepresentationModule.getMasterById("entity._default").extractCleanedConfigParameterValuesFromPlannedParameterValues.apply(this, arguments);
|
Daniel@0
|
44
|
Daniel@0
|
45 // no need to remove recordingURI as there is no default value for it (it is removed automatically)
|
Daniel@0
|
46
|
Daniel@0
|
47 //console.log("CLEANED BEFORE", result);
|
Daniel@0
|
48 // remove all parameters that are not relevant to the chosen library
|
Daniel@0
|
49 var presentParameterNames = _.keys(this._getPresentParameterNamesForLibrary(result.library));
|
Daniel@0
|
50
|
Daniel@0
|
51 for (var parameterName in result) {
|
Daniel@0
|
52 if (result.hasOwnProperty(parameterName) && parameterName !== "library") {
|
Daniel@0
|
53 if (presentParameterNames.indexOf(parameterName) == -1) {
|
Daniel@0
|
54 delete result[parameterName];
|
Daniel@0
|
55 }
|
Daniel@0
|
56 }
|
Daniel@0
|
57 }
|
Daniel@0
|
58
|
Daniel@0
|
59 //console.log("CLEANED AFTER", result);
|
Daniel@0
|
60 return result;
|
Daniel@0
|
61 },
|
Daniel@0
|
62
|
Daniel@0
|
63
|
Daniel@0
|
64 // =================================================================
|
Daniel@0
|
65 // config grid panel
|
Daniel@0
|
66
|
Daniel@0
|
67 _parseLibraryStringToArray: function(library) {
|
Daniel@0
|
68 var fixedLibrary = _.str.trim(library).replace(this.options.librarySeparatorAlternatives, this.options.librarySeparator).toLowerCase();
|
Daniel@0
|
69 if (!fixedLibrary.length) {
|
Daniel@0
|
70 return [];
|
Daniel@0
|
71 } else {
|
Daniel@0
|
72 return _.map(fixedLibrary.split(this.options.librarySeparator), function(v) {return _.str.trim(v);});
|
Daniel@0
|
73 }
|
Daniel@0
|
74 },
|
Daniel@0
|
75
|
Daniel@0
|
76
|
Daniel@0
|
77 _parseLibraryStringToObject: function(library) {
|
Daniel@0
|
78 var result = {};
|
Daniel@0
|
79 var libraryAsArray = this._parseLibraryStringToArray(library);
|
Daniel@0
|
80 for (var i = 0; i < libraryAsArray.length; i++) {
|
Daniel@0
|
81 result[libraryAsArray[i]] = true;
|
Daniel@0
|
82 }
|
Daniel@0
|
83 return result;
|
Daniel@0
|
84 },
|
Daniel@0
|
85
|
Daniel@0
|
86
|
Daniel@0
|
87 _restoreLibraryStringFromArray: function(libraryArray) {
|
Daniel@0
|
88 libraryArray.sort();
|
Daniel@0
|
89 return libraryArray.length ? libraryArray.join(this.options.librarySeparator) : "";
|
Daniel@0
|
90
|
Daniel@0
|
91 },
|
Daniel@0
|
92
|
Daniel@0
|
93 _restoreLibraryStringFromObject: function(libraryObject) {
|
Daniel@0
|
94 return this._restoreLibraryStringFromArray(_.keys(libraryObject));
|
Daniel@0
|
95 },
|
Daniel@0
|
96
|
Daniel@0
|
97
|
Daniel@0
|
98 _getPresentParameterNamesForLibrary: function(library) {
|
Daniel@0
|
99 if (this._cachedPresentParameterNamesByLibrary === undefined) {
|
Daniel@0
|
100 this._cachedPresentParameterNamesByLibrary = {};
|
Daniel@0
|
101 }
|
Daniel@0
|
102 if (this._cachedPresentParameterNamesByLibrary[library] === undefined) {
|
Daniel@0
|
103 var libraries = this._parseLibraryStringToArray(library);
|
Daniel@0
|
104 var result = {};
|
Daniel@0
|
105 if (libraries.length) {
|
Daniel@0
|
106 for (var parameterName in this.options.presenceOfParameters) {
|
Daniel@0
|
107 var fieldPresence = this.options.presenceOfParameters[parameterName];
|
Daniel@0
|
108 if (_.intersection(libraries, fieldPresence).length == libraries.length) {
|
Daniel@0
|
109 result[parameterName] = true;
|
Daniel@0
|
110 }
|
Daniel@0
|
111 }
|
Daniel@0
|
112 }
|
Daniel@0
|
113 this._cachedPresentParameterNamesByLibrary[library] = result;
|
Daniel@0
|
114 }
|
Daniel@0
|
115
|
Daniel@0
|
116 return this._cachedPresentParameterNamesByLibrary[library];
|
Daniel@0
|
117 },
|
Daniel@0
|
118
|
Daniel@0
|
119
|
Daniel@0
|
120 // -----------------------------------------------------------------
|
Daniel@0
|
121 // config grid panel - prepare
|
Daniel@0
|
122
|
Daniel@0
|
123 prepareConfigGridPanelMainArea: function(configGridPanelView) {
|
Daniel@0
|
124 configGridPanelView._$mainArea.data("$libraryLabel_yes", configGridPanelView._$mainArea.find(".cgpma__id_library-label_yes"));
|
Daniel@0
|
125 configGridPanelView._$mainArea.data("$libraryLabel_no", configGridPanelView._$mainArea.find(".cgpma__id_library-label_no"));
|
Daniel@0
|
126
|
Daniel@0
|
127 // Library tickboxes
|
Daniel@0
|
128 for (var i = this.options.availableLibraries.length - 1; i >= 0; --i) {
|
Daniel@0
|
129 var availableLibrary = this.options.availableLibraries[i];
|
Daniel@0
|
130 var $tickbox = configGridPanelView._$mainArea.find(".cgpma__id_" + availableLibrary);
|
Daniel@0
|
131 configGridPanelView._$mainArea.data("$tickbox_library_" + availableLibrary, $tickbox);
|
Daniel@0
|
132 $tickbox.data("libraryId", availableLibrary);
|
Daniel@0
|
133 }
|
Daniel@0
|
134
|
Daniel@0
|
135 // Parent master's behaviour
|
Daniel@0
|
136 RepresentationModule.getMasterById("entity._default").prepareConfigGridPanelMainArea.apply(this, arguments);
|
Daniel@0
|
137 },
|
Daniel@0
|
138
|
Daniel@0
|
139
|
Daniel@0
|
140 __panelInputChangeValueHandler: function(event) {
|
Daniel@0
|
141 if (event.type == "tickboxchangevalue") {
|
Daniel@0
|
142 var $thickbox = $(event.target);
|
Daniel@0
|
143 var libraryId = $thickbox.data("libraryId");
|
Daniel@0
|
144 if (libraryId) {
|
Daniel@0
|
145 var configGridPanelView = $thickbox.data("configGridPanelView");
|
Daniel@0
|
146 var $mainArea = configGridPanelView._$mainArea;
|
Daniel@0
|
147 var master = $thickbox.data("configGridPanelView")._masterBehindMainArea;
|
Daniel@0
|
148 if (!$mainArea.data("ignoreChangesInLibraryTickboxes")) {
|
Daniel@0
|
149 var plannedLibraries = [];
|
Daniel@0
|
150 for (var i = 0; i < master.options.availableLibraries.length; i++) {
|
Daniel@0
|
151 var library = master.options.availableLibraries[i];
|
Daniel@0
|
152 if ($mainArea.data("$tickbox_library_" + library).tickbox("option", "value")) {
|
Daniel@0
|
153 plannedLibraries.push(library);
|
Daniel@0
|
154 }
|
Daniel@0
|
155 };
|
Daniel@0
|
156 master.planConfigParameterUpdateWithRespectToValueAndDefaultValue(configGridPanelView._cachedConfig, "library", plannedLibraries.join(";"));
|
Daniel@0
|
157 }
|
Daniel@0
|
158 return;
|
Daniel@0
|
159 };
|
Daniel@0
|
160 }
|
Daniel@0
|
161
|
Daniel@0
|
162 // Parent master's behaviour
|
Daniel@0
|
163 RepresentationModule.getMasterById("entity._default").__panelInputChangeValueHandler.apply(this, arguments);
|
Daniel@0
|
164 },
|
Daniel@0
|
165
|
Daniel@0
|
166
|
Daniel@0
|
167 // -----------------------------------------------------------------
|
Daniel@0
|
168 // config grid panel - sync
|
Daniel@0
|
169
|
Daniel@0
|
170 syncConfigGridPanelMainArea: function(configGridPanelView, instant) {
|
Daniel@0
|
171
|
Daniel@0
|
172 // bl, charm, ilm tick boxes + field visibility
|
Daniel@0
|
173 var library = this.getConfigParameterValueOrDefaultValue(configGridPanelView._cachedConfig, "library").toLowerCase();
|
Daniel@0
|
174 var plannedLibrary = this.getConfigPlannedParameterValueOrDefaultValue(configGridPanelView._cachedConfig, "library").toLowerCase();
|
Daniel@0
|
175 var libraryHash = library + plannedLibrary;
|
Daniel@0
|
176 if (configGridPanelView._$mainArea.data("libraryCache") != libraryHash) {
|
Daniel@0
|
177 configGridPanelView._$mainArea.data("libraryCache", libraryHash);
|
Daniel@0
|
178 //var libraryAsObject = this._parseLibraryStringToObject(library);
|
Daniel@0
|
179 var plannedLibraryAsArray = this._parseLibraryStringToArray(plannedLibrary);
|
Daniel@0
|
180 var plannedLibraryAsObject = this._parseLibraryStringToObject(plannedLibrary);
|
Daniel@0
|
181
|
Daniel@0
|
182 // tick boxes
|
Daniel@0
|
183 configGridPanelView._$mainArea.data("ignoreChangesInLibraryTickboxes", true);
|
Daniel@0
|
184 for (var i = this.options.availableLibraries.length - 1; i >= 0; --i) {
|
Daniel@0
|
185 var availableLibrary = this.options.availableLibraries[i];
|
Daniel@0
|
186 var $tickbox = configGridPanelView._$mainArea.data("$tickbox_library_" + availableLibrary);
|
Daniel@0
|
187 var value = (plannedLibraryAsObject[availableLibrary] !== undefined) ? "1" : "";
|
Daniel@0
|
188 var baseValue = (library !== plannedLibrary)
|
Daniel@0
|
189 ? (value ? "" : "1")
|
Daniel@0
|
190 : (value ? "1" : "");
|
Daniel@0
|
191
|
Daniel@0
|
192 $tickbox.tickbox("option", {
|
Daniel@0
|
193 "value": value,
|
Daniel@0
|
194 "baseValue": baseValue
|
Daniel@0
|
195 });
|
Daniel@0
|
196 }
|
Daniel@0
|
197 configGridPanelView._$mainArea.removeData("ignoreChangesInLibraryTickboxes");
|
Daniel@0
|
198
|
Daniel@0
|
199 // show / hide input blocks
|
Daniel@0
|
200 var presentParameterNames = _.keys(this._getPresentParameterNamesForLibrary(plannedLibrary));
|
Daniel@0
|
201 var absentParameterNames = _.difference(_.keys(this.options.presenceOfParameters), presentParameterNames);
|
Daniel@0
|
202
|
Daniel@0
|
203 for (var i = 0; i < presentParameterNames.length; i++) {
|
Daniel@0
|
204 configGridPanelView._$mainArea.data("$inputBlock_" + presentParameterNames[i]).show();
|
Daniel@0
|
205 }
|
Daniel@0
|
206 for (var i = 0; i < absentParameterNames.length; i++) {
|
Daniel@0
|
207 configGridPanelView._$mainArea.data("$inputBlock_" + absentParameterNames[i]).hide();
|
Daniel@0
|
208 }
|
Daniel@0
|
209
|
Daniel@0
|
210 // library label
|
Daniel@0
|
211 configGridPanelView._$mainArea.data("$libraryLabel_no") .toggle(plannedLibraryAsArray.length == 0);
|
Daniel@0
|
212 configGridPanelView._$mainArea.data("$libraryLabel_yes").toggle(plannedLibraryAsArray.length != 0);
|
Daniel@0
|
213 }
|
Daniel@0
|
214
|
Daniel@0
|
215 // Parent master's behaviour
|
Daniel@0
|
216 RepresentationModule.getMasterById("entity._default").syncConfigGridPanelMainArea.apply(this, arguments);
|
Daniel@0
|
217 },
|
Daniel@0
|
218
|
Daniel@0
|
219
|
Daniel@0
|
220 // =================================================================
|
Daniel@0
|
221 // config grid header
|
Daniel@0
|
222
|
Daniel@0
|
223 _generateHeaderLabel1: function(viewHeaderView) {
|
Daniel@0
|
224 return this._generateCollectionConfigTitle(viewHeaderView.options.config);
|
Daniel@0
|
225 },
|
Daniel@0
|
226
|
Daniel@0
|
227 _generateHeaderLabel2: function(viewHeader) {
|
Daniel@0
|
228 var rawConfigParameters = viewHeader.options.config.attributes.parameters.attributes;
|
Daniel@0
|
229 var attributesOfDefinitionForCollection = viewHeader.dynamicDerivedConfigData.attributes.dynamicDefinitionForCollection.attributes;
|
Daniel@0
|
230 var attributesOfDefinitionForOverlayedRecording = viewHeader.dynamicDerivedConfigData.attributes.dynamicDefinitionForOverlayedRecording.attributes;
|
Daniel@0
|
231
|
Daniel@0
|
232 var labelParts = [];
|
Daniel@0
|
233
|
Daniel@0
|
234 var collectionSize = attributesOfDefinitionForCollection.fullSize;
|
Daniel@0
|
235 var sampleSize = attributesOfDefinitionForCollection.sampleSize;
|
Daniel@0
|
236 var overlayedRecordingURI = rawConfigParameters.recordingURI;
|
Daniel@0
|
237 var overlayedRecordingLabel = attributesOfDefinitionForOverlayedRecording.label;
|
Daniel@0
|
238
|
Daniel@0
|
239 // collection size
|
Daniel@0
|
240 if (_.isNumber(collectionSize)) {
|
Daniel@0
|
241 var collectionSizeAsStr = collectionSize ? _.str.numberFormat(collectionSize) : "no";
|
Daniel@0
|
242 labelParts.push(_.str.sprintf("%s recording%s", collectionSizeAsStr, collectionSize !== 1 ? "s" : ""));
|
Daniel@0
|
243 } else if (collectionSize === null) {
|
Daniel@0
|
244 labelParts.push("updating...");
|
Daniel@0
|
245 } else {
|
Daniel@0
|
246 if (attributesOfDefinitionForCollection.id === false) {
|
Daniel@0
|
247 labelParts.push("an error occured");
|
Daniel@0
|
248 }
|
Daniel@0
|
249 }
|
Daniel@0
|
250
|
Daniel@0
|
251 // sample size
|
Daniel@0
|
252 if (_.isNumber(sampleSize) && sampleSize !== collectionSize) {
|
Daniel@0
|
253 labelParts.push(" (", sampleSize, " in the sample)");
|
Daniel@0
|
254 }
|
Daniel@0
|
255
|
Daniel@0
|
256 // recordingURI
|
Daniel@0
|
257 if (overlayedRecordingURI) {
|
Daniel@0
|
258 if (_.isString(overlayedRecordingLabel)) {
|
Daniel@0
|
259 labelParts.push(", ‘", overlayedRecordingLabel, "’ selected");
|
Daniel@0
|
260 } else if (overlayedRecordingLabel === null) {
|
Daniel@0
|
261 //labelParts.push(", updating selected recording");
|
Daniel@0
|
262 } else {
|
Daniel@0
|
263 //labelParts.push(", a problem with selected recording");
|
Daniel@0
|
264 }
|
Daniel@0
|
265 }
|
Daniel@0
|
266 return labelParts.join("");
|
Daniel@0
|
267 },
|
Daniel@0
|
268
|
Daniel@0
|
269
|
Daniel@0
|
270 // =================================================================
|
Daniel@0
|
271 // dynamic derived config data
|
Daniel@0
|
272
|
Daniel@0
|
273 __upateMethodOfDynamicDerivedConfigData: function() {
|
Daniel@0
|
274 if (this.attributes.dynamicDefinitionForCollection.attributes.errors) {
|
Daniel@0
|
275 this.attributes.dynamicDefinitionForCollection.update(true);
|
Daniel@0
|
276 }
|
Daniel@0
|
277 if (this.attributes.dynamicDefinitionForOverlayedRecording.attributes.errors) {
|
Daniel@0
|
278 this.attributes.dynamicDefinitionForOverlayedRecording.update(true);
|
Daniel@0
|
279 }
|
Daniel@0
|
280 },
|
Daniel@0
|
281
|
Daniel@0
|
282 generateDynamicDerivedConfigData: function(config, configGrid) {
|
Daniel@0
|
283 var dynamicDefinitionForCollection = App.dynamicDefinitionProviderForCollections.get(config);
|
Daniel@0
|
284 var dynamicDefinitionForOverlayedRecording = App.dynamicDefinitionProviderForRecordings.get(config);
|
Daniel@0
|
285
|
Daniel@0
|
286 var dynamicDerivedConfigData = new RepresentationModule.DynamicDerivedConfigData({
|
Daniel@0
|
287 dynamicDefinitionForCollection: dynamicDefinitionForCollection,
|
Daniel@0
|
288 dynamicDefinitionForOverlayedRecording: dynamicDefinitionForOverlayedRecording
|
Daniel@0
|
289 });
|
Daniel@0
|
290
|
Daniel@0
|
291 dynamicDerivedConfigData.listenTo(dynamicDefinitionForCollection, "change", function() {
|
Daniel@0
|
292 dynamicDerivedConfigData.trigger("change:dynamicDefinitionForCollection");
|
Daniel@0
|
293 dynamicDerivedConfigData.trigger("change");
|
Daniel@0
|
294 });
|
Daniel@0
|
295 dynamicDerivedConfigData.listenTo(dynamicDefinitionForOverlayedRecording, "change", function() {
|
Daniel@0
|
296 dynamicDerivedConfigData.trigger("change:dynamicDefinitionForOverlayedRecording");
|
Daniel@0
|
297 dynamicDerivedConfigData.trigger("change");
|
Daniel@0
|
298 });
|
Daniel@0
|
299
|
Daniel@0
|
300 dynamicDerivedConfigData.update = this.__upateMethodOfDynamicDerivedConfigData;
|
Daniel@0
|
301
|
Daniel@0
|
302 return dynamicDerivedConfigData;
|
Daniel@0
|
303 },
|
Daniel@0
|
304
|
Daniel@0
|
305
|
Daniel@0
|
306 // =================================================================
|
Daniel@0
|
307 // dynamic derived vis instance data
|
Daniel@0
|
308
|
Daniel@0
|
309
|
Daniel@0
|
310 // -----------------------------------------------------------------
|
Daniel@0
|
311 // dynamic derived vis instance data - base
|
Daniel@0
|
312
|
Daniel@0
|
313 __optionsOfDynamicDerivedVisInstanceDataForBase: {
|
Daniel@0
|
314 attributesToExcludeFromHash: ["apiResponse"],
|
Daniel@0
|
315 customHashSuffixGenerator: function (attributes) {
|
Daniel@0
|
316 if (attributes.apiResponse) {
|
Daniel@0
|
317 return JSON.stringify(attributes.apiResponse.errors);
|
Daniel@0
|
318 } else {
|
Daniel@0
|
319 return typeof attributes.apiResponse;
|
Daniel@0
|
320 }
|
Daniel@0
|
321 }
|
Daniel@0
|
322 },
|
Daniel@0
|
323
|
Daniel@0
|
324
|
Daniel@0
|
325 __upateMethodOfDynamicDerivedVisInstanceDataForBase: function(force) {
|
Daniel@0
|
326 var visInstanceView = this.options.visInstanceView;
|
Daniel@0
|
327 var dynamicDefinitionForCollection = visInstanceView.dynamicDerivedConfigDataForEntity.attributes.dynamicDefinitionForCollection;
|
Daniel@0
|
328 if (!dynamicDefinitionForCollection) { // entity kind has changed (e.g. a grid was reset)
|
Daniel@0
|
329 return;
|
Daniel@0
|
330 }
|
Daniel@0
|
331 var collectionId = dynamicDefinitionForCollection.attributes.id;
|
Daniel@0
|
332 var requestParams = _.clone(visInstanceView.dynamicDerivedConfigDataForView.attributes.basePerspectiveRequestParams);
|
Daniel@0
|
333
|
Daniel@0
|
334 if (!requestParams || !collectionId) {
|
Daniel@0
|
335 this.set({
|
Daniel@0
|
336 apiRequestURI: undefined,
|
Daniel@0
|
337 apiRequestParamsHash: undefined,
|
Daniel@0
|
338 apiResponse: undefined
|
Daniel@0
|
339 });
|
Daniel@0
|
340 return;
|
Daniel@0
|
341 }
|
Daniel@0
|
342 requestParams.cid = collectionId;
|
Daniel@0
|
343
|
Daniel@0
|
344 var apiRequestParamsHash = JSON.stringify(requestParams);
|
Daniel@0
|
345
|
Daniel@0
|
346 if (!force && apiRequestParamsHash == this.attributes.apiRequestParamsHash) {
|
Daniel@0
|
347 return;
|
Daniel@0
|
348 }
|
Daniel@0
|
349
|
Daniel@0
|
350 var _this = this;
|
Daniel@0
|
351 var apiRequestURI = App.DataModule.CliopatriaAPI.request("getCollectionPerspective", requestParams, function(data){
|
Daniel@0
|
352 if (JSON.stringify(requestParams) != _this.attributes.apiRequestParamsHash) {
|
Daniel@0
|
353 return;
|
Daniel@0
|
354 }
|
Daniel@0
|
355 _this.set({
|
Daniel@0
|
356 apiRequestParamsHash: undefined,
|
Daniel@0
|
357 apiResponse: data
|
Daniel@0
|
358 });
|
Daniel@0
|
359 });
|
Daniel@0
|
360
|
Daniel@0
|
361 this.set({
|
Daniel@0
|
362 apiRequestURI: apiRequestURI,
|
Daniel@0
|
363 apiRequestParamsHash: apiRequestParamsHash,
|
Daniel@0
|
364 apiResponse: null
|
Daniel@0
|
365 });
|
Daniel@0
|
366 },
|
Daniel@0
|
367
|
Daniel@0
|
368
|
Daniel@0
|
369 generateDynamicDerivedVisInstanceDataForBase: function(visInstanceView) {
|
Daniel@0
|
370 var optionsForThisDynamicDerivedVisInstanceDataForBase = _.clone(this.__optionsOfDynamicDerivedVisInstanceDataForBase);
|
Daniel@0
|
371 optionsForThisDynamicDerivedVisInstanceDataForBase.visInstanceView = visInstanceView;
|
Daniel@0
|
372
|
Daniel@0
|
373 var dynamicDerivedVisInstanceDataForBase = new RepresentationModule.DynamicDerivedVisInstanceData({
|
Daniel@0
|
374 apiRequestURI: undefined,
|
Daniel@0
|
375 apiRequestParamsHash: undefined,
|
Daniel@0
|
376 apiResponse: undefined
|
Daniel@0
|
377 }, optionsForThisDynamicDerivedVisInstanceDataForBase);
|
Daniel@0
|
378
|
Daniel@0
|
379 dynamicDerivedVisInstanceDataForBase.update = this.__upateMethodOfDynamicDerivedVisInstanceDataForBase;
|
Daniel@0
|
380
|
Daniel@0
|
381 dynamicDerivedVisInstanceDataForBase.listenTo(visInstanceView.dynamicDerivedConfigDataForEntity, "change:dynamicDefinitionForCollection", dynamicDerivedVisInstanceDataForBase.update);
|
Daniel@0
|
382 dynamicDerivedVisInstanceDataForBase.listenTo(visInstanceView.dynamicDerivedConfigDataForView, "change:basePerspectiveRequestParams", dynamicDerivedVisInstanceDataForBase.update);
|
Daniel@0
|
383
|
Daniel@0
|
384 dynamicDerivedVisInstanceDataForBase.update();
|
Daniel@0
|
385
|
Daniel@0
|
386 return dynamicDerivedVisInstanceDataForBase;
|
Daniel@0
|
387 },
|
Daniel@0
|
388
|
Daniel@0
|
389
|
Daniel@0
|
390 verifyAllDataForVisInstanceBase: function(visInstanceView) {
|
Daniel@0
|
391 this._verifyThatViewIsNotEmptyOrUnknown(visInstanceView);
|
Daniel@0
|
392
|
Daniel@0
|
393 // if (visInstanceView.options.entityConfig.getParameterValue("library") == "charm"
|
Daniel@0
|
394 // && visInstanceView.options.viewConfig.getParameterValue("kind") == "key-relative-chord-seq") {
|
Daniel@0
|
395 // throw new RepresentationModule.Error({type: "api-message_progress_base", derivedDataToUpdate: "base"});
|
Daniel@0
|
396 // }
|
Daniel@0
|
397
|
Daniel@0
|
398
|
Daniel@0
|
399 var attributesOfDerivedConfigDataForEntity = visInstanceView.dynamicDerivedConfigDataForEntity.attributes;
|
Daniel@0
|
400 var dynamicDefinitionForCollection = attributesOfDerivedConfigDataForEntity.dynamicDefinitionForCollection;
|
Daniel@0
|
401 var attributesOfCollection = dynamicDefinitionForCollection ? dynamicDefinitionForCollection.attributes : {};
|
Daniel@0
|
402
|
Daniel@0
|
403 if (attributesOfCollection.id === null) {
|
Daniel@0
|
404 throw new RepresentationModule.Error({type: "data-preparing_entity-derived"});
|
Daniel@0
|
405 }
|
Daniel@0
|
406 if (attributesOfCollection.id === false) {
|
Daniel@0
|
407 throw new RepresentationModule.Error({type: "api-error_entity-derived", apiErrors: attributesOfCollection.errors, coverTapAction: this.__coverTapActionThatUpdatesDynamicDerivedData, derivedDataToUpdate: "entity"});
|
Daniel@0
|
408 }
|
Daniel@0
|
409 if (attributesOfCollection.id === "") {
|
Daniel@0
|
410 throw new RepresentationModule.Error({type: "collection_no-recordings"});
|
Daniel@0
|
411 }
|
Daniel@0
|
412 if (attributesOfCollection.id === undefined) {
|
Daniel@0
|
413 throw new RepresentationModule.Error({type: "collection_undefined"});
|
Daniel@0
|
414 }
|
Daniel@0
|
415
|
Daniel@0
|
416 var attribytesOfDerivedVisInstanceDataForBase = visInstanceView.dynamicDerivedVisInstanceDataForBase.attributes;
|
Daniel@0
|
417 if (!attribytesOfDerivedVisInstanceDataForBase.apiResponse) {
|
Daniel@0
|
418 throw new RepresentationModule.Error({type: "data-preparing_base"});
|
Daniel@0
|
419 }
|
Daniel@0
|
420 if (attribytesOfDerivedVisInstanceDataForBase.apiResponse.errors) {
|
Daniel@0
|
421 if (attribytesOfDerivedVisInstanceDataForBase.apiResponse.errors && attribytesOfDerivedVisInstanceDataForBase.apiResponse.errors[0]) {
|
Daniel@0
|
422 var error0 = attribytesOfDerivedVisInstanceDataForBase.apiResponse.errors[0];
|
Daniel@0
|
423 if (error0.code == 11 || error0.code == 12 || error0.code == 13) {
|
Daniel@0
|
424
|
Daniel@0
|
425 //FIXME this is a temp hack
|
Daniel@0
|
426 var checkEvery = 2000;
|
Daniel@0
|
427 var checkEveryRandomComponent = 500;
|
Daniel@0
|
428 if (visInstanceView.autoRefreshTimeout) {
|
Daniel@0
|
429 clearTimeout(visInstanceView.autoRefreshTimeout);
|
Daniel@0
|
430 }
|
Daniel@0
|
431 visInstanceView.autoRefreshTimeout = setTimeout(function() {
|
Daniel@0
|
432 if (visInstanceView.dynamicDerivedVisInstanceDataForBase.attributes.apiResponse.errors) {
|
Daniel@0
|
433 var error0 = attribytesOfDerivedVisInstanceDataForBase.apiResponse.errors[0];
|
Daniel@0
|
434 if (error0.code == 11 || error0.code == 12 || error0.code == 13) {
|
Daniel@0
|
435 visInstanceView.dynamicDerivedVisInstanceDataForBase.update();
|
Daniel@0
|
436 }
|
Daniel@0
|
437 }
|
Daniel@0
|
438 }, checkEvery + Math.round(Math.random() * checkEveryRandomComponent));
|
Daniel@0
|
439 // END FIXME
|
Daniel@0
|
440
|
Daniel@0
|
441 throw new RepresentationModule.Error({type: "api-message_progress_base", apiErrors: attribytesOfDerivedVisInstanceDataForBase.apiResponse.errors, coverTapAction: this.__coverTapActionThatUpdatesDynamicDerivedData, derivedDataToUpdate: "base"});
|
Daniel@0
|
442
|
Daniel@0
|
443 // FIXME errors like this should probably go to Master.view.xxx
|
Daniel@0
|
444 } else if (error0.code == 20) {
|
Daniel@0
|
445 throw new RepresentationModule.Error({type: "ok-count-0", apiErrors: attribytesOfDerivedVisInstanceDataForBase.apiResponse.errors});
|
Daniel@0
|
446 }
|
Daniel@0
|
447 }
|
Daniel@0
|
448 throw new RepresentationModule.Error({type: "api-error_base", apiErrors: attribytesOfDerivedVisInstanceDataForBase.apiResponse.errors, coverTapAction: this.__coverTapActionThatUpdatesDynamicDerivedData, derivedDataToUpdate: "base"});
|
Daniel@0
|
449 }
|
Daniel@0
|
450
|
Daniel@0
|
451 },
|
Daniel@0
|
452
|
Daniel@0
|
453
|
Daniel@0
|
454 // -----------------------------------------------------------------
|
Daniel@0
|
455 // dynamic derived vis instance data - overlay
|
Daniel@0
|
456
|
Daniel@0
|
457
|
Daniel@0
|
458 // -----------------------------------------------------------------
|
Daniel@0
|
459 // dynamic derived vis instance data - temp
|
Daniel@0
|
460
|
Daniel@0
|
461 });
|
Daniel@0
|
462 });
|
Daniel@0
|
463 }, Logger);
|