Commit b1dfccc1 authored by Pedro Eduardo Trujillo's avatar Pedro Eduardo Trujillo
Browse files

Corrige carga de selección guardada

Arregla tanto el caso del formato de selección antiguo como el nuevo
mediante settings. En este último, emplea el serivicio 'clone' para
obtener una copia del elemento guardado, sin necesidad de limpiar el
anterior antes (en el antiguo formato si se sigue necesitando limpiar de
manera persistente antes de cargar la selección).
parent cf844a99
Loading
Loading
Loading
Loading
+3 −10
Original line number Diff line number Diff line
@@ -95,11 +95,9 @@ define([
				return;
			}

			this._emitEvt('GET', {
				id: data.id,
				options: {},
				target: this.target,
				requesterId: this.getOwnChannel()
			this._emitEvt('UPDATE_DATA', {
				data: data.item,
				target: this.target
			});
		},

@@ -129,11 +127,6 @@ define([
				});
		},

		_itemAvailable: function(response) {

			this._emitEvt('UPDATE_DATA', response);
		},

		postCreate: function() {

			this.inherited(arguments);
+25 −20
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@ define([
	, "app/designs/textSearchList/main/Selection"
	, "dojo/_base/declare"
	, "dojo/_base/lang"
	, 'dojo/Deferred'
	, "put-selector/put"
	, "redmic/modules/base/_Module"
	, "redmic/modules/base/_Selection"
@@ -17,6 +18,7 @@ define([
	, Selection
	, declare
	, lang
	, Deferred
	, put
	, _Module
	, _Selection
@@ -44,14 +46,16 @@ define([
				ownChannel: "selectionBox",
				events: {
					STORE_SELECTION: 'storeSelection',
					RETRIEVE_SELECTIONS_TARGET: 'retrieveSelectionsTarget'
					RETRIEVE_SELECTIONS_TARGET: 'retrieveSelectionsTarget',
					CLONE_SELECTION: 'cloneSelection'
				},
				actions: {
					REFRESH: "refresh",
					STORE_SELECTION: 'storeSelection',
					SELECTION_STORED: 'selectionStored',
					RETRIEVE_SELECTIONS_TARGET: 'retrieveSelectionsTarget',
					SELECTIONS_TARGET_RETRIEVED: 'selectionsTargetRetrieved'
					SELECTIONS_TARGET_RETRIEVED: 'selectionsTargetRetrieved',
					CLONE_SELECTION: 'cloneSelection'
				},

				idProperty: "id",
@@ -127,6 +131,9 @@ define([
			},{
				event: 'RETRIEVE_SELECTIONS_TARGET',
				channel: this._buildChannel(this.selectorChannel, this.actions.RETRIEVE_SELECTIONS_TARGET)
			},{
				event: 'CLONE_SELECTION',
				channel: this._buildChannel(this.selectorChannel, this.actions.CLONE_SELECTION)
			});
		},

@@ -374,9 +381,8 @@ define([
			}
		},

		_subSelectionLoad: function(req) {
		_subSelectionLoad: function(res) {

			//TODO hay que hacer el clear, select y group escalonados, no todo a la vez
			this._publish(this.loadSelection.getChannel("HIDE"));

			if (this._loadSelectionDfd && !this._loadSelectionDfd.isFulfilled()) {
@@ -384,30 +390,29 @@ define([
			}
			this._loadSelectionDfd = new Deferred();

			this._loadSelectionDfd.then(lang.hitch(this, this._continueSelectionLoadAfterClear, req));
			this._emitEvt('CLEAR_SELECTION');
		},
			this._loadSelectionDfd.then(lang.hitch(this, this._continueSelectionLoadAfterClear, res));

		_continueSelectionLoadAfterClear: function(req) {
			var isOldFormat = res.data && res.data.ids;
			this._emitEvt('CLEAR_SELECTION', {
				omitPersistence: !isOldFormat
			});
		},

			this._loadSelectionDfd = new Deferred();
			this._loadSelectionDfd.then(lang.hitch(this, this._continueSelectionLoadAfterSelect, req));
		_continueSelectionLoadAfterClear: function(res) {

			var data = req.data,
				selection = data && (data.selection || data.ids);
			var data = res.data,
				settingsId = data.id,
				selection = data && data.ids;

			if (selection && selection.length) {
			if (selection) {
				this._emitEvt('SELECT', selection);
				this.idSelectionLoaded = data;
			} else {
				this._loadSelectionDfd.resolve();
				this._emitEvt('CLONE_SELECTION', {
					target: this.selectionTarget,
					id: settingsId
				});
			}
		},

		_continueSelectionLoadAfterSelect: function(req) {

			this._emitEvt('GROUP_SELECTED');
			//this._emitEvt('REFRESH');
		}
	});
});
+5 −2
Original line number Diff line number Diff line
@@ -309,10 +309,13 @@ define([
			});
		},

		_pubClearSelection: function(channel) {
		_pubClearSelection: function(channel, req) {

			var omitPersistence = req && req.omitPersistence;

			this._publish(channel, {
				target: this._getSelectionTarget()
				target: this._getSelectionTarget(),
				omitPersistence: omitPersistence
			});
		},

+26 −4
Original line number Diff line number Diff line
@@ -34,13 +34,16 @@ define([
				ownChannel: 'selection',
				events: {
					STORE_SELECTION: 'storeSelection',
					RETRIEVE_SELECTIONS_TARGET: 'retrieveSelectionsTarget'
					RETRIEVE_SELECTIONS_TARGET: 'retrieveSelectionsTarget',
					CLONE_SELECTION: 'cloneSelection'
				},
				actions: {
					STORE_SELECTION: 'storeSelection',
					SELECTION_STORED: 'selectionStored',
					RETRIEVE_SELECTIONS_TARGET: 'retrieveSelectionsTarget',
					SELECTIONS_TARGET_RETRIEVED: 'selectionsTargetRetrieved'
					SELECTIONS_TARGET_RETRIEVED: 'selectionsTargetRetrieved',
					CLONE_SELECTION: 'cloneSelection',
					SELECTION_CLONED: 'selectionCloned'
				},
				selections: {}
			};
@@ -71,6 +74,9 @@ define([
			},{
				channel : this.getChannel('RETRIEVE_SELECTIONS_TARGET'),
				callback: '_subRetrieveSelectionsTarget'
			},{
				channel : this.getChannel('CLONE_SELECTION'),
				callback: '_subCloneSelection'
			});
		},

@@ -103,6 +109,9 @@ define([
			},{
				event: 'RETRIEVE_SELECTIONS_TARGET',
				channel: this.getChannel('SELECTIONS_TARGET_RETRIEVED')
			},{
				event: 'CLONE_SELECTION',
				channel: this.getChannel('SELECTION_CLONED')
			});
		},

@@ -277,9 +286,10 @@ define([

		_subClearSelection: function(req) {

			var target = req.target;
			var target = req.target,
				omitPersistence = req.omitPersistence;

			if (this._targetHasRedmicPrefixForReplacement(target)) {
			if (!omitPersistence && this._targetHasRedmicPrefixForReplacement(target)) {
				this._emitSelectionTargetLoading(target);
				this._emitSave(this._getDataToSave('CLEAR_SELECTION', req));
			} else {
@@ -387,6 +397,18 @@ define([
			} else {
				console.error('Local selection cannot be retrieved for "%s"', target);
			}
		},

		_subCloneSelection: function(req) {

			var target = req.target;

			if (!this._targetHasRedmicPrefixForReplacement(target)) {
				console.error('Local selection cannot be cloned for "%s"', target);
				return;
			}

			this._cloneSelection(req);
		}
	});
});
+60 −13
Original line number Diff line number Diff line
@@ -22,7 +22,8 @@ define([
		selectionTargetSuffixesByAction: {
			select: 'select',
			deselect: 'deselect',
			clearSelection: 'clearselection'
			clearSelection: 'clearselection',
			cloneSelection: 'clone'
		},

		selectionEndpointsByAction: {
@@ -31,7 +32,8 @@ define([
			clearSelection: 'commands',
			groupSelected: 'view',
			storeSelection: 'commands',
			retrieveSelectionsTarget: 'view'
			retrieveSelectionsTarget: 'view',
			cloneSelection: 'commands'
		},

		endpointVariableName: '{endpoint}',
@@ -167,18 +169,23 @@ define([

		_createDataToSaveInSettingsFormat: function(action, req) {

			var targetWithSuffix = req.target + '/' + this._getTargetSuffix(action),
				selectionTarget = this._getSelectionTarget(action, targetWithSuffix);
			var selectionTarget = this._getSelectionTargetWithSuffixByAction(req.target, action);

			return {
				data: {
					selection: req.items,
					userId: this.userSelectionId
					selection: req.items
				},
				target: selectionTarget
			};
		},

		_getSelectionTargetWithSuffixByAction: function(target, action) {

			var targetWithSuffix = target + '/' + this._getTargetSuffix(action);

			return this._getSelectionTarget(action, targetWithSuffix);
		},

		_getTargetSuffix: function(action) {

			var suffix = this.selectionTargetSuffixesByAction[action];
@@ -197,8 +204,7 @@ define([
			return {
				data: {
					ids: req.items,
					action: action,
					idUser: this.userSelectionId
					action: action
				},
				target: selectionTarget
			};
@@ -231,11 +237,7 @@ define([
				selectionIds = this._getSelectionIds();

			if (suffix === 'settings') {
				this._emitEvt('STORE_SELECTION', {
					data: data,
					target: resTarget
				});

				this._afterSelectionStored(resTarget, data);
				return;
			}

@@ -255,10 +257,33 @@ define([
					this._deselect(deselectedIds, target);
				} else if (action === this.actions.CLEAR_SELECTION) {
					this._clearSelection(target);
				} else if (action === this.actions.CLONE_SELECTION) {
					this._afterSelectionCloned({
						target: target,
						resTarget: resTarget,
						selectedIds: selectedIds
					});
				}
			}
		},

		_afterSelectionStored: function(target, data) {

			this._emitEvt('STORE_SELECTION', {
				data: data,
				target: target
			});
		},

		_afterSelectionCloned: function(obj) {

			this._emitEvt('CLONE_SELECTION', {
				target: obj.resTarget
			});

			this._select(obj.selectedIds, obj.target);
		},

		_afterSavedInOldFormat: function(res, resWrapper) {

			var data = res.data,
@@ -358,6 +383,28 @@ define([
			this._emitEvt('RETRIEVE_SELECTIONS_TARGET', {
				target: selectionTarget
			});
		},

		_cloneSelection: function(req) {

			var target = req.target;

			if (!this._isSettingsSelectionFormat(target)) {
				console.error('Clone is only supported for settings format');
				return;
			}

			var action = this.actions.CLONE_SELECTION,
				selectionTarget = this._getSelectionTargetWithSuffixByAction(target, action),
				settingsId = req.id;

			this._emitSave({
				omitSuccessNotification: true,
				target: selectionTarget,
				data: {
					id: settingsId
				}
			});
		}
	});
});