annotate src/DML/MainVisBundle/Resources/assets/marionette/modules/RepresentationModule/RepresentationModule.20-Master._.js @ 1:f38015048f48 tip

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