comparison src/DML/MainVisBundle/Resources/assets/marionette/modules/RepresentationModule/RepresentationModule.21-Master.entity._pair.js @ 0:493bcb69166c

added public content
author Daniel Wolff
date Tue, 09 Feb 2016 20:54:02 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:493bcb69166c
1 "use strict";
2
3 App.module("RepresentationModule", function(RepresentationModule, App, Backbone, Marionette, $, _, Logger) {
4
5 RepresentationModule.addInitializer(function(options){
6
7 RepresentationModule.registerMaster({
8 id: "entity._pair",
9 inherit: "entity._",
10
11 defaultConfigParameterValues: {
12 comparisonMode: "superposition"
13 },
14
15
16 // =================================================================
17 // config grid panel
18
19
20 // -----------------------------------------------------------------
21 // config grid panel - prepare
22
23 prepareConfigGridPanelMainArea: function(configGridPanelView) {
24 // Comparison mode radio buttons (tick boxes)
25 var $comparisonModeTickBoxes = configGridPanelView._$mainArea.find("[data-comparison-mode]");
26 configGridPanelView._$mainArea.data("$tickboxes_comparisonMode", $comparisonModeTickBoxes);
27 $comparisonModeTickBoxes.each(function() {
28 var $tickbox = $(this);
29 var comparisonMode = $tickbox.data("comparison-mode");
30 configGridPanelView._$mainArea.data("$tickbox_comparison-mode_" + comparisonMode, $tickbox);
31 });
32
33 // Parent master's behaviour
34 RepresentationModule.getMasterById("entity._").prepareConfigGridPanelMainArea.apply(this, arguments);
35 },
36
37
38 __panelInputChangeValueHandler: function(event) {
39 if (event.type == "tickboxchangevalue") {
40 var $thickbox = $(event.target);
41 var comparisonMode = $thickbox.data("comparisonMode");
42 if (comparisonMode) {
43 var configGridPanelView = $thickbox.data("configGridPanelView");
44 if (!configGridPanelView._$mainArea.data("ignoreChangesInComparisonModeTickboxes")) {
45 var master = $thickbox.data("configGridPanelView")._masterBehindMainArea;
46 master.planConfigParameterUpdateWithRespectToValueAndDefaultValue(configGridPanelView._cachedConfig, "comparisonMode", comparisonMode);
47 }
48 return;
49 };
50 }
51
52 // Parent master's behaviour
53 RepresentationModule.getMasterById("entity._").__panelInputChangeValueHandler.apply(this, arguments);
54 },
55
56
57 // -----------------------------------------------------------------
58 // config grid panel - sync
59
60 syncConfigGridPanelMainArea: function(configGridPanelView, instant) {
61
62 // comparison mode tick boxes + field visibility
63 var comparisonMode = this.getConfigParameterValueOrDefaultValue(configGridPanelView._cachedConfig, "comparisonMode").toLowerCase();
64 var plannedComparisonMode = this.getConfigPlannedParameterValueOrDefaultValue(configGridPanelView._cachedConfig, "comparisonMode").toLowerCase();
65 var comparisonModeHash = comparisonMode + plannedComparisonMode;
66 if (configGridPanelView._$mainArea.data("comparisonModeHash") != comparisonModeHash) {
67 configGridPanelView._$mainArea.data("comparisonModeHash", comparisonModeHash);
68
69 // tick boxes
70 configGridPanelView._$mainArea.data("ignoreChangesInComparisonModeTickboxes", true);
71 configGridPanelView._$mainArea.data("$tickboxes_comparisonMode").each(function() {
72 var $tickbox = $(this);
73 var value = plannedComparisonMode == $tickbox.data("comparison-mode") ? "1" : "";
74 var baseValue = (comparisonMode !== plannedComparisonMode)
75 ? (value ? "" : "1")
76 : (value ? "1" : "");
77
78 $tickbox.tickbox("option", {
79 "value": value,
80 "baseValue": baseValue
81 });
82 });
83 configGridPanelView._$mainArea.removeData("ignoreChangesInComparisonModeTickboxes");
84
85 // show / hide input blocks
86 // var presentParameterNames = _.keys(this._getPresentParameterNamesForLibrary(plannedComparisonMode));
87 // var absentParameterNames = _.difference(_.keys(this.options.presenceOfParameters), presentParameterNames);
88 //
89 // for (var i = 0; i < presentParameterNames.length; i++) {
90 // configGridPanelView._$mainArea.data("$inputBlock_" + presentParameterNames[i]).show();
91 // }
92 // for (var i = 0; i < absentParameterNames.length; i++) {
93 // configGridPanelView._$mainArea.data("$inputBlock_" + absentParameterNames[i]).hide();
94 // }
95 }
96
97 // Parent master's behaviour
98 RepresentationModule.getMasterById("entity._").syncConfigGridPanelMainArea.apply(this, arguments);
99 },
100
101
102 // =================================================================
103 // vis instance rendering
104
105
106 // -----------------------------------------------------------------
107 // debug mode
108
109 _mapDerivedVisInstanceDataAttributesToDebugAPIQueryBoxes: function (viewMaster) {
110 if (viewMaster.options.visInstanceSupportedComparisonModes.length) {
111 return [["left", "base", "apiRequestURIOnTheLeft", "apiResponseOnTheLeft"],
112 ["right", "base", "apiRequestURIOnTheRight", "apiResponseOnTheRight"]];
113 } else {
114 return [];
115 }
116 }
117 });
118 });
119 }, Logger);