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

Refactoriza, limpia y omite animaciones en nested

Para simplificar su gestión y evitar bugs extraños de desapariciones de
nodos, se omite toda animación asociada al intercambio de contenidos
anidados en el módulo NestedContent.

Se optimiza y se corrige su funcionamiento, trabajando correctamente con
los contenidos de las consultas en mapa.
parent db887d07
Loading
Loading
Loading
Loading
+39 −45
Original line number Diff line number Diff line
define([
	'dojo/_base/declare'
	, 'dojo/_base/lang'
	, 'redmic/modules/base/_Store'
	, 'redmic/modules/browser/bars/Total'
	, 'redmic/modules/browser/_ButtonsInRow'
	, 'redmic/modules/browser/_Framework'
@@ -13,7 +12,6 @@ define([
], function (
	declare
	, lang
	, _Store
	, Total
	, _ButtonsInRow
	, _Framework
@@ -24,7 +22,7 @@ define([
	, NestedContent
) {

	return declare([NestedContent, _Store], {
	return declare(NestedContent, {
		//	summary:
		//		Main de contenido primario y secundario de tipo listado, donde un item del primero despliega sus
		//		descendientes en el segundo.
@@ -111,10 +109,8 @@ define([
			var BrowserDefinition = declare([ListImpl, _Framework, _ButtonsInRow, _MultiTemplate]);

			this._primaryContentInstance = new BrowserDefinition(this.primaryBrowserConfig);
			this.primaryContentChannel = this._primaryContentInstance.getChannel();

			this._secondaryContentInstance = new BrowserDefinition(this.secondaryBrowserConfig);
			this.secondaryContentChannel = this._secondaryContentInstance.getChannel();
		},

		_defineSubscriptions: function() {
@@ -122,6 +118,9 @@ define([
			this.inherited(arguments);

			this.subscriptionsConfig.push({
				channel : this._primaryContentInstance.getChannel('GOT_DATA'),
				callback: '_subPrimaryGotData'
			},{
				channel : this._primaryContentInstance.getChannel('BUTTON_EVENT'),
				callback: '_subListBtnEvent'
			},{
@@ -153,21 +152,9 @@ define([
			this._emitInjectItem(req);
		},

		_beforeShow: function() {

			this.inherited(arguments);
		_subPrimaryGotData: function(dataWrapper) {

			this._once(this._primaryContentInstance.getChannel('GOT_DATA'), lang.hitch(this,
				this._subOnceGetData));

			this._publish(this._primaryContentInstance.getChannel('GET_DATA'));
		},

		_subOnceGetData: function(data) {

			data = data.data;

			this._setTitle(this.title);
			var data = dataWrapper.data;

			if (data.length === 1) {
				var item = data[0];
@@ -176,16 +163,9 @@ define([
					btnId: 'changeToSecondary',
					id: item[this.idProperty],
					item: item
				}, {
					showAnimation: null,
					title: item.parent[item.parentName]
				});
			} else {
				this._removeBackButton();

				this._showContent(this._primaryContentInstance, {
					hideAnimation: this.primaryOutClass
				});
				this._changeToPrimary();
			}
		},

@@ -228,37 +208,36 @@ define([
			this._secondaryTemplatesByTypeGroup[typeGroup] = childrenTemplate;
		},

		_changeToSecondaryCallback: function(itemData, options) {
		_changeToSecondaryCallback: function(itemData) {

			var primaryData = itemData.item;

			this._updateSecondaryTemplate(primaryData);

			var secondaryOptions = {
				title: this._getSecondaryTitleFromData(primaryData)
			};

			this._changeToSecondary(secondaryOptions);
		},

		_updateSecondaryTemplate: function(primaryData) {

			var typeGroup = itemData.item[this.typeGroupProperty];
			var typeGroup = primaryData[this.typeGroupProperty];

			if (!typeGroup || typeof this._secondaryTemplatesByTypeGroup[typeGroup] === 'object') {
				this._emitInjectData(itemData.item.children);
				this._emitInjectData(primaryData.children);
			} else {
				var template = this._secondaryTemplatesByTypeGroup[typeGroup] || this.secondaryListTemplate ||
					this._defaultTemplate;

				this._once(this._secondaryContentInstance.getChannel('TEMPLATE_UPDATED'), lang.hitch(this,
					this._emitInjectData, itemData.item.children));
					this._emitInjectData, primaryData.children));

				this._publish(this._secondaryContentInstance.getChannel('UPDATE_TEMPLATE'), {
					template: template
				});
			}

			var parentName = itemData.item.parentName,
				parentData = itemData.item.parent,
				title;

			if (typeof parentName === 'function') {
				title = parentName(parentData) || this.title;
			} else {
				title = Utilities.getDeepProp(parentData, parentName) || this.title;
			}

			options = options || { title: title };

			this._changeToSecondary(options);
		},

		_emitInjectData: function(data) {
@@ -267,6 +246,21 @@ define([
				data: data,
				target: this.secondaryTarget
			});
		},

		_getSecondaryTitleFromData: function(primaryData) {

			var parentName = primaryData.parentName,
				parentData = primaryData.parent,
				title;

			if (typeof parentName === 'function') {
				title = parentName(parentData);
			} else {
				title = Utilities.getDeepProp(parentData, parentName);
			}

			return title || this.title;
		}
	});
});
+40 −89
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@ define([
	, 'dojo/_base/lang'
	, 'redmic/modules/base/_Module'
	, 'redmic/modules/base/_Show'
	, 'redmic/modules/base/_Store'
	, 'redmic/modules/layout/genericDisplayer/GenericWithTopbarDisplayerImpl'
	, 'RWidgets/Button'
], function (
@@ -10,11 +11,12 @@ define([
	, lang
	, _Module
	, _Show
	, _Store
	, GenericWithTopbarDisplayerImpl
	, Button
) {

	return declare([_Module, _Show], {
	return declare([_Module, _Show, _Store], {
		//	summary:
		//		Módulo para albergar a una pareja de componentes que manejan información con anidamiento, donde el
		//		primero representa los datos de nivel superior y el segundo muestra los datos anidados en el nivel
@@ -32,16 +34,11 @@ define([
					ADD_NEW_TEMPLATES: 'addNewTemplates'
				},

				'class': 'nestedContentContainer',
				additionalContentClasses: 'nestedContent',
				additionalTopbarContentClasses: 'compactContent',
				primaryInClass: 'primaryIn',
				primaryOutClass: 'primaryOut',
				secondaryInClass: 'secondaryIn',
				secondaryOutClass: 'secondaryOut',

				title: this.i18n.info,
				primaryContentChannel: null,
				secondaryContentChannel: null

				title: this.i18n.info
			};

			lang.mixin(this, this.config, args);
@@ -49,6 +46,12 @@ define([

		_initialize: function() {

			this._createNestedInstance();
			this._createBackButton();
		},

		_createNestedInstance: function() {

			this._nestedContentWithTopbar = new GenericWithTopbarDisplayerImpl({
				parentChannel: this.getChannel(),
				content: this.browserWork,
@@ -57,18 +60,6 @@ define([
			});
		},

		postCreate: function() {

			this.inherited(arguments);

			this._createBackButton();
			this._addBackButton();

			if (!this.primaryContentChannel) {
				console.error('Primary content channel is not specified at module "%s"', this.getChannel());
			}
		},

		_createBackButton: function() {

			this._backButton = new Button({
@@ -79,20 +70,39 @@ define([
			});
		},

		postCreate: function() {

			this._publish(this._nestedContentWithTopbar.getChannel('SHOW'), {
				node: this.domNode
			});
		},

		_addBackButton: function() {

			if (this._backButtonAdded) {
				return;
			}

			this._publish(this._nestedContentWithTopbar.getChannel('ADD_TOPBAR_CONTENT'), {
				content: this._backButton.domNode,
				prependToTitle: true,
				additionalTopbarContentClasses: this.additionalTopbarContentClasses
			});

			this._backButtonAdded = true;
		},

		_removeBackButton: function() {

			if (!this._backButtonAdded) {
				return;
			}

			this._publish(this._nestedContentWithTopbar.getChannel('REMOVE_TOPBAR_CONTENT'), {
				content: this._backButton.domNode
			});

			this._backButtonAdded = false;
		},

		_setTitle: function(title) {
@@ -104,88 +114,29 @@ define([

		_changeToSecondary: function(args) {

			var primaryData = args.primaryData,
				title = args.title,
				showAnimation = this.secondaryInClass,
				hideAnimation = this.secondaryOutClass;

			var hiddenChannel = this._buildChannel(this.primaryContentChannel, this.actions.HIDDEN);

			this._once(hiddenChannel, lang.hitch(this, function(titleArg) {
			var title = args.title

			this._addBackButton();
				this._setTitle(titleArg);
			}, title));

			if (args.showAnimation !== undefined) {
				showAnimation = args.showAnimation;
			}

			if (args.hideAnimation !== undefined) {
				hideAnimation = args.hideAnimation;
			}
			this._setTitle(title);

			this._showContent(this._secondaryContentInstance, {
				data: primaryData,
				showAnimation: showAnimation,
				hideAnimation: hideAnimation
			});
			this._showContent(this._secondaryContentInstance);
		},

		_changeToPrimary: function() {

			var hiddenChannel = this._buildChannel(this.secondaryContentChannel, this.actions.HIDDEN);

			this._once(hiddenChannel, lang.hitch(this, function() {
			this._removeBackButton();

			this._setTitle(this.title);
			}));

			this._removeBackButton();

			this._showContent(this._primaryContentInstance, {
				showAnimation: this.primaryInClass,
				hideAnimation: this.primaryOutClass
			});
			this._showContent(this._primaryContentInstance);
		},

		_showContent: function(contentModule, args) {

			var data = args.data,
				showAnimationClass = args.showAnimation,
				hideAnimationClass = args.hideAnimation;
		_showContent: function(contentModule, showArgs) {

			this._publish(this._nestedContentWithTopbar.getChannel('ADD_CONTENT'), {
				content: contentModule,
				showProps: {
					data: data,
					animation: {
						showAnimation: showAnimationClass,
						hideAnimation: hideAnimationClass
					}
				}
			});
		},

		_getNodeToShow: function() {

			return this._nestedContentWithTopbar._getNodeToShow();
		},

		_beforeShow: function() {

			this._removeBackButton();

			this._setTitle(this.title);
			this._showContent(this._primaryContentInstance, {
				hideAnimation: this.primaryOutClass
			});
		},

		_afterHide: function() {

			this._publish(this._nestedContentWithTopbar.getChannel('HIDE'), {
				omitAnimation: true
				showProps: showArgs || {}
			});
		}
	});