Daniel@0: "use strict"; Daniel@0: Daniel@0: App.module("RepresentationModule", function(RepresentationModule, App, Backbone, Marionette, $, _, Logger) { Daniel@0: Daniel@0: RepresentationModule.addInitializer(function(options){ Daniel@0: Daniel@0: RepresentationModule.registerMaster({ Daniel@0: id: "entity._pair", Daniel@0: inherit: "entity._", Daniel@0: Daniel@0: defaultConfigParameterValues: { Daniel@0: comparisonMode: "superposition" Daniel@0: }, Daniel@0: Daniel@0: Daniel@0: // ================================================================= Daniel@0: // config grid panel Daniel@0: Daniel@0: Daniel@0: // ----------------------------------------------------------------- Daniel@0: // config grid panel - prepare Daniel@0: Daniel@0: prepareConfigGridPanelMainArea: function(configGridPanelView) { Daniel@0: // Comparison mode radio buttons (tick boxes) Daniel@0: var $comparisonModeTickBoxes = configGridPanelView._$mainArea.find("[data-comparison-mode]"); Daniel@0: configGridPanelView._$mainArea.data("$tickboxes_comparisonMode", $comparisonModeTickBoxes); Daniel@0: $comparisonModeTickBoxes.each(function() { Daniel@0: var $tickbox = $(this); Daniel@0: var comparisonMode = $tickbox.data("comparison-mode"); Daniel@0: configGridPanelView._$mainArea.data("$tickbox_comparison-mode_" + comparisonMode, $tickbox); Daniel@0: }); Daniel@0: Daniel@0: // Parent master's behaviour Daniel@0: RepresentationModule.getMasterById("entity._").prepareConfigGridPanelMainArea.apply(this, arguments); Daniel@0: }, Daniel@0: Daniel@0: Daniel@0: __panelInputChangeValueHandler: function(event) { Daniel@0: if (event.type == "tickboxchangevalue") { Daniel@0: var $thickbox = $(event.target); Daniel@0: var comparisonMode = $thickbox.data("comparisonMode"); Daniel@0: if (comparisonMode) { Daniel@0: var configGridPanelView = $thickbox.data("configGridPanelView"); Daniel@0: if (!configGridPanelView._$mainArea.data("ignoreChangesInComparisonModeTickboxes")) { Daniel@0: var master = $thickbox.data("configGridPanelView")._masterBehindMainArea; Daniel@0: master.planConfigParameterUpdateWithRespectToValueAndDefaultValue(configGridPanelView._cachedConfig, "comparisonMode", comparisonMode); Daniel@0: } Daniel@0: return; Daniel@0: }; Daniel@0: } Daniel@0: Daniel@0: // Parent master's behaviour Daniel@0: RepresentationModule.getMasterById("entity._").__panelInputChangeValueHandler.apply(this, arguments); Daniel@0: }, Daniel@0: Daniel@0: Daniel@0: // ----------------------------------------------------------------- Daniel@0: // config grid panel - sync Daniel@0: Daniel@0: syncConfigGridPanelMainArea: function(configGridPanelView, instant) { Daniel@0: Daniel@0: // comparison mode tick boxes + field visibility Daniel@0: var comparisonMode = this.getConfigParameterValueOrDefaultValue(configGridPanelView._cachedConfig, "comparisonMode").toLowerCase(); Daniel@0: var plannedComparisonMode = this.getConfigPlannedParameterValueOrDefaultValue(configGridPanelView._cachedConfig, "comparisonMode").toLowerCase(); Daniel@0: var comparisonModeHash = comparisonMode + plannedComparisonMode; Daniel@0: if (configGridPanelView._$mainArea.data("comparisonModeHash") != comparisonModeHash) { Daniel@0: configGridPanelView._$mainArea.data("comparisonModeHash", comparisonModeHash); Daniel@0: Daniel@0: // tick boxes Daniel@0: configGridPanelView._$mainArea.data("ignoreChangesInComparisonModeTickboxes", true); Daniel@0: configGridPanelView._$mainArea.data("$tickboxes_comparisonMode").each(function() { Daniel@0: var $tickbox = $(this); Daniel@0: var value = plannedComparisonMode == $tickbox.data("comparison-mode") ? "1" : ""; Daniel@0: var baseValue = (comparisonMode !== plannedComparisonMode) Daniel@0: ? (value ? "" : "1") Daniel@0: : (value ? "1" : ""); Daniel@0: Daniel@0: $tickbox.tickbox("option", { Daniel@0: "value": value, Daniel@0: "baseValue": baseValue Daniel@0: }); Daniel@0: }); Daniel@0: configGridPanelView._$mainArea.removeData("ignoreChangesInComparisonModeTickboxes"); Daniel@0: Daniel@0: // show / hide input blocks Daniel@0: // var presentParameterNames = _.keys(this._getPresentParameterNamesForLibrary(plannedComparisonMode)); Daniel@0: // var absentParameterNames = _.difference(_.keys(this.options.presenceOfParameters), presentParameterNames); Daniel@0: // Daniel@0: // for (var i = 0; i < presentParameterNames.length; i++) { Daniel@0: // configGridPanelView._$mainArea.data("$inputBlock_" + presentParameterNames[i]).show(); Daniel@0: // } Daniel@0: // for (var i = 0; i < absentParameterNames.length; i++) { Daniel@0: // configGridPanelView._$mainArea.data("$inputBlock_" + absentParameterNames[i]).hide(); Daniel@0: // } Daniel@0: } Daniel@0: Daniel@0: // Parent master's behaviour Daniel@0: RepresentationModule.getMasterById("entity._").syncConfigGridPanelMainArea.apply(this, arguments); Daniel@0: }, Daniel@0: Daniel@0: Daniel@0: // ================================================================= Daniel@0: // vis instance rendering Daniel@0: Daniel@0: Daniel@0: // ----------------------------------------------------------------- Daniel@0: // debug mode Daniel@0: Daniel@0: _mapDerivedVisInstanceDataAttributesToDebugAPIQueryBoxes: function (viewMaster) { Daniel@0: if (viewMaster.options.visInstanceSupportedComparisonModes.length) { Daniel@0: return [["left", "base", "apiRequestURIOnTheLeft", "apiResponseOnTheLeft"], Daniel@0: ["right", "base", "apiRequestURIOnTheRight", "apiResponseOnTheRight"]]; Daniel@0: } else { Daniel@0: return []; Daniel@0: } Daniel@0: } Daniel@0: }); Daniel@0: }); Daniel@0: }, Logger);