Commit 9c56672f authored by Pedro Eduardo Trujillo's avatar Pedro Eduardo Trujillo
Browse files

Implementa Sidebar colapsable

Extrae escucha de redimensión de ventana a extensión de módulos, en
lugar de implementarlo solo en App.

Prepara primera versión del Sidebar colapsable, junto con un botón en
Topbar para manejarlo.
parent 6c2d6dde
Loading
Loading
Loading
Loading
+3 −40
Original line number Diff line number Diff line
@@ -3,14 +3,12 @@ define([
	, 'redmic/modules/base/_Show'
	, 'dojo/_base/declare'
	, 'dojo/_base/lang'
	, 'dojo/has'
	, './_appItfc'
], function(
	_Module
	, _Show
	, declare
	, lang
	, has
	, _appItfc
){
	return declare([_Module, _Show, _appItfc], {
@@ -25,7 +23,6 @@ define([
			this.config = {
				ownChannel: 'app',
				events: {
					WINDOW_RESIZE: 'windowResize',
					MODULE_SHOWN: 'moduleShown'
				},
				actions: {
@@ -42,9 +39,6 @@ define([
			this.subscriptionsConfig.push({
				channel: this.getChannel('SHOW_MODULE'),
				callback: '_subShowModule'
			/*},{
				channel: this.getChannel('RESIZE_VIEW'),
				callback: '_subResizeView'*/
			});
		},

@@ -53,48 +47,20 @@ define([
			this.publicationsConfig.push({
				event: 'MODULE_SHOWN',
				channel: this.getChannel('MODULE_SHOWN')
			},{
				event: 'WINDOW_RESIZE',
				channel: this.getChannel('WINDOW_RESIZE')
			});
		},

		_doEvtFacade: function() {

			this._onEvt('HIDE', lang.hitch(this, this._onAppHide));

			// TODO puede que no sea necesario, se puede eliminar de aquí y de '_Show' si no se va a usar,
			// o bien implementarse directamente en _Show sin necesidad de publicar (todos los módulos pueden acceder
			// al elemento window)
			//this._getGlobalContext().onresize = lang.hitch(this, this._groupEventArgs, 'WINDOW_RESIZE');
		},

		_setOwnCallbacksForEvents: function() {

			this._onceEvt('SHOW', lang.hitch(this, this._onFirstShow));
			this._onceEvt('SHOW', lang.hitch(this, this._onAppFirstShow));
			this._onEvt('HIDE', lang.hitch(this, this._onAppHide));
		},

		_onFirstShow: function() {
		_onAppFirstShow: function() {

			this.startup();
		},

		_getGlobalContext: function() {

			if (has('host-browser')) {
				return window;
			} else if (has('host-node')) {
				return global;
			} else {
				console.error('Environment not supported');
			}
		},

		/*_subResizeView: function(req) {

			this._doResize();
		},*/

		_subShowModule: function(req) {

			var moduleKey = req.moduleKey,
@@ -110,9 +76,6 @@ define([

		_onModuleShown: function(moduleKey, res) {

			// TODO cuando no sea contenedor dijit, no hará falta
			//this._doResize();

			this._emitEvt('MODULE_SHOWN', {
				key: moduleKey
			});
+33 −1
Original line number Diff line number Diff line
define([
	"dijit/layout/ContentPane"
	, "dijit/registry"
	, "dojo/_base/declare"
	, "dojo/_base/lang"
	, "dojo/dom"
	, "dojo/dom-class"
	, "put-selector/put"
	, "redmic/modules/base/Manager"
], function(
	ContentPane
	, registry
	, declare
	, lang
	, dom
	, domClass
	, put
	, Manager
){
@@ -20,8 +26,9 @@ define([
		constructor: function(args) {

			this.config = {
				"class": "topbar",
				region: "top",
				"class": "topbar",
				collapsedSidebarClass: 'collapsedSidebar',
				doLayout: false,
				show: {
					left: true,
@@ -35,6 +42,9 @@ define([
		postCreate: function() {

			// Se crean los nodos
			this._collapseNode = put(this.domNode, "div.collapseSidebarButton");
			this._collapseNode.onclick = lang.hitch(this, this._onCollapseClicked);

			this.logoNode = put(this.domNode, "div.topbarLogo", {
				innerHTML: "<a href='/home' d-state-url=true title='" + this.i18n.home +
					"'><img class='logo' src='/resources/images/logos/redmicSimple.png'></a>"
@@ -56,6 +66,28 @@ define([
			this.manager = new Manager({
				parentChannel: this.parentChannel
			}, this.leftNode);
		},

		_getGlobalContainer: function() {

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

			var rootNode = dom.byId('rootContainer'),
				globalContainerId = rootNode.firstChild.id,
				globalContainer = registry.byId(globalContainerId);

			this._globalContainer = globalContainer;
			return globalContainer;
		},

		_onCollapseClicked: function() {

			domClass.toggle(this.ownerDocumentBody, this.collapsedSidebarClass);

			var globalContainer = this._getGlobalContainer();
			globalContainer && globalContainer.resize();
		}
	});
});
+7 −4
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@ define([
			this.config = {
				design: 'sidebar',
				'class': 'mainContainer',
				collapsedSidebarClass: 'collapsedSidebar',
				isLayoutContainer: true,
				innerAppActions: {
					UPDATE_ACTIVE: 'updateActive'
@@ -100,6 +101,8 @@ define([

		postCreate: function() {

			this.inherited(arguments);

			this.addChild(this.bc);
			this.addChild(this.sidebarNode);
			this.addChild(this.topbar);
@@ -108,8 +111,6 @@ define([
				node: this.sidebarNode
			});

			this.inherited(arguments);

			// TODO esto es un abuso, no deberíamos acceder a los nodos de un módulo desde fuera. Crear canal para
			// añadir hijos al topbar
			//
@@ -148,7 +149,8 @@ define([
			//		private

			this.sidebar = new MainSidebarImpl({
				parentChannel: this.ownChannel
				parentChannel: this.ownChannel,
				collapsedSidebarClass: this.collapsedSidebarClass
			});

			new QueryStore({
@@ -206,7 +208,8 @@ define([

			this.topbar = new Topbar({
				parentChannel: this.ownChannel,
				i18n: this.i18n
				i18n: this.i18n,
				collapsedSidebarClass: this.collapsedSidebarClass
			});

			this.bc = new BorderContainer({
+61 −0
Original line number Diff line number Diff line
define([
	"dojo/_base/declare"
	, "dojo/_base/lang"
	, "dojo/aspect"
	, "dojo/has"
], function(
	declare
	, lang
	, aspect
	, has
) {

	return declare(null, {
		//	summary:
		//		Permite a los módulos escuchar las redimensiones del contexto global.

		listenWindowResizeEvents: {
			WINDOW_RESIZE: "windowResize"
		},

		constructor: function(args) {

			aspect.after(this, "_mixEventsAndActions", lang.hitch(this, this._mixListenWindowResizeEventsAndActions));
			aspect.after(this, "_doEvtFacade", lang.hitch(this, this._doListenWindowResizeEvtFacade));
			aspect.after(this, "_setOwnCallbacksForEvents", lang.hitch(this,
				this._setListenWindowResizeOwnCallbacksForEvents));
		},

		_mixListenWindowResizeEventsAndActions: function () {

			lang.mixin(this.events, this.listenWindowResizeEvents);
			delete this.listenWindowResizeEvents;
		},

		_doListenWindowResizeEvtFacade: function() {

			this._getGlobalContext().onresize = lang.hitch(this, this._groupEventArgs, 'WINDOW_RESIZE');
		},

		_setListenWindowResizeOwnCallbacksForEvents: function () {

			this._onEvt('WINDOW_RESIZE', lang.hitch(this, this._onWindowResize));
		},

		_onWindowResize: function(evt) {

			this._prepareResize(evt);
		},

		_getGlobalContext: function() {

			if (has('host-browser')) {
				return window;
			} else if (has('host-node')) {
				return global;
			} else {
				console.error('Environment not supported');
			}
		}
	});
});
+4 −24
Original line number Diff line number Diff line
@@ -29,7 +29,6 @@ define([
			LOADING: "loading",
			LOADED: "loaded",
			RESIZE: "resize",
			//RESIZE_VIEW: "resizeView",
			ME_OR_ANCESTOR_SHOWN: "meOrAncestorShown",
			ME_OR_ANCESTOR_HIDDEN: "meOrAncestorHidden",
			STARTED_UP: "startedUp"
@@ -50,8 +49,6 @@ define([
			LOCK: "lock",
			UNLOCK: "unlock",
			TOGGLE_LOCK: "toggleLock",
			WINDOW_RESIZE: "windowResize",
			//RESIZE_VIEW: "resizeView",
			STARTED_UP: "startedUp"
		},

@@ -130,9 +127,6 @@ define([
			},{
				channel: this.getChannel("TOGGLE_LOCK"),
				callback: "_subToggleLock"
			},{
				channel: this._buildChannel(this.rootChannel, this.actions.WINDOW_RESIZE),
				callback: "_subWindowResize"
			});

			this._deleteDuplicatedChannels(this.subscriptionsConfig);
@@ -157,9 +151,6 @@ define([
			},{
				event: 'RESIZE',
				channel: this.getChannel("RESIZED")
			/*},{
				event: 'RESIZE_VIEW',
				channel: this._buildChannel(this.rootChannel, this.actions.RESIZE_VIEW)*/
			},{
				event: 'STARTED_UP',
				channel: this.getChannel("STARTED_UP")
@@ -379,12 +370,6 @@ define([
			}

			if (node.domNode) {
				/*var parentNodeGetter = function() { return node.domNode; },
					childNodeGetter = function() { return nodeToShow; },
					callback = lang.hitch(this, this._emitEvt, 'RESIZE_VIEW');

				this._listenChildrenPlacing(parentNodeGetter, childNodeGetter, callback);*/

				this._addToNode(node.domNode, nodeToShow, inFront);
			} else {
				this._addToNode(node, nodeToShow, inFront);
@@ -651,11 +636,6 @@ define([
			}
		},

		_subWindowResize: function(res) {

			this._prepareResize(res);
		},

		_prepareResize: function(res) {

			clearTimeout(this._additionalResizeHandler);
Loading