Mercurial > hg > rc1
annotate plugins/thunderbird_labels/tb_label.js @ 26:b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
author | Charlie Root |
---|---|
date | Sun, 28 Jan 2018 11:32:20 -0500 |
parents | 4869fae20b88 |
children | f8b3ac77e951 |
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); | |
131 if (pos > -1) { | |
132 tb_labels_for_message.splice(pos, 1); | |
133 } | |
134 } | |
135 // exit function when in detail mode. when preview is active keep going | |
136 if (!rcmail.env.messages) { | |
137 return; | |
138 } | |
139 } | |
140 jQuery.each(flag_uids, function (idx, uid) { | |
141 var message = rcmail.env.messages[uid]; | |
142 var row = rcmail.message_list.rows[uid]; | |
143 if (onoff == true) | |
144 { | |
145 // add colors | |
146 var rowobj = $(row.obj); | |
147 var spanobj = rowobj.find("td.subject span.tb_label_dots"); | |
148 if (rcmail.env.tb_label_style=='bullets') { | |
149 spanobj.append("<span class='label"+toggle_label_no+"'>•</span>"); | |
150 } else { | |
151 rowobj.addClass('label'+toggle_label_no); | |
152 } | |
153 | |
154 // add to flag list | |
155 message.flags.tb_labels.push(toggle_label_no); | |
156 } | |
157 else | |
158 { | |
159 // remove colors | |
160 var rowobj = $(row.obj); | |
161 if (rcmail.env.tb_label_style=='bullets') { | |
162 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
|
163 rowobj.find("td.dates span").remove(); |
0 | 164 } else { |
165 rowobj.removeClass('label'+toggle_label_no); | |
166 } | |
167 | |
168 // remove from flag list | |
169 var pos = jQuery.inArray(toggle_label_no, message.flags.tb_labels); | |
170 if (pos > -1) | |
171 message.flags.tb_labels.splice(pos, 1); | |
172 } | |
173 }); | |
174 } | |
175 | |
176 function rcm_tb_label_flag_msgs(flag_uids, toggle_label_no) | |
177 { | |
178 rcm_tb_label_flag_toggle(flag_uids, toggle_label_no, true); | |
179 } | |
180 | |
181 function rcm_tb_label_unflag_msgs(unflag_uids, toggle_label_no) | |
182 { | |
183 rcm_tb_label_flag_toggle(unflag_uids, toggle_label_no, false); | |
184 } | |
185 | |
186 // helper function to get selected/active messages | |
187 function rcm_tb_label_get_selection() | |
188 { | |
189 var selection = rcmail.message_list ? rcmail.message_list.get_selection() : []; | |
190 if (selection.length == 0 && rcmail.env.uid) | |
191 selection = [rcmail.env.uid, ]; | |
192 return selection; | |
193 } | |
194 | |
195 function rcm_tb_label_create_popupmenu() | |
196 { | |
9 | 197 var max_id = rcmail.env.tb_max_label; |
198 for (i = 0; i <= max_id; i++) | |
0 | 199 { |
200 var cur_a = $('li.label' + i +' a'); | |
201 | |
202 // add/remove active class | |
203 var selection = rcm_tb_label_get_selection(); | |
204 | |
205 if (selection.length == 0) | |
206 cur_a.removeClass('active'); | |
207 else | |
208 cur_a.addClass('active'); | |
209 } | |
210 } | |
211 | |
26
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
212 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
|
213 var toggle_label = props; |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
214 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
|
215 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
|
216 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
|
217 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
|
218 |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
219 if (!selection.length) |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
220 return; |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
221 |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
222 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
|
223 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
|
224 var unset_all = false; |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
225 // 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
|
226 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
|
227 { |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
228 from = 1; |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
229 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
|
230 ; |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
231 unset_all = true; |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
232 } |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
233 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
|
234 { |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
235 toggle_label = 'label' + i; |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
236 toggle_label_no = i; |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
237 // 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
|
238 // 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
|
239 // 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
|
240 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
|
241 if (rcmail.env.messages) |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
242 { |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
243 var first_message = rcmail.env.messages[selection[0]]; |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
244 if (first_message.flags |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
245 && 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
|
246 first_message.flags.tb_labels) >= 0 |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
247 ) |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
248 first_toggle_mode = 'off'; |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
249 else |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
250 first_toggle_mode = 'on'; |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
251 } |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
252 else // single message display |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
253 { |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
254 // flag already set? |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
255 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
|
256 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
|
257 first_toggle_mode = 'off'; |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
258 } |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
259 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
|
260 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
|
261 if (dates!=null){ |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
262 toggle_label+='_'+dates; |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
263 } |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
264 else { |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
265 return; |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
266 } |
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 var flag_uids = []; |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
269 var unflag_uids = []; |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
270 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
|
271 // 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
|
272 if (!rcmail.env.messages) |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
273 { |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
274 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
|
275 flag_uids.push(uid); |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
276 else |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
277 unflag_uids.push(uid); |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
278 // 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
|
279 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
|
280 unflag_uids.push(uid); |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
281 return; |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
282 } |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
283 var message = rcmail.env.messages[uid]; |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
284 if (message.flags |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
285 && 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
|
286 message.flags.tb_labels) >= 0 |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
287 ) |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
288 { |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
289 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
|
290 unflag_uids.push(uid); |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
291 } |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
292 else |
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 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
|
295 flag_uids.push(uid); |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
296 } |
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 |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
299 if (unset_all) |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
300 flag_uids = []; |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
301 |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
302 // 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
|
303 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
|
304 && unflag_uids.length == 0) |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
305 continue; |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
306 |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
307 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
|
308 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
|
309 |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
310 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
|
311 // 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
|
312 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
|
313 |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
314 // 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
|
315 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
|
316 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
|
317 } |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
318 } |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
319 |
0 | 320 function rcm_tb_label_init_onclick() |
321 { | |
9 | 322 var max_id = rcmail.env.tb_max_label; |
323 for (i = 0; i <= max_id ; i++) | |
0 | 324 { |
325 // 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
|
326 var cur_a = $('#tblabelpopup li.label' + i +' a'); |
0 | 327 |
328 // TODO check if click event is defined instead of unbinding? | |
329 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
|
330 cur_a.attr('onclick',"rcmail.command('tblabeldoit','label"+i+"',this,event)"); |
0 | 331 } |
26
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
332 rcmail.register_command('tblabeldoit',function(props,obj,event) {tblabeldoit(props,obj,event);}); |
0 | 333 } |
334 | |
335 function rcmail_ctxm_label(command, el, pos) | |
336 { | |
337 // my code works only on selected rows, contextmenu also on unselected | |
338 // so if no selection is available, use the uid set by contextmenu plugin | |
339 var selection = rcmail.message_list ? rcmail.message_list.get_selection() : []; | |
340 | |
341 if (!selection.length && !rcmail.env.uid) | |
342 return; | |
343 if (!selection.length && rcmail.env.uid) | |
344 rcmail.message_list.select_row(rcmail.env.uid); | |
345 | |
26
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
346 var cur_a = $('#tblabelpopup li.label' + rcmail.tb_label_no +' a'); |
0 | 347 if (cur_a) |
348 { | |
349 cur_a.click(); | |
350 } | |
351 | |
352 return; | |
353 } | |
354 | |
355 function rcmail_ctxm_label_set(which) | |
356 { | |
357 // hack for my contextmenu submenu hack to propagate the selected label-no | |
358 rcmail.tb_label_no = which; | |
359 } | |
360 | |
361 | |
362 $(document).ready(function() { | |
363 rcm_tb_label_init_onclick(); | |
364 // add keyboard shortcuts for keyboard and keypad if pref tb_label_enable_shortcuts=true | |
365 if (rcmail.env.tb_label_enable_shortcuts) { | |
366 $(document).keyup(function(e) { | |
367 //console.log('Handler for .keyup() called.' + e.which); | |
368 var k = e.which; | |
369 if ((k > 47 && k < 58) || (k > 95 && k < 106)) | |
370 { | |
371 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
|
372 var cur_a = $('#tblabelpopup li.label' + label_no + ' a'); |
0 | 373 |
374 if (cur_a) | |
375 { | |
376 cur_a.click(); | |
377 } | |
378 } | |
379 }); | |
380 } | |
26
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
381 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
|
382 // 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
|
383 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
|
384 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
|
385 //.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
|
386 } |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
387 } |
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
388 ); |
0 | 389 // 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
|
390 /*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
|
391 [Doesn't exist -- HST] |
0 | 392 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
|
393 }*/ |
0 | 394 |
395 // single message displayed? | |
396 if (window.tb_labels_for_message) | |
397 { | |
398 var labelbox_parent = $('div.message-headers'); // larry skin | |
399 if (!labelbox_parent.length) { | |
400 labelbox_parent = $("table.headers-table tbody tr:first-child"); // classic skin | |
401 } | |
402 labelbox_parent.append("<div id='labelbox'></div>"); | |
403 tb_labels_for_message.sort(function(a,b) {return a-b;}); | |
404 jQuery.each(tb_labels_for_message, function(idx, val) | |
405 { | |
406 rcm_tb_label_flag_msgs([-1,], val); | |
407 } | |
408 ); | |
409 } | |
410 | |
411 // add roundcube events | |
412 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
|
413 |
0 | 414 rcmail.addEventListener('init', function(evt) { |
415 // 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
|
416 /*var button = $('<A>').attr('href', '#').attr('id', 'tblabelpopuplink').attr('title', rcmail.gettext('label', 'thunderbird_labels')).html(''); |
0 | 417 |
418 button.bind('click', function(e) { | |
419 rcmail.command('plugin.thunderbird_labels.rcm_tb_label_submenu', this); | |
420 return false; | |
421 }); | |
422 | |
423 // add and register | |
424 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
|
425 rcmail.register_button('plugin.thunderbird_labels.rcm_tb_label_submenu', 'tblabelpopuplink', 'link'); |
0 | 426 */ |
427 //rcmail.register_command('plugin.thunderbird_labels.rcm_tb_label_submenu', rcm_tb_label_submenu, true); | |
428 rcmail.register_command('plugin.thunderbird_labels.rcm_tb_label_submenu', rcm_tb_label_submenu, rcmail.env.uid); | |
429 | |
430 // add event-listener to message list | |
431 if (rcmail.message_list) { | |
432 rcmail.message_list.addEventListener('select', function(list){ | |
433 rcmail.enable_command('plugin.thunderbird_labels.rcm_tb_label_submenu', list.get_selection().length > 0); | |
434 }); | |
26
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
435 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
|
436 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
|
437 }); |
0 | 438 } |
26
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
439 }); |
0 | 440 |
441 // -- add my submenu to roundcubes UI (for roundcube classic only?) | |
442 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
|
443 rcube_mail_ui.prototype.tblabelpopup_add = function() { |
0 | 444 add = { |
26
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
445 tblabelpopup: {id:'tblabelpopup'} |
0 | 446 }; |
447 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
|
448 var obj = $('#'+this.popups.tblabelpopup.id); |
0 | 449 if (obj.length) |
26
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
450 this.popups.tblabelpopup.obj = obj; |
0 | 451 else |
26
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
452 delete this.popups.tblabelpopup; |
0 | 453 }; |
454 | |
455 if (window.rcube_mail_ui) | |
456 rcube_mail_ui.prototype.check_tb_popup = function() { | |
457 // larry skin doesn't have that variable, popup works automagically, return true | |
458 if (typeof this.popups == 'undefined') | |
459 return true; | |
26
b2b6c0af2383
remove _ from name, lots of other hacks to get label context menu working
Charlie Root
parents:
24
diff
changeset
|
460 if (this.popups.tblabelpopup) |
0 | 461 return true; |
462 else | |
463 return false; | |
464 }; | |
465 | |
466 }); | |
467 |