e81c826697906f1cad2ccf8c577e4597692282e0
[Packages/TYPO3.CMS.git] / typo3 / js / extjs / viewport.js
1 /***************************************************************
2 * Copyright notice
3 *
4 * (c) 2010 Stefan Galinski <stefan.galinski@gmail.com>
5 * All rights reserved
6 *
7 * This script is part of the TYPO3 project. The TYPO3 project is
8 * free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * The GNU General Public License can be found at
14 * http://www.gnu.org/copyleft/gpl.html.
15 * A copy is found in the textfile GPL.txt and important notices to the license
16 * from the author is found in LICENSE.txt distributed with these scripts.
17 *
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26
27 Ext.ns('TYPO3');
28
29 /**
30 * Extends the viewport with some functionality for TYPO3.
31 *
32 * @author Stefan Galinski <stefan.galinski@gmail.com>
33 */
34 TYPO3.Viewport = Ext.extend(Ext.Viewport, {
35 /**
36 * Contains the navigation widgets in a simple array and identified by an unique idea
37 *
38 * @see registerNavigationWidget()
39 * @var object
40 */
41 navigationWidgetContainer: {},
42
43 /**
44 * Contains the meta informations of the navigation widgets
45 *
46 * @see registerNavigationWidget()
47 * @var object
48 */
49 navigationWidgetMetaData: {},
50
51 /**
52 * The topbar area
53 *
54 * @var Ext.Panel
55 */
56 Topbar: null,
57
58 /**
59 * The content area
60 *
61 * @var Ext.Panel
62 */
63 ContentContainer: null,
64
65 /**
66 * The navigation frame area
67 *
68 * @var Ext.Panel
69 */
70 NavigationContainer: null,
71
72 /**
73 * The module menu area
74 *
75 * @var Ext.Panel
76 */
77 ModuleMenuContainer: null,
78
79 /**
80 * The debug console
81 *
82 * @var Ext.TabPanel
83 */
84 DebugConsole: null,
85
86 /**
87 * Initializes the ExtJS viewport with the given configuration.
88 *
89 * @return void
90 */
91 initComponent: function() {
92 // adjust the width of module menu and the height of the topbar
93 this.initialConfig.items[0].height = TYPO3.configuration.topBarHeight;
94 this.initialConfig.items[1].width = TYPO3.configuration.moduleMenuWidth;
95
96 // call parent constructor
97 TYPO3.Viewport.superclass.initComponent.apply(this, arguments);
98
99 this.ContentContainer = Ext.ComponentMgr.get('typo3-contentContainer');
100 this.NavigationContainer = Ext.ComponentMgr.get('typo3-navigationContainer');
101 this.Topbar = Ext.ComponentMgr.get('typo3-topbar');
102 this.ModuleMenuContainer = Ext.ComponentMgr.get('typo3-module-menu');
103
104 // adds the debug console and some listeners to consider the initial hiding of
105 // the debug console (the viewport needs to be resized if it's expand/collapse)
106 // -> see the TYPO3.BackendSizeManager
107 this.DebugConsole = Ext.ComponentMgr.get('typo3-debug-console');
108 this.DebugConsole.addListener({
109 'resize': {
110 scope: this,
111 fn: function() {
112 this.fireEvent('resize');
113 }
114 },
115 'collapse': {
116 scope: this,
117 fn: function() {
118 this.fireEvent('resize');
119 }
120 }
121 });
122 },
123
124 /**
125 * Loads a module into the content container
126 *
127 * @param mainModuleName string name of the main module (e.g. web)
128 * @param subModuleName string name of the sub module (e.g. page)
129 * @param contentScript string the content provider (path to a php script)
130 * @return void
131 */
132 loadModule: function(mainModuleName, subModuleName, contentScript) {
133 var navigationWidgetActive = false;
134 var widgetMainModule = '';
135 var widgetSubModule = '';
136 var widget = null;
137 for (var widgetId in this.navigationWidgetMetaData) {
138 widgetMainModule = this.navigationWidgetMetaData[widgetId].mainModule;
139 widgetSubModule = this.navigationWidgetMetaData[widgetId].subModule;
140 widget = this.navigationWidgetMetaData[widgetId].widget;
141
142 if ((widgetMainModule === mainModuleName || widgetMainModule === '*') &&
143 (widgetSubModule === subModuleName || widgetSubModule === '*')
144 ) {
145 widget.show();
146 navigationWidgetActive = true;
147 } else {
148 widget.hide();
149 }
150 }
151
152 if (navigationWidgetActive) {
153 this.NavigationContainer.show();
154 } else {
155 this.NavigationContainer.hide();
156 }
157
158 // append the typo3 path if it wasn't already applied
159 // this is important for backwards compatibility (e.g. shortcuts)
160 if (contentScript.indexOf(top.TS.PATH_typo3) !== 0) {
161 contentScript = top.TS.PATH_typo3 + contentScript;
162 }
163 Ext.get('content').set({
164 src: contentScript
165 });
166
167 this.NavigationContainer.ownerCt.doLayout();
168 },
169
170 /**
171 * Adds the given widget to the navigation container. The key will be the id attribute
172 * of the given widget.
173 *
174 * @param mainModule string main module or wildcard (*) for all
175 * @param subModule string sub module or wildcard (*) for all
176 * @param widget object ExtJS widget (e.g. an Ext.Panel); must contain an id attribute!
177 * @return void
178 */
179 registerNavigationWidget: function(mainModule, subModule, widget) {
180 // only one instance of specific widget may be exists!
181 if (this.navigationWidgetMetaData[widget.id] === undefined) {
182 this.navigationWidgetMetaData[widget.id] = {
183 mainModule: mainModule,
184 subModule: subModule,
185 widget: widget
186 };
187
188 // always take the full width and height
189 widget.anchor = '100% 100%';
190 this.NavigationContainer.add(widget);
191 }
192 }
193 });
194
195 Ext.reg('typo3Viewport', TYPO3.Viewport);