annotate plugins/rc_foldersort/rc_foldersort.js @ 34:50ac5484d514

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