66cca1b5ffeb7451ad9b22d2fb956622c55e6c16
[Packages/TYPO3.CMS.git] / t3lib / js / extjs / ux / flashmessages.js
1 /***************************************************************
2 * Copyright notice
3 *
4 * (c) 2010 Steffen Kamper <info@sk-typo3.de>
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 *
16 * This script is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * This copyright notice MUST APPEAR in all copies of the script!
22 ***************************************************************/
23
24 /**
25 * Flashmessage rendered by ExtJS
26 *
27 *
28 * @author Steffen Kamper <info@sk-typo3.de>
29 * @package TYPO3
30 * @subpackage t3lib
31 * @version $Id: $
32 */
33 Ext.ns('TYPO3');
34
35 /**
36 * @class TYPO3.Flashmessage
37 * Passive popup box singleton
38 * @singleton
39 *
40 * Example (Information message):
41 * TYPO3.Flashmessage.display(1, 'TYPO3 Backend - Version 4.4', 'Ready for take off', 3);
42 */
43 TYPO3.Flashmessage = function() {
44 var messageContainer;
45 var severities = ['notice', 'information', 'ok', 'warning', 'error'];
46
47 function createBox(severity, title, message){
48 return ['<div class="typo3-message message-', severity, '" style="width: 400px">',
49 '<div class="header-container">',
50 '<div class="message-header">', title, '</div>',
51 '</div>',
52 '<div class="message-body">', message, '</div>',
53 '</div>'].join('');
54 }
55
56 return {
57 /**
58 * Shows popup
59 * @member TYPO3.Flashmessage
60 * @param int severity (0=notice, 1=information, 2=ok, 3=warning, 4=error)
61 * @param string title
62 * @param string message
63 * @param float duration in sec (default 5)
64 */
65 display : function(severity, title, message, duration){
66 duration = duration || 5;
67 if(!messageContainer){
68 messageContainer = Ext.DomHelper.insertFirst(document.body, {
69 id : 'msg-div',
70 style: 'position:absolute;z-index:10000'
71 }, true);
72 }
73
74 var box = Ext.DomHelper.append(messageContainer, {
75 html: createBox(severities[severity], title, message)
76 }, true);
77 messageContainer.alignTo(document, 't-t');
78 box.slideIn('t').pause(duration).ghost('t', {remove:true});
79 }
80 }
81 }();