Commit 6893bcdc authored by Pedro Eduardo Trujillo's avatar Pedro Eduardo Trujillo
Browse files

Prosigue adaptación al nuevo RestManager

Elimina módulo Persistence, en favor de RestManager que actúa a nivel
global. Todavía quedan restos de otros componentes que lo usaban.

Elimina tests antiguos de Persistence que realmente no comprobaban
nada, solo servían de relleno.

Adapta extensiones de módulos para comunicarse con RestManager y con
Selector, aunque sigue en proceso.
parent cc916c10
Loading
Loading
Loading
Loading
+0 −15
Original line number Diff line number Diff line
@@ -171,21 +171,6 @@ define([
			return false;
		},

		_chkErrorTargetIsMine: function(response) {

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

			var error = response.error;

			if (error.target && error.target.indexOf && (error.target.indexOf(this.baseTarget) >= 0)) {
				return true;
			}

			return false;
		},

		_errorAvailable: function(error) {

		},
+3 −44
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ define([
	declare
	, lang
) {

	return declare(null, {
		//	summary:
		//		Extensión para definir los predicados por defecto.
@@ -53,20 +54,6 @@ define([
			return this._chkTargetIsValid(res) && this._targetIsMine(response.target);
		},

		_chkErrorTargetIsMine: function(response) {

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

			var error = response.error;
			if (error && error.target && !this._targetIsMine(error.target)) {
				return false;
			}

			return true;
		},

		_targetIsMine: function(target) {

			var cleanTarget = this._cleanTrailingSlash(target);
@@ -92,37 +79,9 @@ define([
				this.associatedIds.indexOf(requesterId) !== -1);
		},

		_chkErrorRequesterIsMe: function(response) {

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

			var error = response.error;
			if (error && error.requesterId && ((error.requesterId !== this.getOwnChannel()) &&
				(this.associatedIds.indexOf(error.requesterId) < 0))) {
				return false;
			}

			return true;
		},

		_chkTargetAndRequester: function(response) {

			if (this._chkTargetIsMine(response) && this._chkRequesterIsMe(response)) {
				return true;
			}

			return false;
		},

		_chkErrorTargetAndRequester: function(response) {

			if (this._chkErrorTargetIsMine(response) && this._chkErrorRequesterIsMe(response)) {
				return true;
			}

			return false;
			return this._chkTargetIsMine(response) && this._chkRequesterIsMe(response);
		},

		_chkPublicationIsForMe: function(res) {
+58 −32
Original line number Diff line number Diff line
define([
	"dojo/_base/declare"
	, "dojo/_base/lang"
	, "dojo/aspect"
	, "redmic/modules/store/Persistence"
	'dojo/_base/declare'
	, 'dojo/_base/lang'
	, 'dojo/aspect'
	, './_PersistenceItfc'
], function(
	declare
	, lang
	, aspect
	, Persistence
	, _PersistenceItfc
) {

	return declare(null, {
	return declare(_PersistenceItfc, {
		//	summary:
		//		Permite a los módulos realizar persistencia de datos, comunicándose con RestManager.

		persistenceEvents: {
			SAVE: "save",
			SAVED: "saved"
			SAVE: 'save',
			SAVED: 'saved',
			REMOVE: 'remove',
			REMOVED: 'removed'
		},

		persistenceActions: {},
		persistenceActions: {
			SAVE: 'save',
			SAVED: 'saved',
			REMOVE: 'remove',
			REMOVED: 'removed'
		},

		constructor: function(args) {

			this.config = {
				idProperty: "id"
				idProperty: 'id',
				omitRefreshAfterSuccess: false
			};

			lang.mixin(this, this.config, args);

			aspect.before(this, "_initialize", this._initializePersistence);
			aspect.after(this, "_mixEventsAndActions", lang.hitch(this, this._mixEventsAndActionsPersistence));
			aspect.after(this, "_defineSubscriptions",
			aspect.after(this, '_mixEventsAndActions', lang.hitch(this, this._mixPersistenceEventsAndActions));
			aspect.after(this, '_defineSubscriptions',
				lang.hitch(this, this._definePersistenceSubscriptions));

			aspect.after(this, "_definePublications",
			aspect.after(this, '_definePublications',
				lang.hitch(this, this._definePersistencePublications));
		},

		_mixEventsAndActionsPersistence: function () {
		_mixPersistenceEventsAndActions: function () {

			lang.mixin(this.events, this.persistenceEvents);
			lang.mixin(this.actions, this.persistenceActions);
@@ -49,8 +56,11 @@ define([
		_definePersistenceSubscriptions: function () {

			this.subscriptionsConfig.push({
				channel: this.persistence.getChannel("SAVED"),
				callback: "_subSaved"
				channel: this._buildChannel(this.storeChannel, this.actions.SAVED),
				callback: '_subSaved'
			},{
				channel: this._buildChannel(this.storeChannel, this.actions.REMOVED),
				callback: '_subRemoved'
			});

			this._deleteDuplicatedChannels(this.subscriptionsConfig);
@@ -60,21 +70,16 @@ define([

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

			this._deleteDuplicatedChannels(this.publicationsConfig);
		},

		_initializePersistence: function() {

			this.persistence = new Persistence({
				parentChannel: this.getChannel(),
				notificationSuccess: this.notificationSuccess
			});
		},

		/*_pubSave: function(channel, obj) {

			var target = this._getTarget(obj.target);
@@ -111,14 +116,35 @@ define([
			return this.editionTarget || this.target;
		},*/

		_subSaved: function(result) {
		_subSaved: function(resWrapper) {

			var response = resWrapper.res,
				status = response.status;

			if (!this.omitRefreshAfterSuccess) {
				this._emitEvt('REFRESH');
			}

			if (status >= 200 && status < 400) {
				var savedObj = this._getSavedObjToPublish(response) || response;
				this._emitEvt('SAVED', response);

				this._afterSaved(response, resWrapper);
			} else {
				this._afterSaveError(response.error, status, resWrapper);
			}
		},

		_subRemoved: function(result) {

			if (!this.omitRefreshAfterSuccess) {
				this._emitEvt('REFRESH');
			}

			var savedObj = this._getSavedObjToPublish ? this._getSavedObjToPublish(result) : result;
			this._emitEvt('SAVED', savedObj);
			var removedObj = this._getRemovedObjToPublish(result) || result;
			this._emitEvt('REMOVED', removedObj);

			this._afterSaved && this._afterSaved(result);
			this._afterRemoved(result);
		}
	});
});
+28 −0
Original line number Diff line number Diff line
define([
	'dojo/_base/declare'
	, 'dojo/_base/lang'
	, 'redmic/modules/base/_Itfc'
], function(
	declare
	, lang
	, _Itfc
){
	return declare(_Itfc, {
		//	summary:
		//		Interfaz de _Persistence.
		//	description:
		//		Define los métodos que debe poseer el módulo o la implementación.


		_getMethodsToImplement: function() {

			return lang.mixin(this.inherited(arguments), {
				'_getSavedObjToPublish': {},
				'_afterSaved': {},
				'_afterSaveError': {},
				'_getRemovedObjToPublish': {},
				'_afterRemoved': {}
			});
		}
	});
});
+5 −5
Original line number Diff line number Diff line
@@ -185,8 +185,8 @@ define([

		_subSelected: function(res) {

			var ids = res.body.ids,
				total = res.body.total;
			var ids = res.ids,
				total = res.total;

			this._setEmptySelection(!total);

@@ -207,8 +207,8 @@ define([

		_subDeselected: function(res) {

			var ids = res.body.ids,
				total = res.body.total;
			var ids = res.ids,
				total = res.total;

			this._setEmptySelection(!total);

@@ -233,7 +233,7 @@ define([

		_subSelectedGroup: function(res) {

			var selection = res.body.selection;
			var selection = res.selection;
			selection && this._selectedGroup(selection);

			this._tryToEmitEvt('LOADED');
Loading