Commit 5c651574 authored by Pedro Eduardo Trujillo's avatar Pedro Eduardo Trujillo
Browse files

Añade progreso de remodelación de RestManager

Todos estos cambios son experimentales, no funciona la app por ahora con
ellos.

A grandes rasgos, otorga más protagonismo a RestManager, para que cumpla
también las funciones de Persistence pero a nivel global, además de
reestructurar todas sus comunicaciones. _Store tendrá que remodelarse
para adaptarse a estos cambios, así como seguir revisando y creando
tests unitarios.
parent 2b6b2a53
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -71,10 +71,10 @@ define([

			this._emitEvt('REQUEST', {
				target: this.target,
				type: "API",
				options: {
					sort: [{ attribute: "id", descending: true }]
				}
				sort: [{
					attribute: "id",
					descending: true
				}]
			});
		}
	});
+17 −22
Original line number Diff line number Diff line
@@ -39,18 +39,18 @@ define([
			return false;
		},

		_chkTargetIsMine: function(response) {
		_chkTargetIsValid: function(obj) {

			if (!this._chkSuccessful(response)) {
				return false;
			}
			// TODO eliminar cuando el server no responda con envoltorio body
			var data = obj.body || obj;
			return data && data.target;
		},

			var body = response.body;
			if (body && body.target && !this._targetIsMine(body.target)) {
				return false;
			}
		_chkTargetIsMine: function(res) {

			return true;
			// TODO eliminar cuando el server no responda con envoltorio body
			var response = res.body || res;
			return this._chkTargetIsValid(res) && this._targetIsMine(response.target);
		},

		_chkErrorTargetIsMine: function(response) {
@@ -76,25 +76,20 @@ define([
			}

			if (this.target instanceof Array) {
				return (this.target.indexOf(target) !== -1 || this.target.indexOf(cleanTarget) !== -1);
				return this.target.indexOf(target) !== -1 || this.target.indexOf(cleanTarget) !== -1;
			}

			return (this.target === target || this.target === cleanTarget);
			return this.target === target || this.target === cleanTarget;
		},

		_chkRequesterIsMe: function(response) {
		_chkRequesterIsMe: function(res) {

			if (!this._chkSuccessful(response)) {
				return false;
			}

			var body = response.body;
			if (body && body.requesterId && ((body.requesterId !== this.getOwnChannel()) &&
				(this.associatedIds.indexOf(body.requesterId) < 0))) {
				return false;
			}
			// TODO eliminar cuando el server no responda con envoltorio body
			var response = res.body || res;
			var requesterId = response && response.requesterId;

			return true;
			return !requesterId || (requesterId === this.getOwnChannel() ||
				this.associatedIds.indexOf(requesterId) !== -1);
		},

		_chkErrorRequesterIsMe: function(response) {
+14 −12
Original line number Diff line number Diff line
@@ -9,11 +9,10 @@ define([
	, aspect
	, Persistence
) {

	return declare(null, {
		//	summary:
		//		Base común para todos los módulos con persistenicia de datos.
		//	description:
		//		Aporta la funcionalidad de pedir y obtener datos al módulo que extiende de él.
		//		Permite a los módulos realizar persistencia de datos, comunicándose con RestManager.

		persistenceEvents: {
			SAVE: "save",
@@ -25,8 +24,7 @@ define([
		constructor: function(args) {

			this.config = {
				idProperty: "id",
				notificationSuccess: true
				idProperty: "id"
			};

			lang.mixin(this, this.config, args);
@@ -35,6 +33,7 @@ define([
			aspect.after(this, "_mixEventsAndActions", lang.hitch(this, this._mixEventsAndActionsPersistence));
			aspect.after(this, "_defineSubscriptions",
				lang.hitch(this, this._definePersistenceSubscriptions));

			aspect.after(this, "_definePublications",
				lang.hitch(this, this._definePersistencePublications));
		},
@@ -61,8 +60,8 @@ define([

			this.publicationsConfig.push({
				event: 'SAVE',
				channel: this.persistence.getChannel("SAVE"),
				callback: "_pubSave"
				channel: this.persistence.getChannel("SAVE")/*,
				callback: "_pubSave"*/
			});

			this._deleteDuplicatedChannels(this.publicationsConfig);
@@ -76,9 +75,10 @@ define([
			});
		},

		_pubSave: function(channel, obj) {
		/*_pubSave: function(channel, obj) {

			var target = this._getPersistenceTarget(obj.target);
			var target = this._getTarget(obj.target);
			//var target = this._getPersistenceTarget(obj.target);

			this._publish(channel, {
				idInTarget: obj.idInTarget,
@@ -88,8 +88,10 @@ define([
			});
		},

		_getPersistenceTarget: function(target) {
		_getTarget: function(target) {
		//_getPersistenceTarget: function(target) {

			console.debug('JAMAS DE LOS JAMASES')
			if (target) {
				return target;
			}
@@ -107,7 +109,7 @@ define([
			}

			return this.editionTarget || this.target;
		},
		},*/

		_subSaved: function(result) {

+6 −12
Original line number Diff line number Diff line
@@ -2,17 +2,16 @@ define([
	"dojo/_base/declare"
	, "dojo/_base/lang"
	, "dojo/aspect"
	, "dojo/when"
	, "redmic/modules/base/_SelectionBase"
	, "redmic/modules/base/_SelectionItfc"
], function(
	declare
	, lang
	, aspect
	, when
	, _SelectionBase
	, _SelectionItfc
) {

	return declare([_SelectionBase, _SelectionItfc], {
		//	summary:
		//		Base común para todos los módulos con selección.
@@ -181,11 +180,7 @@ define([

		_chkSelectionTargetAndRequester: function(res) {

			if (this._chkSelectionTargetIsMine(res) && this._chkRequesterIsMe(res)) {
				return true;
			}

			return false;
			return this._chkSelectionTargetIsMine(res) && this._chkRequesterIsMe(res);
		},

		_subSelected: function(res) {
@@ -298,7 +293,7 @@ define([

			var obj = {
				items: ids,
				selectionTarget: this._getSelectionTarget()
				target: this._getSelectionTarget()
			};

			this._publish(channel, obj);
@@ -308,7 +303,7 @@ define([

			var obj = {
				items: ids,
				selectionTarget: this._getSelectionTarget()
				target: this._getSelectionTarget()
			};

			this._publish(channel, obj);
@@ -318,14 +313,13 @@ define([

			this._publish(channel, {
				selectionTarget: this._getSelectionTarget()
				//requesterId: this.getOwnChannel()
			});
		},

		_pubClearSelection: function(channel) {

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

+30 −29
Original line number Diff line number Diff line
define([
	"dojo/_base/declare"
	, "dojo/_base/lang"
	, "dojo/aspect"
	'dojo/_base/declare'
	, 'dojo/_base/lang'
	, 'dojo/aspect'
], function(
	declare
	, lang
	, aspect
) {

	return declare(null, {
		//	summary:
		//		Base común para todos los módulos con selección
		//		Definición de eventos y acciones relacionados con la selección

		constructor: function(args) {

			this.selectionBaseConfig = {
				selectionBaseEvents: {
					SELECTED: "selected",
					DESELECTED: "deselected",
					SELECT: "select",
					DESELECT: "deselect",
					GROUP_SELECTED: "groupSelected",
					CLEAR_SELECTION: "clearSelection",
					SELECTION_CLEARED: "selectionCleared",
					TOTAL: "total",
					SELECTION_TARGET_LOADING: "selectionTargetLoading",
					SELECTION_TARGET_LOADED: "selectionTargetLoaded"
					SELECTED: 'selected',
					DESELECTED: 'deselected',
					SELECT: 'select',
					DESELECT: 'deselect',
					GROUP_SELECTED: 'groupSelected',
					CLEAR_SELECTION: 'clearSelection',
					SELECTION_CLEARED: 'selectionCleared',
					TOTAL: 'total',
					SELECTION_TARGET_LOADING: 'selectionTargetLoading',
					SELECTION_TARGET_LOADED: 'selectionTargetLoaded'
				},

				selectionBaseActions: {
					SELECT: "select",
					DESELECT: "deselect",
					SELECTED: "selected",
					DESELECTED: "deselected",
					SELECTED_GROUP: "selectedGroup",
					GROUP_SELECTED: "groupSelected",
					CLEAR_SELECTION: "clearSelection",
					SELECTION_CLEARED: "selectionCleared",
					TOTAL: "total",
					TOTAL_AVAILABLE: "totalAvailable",
					SELECTION_TARGET_LOADING: "selectionTargetLoading",
					SELECTION_TARGET_LOADED: "selectionTargetLoaded",
					UPDATE_SELECTOR_CHANNEL: "updateSelectorChannel"
					SELECT: 'select',
					DESELECT: 'deselect',
					SELECTED: 'selected',
					DESELECTED: 'deselected',
					SELECTED_GROUP: 'selectedGroup',
					GROUP_SELECTED: 'groupSelected',
					CLEAR_SELECTION: 'clearSelection',
					SELECTION_CLEARED: 'selectionCleared',
					TOTAL: 'total',
					TOTAL_AVAILABLE: 'totalAvailable',
					SELECTION_TARGET_LOADING: 'selectionTargetLoading',
					SELECTION_TARGET_LOADED: 'selectionTargetLoaded',
					UPDATE_SELECTOR_CHANNEL: 'updateSelectorChannel'
				}
			};

			lang.mixin(this, this.selectionBaseConfig);

			aspect.before(this, "_mixEventsAndActions", lang.hitch(this, this._mixSelectionBaseEventsAndActions));
			aspect.before(this, '_mixEventsAndActions', lang.hitch(this, this._mixSelectionBaseEventsAndActions));
		},

		_mixSelectionBaseEventsAndActions: function() {
Loading