Commit 5849033f authored by Pedro Eduardo Trujillo's avatar Pedro Eduardo Trujillo
Browse files

Refactoriza y corrige toggle de SmartLegend

Controla casos de desactivación de toggle de gráficas, tras
interacciones con la leyenda.
parent 8d020444
Loading
Loading
Loading
Loading
+18 −3
Original line number Diff line number Diff line
@@ -46,13 +46,28 @@ define([
			delete this._rowsOld;
		},

		_getItemIdProperty: function(item) {

			if (!item) {
				return;
			}

			var itemId = item[this.idProperty];

			if (typeof itemId === 'number') {
				return itemId.toString();
			}

			return itemId;
		},

		_rescueOldInstance: function(item) {

			if (!this._rowsOld) {
				return;
			}

			var idProperty = item[this.idProperty],
			var idProperty = this._getItemIdProperty(item),
				row = this._rowsOld[idProperty],
				rowInstance = row && row.instance;

@@ -72,7 +87,7 @@ define([

			this._rescueOldInstance(item);

			var idProperty = item[this.idProperty],
			var idProperty = this._getItemIdProperty(item),
				rowInstance = this._addOrUpdateRow(item),
				obj = {
					node: this.rowsContainerNode
@@ -89,7 +104,7 @@ define([

		_addOrUpdateRow: function(item) {

			var idProperty = item[this.idProperty],
			var idProperty = this._getItemIdProperty(item),
				rowInstance = this._getRowInstance(idProperty);

			if (!rowInstance) {
+9 −28
Original line number Diff line number Diff line
@@ -30,7 +30,8 @@ define([
					CHANGE_ROW_BUTTON_TO_ALT_CLASS: "changeRowButtonToAltClass"
				},

				_dfdChangeButtonClass: {}
				_dfdChangeButtonClass: {},
				pathSeparator: '.'
			};

			lang.mixin(this, this.config, args);
@@ -94,35 +95,15 @@ define([

		_subChangeRowButtonToMainClass: function(req) {

			var idProperty = req.idProperty;

			if (!this._isIdProperty(idProperty)) {
				return;
			}

			var instance = this._getRowInstance(idProperty);

			if (instance) {
				this._publishChangeButtonClass(instance, 'CHANGE_ROW_BUTTON_TO_MAIN_CLASS', req);

				return;
			}

			var layerId = idProperty.split(this.pathSeparator).pop(),
				dfd = this._dfdChangeButtonClass[layerId];

			if (dfd && !dfd.isFulfilled()) {
				return;
			}
			this._changeRowButtonClass(req, 'CHANGE_ROW_BUTTON_TO_MAIN_CLASS');
		},

			dfd = this._dfdChangeButtonClass[layerId] = new Deferred();
			dfd.then(lang.hitch(this, function(originalReq, dfdInstance) {
		_subChangeRowButtonToAltClass: function(req) {

				this._publishChangeButtonClass(dfdInstance, 'CHANGE_ROW_BUTTON_TO_MAIN_CLASS', originalReq);
			}, req));
			this._changeRowButtonClass(req, 'CHANGE_ROW_BUTTON_TO_ALT_CLASS');
		},

		_subChangeRowButtonToAltClass: function(req) {
		_changeRowButtonClass: function(req, action) {

			var idProperty = req.idProperty;

@@ -133,7 +114,7 @@ define([
			var instance = this._getRowInstance(idProperty);

			if (instance) {
				this._publishChangeButtonClass(instance, 'CHANGE_ROW_BUTTON_TO_ALT_CLASS', req);
				this._publishChangeButtonClass(instance, action, req);

				return;
			}
@@ -148,7 +129,7 @@ define([
			dfd = this._dfdChangeButtonClass[layerId] = new Deferred();
			dfd.then(lang.hitch(this, function(originalReq, dfdInstance) {

				this._publishChangeButtonClass(dfdInstance, 'CHANGE_ROW_BUTTON_TO_ALT_CLASS', originalReq);
				this._publishChangeButtonClass(dfdInstance, action, originalReq);
			}, req));
		},

+42 −9
Original line number Diff line number Diff line
@@ -284,12 +284,10 @@ define([

		_onLayerInfoUpdate: function(res) {

			var layerId = res.chart,
				layerPath = this._pathsByLayerId[layerId];
			var layerId = res.chart;

			this._updateLegendContentWithNewInfo(res);
			this._deactivateHiddenLayer(this._pathsByLayerId[layerId]);
			this._activateToggleShowLayerButton(layerPath);
		},

		_updateLegendContentWithNewInfo: function(res) {
@@ -577,6 +575,10 @@ define([
				data: this._currentData[layerPath],
				target: this._localTarget
			});

			if (this._stateByLayerId[layerId]) {
				this._activateToggleShowLayerButton(layerPath);
			}
		},

		_subChartsListButtonEvent: function(res) {
@@ -634,16 +636,19 @@ define([
			iconNode.setAttribute("style", "color:" + color);
			this._changeColorItem.item.color = color;

			// TODO se debe de actualizar, pero el inject lo que hace es eliminar los nodos y regenerarlos, y eso afecta al tooltip
			/*this._emitEvt("INJECT_ITEM", {
			this._emitEvt("INJECT_ITEM", {
				data: this._changeColorItem.item,
				target: this._localTarget
			});*/
			});

			var layerPath = this._changeColorItem[this.idProperty],
				layerId = layerPath.split(this.pathSeparator).pop();

			this._setLayerColor(layerId, oldColor, color);

			if (this._stateByLayerId[layerId]) {
				this._activateToggleShowLayerButton(layerPath);
			}
		},

		_setLayerColor: function(layerId, oldColor, color) {
@@ -739,15 +744,43 @@ define([
				template: template
			});

			var loadedLayerIds = this._getLoadedLayerIds();

			this._currentData = {};
			this._publish(this.chartsList.getChildChannel("browser", "CLEAR"));

			this._emitEvt("GET_LAYER_INFO");

			for (var layerId in this._layerEntries) {
				var layerEntryInfo = this._layerEntries[layerId];
			for (var layerEntryId in this._layerEntries) {
				var layerEntryInfo = this._layerEntries[layerEntryId];
				this._onLayerInfoUpdate(layerEntryInfo);
			}

			this._enablePreviouslySelectedItems(loadedLayerIds);
		},

		_getLoadedLayerIds: function() {

			var loadedLayerPaths = Object.keys(this._currentData).map(lang.hitch(this, function(layerPath) {

				return layerPath.split(this.pathSeparator).pop();
			}));

			return loadedLayerPaths.filter(lang.hitch(this, function(layerId) {

				return layerId && isNaN(parseInt(layerId, 10));
			}));
		},

		_enablePreviouslySelectedItems: function(layerIds) {

			for (var i = 0; i < layerIds.length; i++) {
				var layerId = layerIds[i];

				if (this._stateByLayerId[layerId]) {
					var layerPath = this._pathsByLayerId[layerId];
					this._activateToggleShowLayerButton(layerPath);
				}
			}
		}
	});
});