support mailto links
[tine20] / tine20 / Tinebase / js / MainMenu.js
1 /*
2  * Tine 2.0
3  * 
4  * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
5  * @author      Cornelius Weiss <c.weiss@metaways.de>
6  * @copyright   Copyright (c) 2007-2011 Metaways Infosystems GmbH (http://www.metaways.de)
7  */
8 Ext.ns('Tine.Tinebase');
9
10 /**
11  * Tine 2.0 jsclient main menu
12  * 
13  * @namespace   Tine.Tinebase
14  * @class       Tine.Tinebase.MainMenu
15  * @extends     Ext.Toolbar
16  * @author      Cornelius Weiss <c.weiss@metaways.de>
17  */
18 Tine.Tinebase.MainMenu = Ext.extend(Ext.Toolbar, {
19     /**
20      * @cfg {Boolean} showMainMenu
21      */
22     showMainMenu: false,
23     style: {'padding': '0px 2px'},
24     cls: 'tbar-mainmenu',
25     
26     /**
27      * @type Array
28      * @property mainActions
29      */
30     mainActions: null,
31     
32     initComponent: function() {
33         this.initActions();
34         this.onlineStatus = new Ext.ux.ConnectionStatus({
35             showIcon: false
36         });
37         
38         this.items = this.getItems();
39         
40         var buttonTpl = new Ext.Template(
41             '<table id="{4}" cellspacing="0" class="x-btn {3}"><tbody class="{1}">',
42             '<tr><td class="x-btn-ml"><i>&#160;</i></td><td class="x-btn-mc"><em class="{2}" unselectable="on"><button type="{0}"></button></em></td><td class="x-btn-mr"><i>&#160;</i></td></tr>',
43             '</tbody></table>'
44         ).compile();
45         
46         Ext.each(this.items, function(item) {
47             item.template = buttonTpl;
48         }, this);
49         
50         this.supr().initComponent.call(this);
51     },
52     
53     getItems: function() {
54         return [{
55             text: Tine.title,
56             hidden: !this.showMainMenu,
57             menu: {
58                 id: 'Tinebase_System_Menu', 
59                 items: this.getMainActions()
60         }},
61         '->',
62         this.actionLearnMore,
63         // TODO add a bigger spacer here?
64         { xtype: 'spacer' },
65         {
66             text: String.format(_('User: {0}'), Tine.Tinebase.registry.get('currentAccount').accountDisplayName),
67             menu: this.getUserActions(),
68             menuAlign: 'tr-br',
69             iconCls: 'renderer_accountUserIcon'
70         },
71         this.onlineStatus, 
72         this.action_logout];
73     },
74     
75     /**
76      * returns all main actions
77      * 
78      * @return {Array}
79      */
80     getMainActions: function() {
81         if (! this.mainActions) {
82             this.mainActions = [
83                 this.action_aboutTine,
84                 this.action_loadTutorial,
85                 '-',
86                 this.getUserActions(),
87                 '-',
88                 this.action_logout
89             ];
90             
91             if (Tine.Tinebase.registry.get("version").buildType.match(/(DEVELOPMENT|DEBUG)/)) {
92                 this.mainActions.splice(2, 0, '-', this.action_showDebugConsole);
93             }
94         }
95         
96         return this.mainActions;
97     },
98     
99     getUserActions: function() {
100
101         if (! this.userActions) {
102             this.userActions = [
103                 this.action_editProfile,
104                 this.action_showPreferencesDialog,
105                 this.action_changePassword,
106                 this.action_notificationPermissions,
107                 this.action_installChromeWebApp
108             ];
109
110             var regItems = Ext.ux.ItemRegistry.itemMap['Tine.Tinebase.MainMenu.userActions'] || [];
111
112             Ext.each(regItems, function(reg) {
113                 var addItem = def = reg.item;
114
115                 this.userActions.push(addItem);
116             }, this);
117         }
118         return this.userActions;
119     },
120     
121     /**
122      * initialize actions
123      * @private
124      */
125     initActions: function() {
126         this.action_aboutTine = new Ext.Action({
127             text: String.format(_('About {0}'), Tine.title),
128             handler: this.onAboutTine20,
129             iconCls: 'action_about'
130         });
131         
132         this.action_loadTutorial = new Ext.Action({
133             text: String.format(_('Help')),
134             iconCls: 'action_loadTutorial',
135             handler: this.onLoadTutorial,
136             scope: this
137         });
138
139         this.action_showDebugConsole = new Ext.Action({
140             text: _('Debug Console (Ctrl + F11)'),
141             handler: Tine.Tinebase.common.showDebugConsole,
142             iconCls: 'tinebase-action-debug-console'
143         });
144         
145         this.action_showPreferencesDialog = new Ext.Action({
146             text: _('Preferences'),
147             disabled: false,
148             handler: this.onEditPreferences,
149             iconCls: 'action_adminMode'
150         });
151
152         this.action_editProfile = new Ext.Action({
153             text: _('Edit Profile'),
154             disabled: false,
155             handler: this.onEditProfile,
156             iconCls: 'tinebase-accounttype-user'
157         });
158         
159         this.action_changePassword = new Ext.Action({
160             text: _('Change password'),
161             handler: this.onChangePassword,
162             disabled: (! Tine.Tinebase.configManager.get('changepw')),
163             iconCls: 'action_password'
164         });
165         
166         this.action_logout = new Ext.Action({
167             text: _('Logout'),
168             tooltip:  String.format(_('Logout from {0}'), Tine.title),
169             iconCls: 'action_logOut',
170             handler: this.onLogout,
171             scope: this
172         });
173         
174         this.actionLearnMore = new Ext.Action({
175             text: String.format(_('Learn more about {0}'), Tine.title),
176             tooltip: Tine.weburl,
177             iconCls: 'tine-favicon',
178             handler: function() {
179                 window.open(Tine.weburl, '_blank');
180             },
181             scope: this
182         });
183         
184         this.action_notificationPermissions = new Ext.Action({
185             text: _('Allow desktop notifications'),
186             tooltip:  _('Request permissions for webkit desktop notifications.'),
187             iconCls: 'action_edit',
188             disabled: ! (window.webkitNotifications && window.webkitNotifications.checkPermission() != 0),
189             handler: function() {
190                 window.webkitNotifications.requestPermission(Ext.emptyFn);
191             },
192             scope: this
193         });
194         
195         this.action_installChromeWebApp = new Ext.Action({
196             text: _('Install web app'),
197             tooltip:  _('Install Tine 2.0 as web app in your browser.'),
198             iconCls: 'action_edit',
199             disabled: ! (Ext.isChrome && chrome.app && !chrome.app.isInstalled),
200             handler: function() {
201                 chrome.app.install();
202             },
203             scope: this
204         });
205     },
206     
207     /**
208      * open new window/tab to show help and tutorial
209      */
210     onLoadTutorial: function() {
211         window.open(Tine.helpUrl,'_blank');
212     },
213     
214     /**
215      * @private
216      */
217     onAboutTine20: function() {
218         var aboutDialog = new Tine.Tinebase.AboutDialog();
219         aboutDialog.show();
220     },
221     
222     /**
223      * @private
224      */
225     onChangePassword: function() {
226         var passwordDialog = new Tine.Tinebase.PasswordChangeDialog();
227         passwordDialog.show();
228     },
229     
230     /**
231      * @private
232      */
233     onEditPreferences: function() {
234         Tine.widgets.dialog.Preferences.openWindow({});
235     },
236
237     /**
238      * @private
239      */
240     onEditProfile: function() {
241         Tine.widgets.dialog.Preferences.openWindow({
242             initialCardName: 'Tinebase.UserProfile'
243         });
244     },
245     
246     /**
247      * the logout button handler function
248      * @private
249      */
250     onLogout: function() {
251         if (Tine.Tinebase.registry.get('confirmLogout') != '0') {
252             Ext.MessageBox.confirm(_('Confirm'), _('Are you sure you want to logout?'), function(btn, text) {
253                 if (btn == 'yes') {
254                     this._doLogout();
255                 }
256             }, this);
257         } else {
258             this._doLogout();
259         }
260     },
261     
262     /**
263      * logout user & redirect
264      */
265     _doLogout: function() {
266         Ext.MessageBox.wait(_('Logging you out...'), _('Please wait!'));
267         Ext.Ajax.request( {
268             params : {
269                 method : 'Tinebase.logout'
270             },
271             callback : function(options, Success, response) {
272                 // clear the authenticated mod_ssl session
273                 if (document.all == null) {
274                     if (window.crypto && Ext.isFunction(window.crypto.logout)) {
275                         window.crypto.logout();
276                     }
277                 } else {
278                     document.execCommand('ClearAuthenticationCache');
279                 }
280
281                 // clear registry
282                 Tine.Tinebase.tineInit.clearRegistry();
283
284                 // remove the event handler
285                 // the reload() trigers the unload event
286                 var redirect = (Tine.Tinebase.registry.get('redirectUrl'));
287                 if (redirect && redirect != '') {
288                     window.location = Tine.Tinebase.registry.get('redirectUrl');
289                 } else {
290                     window.location.reload();
291                 }
292             }
293         });
294     }
295 });