Commit ecfae095 authored by CarlosGC1989's avatar CarlosGC1989
Browse files

Refactoriza vistas de detalles

Arregla algunos errores detectados en las vistas de detalles.
Refactoriza el código, ya que existían elementos repetidos.

Fix #6.
parent 49b333f8
Loading
Loading
Loading
Loading
+33 −33
Original line number Diff line number Diff line
@@ -99,6 +99,11 @@ define([
			this._onEvt('BUTTON_EVENT', lang.hitch(this, this._onButtonEvent));
		},

		_afterShow: function(request) {

			this.startup();
		},

		_afterControllerShow: function() {

			if (!this._widgetsAlreadyGenerated) {
@@ -123,21 +128,25 @@ define([
			this._classRow = this.noScroll ? this._relativeRowsClass : this._fixedRowsClass;

			for (var key in this.widgetConfigs) {
				var config = this.widgetConfigs[key],
					noCreate = true;

				if (this._nodes[key]) {
					noCreate = false;
				this._widgetVisualization(key);
			}

				noCreate && this._createBox(key, config);
			this._updateInteractive();
		},

				noCreate && this._showWidget(key, config);
		_widgetVisualization: function(key) {

				noCreate && this._makeNodeInteractive(this._nodes[key]);
			var config = this.widgetConfigs[key];

			if (this._nodes[key]) {
				return;
			}

			this._updateInteractive();
			this._createBox(key, config);

			this._showWidget(key, config);

			this._makeNodeInteractive(this._nodes[key]);
		},

		_subParentResized: function() {
@@ -180,28 +189,6 @@ define([
			return this.centerNode;
		},

		_insertIcon: function(config, node) {

			if (config.condition && this._evaluateCondition(config.condition)) {
				return;
			}

			var iconNode = put(node, (config.href ? 'a' : 'i') + ".iconList." + config.icon.split("-")[0] + "." + config.icon);

			if (config.title) {
				iconNode.setAttribute("title", config.title);
			}

			if (config.href) {
				iconNode.setAttribute('href', lang.replace(config.href, this.data));
				iconNode.setAttribute('d-state-url', true);
			}

			if (config.btnId) {
				iconNode.onclick = lang.hitch(this, this._emitEvt, 'BUTTON_EVENT', config.btnId);
			}
		},

		_evaluateCondition: function(condition) {

			if (typeof condition === "function") {
@@ -222,7 +209,6 @@ define([
			}

			config.props = this._merge([this.propsWidget || {}, config.props]);

			config.props.ownChannel = key;
			config.props.parentChannel = this.getChannel();

@@ -379,13 +365,27 @@ define([
			}
		},

		_showWindow: function(key, config) {
		_showWindow: function(key) {

			var module = this._widgets[key];

			this._publish(module.getChannel('SHOW_WINDOW'));
		},

		_resizeWindowContainers: function() {

			for (var key in this._widgets) {
				this._resizeWindowContainer(key);
			}
		},

		_resizeWindowContainer: function(key) {

			var module = this._widgets[key];

			this._publish(module.getChannel('RESIZE'));
		},

		_reportClicked: function() {

			this._publish(this._buildChannel(this.taskChannel, this.actions.GET_REPORT), {
+0 −3
Original line number Diff line number Diff line
@@ -3,13 +3,11 @@ define([
	, "dojo/_base/lang"
	, "dojo/aspect"
	, "app/designs/details/_AddTitle"
	, "templates/DefaultDetailsTitle"
], function (
	declare
	, lang
	, aspect
	, _AddTitle
	, TemplateTitle
){
	return declare(_AddTitle, {
		//	summary:
@@ -30,7 +28,6 @@ define([
		_setAddBasicTitleConfigurations: function() {

			this.titleWidgetConfig = this._merge([{
				template: TemplateTitle,
				target: this.getOwnChannel() + "DetailsTitle"
			}, this.titleWidgetConfig || {}]);
		},
+77 −31
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@ define([
	, "put-selector/put"
	, "redmic/modules/layout/templateDisplayer/TemplateDisplayer"
	, "RWidgets/Utilities"
	, "templates/DefaultDetailsTitle"
], function (
	declare
	, lang
@@ -14,6 +15,7 @@ define([
	, put
	, TemplateDisplayer
	, Utilities
	, TemplateTitle
){
	return declare(null, {
		//	summary:
@@ -22,12 +24,6 @@ define([
		constructor: function(args) {

			this.configTitle = {
				_titleWidgetConfig: {
					parentChannel: this.getChannel(),
					ownChannel: "title",
					associatedIds: [this.ownChannel]
				},

				_titleLeftButtonsList: [],

				_titleRightButtonsList: [{
@@ -37,13 +33,9 @@ define([
				}],

				tabs: [],

				centerTitle: false,

				pathParent: null,

				_closeTitle: false,

				_idTitle: false,

				_close: {
@@ -54,18 +46,41 @@ define([

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

			aspect.after(this, "_afterSetConfigurations", lang.hitch(this, this._setTitleConfigurations));
			aspect.before(this, "_initialize", this._initializeTitle);
			aspect.before(this, "_defineSubscriptions", this._defineTitleSubscriptions);
			aspect.after(this, "postCreate", this._postCreateTitle);
		},

		_initializeTitle: function() {
		_setTitleConfigurations: function() {

			this._titleWidgetConfig = this._merge([{
				parentChannel: this.getChannel(),
				ownChannel: "title",
				associatedIds: [this.ownChannel],
				template: TemplateTitle,
				target: this.target instanceof Array ? this.target[0] : this.target
			}, this.titleWidgetConfig || {}]);
		},

			lang.mixin(this._titleWidgetConfig, this.titleWidgetConfig);
		_initializeTitle: function() {

			this.titleWidget = new TemplateDisplayer(this._titleWidgetConfig);

			aspect.after(this.titleWidget, "_dataAvailable", lang.hitch(this, this._dataInTitle));
			aspect.after(this.titleWidget, "_itemAvailable", lang.hitch(this, this._dataInTitle));
			aspect.after(this.titleWidget, "_dataAvailable", lang.hitch(this, this._addDataInTitle));
			aspect.after(this.titleWidget, "_itemAvailable", lang.hitch(this, this._addDataInTitle));
		},

		_defineTitleSubscriptions: function () {

			this.subscriptionsConfig.push({
				channel : this.titleWidget.getChannel("UPDATED"),
				callback: "_subTitleUpdated"
			});
		},

		_subTitleUpdated: function(res) {

		},

		_postCreateTitle: function() {
@@ -86,19 +101,19 @@ define([
			put(this.containerNode.firstChild, "-", this.topNode);
		},

		_dataInTitle: function() {
		_addDataInTitle: function() {

			this._updateDataTitle();
			this._createTitle();
			this._addIconsAndTabs();
		},

			this.data = this.titleWidget.data;
		_updateDataTitle: function() {

			if (this._idTitle) {
				this._addIdTitle();
			}
			this.data = this.titleWidget.data;
		},

			if (this.pathParent && this.activeTitleParent) {
				this._addParentTitle();
			}
		_addIconsAndTabs: function() {

			var leftButtons = this._titleLeftButtonsList.concat(this.titleLeftButtonsList || []),
				rightButtons = this._titleRightButtonsList.concat(this.titleRightButtonsList || []);
@@ -111,7 +126,24 @@ define([

		_createTitle: function() {

			if (this._titleLeftNode) {
			this._createTitleNodes();

			this._publish(this.titleWidget.getChannel("SHOW"), {
				node: this._titleCenterNode
			});

			if (this._idTitle) {
				this._addIdTitle();
			}

			if (this.pathParent && this.activeTitleParent) {
				this._addParentTitle();
			}
		},

		_createTitleNodes: function() {

			if (this._titleLeftNode || !this.titleNode) {
				return;
			}

@@ -119,10 +151,6 @@ define([
			this._titleCenterNode = put(this.titleNode, "div.center");
			this._titleRightNode = put(this.titleNode, "div.right.hidden");
			put(this.titleNode, "div.rightSpace");

			this._publish(this.titleWidget.getChannel("SHOW"), {
				node: this._titleCenterNode
			});
		},

		_addIdTitle: function() {
@@ -172,10 +200,6 @@ define([
			if (this._insertTabByCondition(this.tabs[pos])) {
				var classTab = ".tab.tabSelect";

				/*if (this.tabs[pos].select) {
					classTab += ".tabSelect";
				}*/

				tabNode = put(this._tabstitleNode, "div" + classTab + " a",
					this.i18n[this.tabs[pos].title] ? this.i18n[this.tabs[pos].title] : this.tabs[pos].title);

@@ -239,6 +263,28 @@ define([
			if ((!buttonProp.condition) || (buttonProp.condition && this.data && this.data[buttonProp.condition])) {
				this._insertIcon(buttonProp, node);
			}
		},

		_insertIcon: function(config, node) {

			if (config.condition && this._evaluateCondition(config.condition)) {
				return;
			}

			var iconNode = put(node, (config.href ? 'a' : 'i') + ".iconList." + config.icon.split("-")[0] + "." + config.icon);

			if (config.title) {
				iconNode.setAttribute("title", config.title);
			}

			if (config.href) {
				iconNode.setAttribute('href', lang.replace(config.href, this.data));
				iconNode.setAttribute('d-state-url', true);
			}

			if (config.btnId) {
				iconNode.onclick = lang.hitch(this, this._emitEvt, 'BUTTON_EVENT', config.btnId);
			}
		}
	});
});
+19 −191
Original line number Diff line number Diff line
define([
	"app/designs/base/_Main"
	, "app/designs/details/Controller"
	, "app/designs/details/Layout"
	, "app/designs/details/_AddTitle"
	, "app/designs/details/_TitleSelection"
	, "app/redmicConfig"
	"app/redmicConfig"
	, "dojo/_base/declare"
	, "dojo/_base/lang"
	, "redmic/modules/browser/_ButtonsInRow"
	, "redmic/modules/browser/_Framework"
	, "redmic/modules/browser/ListImpl"
	, "redmic/modules/browser/bars/Total"
	, "redmic/modules/layout/TabsDisplayer"
	, "redmic/modules/layout/templateDisplayer/TemplateDisplayer"
	, "templates/ActivityTitle"
	, "templates/ContactSet"
	, "templates/DocumentList"
	, "templates/OrganisationSet"
	, "templates/PlatformSet"
	, "templates/ActivityInfo"
	, "templates/ActivityInfoHelp"
	, "./_ActivityBase"
], function(
	_Main
	, Controller
	, Layout
	, _AddTitle
	, _TitleSelection
	, redmicConfig
	redmicConfig
	, declare
	, lang
	, _ButtonsInRow
	, _Framework
	, ListImpl
	, Total
	, TabsDisplayer
	, TemplateDisplayer
	, TemplateTitle
	, TemplateContacts
	, TemplateDocuments
	, TemplateOrganisation
	, TemplatePlatform
	, TemplateInfo
	, TemplateInfoHelp
	, _ActivityBase
){
	return declare([Layout, Controller, _Main, _AddTitle, _TitleSelection], {
	return declare([_ActivityBase], {
		//	summary:
		//		Vista detalle de Activity.

@@ -52,28 +26,12 @@ define([
			this.target = redmicConfig.services.activity;
			this.reportService = "activity";
			this.ancestorsTarget = redmicConfig.services.activityAncestors;
			this.documentTarget = "documents";
			this.contactTarget = "contacts";
			this.organisationTarget = "organisations";
			this.platformTarget = "platforms";
			this.infoWidgetTarget = "infoWidgetTarget";

			this.config = {
				noScroll: true
			};

			this.titleRightButtonsList = [];

			lang.mixin(this, this.config, args);
			this.infoTarget = "infoWidgetTarget";
		},

		_setMainConfigurations: function() {

			this.titleWidgetConfig = this._merge([{
				template: TemplateTitle,
				target: this.target
			}, this.titleWidgetConfig || {}]);

			this.widgetConfigs = this._merge([{
				helpText: {
					width: 6,
@@ -86,123 +44,29 @@ define([
						target: "helpTextActivity"
					}
				},
				info: {
					width: 3,
				info: this._infoConfig({
					height: 5,
					type: TemplateDisplayer,
					props: {
						title: this.i18n.info,
						template: TemplateInfo,
						"class": "containerDetails",
						classEmptyTemplate: "contentListNoData",
						target: this.infoWidgetTarget,
						associatedIds: [this.ownChannel],
						shownOption: this.shownOptionInfo
					}
				},
					template: TemplateInfo
				}),
				additionalInfo: {
					width: 3,
					height: 5,
					type: TabsDisplayer,
					props: {
						title: this.i18n.additionalInfo,
						childTabs: [{
							title: this.i18n.organisations,
							type: declare([ListImpl, _Framework, _ButtonsInRow]),
							props: {
								target: this.organisationTarget,
								template: TemplateOrganisation,
								bars: [{
									instance: Total
								}],
								rowConfig: {
									buttonsConfig: {
										listButton: [{
											icon: "fa-info-circle",
											btnId: "details",
											title: this.i18n.info,
											href: this.viewPathsWidgets.organisations,
											pathToItem: "organisation"
										}]
									}
								}
							}
						},{
							title: this.i18n.platforms,
							type: declare([ListImpl, _Framework, _ButtonsInRow]),
							props: {
								target: this.platformTarget,
								template: TemplatePlatform,
								bars: [{
									instance: Total
								}],
								rowConfig: {
									buttonsConfig: {
										listButton: [{
											icon: "fa-info-circle",
											btnId: "details",
											title: this.i18n.info,
											href: this.viewPathsWidgets.platforms,
											pathToItem: "platform"
										}]
									}
								}
							}
						},{
							title: this.i18n.contacts,
							type: declare([ListImpl, _Framework]),
							props: {
								target: this.contactTarget,
								template: TemplateContacts,
								bars: [{
									instance: Total
								}]
							}
						},{
							title: this.i18n.documents,
							type: declare([ListImpl, _Framework, _ButtonsInRow]),
							props: {
								target: this.documentTarget,
								template: TemplateDocuments,
								bars: [{
									instance: Total
								}],
								rowConfig: {
									buttonsConfig: {
										listButton: [{
											icon: "fa-file-pdf-o",
											btnId: "downloadPdf",
											title: this.i18n.download,
											condition: "url",
											href: redmicConfig.viewPaths.bibliographyPDF
										},{
											icon: "fa-info-circle",
											btnId: "details",
											title: this.i18n.info,
											href: this.viewPathsWidgets.documents
										}]
									}
								}
							}
						}]
						childTabs: [
							this._organisationsConfig(),
							this._platformsConfig(),
							this._contactsConfig(),
							this._documentsConfig()
						]
					}
				}
			}, this.widgetConfigs || {}]);
		},

		_clearModules: function() {

			this._publish(this._widgets.info.getChannel("CLEAR"));
			this._publish(this._widgets.additionalInfo.getChildChannel("childInstances.0", "CLEAR"));
			this._publish(this._widgets.additionalInfo.getChildChannel("childInstances.1", "CLEAR"));
			this._publish(this._widgets.additionalInfo.getChildChannel("childInstances.2", "CLEAR"));
			this._publish(this._widgets.additionalInfo.getChildChannel("childInstances.3", "CLEAR"));
		},

		_refreshModules: function() {

			this._checkPathVariableId();

			var object = {};

			object.info = this.i18n.helpTextActivityDetails;
@@ -212,11 +76,7 @@ define([
				target: "helpTextActivity"
			});

			this._emitEvt('GET', {
				target: this.target,
				requesterId: this.ownChannel,
				id: this.pathVariableId
			});
			this.inherited(arguments);
		},

		_itemAvailable: function(res) {
@@ -230,7 +90,7 @@ define([

			this._emitEvt('INJECT_DATA', {
				data: this._activityData,
				target: this.infoWidgetTarget
				target: this.infoTarget
			});

			this._emitEvt('REQUEST', {
@@ -241,39 +101,7 @@ define([
				}
			});

			var documents = res.data.documents;
			if (documents && documents.length) {
				for (var i = 0; i < documents.length; i++) {
					this._emitEvt('INJECT_ITEM', {
						data: documents[i].document,
						target: this.documentTarget
					});
				}
			}

			var contacts = res.data.contacts;
			if (contacts && contacts.length) {
				this._emitEvt('INJECT_DATA', {
					data: contacts,
					target: this.contactTarget
				});
			}

			var platforms = res.data.platforms;
			if (platforms && platforms.length) {
				this._emitEvt('INJECT_DATA', {
					data: platforms,
					target: this.platformTarget
				});
			}

			var organisations = res.data.organisations;
			if (organisations && organisations.length) {
				this._emitEvt('INJECT_DATA', {
					data: organisations,
					target: this.organisationTarget
				});
			}
			this.inherited(arguments);
		},

		_dataAvailable: function(res) {
@@ -287,7 +115,7 @@ define([

			this._emitEvt('INJECT_DATA', {
				data: this._activityData,
				target: this.infoWidgetTarget
				target: this.infoTarget
			});
		}
	});
+0 −7
Original line number Diff line number Diff line
@@ -10,7 +10,6 @@ define([
	, "redmic/modules/map/layer/PruneClusterLayerImpl"
	, "redmic/modules/map/layer/_RadiusOnClick"
	, "app/designs/mapWithSideContent/main/Geographic"
	, "templates/ActivityTitle"
], function(
	_ListenActivityDataAndAccessByActivityCategory
	, _Main
@@ -23,7 +22,6 @@ define([
	, PruneClusterLayerImpl
	, _RadiusOnClick
	, Geographic
	, TemplateTitle
){
	return declare([Layout, Controller, _Main, _AddTitle, _TitleSelection, _ListenActivityDataAndAccessByActivityCategory], {
		//	summary:
@@ -48,11 +46,6 @@ define([

			this.targetChange = lang.replace(this.templateTargetChange, {id: this.pathVariableId});

			this.titleWidgetConfig = this._merge([{
				template: TemplateTitle,
				target: this.target
			}, this.titleWidgetConfig || {}]);

			this.widgetConfigs = this._merge([{
				geographic: {
					width: 6,
Loading