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

Sustituye paso de queryParameters a vistas

Elimina el antiguo modo de compartir los parámetros obtenidos a partir
de la ruta actual, pasándolos en cascada al módulo vista que se iba a
instanciar.

En su lugar, se crea una extensión de módulos que permite consultar y
obtener respuesta por parte de Router, con los parámetros extraídos de
la ruta actual.

Sustituye el uso de los parámetros como atributo propio, usando el nuevo
método descrito.

Fix #44.
parent bcff1ab4
Loading
Loading
Loading
Loading
+6 −12
Original line number Diff line number Diff line
@@ -123,7 +123,7 @@ define([
				return;
			}

			var moduleDfd = this._getModuleInstance(req.key, req.query);
			var moduleDfd = this._getModuleInstance(req.key);

			if (!moduleDfd) {
				this._emitEvt('GET_MODULE');
@@ -264,15 +264,13 @@ define([
			}));
		},

		_getModuleInstance: function(/*String*/ key, /*Object*/ query) {
		_getModuleInstance: function(/*String*/ key) {
			//	summary:
			//		Devuelve la instancia de un módulo, y si aun no existe la crea antes.
			//	tags:
			//		private
			//	key:
			//		Clave del módulo buscado
			//	query:
			//		Objeto de consulta
			//	returns:
			//		Promesa de la instancia del módulo

@@ -286,7 +284,7 @@ define([

			// Si aun no se ha creado la vista
			if (!moduleItem.instance) {
				return this._createModule(moduleItem, query);	// return Object
				return this._createModule(moduleItem);	// return Object
			}

			// Si ya se creó la vista anteriormente
@@ -296,8 +294,7 @@ define([
			this._publish(moduleItem.instance.getChannel("CONNECT"));

			this._publish(moduleItem.instance.getChannel('SET_PROPS'), {
				pathVariableId: this.pathVariableId !== "$1" ? this.pathVariableId : null,
				queryParameters: query
				pathVariableId: this.pathVariableId !== "$1" ? this.pathVariableId : null
			});

			var dfd = new Deferred();
@@ -306,15 +303,13 @@ define([
			return dfd;	// return Object
		},

		_createModule: function(/*Object*/ moduleItem, /*Object*/ query) {
		_createModule: function(/*Object*/ moduleItem) {
			//	summary:
			//		Crea la instancia de un módulo de la aplicación.
			//	tags:
			//		private
			//	moduleItem:
			//		Módulo a crear
			//	query:
			//		Objeto de consulta
			//	returns:
			//		Promesa de la instancia del módulo

@@ -327,8 +322,7 @@ define([
					perms: moduleItem.perms,
					parentChannel: this.parentChannel,
					ownChannel: this.viewSeparator + moduleItem.id,
					pathVariableId: this.pathVariableId !== "$1" ? this.pathVariableId : null,
					queryParameters: query
					pathVariableId: this.pathVariableId !== "$1" ? this.pathVariableId : null
				});

				// Añadimos al store la instancia del módulo
+31 −25
Original line number Diff line number Diff line
@@ -92,8 +92,6 @@ define([
		//		usuario invitado). Maneja las instancias de layout de aplicación y de los módulos cargados dentro de
		//		dichos layouts.

		//	query: String
		//		Filtros de consulta procedentes de Router.
		//	paths: Object
		//		Constantes de rutas base

@@ -135,7 +133,6 @@ define([
					HOME: 'home',
					LOGIN: 'login'
				},
				query: '',
				target: '/env',
				_reconnectTimeout: 10000
			};
@@ -273,11 +270,11 @@ define([

		_handleAppHref: function(event, target) {

			var url = target.pathname + target.search;
			var url = target.pathname + target.search + target.hash;

			if (mouse.isMiddle(event)) {
				var gCtx = getGlobalContext(),
					newPageUrl = gCtx.location.protocol + '//' + gCtx.location.hostname + url;
					newPageUrl = target.protocol + '//' + target.hostname + url;

				gCtx.open(newPageUrl, '_blank');
			} else {
@@ -301,9 +298,7 @@ define([

			var locationObj = getGlobalContext().location,
				locationPath = locationObj.pathname,
				locationQuery = locationObj.search,
				route = locationPath.substr(1),
				query = locationQuery.substr(1),
				routeIsEmpty = !route || route === '' || route === this.paths.ROOT,
				loginWasSuccessful = route === this.paths.LOGIN && this._userFound;

@@ -312,8 +307,17 @@ define([
				this._addHistory(route);
			}

			this._handleQueryParameters(query);
			this._changeModule(route, query);
			var locationQuery = locationObj.search;

			this._handleQueryParameters(locationQuery.substr(1));

			var routeChanged = this._changeModule(route);
			if (routeChanged) {
				this._emitEvt('TRACK', {
					type: TRACK.type.page,
					info: route + locationQuery
				});
			}
		},

		_evaluatePopStateEvt: function(evt) {
@@ -385,6 +389,8 @@ define([
		_handleQueryParameters: function(queryString) {

			this._currentQueryParams = this._getQueryParameters(queryString);

			this._removeQueryParametersFromHref();
		},

		_getQueryParameters: function(queryString) {
@@ -392,36 +398,37 @@ define([
			return ioQuery.queryToObject(queryString);
		},

		_changeModule: function(route, query) {
		_removeQueryParametersFromHref: function() {

			var locationObj = getGlobalContext().location,
				href = locationObj.protocol + '//' + locationObj.hostname + locationObj.pathname + locationObj.hash;

			getGlobalContext().history.replaceState(null, null, href);
		},

		_changeModule: function(route) {
			//	summary:
			//		Actualiza el módulo que se visualiza.
			//	tags:
			//		private
			//	route:
			//		ruta del nuevo módulo
			//	query:
			//		queryString [Opcional]

			this._currModuleKey = route;

			var newQuery = query ? query : '';

			if (this._currModuleKey === this._prevModuleKey && this.query === newQuery) {
				return;
			if (this._currModuleKey === this._prevModuleKey) {
				return false;
			}

			this._prevModuleKey = this._currModuleKey;
			this.query = newQuery;

			this._emitEvt('TRACK', {
				type: TRACK.type.page,
				info: query ? (route + '?' + query) : route
			});

			this._once(this._loading.getChannel('LOADING_DRAWN'), lang.hitch(this, this._onLoadingDrawn));

			this._publish(this._loading.getChannel('LOADING'), {
				instant: !this._currModuleInstance
			});

			return true;
		},

		_onLoadingDrawn: function() {
@@ -442,8 +449,7 @@ define([
			this._prepareApplicationLayout();

			this._emitEvt('GET_MODULE', {
				key: this._currModuleKey,
				query: this._getQueryParameters(this.query)
				key: this._currModuleKey
			});
		},

+25 −21
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@ define([
	, "dojo/aspect"
	, "dojo/Deferred"
	, "RWidgets/Utilities"
	, 'redmic/modules/base/_ListenQueryParams'
	, "redmic/modules/base/_Store"
	, "redmic/modules/base/_Persistence"
	, "redmic/modules/layout/wizard/Wizard"
@@ -19,6 +20,7 @@ define([
	, aspect
	, Deferred
	, Utilities
	, _ListenQueryParams
	, _Store
	, _Persistence
	, Wizard
@@ -26,7 +28,7 @@ define([
	, _StepBreadcrumbs
) {

	return declare([_Controller, _Store, _Persistence, _EditionCommons], {
	return declare([_Controller, _Store, _Persistence, _ListenQueryParams, _EditionCommons], {
		//	summary:
		//		Controller para vistas de detalle.

@@ -128,16 +130,27 @@ define([
			if (typeof this.pathVariableId === 'object') {
				this._pathVariableIdIsObject();
			} else {
				if (this.pathVariableId === 'new') {
					var copySource = this.queryParameters ? this.queryParameters['copy-source'] : null;
					if (copySource != null) {
						this._emitGet(copySource);
					} else {
						this._emitShowForm();
				this._prepareItemEditionOrCreation(this.pathVariableId);
			}
		},

		_prepareItemEditionOrCreation: function(itemId, urlId) {

			if (itemId === 'new') {
				this._emitEvt('GET_QUERY_PARAMS');
			} else {
					this._emitGet(this.pathVariableId);
				this._emitGet(urlId || itemId);
			}
		},

		_gotQueryParams: function(queryParams) {

			var copySource = queryParams['copy-source'];

			if (copySource) {
				this._emitGet(copySource);
			} else {
				this._emitShowForm();
			}
		},

@@ -194,16 +207,7 @@ define([
			// TODO borrar este seteo, que cambia el target para siempre (efecinquitis) y creo que no es necesario
			//this.target = lang.replace(this.target, this.pathVariableId);

			if (this.pathVariableId.id === "new") {
				var copySource = this.queryParameters ? this.queryParameters['copy-source'] : null;
				if (copySource != null) {
					this._emitGet(copySource);
				} else {
					this._emitShowForm();
				}
			} else {
				this._emitGet(this.pathVariableId[this.idProperty]);
			}
			this._prepareItemEditionOrCreation(this.pathVariableId.id, this.pathVariableId[this.idProperty]);
		},

		_emitShowForm: function(item) {
+0 −1
Original line number Diff line number Diff line
@@ -281,7 +281,6 @@ define([
				activityData: this.activityData,
				activityCategory: this.activityCategory,
				pathVariableId: this.pathVariableId,
				queryParameters: this.queryParameters,
				editorConfig: {
					_additionalData: {
						activityCategory: this.activityCategory,
+9 −2
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ define([
	, "dojo/_base/declare"
	, "dojo/_base/lang"
	, "dojo/text!./templates/ConfirmResetting.html"
	, 'redmic/modules/base/_ListenQueryParams'
	, 'redmic/modules/base/_Store'
], function(
	alertify
@@ -13,10 +14,11 @@ define([
	, declare
	, lang
	, template
	, _ListenQueryParams
	, _Store
) {

	return declare([_ExternalUserBaseView, _Store], {
	return declare([_ExternalUserBaseView, _Store, _ListenQueryParams], {
		//	summary:
		//		Vista que permite resetear la contraseña de un usuario, a partir de un enlace enviado al correo
		//		electrónico asociado a dicha cuenta.
@@ -41,7 +43,12 @@ define([

			this.inherited(arguments);

			var token = this.queryParameters ? this.queryParameters.token : null;
			this._emitEvt('GET_QUERY_PARAMS');
		},

		_gotQueryParams: function(queryParams) {

			var token = queryParams.token;

			if (token) {
				this.token = token;
Loading