Mercurial > hg > dml-open-vis
diff src/DML/MainVisBundle/Resources/assets/marionette/modules/RepresentationModule/RepresentationModule.02-DynamicDerivedConfigDataProvider.js @ 0:493bcb69166c
added public content
author | Daniel Wolff |
---|---|
date | Tue, 09 Feb 2016 20:54:02 +0100 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/DML/MainVisBundle/Resources/assets/marionette/modules/RepresentationModule/RepresentationModule.02-DynamicDerivedConfigDataProvider.js Tue Feb 09 20:54:02 2016 +0100 @@ -0,0 +1,53 @@ +"use strict"; + +App.module("RepresentationModule", function(RepresentationModule, App, Backbone, Marionette, $, _, Logger) { + + // Define private variables + var logger = null; + + /** + * Module initializer + * + */ + RepresentationModule.addInitializer(function(){ + + logger = Logger.get("App.RepresentationModule"); + + RepresentationModule.DynanicDerivedConfigDataProvider = Marionette.Object.extend({ + initialize: function() { + this._dynamicDerivedConfigDataByConfigClientId = {}; + this._kindByConfigClientId = {}; + }, + + get: function(config) { + if (!config) { + return null; + } + var configClientId = config.getClientId(); + + var configKind = config.getParameterValue("kind"); + if (this._kindByConfigClientId[configClientId] !== configKind) { + this.retire(configClientId); + this._kindByConfigClientId[configClientId] = configKind; + } + if (!this._dynamicDerivedConfigDataByConfigClientId[configClientId]) { + var master = App.RepresentationModule.getMasterForConfig(config); + var configGrid = this.options.configGridsByType[config.getConfigGridType()]; + this._dynamicDerivedConfigDataByConfigClientId[configClientId] = master.generateDynamicDerivedConfigData(config, configGrid); + } + + return this._dynamicDerivedConfigDataByConfigClientId[configClientId]; + }, + + retire: function (configClientId) { + var dynamicDerivedDataToRetire = this._dynamicDerivedConfigDataByConfigClientId[configClientId]; + if (dynamicDerivedDataToRetire) { + dynamicDerivedDataToRetire.destroy(); + } + delete this._dynamicDerivedConfigDataByConfigClientId[configClientId]; + delete this._kindByConfigClientId[configClientId]; + }, + + }); + }); +}, Logger);