33
|
1 if (window.rcmail) {
|
|
2 /*
|
|
3 * EventListener to add the sort order to the request
|
|
4 */
|
|
5 rcmail.addEventListener('requestlist', function(props) {
|
|
6 if (rcmail.task == 'mail') {
|
|
7 var folder_sort = '';
|
|
8 var folder = props._mbox;
|
|
9 var col = rcmail.env.sort_col;
|
|
10 var order = rcmail.env.sort_order;
|
|
11
|
|
12 if (props._sort) {
|
|
13 folder_sort = props._sort;
|
|
14 } else {
|
|
15 if (rcmail.env.per_folder_sort) {
|
|
16 if (rcmail.env.per_folder_sort[folder]) {
|
|
17 folder_sort = rcmail.env.per_folder_sort[folder];
|
|
18 } else if (rcmail.env.per_folder_sort['default']) {
|
|
19 folder_sort = rcmail.env.per_folder_sort['default'];
|
|
20 }
|
|
21 }
|
|
22 }
|
|
23
|
|
24 if (folder_sort == '') {
|
|
25 folder_sort = col + '_' + order;
|
|
26 }
|
|
27
|
|
28 var y = folder_sort.split("_", 2);
|
|
29 col = y[0];
|
|
30 order = y[1];
|
|
31
|
|
32 rcmail.env.sort_col = col;
|
|
33 rcmail.env.sort_order = order;
|
|
34
|
|
35 http_lock = rcmail.set_busy(true, 'rc_foldersort.savingsession');
|
|
36 var data = {
|
|
37 cmd: 'change_session',
|
|
38 folder: folder,
|
|
39 col: col,
|
|
40 order: order
|
|
41 };
|
|
42 rcmail.http_post('plugin.rc_foldersort_json', data, http_lock);
|
|
43 props._sort = folder_sort;
|
|
44 }
|
|
45
|
|
46 return props;
|
|
47 });
|
|
48
|
|
49 /*
|
|
50 * EventListener to change the sorting order before we list the messages
|
|
51 */
|
|
52 rcmail.addEventListener('beforelist', function(props) {
|
|
53 var folder = rcmail.env.mailbox;
|
|
54 if (props) {
|
|
55 if (rcmail.task == 'mail') {
|
|
56 if (typeof(props) == 'object' && props.ref == 'rcmail') {
|
|
57 folder = props.env.mailbox;
|
|
58 } else if (typeof(props) == 'string') {
|
|
59 folder = props;
|
|
60 }
|
|
61
|
|
62 var folder_sort;
|
|
63 orig_col = rcmail.env.sort_col;
|
|
64 orig_order = rcmail.env.sort_order;
|
|
65
|
|
66 if (rcmail.env.per_folder_sort) {
|
|
67 if (rcmail.env.per_folder_sort[folder]) {
|
|
68 folder_sort = rcmail.env.per_folder_sort[folder];
|
|
69 } else if (rcmail.env.per_folder_sort['default']) {
|
|
70 folder_sort = rcmail.env.per_folder_sort['default'];
|
|
71 } else {
|
|
72 folder_sort = orig_col + '_' + orig_order;
|
|
73 }
|
|
74
|
|
75 var y = folder_sort.split("_", 2);
|
|
76 col = y[0];
|
|
77 order = y[1];
|
|
78 if (orig_col != col || orig_order != order) {
|
|
79 $('#rcm' + orig_col).removeClass('sorted' + (orig_order.toUpperCase()));
|
|
80 $('#rcm' + col).addClass('sorted' + order);
|
|
81 rcmail.env.sort_col = col;
|
|
82 rcmail.env.sort_order = order;
|
|
83
|
|
84 http_lock = rcmail.set_busy(true, 'rc_foldersort.savingsession');
|
|
85 var data = {
|
|
86 cmd: 'change_session',
|
|
87 folder: folder,
|
|
88 col: col,
|
|
89 order: order
|
|
90 };
|
|
91 rcmail.http_post('plugin.rc_foldersort_json', data, http_lock);
|
|
92 }
|
|
93 }
|
|
94 }
|
|
95 }
|
|
96 });
|
|
97
|
|
98 /*
|
|
99 * EventListener to handle the header sort clicks
|
|
100 */
|
|
101 rcmail.addEventListener('aftersort', function(prop) {
|
|
102 if (rcmail.task == 'mail') {
|
|
103 mbox = rcmail.env.mailbox;
|
|
104
|
|
105 http_lock = rcmail.set_busy(true, 'rc_foldersort.savingdata');
|
|
106 var data = {
|
|
107 cmd: 'save_order',
|
|
108 folder: mbox,
|
|
109 col: rcmail.env.sort_col,
|
|
110 order: rcmail.env.sort_order
|
|
111 };
|
|
112 rcmail.http_post('plugin.rc_foldersort_json', data, http_lock);
|
|
113 }
|
|
114 });
|
|
115 }
|