This repository has been archived by the owner on Jul 30, 2022. It is now read-only.
forked from akoeb/amacube
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathamacube.js
107 lines (103 loc) · 4.14 KB
/
amacube.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
This file is part of the amacube Roundcube plugin
Copyright (C) 2013, Alexander Köb
Licensed under the GNU General Public License version 3.
See the COPYING file for a full license statement.
*/
// Extend rcmail with amacube methods for ajax pagination
rcube_webmail.prototype.amacube = {
// Function for pagination
// Send ajax requests for specified page || Enable/disable specified page button
page : function(page,status) {
var obj = {};
switch (page) {
case 'first':
if (status == 'enabled' || status == 'disabled') {
if (rcmail.commands['plugin.firstpage']) { rcmail.enable_command('plugin.firstpage', ((status == 'enabled') ? true : false)); }
else { rcmail.register_command('plugin.firstpage', function() { rcmail.amacube.page('first'); }, ((status == 'enabled') ? true : false)); }
return;
}
var obj = { page : 1, msgcount: rcmail.env.msgcount };
break;
case 'previous':
if (status == 'enabled' || status == 'disabled') {
if (rcmail.commands['plugin.previouspage']) { rcmail.enable_command('plugin.previouspage', ((status == 'enabled') ? true : false)); }
else { rcmail.register_command('plugin.previouspage', function() { rcmail.amacube.page('previous'); }, ((status == 'enabled') ? true : false)); }
return;
}
var obj = { page : (rcmail.env.page - 1), msgcount: rcmail.env.msgcount };
break;
case 'next':
if (status == 'enabled' || status == 'disabled') {
if (rcmail.commands['plugin.nextpage']) { rcmail.enable_command('plugin.nextpage', ((status == 'enabled') ? true : false)); }
else { rcmail.register_command('plugin.nextpage', function() { rcmail.amacube.page('next'); }, ((status == 'enabled') ? true : false)); }
return;
}
var obj = { page : (rcmail.env.page + 1), msgcount: rcmail.env.msgcount };
break;
case 'last':
if (status == 'enabled' || status == 'disabled') {
if (rcmail.commands['plugin.lastpage']) { rcmail.enable_command('plugin.lastpage', ((status == 'enabled') ? true : false)); }
else { rcmail.register_command('plugin.lastpage', function() { rcmail.amacube.page('last'); }, ((status == 'enabled') ? true : false)); }
return;
}
var obj = { page : rcmail.env.pagecount, msgcount: rcmail.env.msgcount };
break;
}
rcmail.http_post('quarantine/amacube-quarantine', obj);
},
// Function for updating the list of quarantined messages
messagelist : function(data) {
if (data && data.messages) {
var messages = $('table#messagelist.quarantine-messagelist').children('tbody');
messages.empty();
$.each(data.messages, function(index, value) {
messages.append(value);
});
}
},
// Function for updating message count
messagecount : function(string) {
var message = $('span.quarantine-countdisplay');
message.text(string);
}
};
// Init rcmail
if (window.rcmail) {
// Catch clicks to quarantine task button and apply action to url
rcmail.addEventListener('beforeswitch-task', function(prop) {
if (prop == 'quarantine') {
rcmail.redirect(rcmail.url('quarantine/amacube-quarantine'), false);
return false;
}
});
// Init buttons & commands
rcmail.addEventListener('init', function(evt) {
if (evt.task == 'settings') {
// Settings post command
rcmail.register_command('plugin.amacube-settings-post', function() { rcmail.gui_objects.amacubeform.submit(); }, true);
}
if (evt.task == 'quarantine') {
// Quarantine post command
rcmail.register_command('amacube-quarantine-post', function() { rcmail.gui_objects.quarantineform.submit(); }, true);
// Pagination commands
if (rcmail.env.page > 1) {
// Enable first & previous
rcmail.amacube.page('first','enabled');
rcmail.amacube.page('previous','enabled');
// Disable first & previous by default
}
else if (rcmail.env.pagecount > 1) {
if (rcmail.env.page < rcmail.env.pagecount) {
// Enable next & last
rcmail.amacube.page('next','enabled');
rcmail.amacube.page('last','enabled');
} else {
// Disable next & last
rcmail.amacube.page('next','disabled');
rcmail.amacube.page('last','disabled');
}
}
}
});
}