Daniel@0
|
1 "use strict";
|
Daniel@0
|
2
|
Daniel@0
|
3 App.module("DataModule", function(DataModule, App, Backbone, Marionette, $, _, Logger) {
|
Daniel@0
|
4 // Prevent auto start
|
Daniel@0
|
5 //CollectionDefinitionProvider.startWithParent = false;
|
Daniel@0
|
6
|
Daniel@0
|
7 // Define private variables
|
Daniel@0
|
8 var logger = null;
|
Daniel@0
|
9
|
Daniel@0
|
10 /**
|
Daniel@0
|
11 * Module initializer
|
Daniel@0
|
12 *
|
Daniel@0
|
13 */
|
Daniel@0
|
14 DataModule.addInitializer(function(){
|
Daniel@0
|
15
|
Daniel@0
|
16 logger = Logger.get("App.DataModule");
|
Daniel@0
|
17
|
Daniel@0
|
18 DataModule.DynamicDefinitionForRecording = DataModule.DynamicDefinition.extend({});
|
Daniel@0
|
19 DataModule.DymanicDefinitionProviderForRecordings = DataModule.DynamicDefinitionProvider.extend({
|
Daniel@0
|
20
|
Daniel@0
|
21 options: {
|
Daniel@0
|
22 DynamicDefinition: DataModule.DynamicDefinitionForRecording,
|
Daniel@0
|
23 apiMethod: "getRecordingPerspective",
|
Daniel@0
|
24 customAttributesWhenNotApplicable: {label: undefined},
|
Daniel@0
|
25 customAttributesWhileBeingUpdated: {label: null},
|
Daniel@0
|
26 customAttributesWhenFaulty: {label: false}
|
Daniel@0
|
27 },
|
Daniel@0
|
28
|
Daniel@0
|
29 isFaulty: function(dynamicDefinition) {
|
Daniel@0
|
30 return dynamicDefinition.attributes.label === false;
|
Daniel@0
|
31 },
|
Daniel@0
|
32
|
Daniel@0
|
33 isBeingUpdated: function(dynamicDefinition) {
|
Daniel@0
|
34 return dynamicDefinition.attributes.label === null;
|
Daniel@0
|
35 },
|
Daniel@0
|
36
|
Daniel@0
|
37 configParametersToRequestParameters: function(config) {
|
Daniel@0
|
38 var rawConfigParameters = config.attributes.parameters.attributes;
|
Daniel@0
|
39 if (rawConfigParameters.recordingURI) {
|
Daniel@0
|
40 return {"uri": rawConfigParameters.recordingURI, "pid": "properties"};
|
Daniel@0
|
41 } else {
|
Daniel@0
|
42 return null;
|
Daniel@0
|
43 }
|
Daniel@0
|
44 },
|
Daniel@0
|
45
|
Daniel@0
|
46 apiResponseToAttributes: function(data, query) {
|
Daniel@0
|
47 var attributes = {};
|
Daniel@0
|
48
|
Daniel@0
|
49 if (data && data.label) {
|
Daniel@0
|
50 attributes = data;
|
Daniel@0
|
51 } else {
|
Daniel@0
|
52 attributes = {label: false};
|
Daniel@0
|
53 if (data.errors) {
|
Daniel@0
|
54 attributes = _.clone(this.options.customAttributesWhenFaulty)
|
Daniel@0
|
55 attributes.errors = data.errors;
|
Daniel@0
|
56 }
|
Daniel@0
|
57 logger.warn("An error occured when attempting to obtain new recording definition. Query / response:", query, data);
|
Daniel@0
|
58 };
|
Daniel@0
|
59 attributes.query = query;
|
Daniel@0
|
60 return attributes;
|
Daniel@0
|
61 }
|
Daniel@0
|
62 });
|
Daniel@0
|
63 });
|
Daniel@0
|
64 }, Logger);
|