forked from chilek/google_addressbook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
google_addressbook.js
47 lines (39 loc) · 1.35 KB
/
google_addressbook.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
/**
* Javascript events and handlers
*
* @version 1.0
* @author Stefan L. Wagner
*/
function is_addressbook_view() {
if(rcmail.env.address_sources) {
for(var key in rcmail.env.address_sources) {
if(rcmail.env.address_sources[key].id === 'google_addressbook') {
return true;
}
}
}
return false;
}
function sync_handler() {
var lock = rcmail.set_busy(true, 'sync');
rcmail.http_post('plugin.google_addressbook.sync', '', lock);
}
function sync_finished(response) {
if(is_addressbook_view()) {
rcmail.command('list','google_addressbook');
}
}
if (window.rcmail) {
rcmail.addEventListener('init', function(evt) {
rcmail.addEventListener('plugin.google_addressbook.autosync', sync_handler);
rcmail.addEventListener('plugin.google_addressbook.finished', sync_finished);
if(is_addressbook_view()) {
var button = $('<A>').attr('id', 'rcmbtnsyncgoogle').attr('href', '#');
button.addClass('button checkmail').html(rcmail.gettext('sync', 'google_addressbook'));
button.bind('click', function(e){ return rcmail.command('plugin.google_addressbook.sync', this); });
rcmail.add_element(button, 'toolbar');
rcmail.register_button('plugin.google_addressbook.sync', 'rcmbtnsyncgoogle', 'link');
rcmail.register_command('plugin.google_addressbook.sync', sync_handler, true);
}
});
}