Mercurial > hg > rc1
annotate plugins/thunderbird_labels/tb_label.js @ 43:771f6803cc4b default tip
somehow lost the correctly updated metadata so e.g. 'mail' package wasn't being imported
author | Charlie Root |
---|---|
date | Sun, 26 Jan 2025 13:13:49 -0500 |
parents | f8b3ac77e951 |
children |
rev | line source |
---|---|
0 | 1 /** |
2 * Version: | |
3 * $Revision$ | |
4 * Author: | |
5 * Michael Kefeder | |
6 * http://code.google.com/p/rcmail-thunderbird-labels/ | |
7 */ | |
8 | |
9 // global variable for contextmenu actions | |
10 rcmail.tb_label_no = ''; | |
11 | |
12 function rcmail_tb_label_menu(p) | |
13 { | |
14 if (typeof rcmail_ui == "undefined") | |
15 rcmail_ui = UI; | |
16 if (!rcmail_ui.check_tb_popup()) | |
26
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
17 rcmail_ui.tblabelpopup_add(); |
0 | 18 |
19 // Show the popup menu with tags | |
20 // -- skin larry vs classic | |
21 if (typeof rcmail_ui.show_popupmenu == "undefined") | |
26
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
22 rcmail_ui.show_popup('tblabelpopup'); |
0 | 23 else |
26
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
24 rcmail_ui.show_popupmenu('tblabelpopup'); |
0 | 25 |
26 return false; | |
27 } | |
28 | |
29 /** | |
30 * Shows the colors based on flag info like in Thunderbird | |
31 * (called when a new message in inserted in list of messages) | |
32 * maybe slow ? called for each message in mailbox at init | |
33 */ | |
34 function rcm_tb_label_insert(uid, row) | |
35 { | |
36 if (typeof rcmail.env == 'undefined' || typeof rcmail.env.messages == 'undefined') | |
37 return; | |
9 | 38 var max_id = rcmail.env.tb_max_label; |
0 | 39 var message = rcmail.env.messages[uid]; |
40 var rowobj = $(row.obj); | |
41 // add span container for little colored bullets | |
42 rowobj.find("td.subject").append("<span class='tb_label_dots'></span>"); | |
43 | |
44 if (message.flags && message.flags.tb_labels) { | |
45 if (message.flags.tb_labels.length) { | |
46 var spanobj = rowobj.find("td.subject span.tb_label_dots"); | |
47 message.flags.tb_labels.sort(function(a,b) {return a-b;}); | |
48 if (rcmail.env.tb_label_style=='bullets') { | |
49 // bullets UI style | |
20 | 50 for (idx in message.flags.tb_labels) { |
51 spanobj.append("<span class='label"+message.flags.tb_labels[idx]+"'>•</span>"); | |
52 } | |
53 } else { | |
54 // thunderbird UI style | |
55 for (idx in message.flags.tb_labels) { | |
56 rowobj.addClass('label' + message.flags.tb_labels[idx]); | |
57 } | |
58 } | |
59 } | |
60 } | |
61 if (message.flags && message.flags.tb_lparms) { | |
62 if (message.flags.tb_lparms.length) { | |
22
61316094e61d
a bit better wrt Dates: displaying, but not popup for setting
Charlie Root
parents:
20
diff
changeset
|
63 for (i=0,p=message.flags.tb_lparms,l=p.length;i<l;i++) { |
20 | 64 col="dates"; // should look up parm.number somewhere FIXME |
65 var tdobj = rowobj.find("td."+col); | |
22
61316094e61d
a bit better wrt Dates: displaying, but not popup for setting
Charlie Root
parents:
20
diff
changeset
|
66 tdobj.append("<span class='labelparm"+p[i].number+"'>"+ |
61316094e61d
a bit better wrt Dates: displaying, but not popup for setting
Charlie Root
parents:
20
diff
changeset
|
67 p[i].parm+"</span>"); |
20 | 68 } |
69 } | |
0 | 70 } |
71 } | |
72 | |
73 /** | |
74 * Shows the submenu of thunderbird labels | |
75 */ | |
76 function rcm_tb_label_submenu(p) | |
77 { | |
78 if (typeof rcmail_ui == "undefined") | |
79 rcmail_ui = UI; | |
80 // setup onclick and active/non active classes | |
81 rcm_tb_label_create_popupmenu(); | |
82 | |
83 // -- create sensible popup, using roundcubes internals | |
84 if (!rcmail_ui.check_tb_popup()) | |
26
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
85 rcmail_ui.tblabelpopup_add(); |
0 | 86 // -- skin larry vs classic |
87 if (typeof rcmail_ui.show_popupmenu == "undefined") | |
26
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
88 rcmail_ui.show_popup('tblabelpopup'); |
0 | 89 else |
26
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
90 rcmail_ui.show_popupmenu('tblabelpopup'); |
0 | 91 return false; |
92 } | |
93 | |
94 function rcm_tb_label_flag_toggle(flag_uids, toggle_label_no, onoff) | |
95 { | |
96 var headers_table = $('table.headers-table'); | |
97 var preview_frame = $('#messagecontframe'); | |
20 | 98 var label_name = rcmail.env.tb_label_custom_labels[toggle_label_no]; |
0 | 99 // preview frame exists, simulate environment of single message view |
100 if (preview_frame.length) | |
101 { | |
102 tb_labels_for_message = preview_frame.get(0).contentWindow.tb_labels_for_message; | |
103 headers_table = preview_frame.contents().find('table.headers-table'); | |
104 } | |
105 | |
106 if (!rcmail.message_list | |
107 && !headers_table) | |
108 return; | |
109 // for single message view | |
110 if (headers_table.length && flag_uids.length) { | |
111 if (onoff == true) { | |
112 if (rcmail.env.tb_label_style=='bullets') { | |
113 $('#labelbox').append("<span class='tb_label_span"+toggle_label_no+"'>" + | |
20 | 114 label_name + "</span>"); |
0 | 115 } else { |
116 headers_table.addClass('label'+toggle_label_no); | |
117 } | |
118 // add to flag list | |
119 tb_labels_for_message.push(toggle_label_no); | |
120 | |
121 } | |
122 else | |
123 { | |
124 if (rcmail.env.tb_label_style=='bullets') { | |
125 $("span.tb_label_span"+toggle_label_no).remove(); | |
126 } else { | |
127 headers_table.removeClass('label'+toggle_label_no); | |
128 } | |
129 | |
130 var pos = jQuery.inArray(toggle_label_no, tb_labels_for_message); | |
32 | 131 while (pos > -1) { |
0 | 132 tb_labels_for_message.splice(pos, 1); |
32 | 133 pos = jQuery.inArray(toggle_label_no, tb_labels_for_message); |
0 | 134 } |
135 } | |
136 // exit function when in detail mode. when preview is active keep going | |
137 if (!rcmail.env.messages) { | |
138 return; | |
139 } | |
140 } | |
141 jQuery.each(flag_uids, function (idx, uid) { | |
142 var message = rcmail.env.messages[uid]; | |
143 var row = rcmail.message_list.rows[uid]; | |
144 if (onoff == true) | |
145 { | |
146 // add colors | |
147 var rowobj = $(row.obj); | |
148 var spanobj = rowobj.find("td.subject span.tb_label_dots"); | |
149 if (rcmail.env.tb_label_style=='bullets') { | |
150 spanobj.append("<span class='label"+toggle_label_no+"'>•</span>"); | |
151 } else { | |
152 rowobj.addClass('label'+toggle_label_no); | |
153 } | |
154 | |
155 // add to flag list | |
156 message.flags.tb_labels.push(toggle_label_no); | |
157 } | |
158 else | |
159 { | |
160 // remove colors | |
161 var rowobj = $(row.obj); | |
162 if (rcmail.env.tb_label_style=='bullets') { | |
163 rowobj.find("td.subject span.tb_label_dots span.label"+toggle_label_no).remove(); | |
24
4869fae20b88
do better at flag deletion, unthreaded dates sort working, preparing for threaded
Charlie Root
parents:
22
diff
changeset
|
164 rowobj.find("td.dates span").remove(); |
0 | 165 } else { |
166 rowobj.removeClass('label'+toggle_label_no); | |
167 } | |
168 | |
169 // remove from flag list | |
170 var pos = jQuery.inArray(toggle_label_no, message.flags.tb_labels); | |
171 if (pos > -1) | |
172 message.flags.tb_labels.splice(pos, 1); | |
173 } | |
174 }); | |
175 } | |
176 | |
177 function rcm_tb_label_flag_msgs(flag_uids, toggle_label_no) | |
178 { | |
179 rcm_tb_label_flag_toggle(flag_uids, toggle_label_no, true); | |
180 } | |
181 | |
182 function rcm_tb_label_unflag_msgs(unflag_uids, toggle_label_no) | |
183 { | |
184 rcm_tb_label_flag_toggle(unflag_uids, toggle_label_no, false); | |
185 } | |
186 | |
187 // helper function to get selected/active messages | |
188 function rcm_tb_label_get_selection() | |
189 { | |
190 var selection = rcmail.message_list ? rcmail.message_list.get_selection() : []; | |
191 if (selection.length == 0 && rcmail.env.uid) | |
192 selection = [rcmail.env.uid, ]; | |
193 return selection; | |
194 } | |
195 | |
196 function rcm_tb_label_create_popupmenu() | |
197 { | |
9 | 198 var max_id = rcmail.env.tb_max_label; |
199 for (i = 0; i <= max_id; i++) | |
0 | 200 { |
201 var cur_a = $('li.label' + i +' a'); | |
202 | |
203 // add/remove active class | |
204 var selection = rcm_tb_label_get_selection(); | |
205 | |
206 if (selection.length == 0) | |
207 cur_a.removeClass('active'); | |
208 else | |
209 cur_a.addClass('active'); | |
210 } | |
211 } | |
212 | |
26
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
213 function tblabeldoit(props,obj,event) { |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
214 var toggle_label = props; |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
215 var toggle_label_no = parseInt(toggle_label.replace('label', '')); |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
216 var label_name = rcmail.env.tb_label_custom_labels[toggle_label_no]; |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
217 var hasParm = rcmail.env.tb_label_parm_labels[toggle_label_no]; |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
218 var selection = rcm_tb_label_get_selection(); |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
219 |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
220 if (!selection.length) |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
221 return; |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
222 |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
223 var from = toggle_label_no; |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
224 var to = toggle_label_no; |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
225 var unset_all = false; |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
226 // special case flag 0 means remove all flags |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
227 if (toggle_label_no == 0) |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
228 { |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
229 from = 1; |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
230 to = rcmail.env.tb_max_label; |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
231 ; |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
232 unset_all = true; |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
233 } |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
234 for (i = from; i <= to; i++) |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
235 { |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
236 toggle_label = 'label' + i; |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
237 toggle_label_no = i; |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
238 // compile list of unflag and flag msgs and then send command |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
239 // Thunderbird modifies multiple message flags like it did the first in the selection |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
240 // e.g. first message has flag1, you click flag1, every message select loses flag1, the ones not having flag1 don't get it! |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
241 var first_toggle_mode = 'on'; |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
242 if (rcmail.env.messages) |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
243 { |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
244 var first_message = rcmail.env.messages[selection[0]]; |
32 | 245 if ((first_message.flags |
246 && jQuery.inArray(toggle_label_no, | |
247 first_message.flags.tb_labels) >= 0) || | |
248 (hasParm && jQuery.grep(first_message.flags.tb_lparms, | |
249 function(p) {return p['number'] == toggle_label_no;}).length) | |
26
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
250 ) |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
251 first_toggle_mode = 'off'; |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
252 else |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
253 first_toggle_mode = 'on'; |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
254 } |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
255 else // single message display |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
256 { |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
257 // flag already set? |
32 | 258 // Not sure this works if this flag has a parm |
26
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
259 if (jQuery.inArray(toggle_label_no, |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
260 tb_labels_for_message) >= 0) |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
261 first_toggle_mode = 'off'; |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
262 } |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
263 if (hasParm && first_toggle_mode == 'on') { |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
264 var dates=prompt("Booking dates in form d/m-d/m : ","25/7-1/8"); |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
265 if (dates!=null){ |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
266 toggle_label+='_'+dates; |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
267 } |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
268 else { |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
269 return; |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
270 } |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
271 } |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
272 var flag_uids = []; |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
273 var unflag_uids = []; |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
274 jQuery.each(selection, function (idx, uid) { |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
275 // message list not available (example: in detailview) |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
276 if (!rcmail.env.messages) |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
277 { |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
278 if (first_toggle_mode == 'on') |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
279 flag_uids.push(uid); |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
280 else |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
281 unflag_uids.push(uid); |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
282 // make sure for unset all there is the single message id |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
283 if (unset_all && unflag_uids.length == 0) |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
284 unflag_uids.push(uid); |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
285 return; |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
286 } |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
287 var message = rcmail.env.messages[uid]; |
32 | 288 if ((message.flags |
289 && jQuery.inArray(toggle_label_no, | |
290 message.flags.tb_labels) >= 0) || | |
291 (hasParm && jQuery.grep(message.flags.tb_lparms, | |
292 function(p) {return p['number'] == toggle_label_no;}).length) | |
26
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
293 ) |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
294 { |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
295 if (first_toggle_mode == 'off') |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
296 unflag_uids.push(uid); |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
297 } |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
298 else |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
299 { |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
300 if (first_toggle_mode == 'on') |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
301 flag_uids.push(uid); |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
302 } |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
303 }); |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
304 |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
305 if (unset_all) |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
306 flag_uids = []; |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
307 |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
308 // skip sending flags to backend that are not set anywhere |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
309 if (flag_uids.length == 0 |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
310 && unflag_uids.length == 0) |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
311 continue; |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
312 |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
313 var str_flag_uids = flag_uids.join(','); |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
314 var str_unflag_uids = unflag_uids.join(','); |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
315 |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
316 var lock = rcmail.set_busy(true, 'loading'); |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
317 // call PHP set_flags to set the flags in IMAP server |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
318 rcmail.http_request('plugin.thunderbird_labels.set_flags', '_flag_uids=' + str_flag_uids + '&_unflag_uids=' + str_unflag_uids + '&_mbox=' + urlencode(rcmail.env.mailbox) + "&_toggle_label=" + toggle_label, lock); |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
319 |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
320 // remove/add classes and tb labels from messages in JS |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
321 rcm_tb_label_flag_msgs(flag_uids, toggle_label_no); |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
322 rcm_tb_label_unflag_msgs(unflag_uids, toggle_label_no); |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
323 } |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
324 } |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
325 |
0 | 326 function rcm_tb_label_init_onclick() |
327 { | |
9 | 328 var max_id = rcmail.env.tb_max_label; |
329 for (i = 0; i <= max_id ; i++) | |
0 | 330 { |
331 // find the "HTML a tags" of tb-label submenus | |
26
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
332 var cur_a = $('#tblabelpopup li.label' + i +' a'); |
0 | 333 |
334 // TODO check if click event is defined instead of unbinding? | |
335 cur_a.unbind('click'); | |
26
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
336 cur_a.attr('onclick',"rcmail.command('tblabeldoit','label"+i+"',this,event)"); |
0 | 337 } |
26
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
338 rcmail.register_command('tblabeldoit',function(props,obj,event) {tblabeldoit(props,obj,event);}); |
0 | 339 } |
340 | |
341 function rcmail_ctxm_label(command, el, pos) | |
342 { | |
343 // my code works only on selected rows, contextmenu also on unselected | |
344 // so if no selection is available, use the uid set by contextmenu plugin | |
345 var selection = rcmail.message_list ? rcmail.message_list.get_selection() : []; | |
346 | |
347 if (!selection.length && !rcmail.env.uid) | |
348 return; | |
349 if (!selection.length && rcmail.env.uid) | |
350 rcmail.message_list.select_row(rcmail.env.uid); | |
351 | |
26
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
352 var cur_a = $('#tblabelpopup li.label' + rcmail.tb_label_no +' a'); |
0 | 353 if (cur_a) |
354 { | |
355 cur_a.click(); | |
356 } | |
357 | |
358 return; | |
359 } | |
360 | |
361 function rcmail_ctxm_label_set(which) | |
362 { | |
363 // hack for my contextmenu submenu hack to propagate the selected label-no | |
364 rcmail.tb_label_no = which; | |
365 } | |
366 | |
367 | |
368 $(document).ready(function() { | |
369 rcm_tb_label_init_onclick(); | |
370 // add keyboard shortcuts for keyboard and keypad if pref tb_label_enable_shortcuts=true | |
371 if (rcmail.env.tb_label_enable_shortcuts) { | |
372 $(document).keyup(function(e) { | |
373 //console.log('Handler for .keyup() called.' + e.which); | |
374 var k = e.which; | |
375 if ((k > 47 && k < 58) || (k > 95 && k < 106)) | |
376 { | |
377 var label_no = k % 48; | |
26
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
378 var cur_a = $('#tblabelpopup li.label' + label_no + ' a'); |
0 | 379 |
380 if (cur_a) | |
381 { | |
382 cur_a.click(); | |
383 } | |
384 } | |
385 }); | |
386 } | |
26
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
387 rcmail.addEventListener('contextmenu_init', function(menu) { |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
388 // identify the folder list context menu |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
389 if (menu.menu_name == 'messagelist') { |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
390 var mc = menu.menu_source.length; // BREAK HERE |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
391 //.push({label: 'Labels', command: 'folders', props: '', classes: 'managefolders'}); } |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
392 } |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
393 } |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
394 ); |
0 | 395 // if exists add contextmenu entries |
26
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
396 /*if (window.rcm_contextmenu_register_command) { |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
397 [Doesn't exist -- HST] |
0 | 398 rcm_contextmenu_register_command('ctxm_tb_label', rcmail_ctxm_label, $('#tb_label_ctxm_mainmenu'), 'moreacts', 'after', true); |
26
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
399 }*/ |
0 | 400 |
401 // single message displayed? | |
402 if (window.tb_labels_for_message) | |
403 { | |
404 var labelbox_parent = $('div.message-headers'); // larry skin | |
405 if (!labelbox_parent.length) { | |
406 labelbox_parent = $("table.headers-table tbody tr:first-child"); // classic skin | |
407 } | |
408 labelbox_parent.append("<div id='labelbox'></div>"); | |
409 tb_labels_for_message.sort(function(a,b) {return a-b;}); | |
410 jQuery.each(tb_labels_for_message, function(idx, val) | |
411 { | |
412 rcm_tb_label_flag_msgs([-1,], val); | |
413 } | |
414 ); | |
415 } | |
416 | |
417 // add roundcube events | |
418 rcmail.addEventListener('insertrow', function(event) { rcm_tb_label_insert(event.uid, event.row); }); | |
26
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
419 |
0 | 420 rcmail.addEventListener('init', function(evt) { |
421 // create custom button, JS method, broken layout in Firefox 9 using PHP method now | |
26
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
422 /*var button = $('<A>').attr('href', '#').attr('id', 'tblabelpopuplink').attr('title', rcmail.gettext('label', 'thunderbird_labels')).html(''); |
0 | 423 |
424 button.bind('click', function(e) { | |
425 rcmail.command('plugin.thunderbird_labels.rcm_tb_label_submenu', this); | |
426 return false; | |
427 }); | |
428 | |
429 // add and register | |
430 rcmail.add_element(button, 'toolbar'); | |
26
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
431 rcmail.register_button('plugin.thunderbird_labels.rcm_tb_label_submenu', 'tblabelpopuplink', 'link'); |
0 | 432 */ |
433 //rcmail.register_command('plugin.thunderbird_labels.rcm_tb_label_submenu', rcm_tb_label_submenu, true); | |
434 rcmail.register_command('plugin.thunderbird_labels.rcm_tb_label_submenu', rcm_tb_label_submenu, rcmail.env.uid); | |
435 | |
436 // add event-listener to message list | |
437 if (rcmail.message_list) { | |
438 rcmail.message_list.addEventListener('select', function(list){ | |
439 rcmail.enable_command('plugin.thunderbird_labels.rcm_tb_label_submenu', list.get_selection().length > 0); | |
440 }); | |
26
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
441 rcmail.message_list.addEventListener('select', function(list) { |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
442 rcmail.enable_command('tblabeldoit',list.get_selection().length > 0); |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
443 }); |
0 | 444 } |
26
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
445 }); |
0 | 446 |
447 // -- add my submenu to roundcubes UI (for roundcube classic only?) | |
448 if (window.rcube_mail_ui) | |
26
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
449 rcube_mail_ui.prototype.tblabelpopup_add = function() { |
0 | 450 add = { |
26
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
451 tblabelpopup: {id:'tblabelpopup'} |
0 | 452 }; |
453 this.popups = $.extend(this.popups, add); | |
26
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
454 var obj = $('#'+this.popups.tblabelpopup.id); |
0 | 455 if (obj.length) |
26
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
456 this.popups.tblabelpopup.obj = obj; |
0 | 457 else |
26
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
458 delete this.popups.tblabelpopup; |
0 | 459 }; |
460 | |
461 if (window.rcube_mail_ui) | |
462 rcube_mail_ui.prototype.check_tb_popup = function() { | |
463 // larry skin doesn't have that variable, popup works automagically, return true | |
464 if (typeof this.popups == 'undefined') | |
465 return true; | |
26
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
466 if (this.popups.tblabelpopup) |
0 | 467 return true; |
468 else | |
469 return false; | |
470 }; | |
471 | |
472 }); | |
473 |