Commit 42970f8c authored by Pedro Eduardo Trujillo's avatar Pedro Eduardo Trujillo
Browse files

Refactoriza base de añadir búsqueda compuesta

En lugar de pisar métodos y repetir código ya implementado, desacopla la
base existente para reutilizarla de forma más granular. La funcionalidad
permanece igual, si todo ha ido bien.
parent c478c61a
Loading
Loading
Loading
Loading
+58 −76
Original line number Diff line number Diff line
define([
	"dojo/_base/declare"
	, "dojo/_base/lang"
	, "dojo/aspect"
	, "put-selector/put"
	, "redmic/modules/base/_ShowInTooltip"
	, "redmic/modules/base/_ShowOnEvt"
	, "redmic/modules/components/Keypad/IconKeypadImpl"
	, "redmic/modules/search/CompositeImpl"
	, "redmic/modules/search/_HideFormByAction"
	'app/base/views/extensions/_CompositeSearchInTooltip'
	, 'dojo/_base/declare'
	, 'dojo/_base/lang'
	, 'dojo/aspect'
	, 'put-selector/put'
	, 'redmic/modules/components/Keypad/IconKeypadImpl'
], function(
	declare
	_CompositeSearchInTooltip
	, declare
	, lang
	, aspect
	, put
	, _ShowInTooltip
	, _ShowOnEvt
	, IconKeypadImpl
	, CompositeImpl
	, _HideFormByAction
) {
	return declare(null, {

	return declare(_CompositeSearchInTooltip, {
		//	summary:
		//
		//		Muestra la instancia de CompositeImpl (Search) en tooltip, asociado a un botón.
		//	description:
		//
		//		Instancia una botonera IconKeypadImpl (Keypad) que contiene un botón para desplegar el tooltip y mostrar
		//		así la búsqueda compuesta.
		//		Deja disponible la instancia en 'this.iconKeypadComposite' y su canal mediator en
		//		'this.iconKeypadChannel'. Espera que se implemente el método 'this.getIconKeypadNode()', y que devuelva
		//		el nodo donde se desea colocar la botonera (y si no, se coloca en 'this.topNode').

		constructor: function(args) {

			this.config = {
				buttonsComposite: {
					"filters": {
						className: "fa-filter",
						title: this.i18n.filterTitle
					}
				},
				compositeActions: {
					KEYPAD_INPUT: "keypadInput"
				compositeSearchInTooltipFromIconKeypadActions: {
					KEYPAD_INPUT: 'keypadInput'
				}
			};

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

			aspect.before(this, "_mixEventsAndActions", lang.hitch(this, this._mixCompositeEventsAndActions));
			aspect.before(this, "_afterSetConfigurations", lang.hitch(this, this._setCompositeConfigurations));
			aspect.before(this, "_initialize", lang.hitch(this, this._initializeBeforeCompositeView));
			aspect.before(this, "_defineSubscriptions", lang.hitch(this, this._initializeAfterCompositeView));
			aspect.after(this, "_defineSubscriptions", lang.hitch(this, this._defineCompositeSubcriptions));
		},

		_mixCompositeEventsAndActions: function () {
			aspect.before(this, '_mixEventsAndActions', lang.hitch(this,
				this._mixCompositeSearchInTooltipFromIconKeypadEventsAndActions));

			lang.mixin(this.actions, this.compositeActions);

			delete this.compositeActions;
		},

		_setCompositeConfigurations: function() {

			this.compositeConfig = this._merge([{
				parentChannel: this.getChannel(),
				timeClose: null,
				'class': 'compositeSearchInTooltip'
			}, this.compositeConfig || {}]);
			aspect.before(this, '_initialize', lang.hitch(this, this._initializeCompositeSearchInTooltipFromIconKeypad));
			aspect.after(this, '_defineSubscriptions', lang.hitch(this,
				this._defineCompositeSearchInTooltipFromIconKeypadSubcriptions));
		},

		_initializeBeforeCompositeView: function() {
		_mixCompositeSearchInTooltipFromIconKeypadEventsAndActions: function () {

			this.compositeConfig.filterChannel = this.queryChannel;
			lang.mixin(this.actions, this.compositeSearchInTooltipFromIconKeypadActions);

			this.composite = new declare([CompositeImpl, _HideFormByAction, _ShowOnEvt])
				.extend(_ShowInTooltip)(this.compositeConfig);
			delete this.compositeSearchInTooltipFromIconKeypadActions;
		},

		_initializeAfterCompositeView: function() {
		_initializeCompositeSearchInTooltipFromIconKeypad: function() {

			if (!this.iconKeypadChannel) {
			this.iconKeypadComposite = new IconKeypadImpl({
				parentChannel: this.getChannel(),
					items: this.buttonsComposite
				items: {
					filters: {
						className: 'fa-filter',
						title: this.i18n.filterTitle
					}
				}
			});

			this.iconKeypadChannel = this.iconKeypadComposite.getChannel();
			}
		},

		_defineCompositeSubcriptions: function () {
		_defineCompositeSearchInTooltipFromIconKeypadSubcriptions: function () {

			this.subscriptionsConfig.push({
				channel: this._buildChannel(this.iconKeypadChannel, this.actions.KEYPAD_INPUT),
				callback: "_subKeypadInputComposite"
				callback: '_subKeypadInputComposite'
			});
		},

@@ -97,10 +77,9 @@ define([
			this.inherited(arguments);

			if (this.iconKeypadComposite) {
				this.keypadZoneNode = put(this._getIconKeypadNode(), 'div.keypadZone');

				this.keypadZoneNode = put(this._getIconKeypadNode(), "div.keypadZone");

				this._publish(this.iconKeypadComposite.getChannel("SHOW"), {
				this._publish(this.iconKeypadComposite.getChannel('SHOW'), {
					node: this.keypadZoneNode
				});
			}
@@ -108,26 +87,29 @@ define([

		_subKeypadInputComposite: function(res) {

			if (res.inputKey === "filters") {
				if (!this._initFilters) {
					this._publish(this.composite.getChannel("ADD_EVT"), {
						sourceNode: res.node.firstChild,
			if (res.inputKey !== 'filters' || this._compositeSearchInTooltipFromIconKeypadShowEventAdded) {
				return;
			}

			var sourceNode = res.node.firstChild;

			this._publish(this.composite.getChannel('ADD_EVT'), {
				sourceNode: sourceNode,
				initAction: 'hide'
			});

					this._publish(this.composite.getChannel("SHOW"), {
						node: res.node.firstChild
			this._publish(this.composite.getChannel('SHOW'), {
				node: sourceNode
			});

					this._initFilters = true;
				}
			}
			this._compositeSearchInTooltipFromIconKeypadShowEventAdded = true;
		},

		_getIconKeypadNode: function() {

			if (this.getIconKeypadNode)
			if (this.getIconKeypadNode) {
				return this.getIconKeypadNode();
			}

			return this.topNode;
		}
+53 −0
Original line number Diff line number Diff line
define([
	'dojo/_base/declare'
	, 'dojo/_base/lang'
	, 'dojo/aspect'
	, 'redmic/modules/base/_ShowInTooltip'
	, 'redmic/modules/base/_ShowOnEvt'
	, 'redmic/modules/search/CompositeImpl'
	, 'redmic/modules/search/_HideFormByAction'
], function(
	declare
	, lang
	, aspect
	, _ShowInTooltip
	, _ShowOnEvt
	, CompositeImpl
	, _HideFormByAction
) {

	return declare(null, {
		//	summary:
		//		Permite crear una instancia de CompositeImpl (Search) mostrada mediante tooltip.
		//	description:
		//		Extensión que instancia una búsqueda compuesta para ser mostrada en tooltip, a determinar por la lógica
		//		de quien importe esta extensión.
		//		Se puede configurar añadiendo propiedades a 'this.compositeConfig' y la instancia creada se coloca en
		//		'this.composite'.

		constructor: function(args) {

			aspect.before(this, '_afterSetConfigurations', lang.hitch(this,
				this._setCompositeSearchInTooltipConfigurations));

			aspect.before(this, '_initialize', lang.hitch(this, this._initializeCompositeSearchInTooltip));
		},

		_setCompositeSearchInTooltipConfigurations: function() {

			this.compositeConfig = this._merge([{
				parentChannel: this.getChannel(),
				timeClose: null,
				'class': 'compositeSearchInTooltip'
			}, this.compositeConfig || {}]);
		},

		_initializeCompositeSearchInTooltip: function() {

			this.compositeConfig.filterChannel = this.queryChannel;

			var Definition = declare([CompositeImpl, _HideFormByAction, _ShowOnEvt]).extend(_ShowInTooltip);
			this.composite = new Definition(this.compositeConfig);
		}
	});
});
+41 −26
Original line number Diff line number Diff line
define([
	"app/base/views/extensions/_CompositeInTooltipFromIconKeypad"
	, "dojo/_base/declare"
	'app/base/views/extensions/_CompositeSearchInTooltip'
	, 'dojo/_base/declare'
	, 'dojo/_base/lang'
	, 'dojo/aspect'
], function(
	_CompositeInTooltipFromIconKeypad
	_CompositeSearchInTooltip
	, declare
	, lang
	, aspect
) {
	return declare(_CompositeInTooltipFromIconKeypad, {

	return declare(_CompositeSearchInTooltip, {
		//	summary:
		//
		//		Muestra la instancia de CompositeImpl (Search) en tooltip, asociado a una suscripción a TextImpl
		//		(Search).
		//	description:
		//

		_setCompositeConfigurations: function() {
		//		Escucha la publicación de "expandir búsqueda" desde una instancia de buscador de texto, para vincular
		//		al nodo recibido el despliegue del tooltip con la búsqueda compuesta.
		//		Da por hecho que la instancia del buscador de texto se encuentra en 'this.textSearch'.

			this.inherited(arguments);
		constructor: function(args) {

			this.compositeConfig = this._merge([{
			this.config = {
				compositeConfig: {
					formConfig: {
						dataTemplate: {
							formTitle: this.i18n.advancedSearch
						}
					}
			}, this.compositeConfig || {}]);
				}
			};

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

			aspect.after(this, '_defineSubscriptions', lang.hitch(this,
				this._defineAddCompositeSearchInTooltipSubcriptions));
		},

		// TODO pisar/limpiar de manera más elegante
		_initializeAfterCompositeView: function() {},
		_defineAddCompositeSearchInTooltipSubcriptions: function () {

		// TODO pisar/limpiar de manera más elegante
		_defineCompositeSubcriptions: function () {
			if (!this.textSearch) {
				return;
			}

			this.subscriptionsConfig.push({
				channel: this.textSearch.getChannel('EXPAND_SEARCH'),
				callback: "_subTextSearchExpand"
				callback: '_subTextSearchExpand'
			});
		},

		_subTextSearchExpand: function(res) {

			if (this._initFilters) {
			if (this._addCompositeSearchInTooltipShowEventAdded) {
				return;
			}

			this._publish(this.composite.getChannel("ADD_EVT"), {
				sourceNode: res.node,
			var sourceNode = res.node;

			this._publish(this.composite.getChannel('ADD_EVT'), {
				sourceNode: sourceNode,
				initAction: 'hide'
			});

			this._publish(this.composite.getChannel("SHOW"), {
				node: res.node
			this._publish(this.composite.getChannel('SHOW'), {
				node: sourceNode
			});

			this._initFilters = true;
			this._addCompositeSearchInTooltipShowEventAdded = true;
		}
	});
});