-
Notifications
You must be signed in to change notification settings - Fork 3
/
com_zimbra_tabiframe.js
85 lines (78 loc) · 3.19 KB
/
com_zimbra_tabiframe.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/**
* Zimlet to load an iframe in a tab
* Copyright (C) 2015 Truong Anh Tuan <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* Defines the Zimlet handler class.
*
*/
function com_zimbra_tabiframe_HandlerObject() {
}
/**
* Makes the Zimlet class a subclass of ZmZimletBase.
*
*/
com_zimbra_tabiframe_HandlerObject.prototype = new ZmZimletBase();
com_zimbra_tabiframe_HandlerObject.prototype.constructor = com_zimbra_tabiframe_HandlerObject;
/**
* This method gets called by the Zimlet framework when the zimlet loads.
*
*/
com_zimbra_tabiframe_HandlerObject.prototype.init = function() {
this.url = this.getZimletContext().getConfig('tab-url');
var label = this.getZimletContext().getConfig('tab-label');
var desc = AjxMessageFormat.format(this.getMessage('tab-description'), this.url);
this._simpleAppName = this.createApp(label, 'zimbraIcon', desc);
};
/**
* This method gets called by the Zimlet framework each time the application is opened or closed.
*
* @param {String} appName the application name
* @param {Boolean} active if true, the application status is open; otherwise, false
*/
com_zimbra_tabiframe_HandlerObject.prototype.appActive = function(appName, active) {
switch (appName) {
case this._simpleAppName: {
var app = appCtxt.getApp(appName); // get access to ZmZimletApp
break;
}
}
};
/**
* This method gets called by the Zimlet framework when the application is opened for the first time.
*
* @param {String} appName the application name
*/
com_zimbra_tabiframe_HandlerObject.prototype.appLaunch = function(appName) {
switch (appName) {
case this._simpleAppName: {
var queryStr = AjxStringUtil.queryStringSet({
'account': this.getAccountAddress().getAddress()
});
var url = [this.url, queryStr].join('');
var app = appCtxt.getApp(appName); // get access to ZmZimletApp
app.setContent("<iframe id=\"tabiframe-app\" name=\"tabiframe-app\" src=" + url + " width=\"100%\" height=\"100%\" /></iframe>"); // write HTML to app
break;
}
}
};
com_zimbra_tabiframe_HandlerObject.prototype.getAccountAddress = function() {
var account = (appCtxt.accountList.defaultAccount ||
appCtxt.accountList.activeAccount ||
appCtxt.accountList.mainAccount);
var identity = appCtxt.getIdentityCollection(account).defaultIdentity;
return new AjxEmailAddress(identity.sendFromAddress, AjxEmailAddress.FROM, identity.sendFromDisplay);
};