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

Elimina componente Manager y restos en desuso

Integra la funcionalidad que quedaba en uso del componente Manager
dentro del componente Topbar, el lugar donde debía estar. Como el resto
ya no sirve para nada, se elimina el componente, junto con otros restos
antiguos relacionados con la base de las vistas.

Actualiza submódulo.
parent c4d1f611
Loading
Loading
Loading
Loading
+19 −14
Original line number Diff line number Diff line
@@ -4,27 +4,26 @@ define([
	, 'put-selector/put'
	, 'src/component/base/_Module'
	, 'src/component/base/_Show'
	, 'src/component/base/Manager'
	, 'src/component/user/FullscreenToggle'
	, 'src/component/user/LanguageSelector'
	, 'src/component/user/UserArea'
	, 'src/redmicConfig'
], function(
	declare
	, lang
	, put
	, _Module
	, _Show
	, Manager
	, FullscreenToggle
	, LanguageSelector
	, UserArea
	, redmicConfig
) {

	return declare([_Module, _Show], {
		//	summary:
		//		Widget que controla la barra superior, siempre visible y compartida.
		//	description:
		//		Zona común que comparten todos los módulos.
		//		Componente que controla la barra superior, siempre visible y compartida para toda la aplicación (salvo
		//		para la zona externa).

		constructor: function(args) {

@@ -36,7 +35,9 @@ define([

				logoClass: 'topbarLogo',
				logoHref: '/home',
				logoImgSrc: '/res/images/logos/logo.svg'
				logoImgSrc: '/res/images/logos/logo.svg',

				_isProductionEnvironment: (/true/i).test(redmicConfig.getEnvVariableValue('envProduction'))
			};

			if (args && args.ecomarcan) {
@@ -94,20 +95,24 @@ define([
		_createContentNode: function() {

			var contentNode = put(this.domNode, 'div.topbarContent'),
				managerNode = put(contentNode, 'div.manager'),
				centerNode = put(contentNode, 'div.center'),
				buttonsNode = put(contentNode, 'div.buttons');

			this._createManagerNode(managerNode);
			this._addGobCanLogos(centerNode);

			if (!this._isProductionEnvironment) {
				put(contentNode, '.appDev');
				put(centerNode, 'span.fontExo2', this.i18n.messageAppDev);
			}

			this._showModules(buttonsNode);
		},

		_createManagerNode: function(containerNode) {
		_addGobCanLogos: function(containerNode) {

			var logosContainer = put(containerNode, 'div.gobcan-logos');

			// TODO integrar manager con topbar, manager está desfasado casi por completo
			this._manager = new Manager({
				//parentChannel: this.getChannel()
				parentChannel: this.getParentChannel()
			}, containerNode);
			put(logosContainer, 'img[src=/res/images/logos/gobcan-logos.png]');
		},

		_showModules: function(containerNode) {
+0 −306
Original line number Diff line number Diff line
define([
	'src/redmicConfig'
	, 'dijit/form/Button'
	, 'dojo/_base/declare'
	, 'dojo/_base/lang'
	, 'dojo/topic'
	, 'put-selector/put'
	, 'src/util/Credentials'
	, 'src/component/base/_Module'
	, 'src/component/base/_Show'
],
function(
	redmicConfig
	, Button
	, declare
	, lang
	, topic
	, put
	, Credentials
	, _Module
	, _Show
) {

	return declare([_Module, _Show], {
		//	summary:
		//		Este widget reune todos los elementos dinámicos de la barra superior de la aplicación.
		//	description:
		//		Permite tener una zona común para todos los módulos, donde colocar elementos de
		//		acción o informativos.

		//	zones: Object
		//		Json para generar los elementos del Manager de forma dinámica.
		//	handlers: Object
		//		Controladores de las escuchas a los eventos.
		//	perms: Object
		//		Permisos del usuario para el módulo actual.

		constructor: function(args) {

			this.config = {
				// own events
				events: {
					UPLOAD_FILE: 'uploadFile',
					DOWNLOAD_FILE: 'downloadFile'
				},
				// own actions
				actions: {
					UPLOAD_FILE: 'uploadFile',
					DOWNLOAD_FILE: 'downloadFile'
				},
				zones: {
					filter: {
						node: null,
						align: 'right',
						'class': 'div.btnGroup',
						btns: {
							upload: {
								node: null,
								shared: 0,
								permission: false,
								props: {
									showLabel: false,
									'class': 'primary',
									label: this.i18n.upload,
									iconClass: 'fa-upload',
									action: '_uploadFile'
								}
							},
							download: {
								node: null,
								shared: 0,
								permission: true,
								props: {
									showLabel: false,
									'class': 'primary',
									label: this.i18n.createReport,
									iconClass: 'fa-print',
									action: '_downloadFile'
								}
							}
						}
					}
				},
				handlers: {},
				perms: {},
				ownChannel: 'manager',
				viewSeparator: '/'
			};

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

			this._listen();  // TODO: cambiar por mediator
		},

		_defineSubscriptions: function() {

			this.subscriptionsConfig.push({
				channel: this.getParentChannel(),
				callback: '_subChangeView',
				options: {
					predicate: lang.hitch(this, this._chkChangeView)
				}
			});
		},

		_definePublications: function() {

			this.publicationsConfig.push({
				event: 'UPLOAD_FILE',
				channel: this.getChannel('UPLOAD_FILE')
			},{
				event: 'DOWNLOAD_FILE',
				channel: this.getChannel('DOWNLOAD_FILE')
			});
		},

		postCreate: function() {

			this.leftContainer = put(this.domNode, 'div.left');
			this.rightContainer = put(this.domNode, 'div.right');

			this._addGobCanLogos();
			this._checkDomainToAddMessage();
		},

		_addGobCanLogos: function() {

			var logosContainer = put(this.leftContainer, 'div.gobcan-logos');

			put(logosContainer, 'img[src=/res/images/logos/gobcan-logos.png]');
		},

		_checkDomainToAddMessage: function() {

			if ((/false/i).test(redmicConfig.getEnvVariableValue('envProduction'))) {
				this._addMessage('.appDev', this.i18n.messageAppDev);
			}
		},

		_addMessage: function(typeClass, message) {

			put(this.domNode.parentNode, typeClass);
			put(this.leftContainer, 'span.fontExo2', message);
		},

		_listen: function() {
			// summary:
			// 	Pone a escuchar al Manager para que reaccione a los cambios.
			// tags:
			// 	private

			// Eventos procedentes de los módulos
			this.handlers.create = topic.subscribe('/manager/create', lang.hitch(this, this._createManager));
		},

		_findPerms: function(/*String*/ moduleKey) {
			//	summary:
			//		Busca un módulo y devuelve los permisos que tiene el usuario para el mismo.
			//	tags:
			//		private
			//	moduleKey:
			//		Clave completa del módulo buscado
			//	returns:
			//		Permisos del módulo si se encuentra, o 0 si no se encuentra

			// Categorías a las que tiene acceso el usuario
			var categories = Credentials.get('allowedModules'),
				moduleKeySplitted = moduleKey.split(this.viewSeparator);

			if (!categories) {
				return 0;	// Integer
			}

			// Buscamos nuestra categoría
			for (var i = 0; i < categories.length; i++) {
				var category = categories[i];

				// Si es la buscada, miramos sus módulos
				if (category.name === moduleKeySplitted[0]) {
					if (!category.modules) {
						return category.perms;	// Integer
					}

					// Buscamos nuestro módulo
					for (var j = 0; j < category.modules.length; j++) {
						var module = category.modules[j];

						// Si es el buscado, obtenemos sus permisos
						if (module.name === moduleKeySplitted[1]) {
							return module.perms;	// Integer
						}
					}
				}
			}

			// Si no se encontró el módulo
			return 0;	// Integer
		},

		_cleanManager: function() {
			//	summary:
			//		Limpia los contenidos de Manager para que otro módulo lo use.
			//	tags:
			//		private

			for (var item in this.zones) {
				var zone = this.zones[item];

				// Destruimos los botones
				for (var key2 in zone.btns) {
					var btn = zone.btns[key2];
					btn.shared = 0;
					if (btn.node) {
						btn.node.destroyRecursive();
						btn.node = null;
					}
				}
				// Destruimos la zona
				zone.node && put(zone.node, '!');
				zone.node = null;
			}
		},

		_createManager: function(showBtn) {

			for (var item in this.zones) {
				var zone = this.zones[item];
				if (!zone.node) {
					var node = this.rightContainer;

					if (zone.align == 'left') {
						node = this.leftContainer;
					}

					zone.node = put(node, zone['class'], {});
				}
				// Si tiene permisos de edición o no es la zona de edición
				if (this.perms > 0 || item !== 'edit') {
					// Elementos tipo botón
					for (var key2 in zone.btns) {
						var btn = zone.btns[key2];
						// Si lo podemos mostrar
						if (showBtn[key2] && (!btn.node)) {
							btn.props.onClick = lang.hitch(this, this[btn.props.action]);
							btn.node = new Button(btn.props).placeAt(zone.node);
							btn.node.domNode.removeAttribute('widgetId');
							btn.shared += 1;
						} else if (showBtn[key2] && (btn.node)) { // Hay más de un widget usando este botón
							btn.shared += 1;
						}
					}
				}
			}
		},

		_chkChangeView: function(data, channel) {
			// TODO seguro que hay una manera mejor de limpiar Manager, revisar cuando se integre en Topbar

			var namespaceSplitted = this._getNamespaceSplitted(data, channel),
				channelLength = namespaceSplitted.length;

			// Si el número de eslabones es distinto, la publicación no era de una vista
			if (channelLength !== 4) {
				return;
			}

			var action = namespaceSplitted[channelLength - 1],
				subPath = namespaceSplitted[channelLength - 2];

			return action === this.actions.SHOWN && subPath.indexOf(this.viewSeparator) !== -1;
		},

		_subChangeView: function(data, channel) {

			var namespaceSplitted = this._getNamespaceSplitted(data, channel),
				viewKey = namespaceSplitted[1];

			this.perms = this._findPerms(viewKey);

			this._cleanManager();
		},

		_getNamespaceSplitted: function(data, channel) {

			var channelObj = channel || data,
				namespace = channelObj.namespace;

			return namespace.split(this.channelSeparator);
		},

		_uploadFile: function() {

			this._emitEvt('UPLOAD_FILE');
		},

		_downloadFile: function() {

			this._emitDownloadFile('pdf');
		},

		_emitDownloadFile: function(/*String*/ format) {

			this._emitEvt('DOWNLOAD_FILE', {format: format});
		}
	});
});
+0 −76
Original line number Diff line number Diff line
define([
	"dojo/_base/declare"
	, "dijit/_WidgetBase"
	, "dojo/_base/lang"
	, "put-selector/put"
	, "dojo/dom-class"
	, "dojo/domReady!"
    , "dojo/when"
    , "dojo/dom-construct"
], function(
	declare
	, _WidgetBase
	, lang
	, put
	, domClass
	, domReady
	, when
	, domConstruct
) {
	return declare(_WidgetBase, {
		//	summary:
		//		Widget
		//
		// description:
		//
		//		Author:  Carlos Glez
		//		<br>
		//		Last Update: 09/12/2014 - Carlos

		constructor: function(args) {

			lang.mixin(this, args);
		},

		postCreate: function() {
			this.inherited(arguments);

			domClass.add(this.contentNode, "hidden");
			this.loadingNode = put(this.containerNode ? this.containerNode : this.domNode, "div.loadingContainer");
			put(this.loadingNode, "span.fa.fa-refresh.symbolG.spinningElement");

			when(this.load(), lang.hitch(this, this._hiddenLoading), lang.hitch(this._errorLoad));
		},

		reload: function() {
			domConstruct.empty(this.contentNode);
			domClass.add(this.contentNode, "hidden");
			domClass.remove(this.loadingNode, "hidden");
			when(this.load(), lang.hitch(this, this._hiddenLoading), lang.hitch(this._errorLoad));
		},

		/*
		load: function() {

		},

		loading: function() {

		},

		loaded: function() {

		}
		*/

		_hiddenLoading: function() {
			domClass.remove(this.contentNode, "hidden");
			domClass.add(this.loadingNode, "hidden");
		},

		_errorLoad: function() {

		}

	});
});
+1 −3
Original line number Diff line number Diff line
@@ -3,18 +3,16 @@ define([
	, "dojo/_base/lang"
	, "dojo/aspect"
	, "app/base/views/_ListenRequestError"
	, "app/base/views/_ViewHandle"	// QUITAR
	,'./_SettingsHandler'
], function(
	declare
	, lang
	, aspect
	, _ListenRequestError
	, _ViewHandle	// QUITAR
	, _SettingsHandler
) {

	return declare([_ListenRequestError, _ViewHandle, _SettingsHandler], {
	return declare([_ListenRequestError, _SettingsHandler], {
		//	summary:
		//		Extensión común para todas los módulos usados como vistas. Se adjunta automáticamente cuando la
		//		navegación a través de la app requiere un módulo como contenido principal a mostrar.
+0 −65
Original line number Diff line number Diff line
define([
	"dojo/_base/declare"
	, "dojo/_base/lang"
	, "dojo/aspect"
	, "dojo/topic"
],
function(
	declare
	, lang
	, aspect
	, topic
){
	return declare(null, {
		//	summary:
		//		Controlador de suscripciones para los módulos.
		//	description:
		//		Permite comunicar los módulos con el Manager común a todos.

		//TODO: esto tiene que dejar de usar topic, y ya veremos si se conserva o se elimina

		constructor: function(args) {

			aspect.after(this, "_subShow", lang.hitch(this, this.onEnable));
			aspect.after(this, "_subHide", lang.hitch(this, this.onDisable));
		},

		onEnable: function(/*Object*/ evt) {
			//	summary:
			//		Activa la suscripción del módulo.
			//	evt:
			//		Datos procedentes del evento disparado.

			if (this.mask) {
				if (this.perms < 2) {
					delete this.mask.add;
					delete this.mask.edit;
					delete this.mask.remove;
				}

				topic.publish("/manager/create", this.mask);
				/*if (this.title.length)
					topic.publish("/manager/location", this.title);*/
				// Por defecto se limpia la info del manager
				//topic.publish("/manager/info", "");
			}

			if ((!this.handleSubs) || ((this.handleSubs) && (!this.handleSubs.advice))) {
			this.handleSubs = topic.subscribe("/manager/event", lang.hitch(this, function(args){
				if(this[args.action])
					this[args.action](args.args);
				}));
			}
		},

		onDisable: function(/*Object*/ evt) {
			//	summary:
			//		Desactiva la suscripción del módulo.
			//	evt:
			//		Datos procedentes del evento disparado.

			this.handleSubs && this.handleSubs.remove();
		}

	});
});
Loading