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 // Define private variables
|
Daniel@0
|
6 var logger = null;
|
Daniel@0
|
7
|
Daniel@0
|
8 /**
|
Daniel@0
|
9 * Module initializer
|
Daniel@0
|
10 *
|
Daniel@0
|
11 */
|
Daniel@0
|
12 RepresentationModule.addInitializer(function(){
|
Daniel@0
|
13
|
Daniel@0
|
14 logger = Logger.get("App.RepresentationModule");
|
Daniel@0
|
15
|
Daniel@0
|
16 RepresentationModule.DynanicDerivedConfigDataProvider = Marionette.Object.extend({
|
Daniel@0
|
17 initialize: function() {
|
Daniel@0
|
18 this._dynamicDerivedConfigDataByConfigClientId = {};
|
Daniel@0
|
19 this._kindByConfigClientId = {};
|
Daniel@0
|
20 },
|
Daniel@0
|
21
|
Daniel@0
|
22 get: function(config) {
|
Daniel@0
|
23 if (!config) {
|
Daniel@0
|
24 return null;
|
Daniel@0
|
25 }
|
Daniel@0
|
26 var configClientId = config.getClientId();
|
Daniel@0
|
27
|
Daniel@0
|
28 var configKind = config.getParameterValue("kind");
|
Daniel@0
|
29 if (this._kindByConfigClientId[configClientId] !== configKind) {
|
Daniel@0
|
30 this.retire(configClientId);
|
Daniel@0
|
31 this._kindByConfigClientId[configClientId] = configKind;
|
Daniel@0
|
32 }
|
Daniel@0
|
33 if (!this._dynamicDerivedConfigDataByConfigClientId[configClientId]) {
|
Daniel@0
|
34 var master = App.RepresentationModule.getMasterForConfig(config);
|
Daniel@0
|
35 var configGrid = this.options.configGridsByType[config.getConfigGridType()];
|
Daniel@0
|
36 this._dynamicDerivedConfigDataByConfigClientId[configClientId] = master.generateDynamicDerivedConfigData(config, configGrid);
|
Daniel@0
|
37 }
|
Daniel@0
|
38
|
Daniel@0
|
39 return this._dynamicDerivedConfigDataByConfigClientId[configClientId];
|
Daniel@0
|
40 },
|
Daniel@0
|
41
|
Daniel@0
|
42 retire: function (configClientId) {
|
Daniel@0
|
43 var dynamicDerivedDataToRetire = this._dynamicDerivedConfigDataByConfigClientId[configClientId];
|
Daniel@0
|
44 if (dynamicDerivedDataToRetire) {
|
Daniel@0
|
45 dynamicDerivedDataToRetire.destroy();
|
Daniel@0
|
46 }
|
Daniel@0
|
47 delete this._dynamicDerivedConfigDataByConfigClientId[configClientId];
|
Daniel@0
|
48 delete this._kindByConfigClientId[configClientId];
|
Daniel@0
|
49 },
|
Daniel@0
|
50
|
Daniel@0
|
51 });
|
Daniel@0
|
52 });
|
Daniel@0
|
53 }, Logger);
|