3027f57811d5be85779aa98c665c7dd8d2198765
[Packages/TYPO3.CMS.git] / t3lib / js / extjs / notifications.js
1 /***************************************************************
2 * Copyright notice
3 *
4 * (c) 2010 Oliver Hader <oliver@typo3.org>
5 * (c) 2010 Steffen Kamper <steffen@typo3.org>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27
28 Ext.ns('TYPO3', 'TYPO3.Components');
29
30 /**
31 * TYPO3window - General TYPO3 window component
32 */
33 TYPO3.Components.Window = Ext.extend(Ext.Window, {
34 width: 450,
35 autoHeight: true,
36 closable: true,
37 resizable: false,
38 plain: true,
39 border: false,
40 modal: true,
41 draggable: true,
42 closeAction: 'hide',
43 cls: 't3-window',
44
45 constructor: function(config) {
46 config = config || {};
47 Ext.apply(this, config);
48 TYPO3.Components.Window.superclass.constructor.call(this, config);
49 }
50 });
51 Ext.reg('TYPO3window', TYPO3.Components.Window);
52
53
54 /**
55 * Helper class for managing windows.
56 * Once a window is created, it is permanent until you close
57 * [TYPO3.Windows.close(id)] or remove all [TYPO3.Windows.closeAll()]
58 *
59 * Example usage:
60 *
61 * var w = TYPO3.Windows.getWindow({
62 * title: 'Testwindow',
63 * html: 'some content!',
64 * width: 400
65 * }).show();
66 */
67 TYPO3.Windows = function() {
68 /** @private */
69 var windowCollection = new Ext.util.MixedCollection(true);
70
71 return {
72 /** @public */
73
74 /**
75 * Get a window. If already in collection return it, otherwise create a new one
76 *
77 * @param {Object} configuration
78 * @return {Object} window
79 */
80 getWindow: function(configuration) {
81 var id = configuration.id || '', window;
82
83 if (id) {
84 window = this.getById(id);
85 }
86 if (window) {
87 return window;
88 } else {
89 window = new TYPO3.Components.Window(configuration);
90 windowCollection.add(window);
91 return window;
92 }
93 },
94
95 /**
96 * Get a window and show. If already in collection return it, otherwise create a new one
97 *
98 * @param {Object} configuration
99 * @return {Object} window
100 */
101 showWindow: function(configuration) {
102 var window = this.getWindow(configuration);
103 window.show();
104 return window;
105 },
106
107 /**
108 * Shows window with id and return reference. If not exist return false
109 *
110 * @param {String} id
111 * @return {Object} window false if not found
112 */
113 show: function(id) {
114 var window = this.getById(id);
115 if (window) {
116 window.show();
117 return window;
118 }
119 return false;
120 },
121
122 /**
123 * Shows window with id and return reference. If not exist return false
124 *
125 * @param {String} id
126 * @return {Object} window or false if not found
127 */
128 getById: function(id) {
129 return windowCollection.key(id);
130 },
131
132 /**
133 * Get the window collection
134 *
135 * @return {Ext.util.MixedCollection} windowCollection
136 */
137 getCollection: function () {
138 return windowCollection;
139 },
140
141 /**
142 * Get count of windows
143 *
144 * @return {Int} count
145 */
146 getCount: function() {
147 return windowCollection.length;
148 },
149
150 /**
151 * Each for windowCollection
152 *
153 * @param {Function} function
154 * @param {Object} scope
155 * @return void
156 */
157 each : function(fn, scope) {
158 windowCollection.each(fn, scope);
159 },
160
161 /**
162 * Close window and remove from stack
163 *
164 * @param {Int} id
165 * @return void
166 */
167 close: function(id) {
168 var window = this.getById(id);
169 if (window) {
170 window.close();
171 windowCollection.remove(id);
172 }
173 },
174
175 /**
176 * Close all windows and clear stack
177 *
178 * @return void
179 */
180 closeAll: function() {
181 windowCollection.each(function(window) {
182 window.close();
183 });
184 windowCollection.clear();
185 }
186 }
187 }();
188
189 /**
190 * Helper class for dialog windows
191 *
192 * Example usage:
193 *
194 * TYPO3.Dialog.InformationDialog({
195 * title: 'Test',
196 * msg: 'some information'
197 * });
198
199 */
200 TYPO3.Dialog = function() {
201 /** @private functions */
202 var informationDialogConfiguration = {
203 buttons: Ext.MessageBox.OK,
204 icon: Ext.MessageBox.INFO,
205 fn: Ext.emptyFn
206 };
207
208 var questionDialogConfiguration = {
209 buttons: Ext.MessageBox.YESNO,
210 icon: Ext.MessageBox.QUESTION
211 };
212
213 var warningDialogConfiguration = {
214 buttons: Ext.MessageBox.OK,
215 icon: Ext.MessageBox.WARNING,
216 fn: Ext.emptyFn
217 };
218
219 var errorDialogConfiguration = {
220 buttons: Ext.MessageBox.OK,
221 icon: Ext.MessageBox.ERROR,
222 fn: Ext.emptyFn
223 };
224
225
226 return {
227 /** @public functions */
228 InformationDialog: function(configuration) {
229 configuration = configuration || {};
230 configuration = Ext.apply(
231 informationDialogConfiguration,
232 configuration
233 );
234 Ext.Msg.show(configuration);
235 },
236
237 QuestionDialog: function(configuration) {
238 configuration = configuration || {};
239 configuration = Ext.apply(
240 questionDialogConfiguration,
241 configuration
242 );
243 Ext.Msg.show(configuration);
244 },
245
246 WarningDialog: function(configuration) {
247 configuration = configuration || {};
248 configuration = Ext.apply(
249 warningDialogConfiguration,
250 configuration
251 );
252 Ext.Msg.show(configuration);
253 },
254
255 ErrorDialog: function(configuration) {
256 configuration = configuration || {};
257 configuration = Ext.apply(
258 errorDialogConfiguration,
259 configuration
260 );
261 Ext.Msg.show(configuration);
262 }
263 }
264 }();
265
266 /**
267 * Helper class for dialog windows
268 *
269 * Example usage:
270 *
271 * TYPO3.ContextHelpWindow.open(identifier);
272 */
273 TYPO3.ContextHelpWindow = function() {
274 /**
275 * Path to typo3 directory
276 *
277 * @type {String}
278 * @private
279 */
280 var typo3Path = '';
281
282 /**
283 * Context for open a window
284 * "window" - open a new window
285 * "inline" - open a TYPO3.Window (not currently implementy)
286 *
287 * @type {String}
288 * @private
289 */
290 var openContext;
291
292 /**
293 * Width for the window
294 *
295 * @type {Number}
296 * @private
297 */
298 var width;
299 /**
300 * Height of the window
301 *
302 * @type {Number}
303 * @private
304 */
305 var height;
306
307
308 return {
309 /**
310 * init class vars
311 *
312 * @return void
313 */
314 init: function() {
315 this.typo3Path = top.TYPO3.configuration.PATH_typo3;
316 this.openContext = 'window';
317 this.width = top.TYPO3.configuration.ContextHelpWindows.width;
318 this.height = top.TYPO3.configuration.ContextHelpWindows.height;
319 },
320
321 /**
322 * Open window for TYPO3 inline help
323 *
324 * @param {String} help identifier
325 * @return {Object} window
326 */
327 open: function(helpIdentifier) {
328 if (this.openContext === 'window') {
329 var cshWindow = window.open(
330 this.typo3Path + 'view_help.php?tfID=' + helpIdentifier,
331 'ContextHelpWindow',
332 'height=' + this.height + ',width=' + this.width + ',status=0,menubar=0,scrollbars=1'
333 );
334 cshWindow.focus();
335 return cshWindow;
336 }
337 }
338 }
339 }();