Mercurial > hg > rc1
comparison 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 |
comparison
equal
deleted
inserted
replaced
25:4b2bc456ce42 | 26:b2b6c0af2383 |
---|---|
12 function rcmail_tb_label_menu(p) | 12 function rcmail_tb_label_menu(p) |
13 { | 13 { |
14 if (typeof rcmail_ui == "undefined") | 14 if (typeof rcmail_ui == "undefined") |
15 rcmail_ui = UI; | 15 rcmail_ui = UI; |
16 if (!rcmail_ui.check_tb_popup()) | 16 if (!rcmail_ui.check_tb_popup()) |
17 rcmail_ui.tb_label_popup_add(); | 17 rcmail_ui.tblabelpopup_add(); |
18 | 18 |
19 // Show the popup menu with tags | 19 // Show the popup menu with tags |
20 // -- skin larry vs classic | 20 // -- skin larry vs classic |
21 if (typeof rcmail_ui.show_popupmenu == "undefined") | 21 if (typeof rcmail_ui.show_popupmenu == "undefined") |
22 rcmail_ui.show_popup('tb_label_popup'); | 22 rcmail_ui.show_popup('tblabelpopup'); |
23 else | 23 else |
24 rcmail_ui.show_popupmenu('tb_label_popup'); | 24 rcmail_ui.show_popupmenu('tblabelpopup'); |
25 | 25 |
26 return false; | 26 return false; |
27 } | 27 } |
28 | 28 |
29 /** | 29 /** |
80 // setup onclick and active/non active classes | 80 // setup onclick and active/non active classes |
81 rcm_tb_label_create_popupmenu(); | 81 rcm_tb_label_create_popupmenu(); |
82 | 82 |
83 // -- create sensible popup, using roundcubes internals | 83 // -- create sensible popup, using roundcubes internals |
84 if (!rcmail_ui.check_tb_popup()) | 84 if (!rcmail_ui.check_tb_popup()) |
85 rcmail_ui.tb_label_popup_add(); | 85 rcmail_ui.tblabelpopup_add(); |
86 // -- skin larry vs classic | 86 // -- skin larry vs classic |
87 if (typeof rcmail_ui.show_popupmenu == "undefined") | 87 if (typeof rcmail_ui.show_popupmenu == "undefined") |
88 rcmail_ui.show_popup('tb_label_popup'); | 88 rcmail_ui.show_popup('tblabelpopup'); |
89 else | 89 else |
90 rcmail_ui.show_popupmenu('tb_label_popup'); | 90 rcmail_ui.show_popupmenu('tblabelpopup'); |
91 return false; | 91 return false; |
92 } | 92 } |
93 | 93 |
94 function rcm_tb_label_flag_toggle(flag_uids, toggle_label_no, onoff) | 94 function rcm_tb_label_flag_toggle(flag_uids, toggle_label_no, onoff) |
95 { | 95 { |
207 else | 207 else |
208 cur_a.addClass('active'); | 208 cur_a.addClass('active'); |
209 } | 209 } |
210 } | 210 } |
211 | 211 |
212 function tblabeldoit(props,obj,event) { | |
213 var toggle_label = props; | |
214 var toggle_label_no = parseInt(toggle_label.replace('label', '')); | |
215 var label_name = rcmail.env.tb_label_custom_labels[toggle_label_no]; | |
216 var hasParm = rcmail.env.tb_label_parm_labels[toggle_label_no]; | |
217 var selection = rcm_tb_label_get_selection(); | |
218 | |
219 if (!selection.length) | |
220 return; | |
221 | |
222 var from = toggle_label_no; | |
223 var to = toggle_label_no; | |
224 var unset_all = false; | |
225 // special case flag 0 means remove all flags | |
226 if (toggle_label_no == 0) | |
227 { | |
228 from = 1; | |
229 to = rcmail.env.tb_max_label; | |
230 ; | |
231 unset_all = true; | |
232 } | |
233 for (i = from; i <= to; i++) | |
234 { | |
235 toggle_label = 'label' + i; | |
236 toggle_label_no = i; | |
237 // compile list of unflag and flag msgs and then send command | |
238 // Thunderbird modifies multiple message flags like it did the first in the selection | |
239 // e.g. first message has flag1, you click flag1, every message select loses flag1, the ones not having flag1 don't get it! | |
240 var first_toggle_mode = 'on'; | |
241 if (rcmail.env.messages) | |
242 { | |
243 var first_message = rcmail.env.messages[selection[0]]; | |
244 if (first_message.flags | |
245 && jQuery.inArray(toggle_label_no, | |
246 first_message.flags.tb_labels) >= 0 | |
247 ) | |
248 first_toggle_mode = 'off'; | |
249 else | |
250 first_toggle_mode = 'on'; | |
251 } | |
252 else // single message display | |
253 { | |
254 // flag already set? | |
255 if (jQuery.inArray(toggle_label_no, | |
256 tb_labels_for_message) >= 0) | |
257 first_toggle_mode = 'off'; | |
258 } | |
259 if (hasParm && first_toggle_mode == 'on') { | |
260 var dates=prompt("Booking dates in form d/m-d/m : ","25/7-1/8"); | |
261 if (dates!=null){ | |
262 toggle_label+='_'+dates; | |
263 } | |
264 else { | |
265 return; | |
266 } | |
267 } | |
268 var flag_uids = []; | |
269 var unflag_uids = []; | |
270 jQuery.each(selection, function (idx, uid) { | |
271 // message list not available (example: in detailview) | |
272 if (!rcmail.env.messages) | |
273 { | |
274 if (first_toggle_mode == 'on') | |
275 flag_uids.push(uid); | |
276 else | |
277 unflag_uids.push(uid); | |
278 // make sure for unset all there is the single message id | |
279 if (unset_all && unflag_uids.length == 0) | |
280 unflag_uids.push(uid); | |
281 return; | |
282 } | |
283 var message = rcmail.env.messages[uid]; | |
284 if (message.flags | |
285 && jQuery.inArray(toggle_label_no, | |
286 message.flags.tb_labels) >= 0 | |
287 ) | |
288 { | |
289 if (first_toggle_mode == 'off') | |
290 unflag_uids.push(uid); | |
291 } | |
292 else | |
293 { | |
294 if (first_toggle_mode == 'on') | |
295 flag_uids.push(uid); | |
296 } | |
297 }); | |
298 | |
299 if (unset_all) | |
300 flag_uids = []; | |
301 | |
302 // skip sending flags to backend that are not set anywhere | |
303 if (flag_uids.length == 0 | |
304 && unflag_uids.length == 0) | |
305 continue; | |
306 | |
307 var str_flag_uids = flag_uids.join(','); | |
308 var str_unflag_uids = unflag_uids.join(','); | |
309 | |
310 var lock = rcmail.set_busy(true, 'loading'); | |
311 // call PHP set_flags to set the flags in IMAP server | |
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); | |
313 | |
314 // remove/add classes and tb labels from messages in JS | |
315 rcm_tb_label_flag_msgs(flag_uids, toggle_label_no); | |
316 rcm_tb_label_unflag_msgs(unflag_uids, toggle_label_no); | |
317 } | |
318 } | |
319 | |
212 function rcm_tb_label_init_onclick() | 320 function rcm_tb_label_init_onclick() |
213 { | 321 { |
214 var max_id = rcmail.env.tb_max_label; | 322 var max_id = rcmail.env.tb_max_label; |
215 for (i = 0; i <= max_id ; i++) | 323 for (i = 0; i <= max_id ; i++) |
216 { | 324 { |
217 // find the "HTML a tags" of tb-label submenus | 325 // find the "HTML a tags" of tb-label submenus |
218 var cur_a = $('#tb_label_popup li.label' + i +' a'); | 326 var cur_a = $('#tblabelpopup li.label' + i +' a'); |
219 | 327 |
220 // TODO check if click event is defined instead of unbinding? | 328 // TODO check if click event is defined instead of unbinding? |
221 cur_a.unbind('click'); | 329 cur_a.unbind('click'); |
222 cur_a.click(function() { | 330 cur_a.attr('onclick',"rcmail.command('tblabeldoit','label"+i+"',this,event)"); |
223 var toggle_label = $(this).parent().attr('class'); | 331 } |
224 var toggle_label_no = parseInt(toggle_label.replace('label', '')); | 332 rcmail.register_command('tblabeldoit',function(props,obj,event) {tblabeldoit(props,obj,event);}); |
225 var label_name = rcmail.env.tb_label_custom_labels[toggle_label_no]; | |
226 var hasParm = rcmail.env.tb_label_parm_labels[toggle_label_no]; | |
227 var selection = rcm_tb_label_get_selection(); | |
228 | |
229 if (!selection.length) | |
230 return; | |
231 | |
232 var from = toggle_label_no; | |
233 var to = toggle_label_no; | |
234 var unset_all = false; | |
235 // special case flag 0 means remove all flags | |
236 if (toggle_label_no == 0) | |
237 { | |
238 from = 1; | |
239 to = rcmail.env.tb_max_label; | |
240 ; | |
241 unset_all = true; | |
242 } | |
243 for (i = from; i <= to; i++) | |
244 { | |
245 toggle_label = 'label' + i; | |
246 toggle_label_no = i; | |
247 // compile list of unflag and flag msgs and then send command | |
248 // Thunderbird modifies multiple message flags like it did the first in the selection | |
249 // e.g. first message has flag1, you click flag1, every message select loses flag1, the ones not having flag1 don't get it! | |
250 var first_toggle_mode = 'on'; | |
251 if (rcmail.env.messages) | |
252 { | |
253 var first_message = rcmail.env.messages[selection[0]]; | |
254 if (first_message.flags | |
255 && jQuery.inArray(toggle_label_no, | |
256 first_message.flags.tb_labels) >= 0 | |
257 ) | |
258 first_toggle_mode = 'off'; | |
259 else | |
260 first_toggle_mode = 'on'; | |
261 } | |
262 else // single message display | |
263 { | |
264 // flag already set? | |
265 if (jQuery.inArray(toggle_label_no, | |
266 tb_labels_for_message) >= 0) | |
267 first_toggle_mode = 'off'; | |
268 } | |
269 if (hasParm && first_toggle_mode == 'on') { | |
270 var dates=prompt("Booking dates in form d/m-d/m : ","25/7-1/8"); | |
271 if (dates!=null){ | |
272 toggle_label+='_'+dates; | |
273 } | |
274 else { | |
275 return; | |
276 } | |
277 } | |
278 var flag_uids = []; | |
279 var unflag_uids = []; | |
280 jQuery.each(selection, function (idx, uid) { | |
281 // message list not available (example: in detailview) | |
282 if (!rcmail.env.messages) | |
283 { | |
284 if (first_toggle_mode == 'on') | |
285 flag_uids.push(uid); | |
286 else | |
287 unflag_uids.push(uid); | |
288 // make sure for unset all there is the single message id | |
289 if (unset_all && unflag_uids.length == 0) | |
290 unflag_uids.push(uid); | |
291 return; | |
292 } | |
293 var message = rcmail.env.messages[uid]; | |
294 if (message.flags | |
295 && jQuery.inArray(toggle_label_no, | |
296 message.flags.tb_labels) >= 0 | |
297 ) | |
298 { | |
299 if (first_toggle_mode == 'off') | |
300 unflag_uids.push(uid); | |
301 } | |
302 else | |
303 { | |
304 if (first_toggle_mode == 'on') | |
305 flag_uids.push(uid); | |
306 } | |
307 }); | |
308 | |
309 if (unset_all) | |
310 flag_uids = []; | |
311 | |
312 // skip sending flags to backend that are not set anywhere | |
313 if (flag_uids.length == 0 | |
314 && unflag_uids.length == 0) | |
315 continue; | |
316 | |
317 var str_flag_uids = flag_uids.join(','); | |
318 var str_unflag_uids = unflag_uids.join(','); | |
319 | |
320 var lock = rcmail.set_busy(true, 'loading'); | |
321 // call PHP set_flags to set the flags in IMAP server | |
322 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); | |
323 | |
324 // remove/add classes and tb labels from messages in JS | |
325 rcm_tb_label_flag_msgs(flag_uids, toggle_label_no); | |
326 rcm_tb_label_unflag_msgs(unflag_uids, toggle_label_no); | |
327 } | |
328 }); | |
329 } | |
330 } | 333 } |
331 | 334 |
332 function rcmail_ctxm_label(command, el, pos) | 335 function rcmail_ctxm_label(command, el, pos) |
333 { | 336 { |
334 // my code works only on selected rows, contextmenu also on unselected | 337 // my code works only on selected rows, contextmenu also on unselected |
338 if (!selection.length && !rcmail.env.uid) | 341 if (!selection.length && !rcmail.env.uid) |
339 return; | 342 return; |
340 if (!selection.length && rcmail.env.uid) | 343 if (!selection.length && rcmail.env.uid) |
341 rcmail.message_list.select_row(rcmail.env.uid); | 344 rcmail.message_list.select_row(rcmail.env.uid); |
342 | 345 |
343 var cur_a = $('#tb_label_popup li.label' + rcmail.tb_label_no +' a'); | 346 var cur_a = $('#tblabelpopup li.label' + rcmail.tb_label_no +' a'); |
344 if (cur_a) | 347 if (cur_a) |
345 { | 348 { |
346 cur_a.click(); | 349 cur_a.click(); |
347 } | 350 } |
348 | 351 |
364 //console.log('Handler for .keyup() called.' + e.which); | 367 //console.log('Handler for .keyup() called.' + e.which); |
365 var k = e.which; | 368 var k = e.which; |
366 if ((k > 47 && k < 58) || (k > 95 && k < 106)) | 369 if ((k > 47 && k < 58) || (k > 95 && k < 106)) |
367 { | 370 { |
368 var label_no = k % 48; | 371 var label_no = k % 48; |
369 var cur_a = $('#tb_label_popup li.label' + label_no + ' a'); | 372 var cur_a = $('#tblabelpopup li.label' + label_no + ' a'); |
370 | 373 |
371 if (cur_a) | 374 if (cur_a) |
372 { | 375 { |
373 cur_a.click(); | 376 cur_a.click(); |
374 } | 377 } |
375 } | 378 } |
376 }); | 379 }); |
377 } | 380 } |
378 | 381 rcmail.addEventListener('contextmenu_init', function(menu) { |
382 // identify the folder list context menu | |
383 if (menu.menu_name == 'messagelist') { | |
384 var mc = menu.menu_source.length; // BREAK HERE | |
385 //.push({label: 'Labels', command: 'folders', props: '', classes: 'managefolders'}); } | |
386 } | |
387 } | |
388 ); | |
379 // if exists add contextmenu entries | 389 // if exists add contextmenu entries |
380 if (window.rcm_contextmenu_register_command) { | 390 /*if (window.rcm_contextmenu_register_command) { |
391 [Doesn't exist -- HST] | |
381 rcm_contextmenu_register_command('ctxm_tb_label', rcmail_ctxm_label, $('#tb_label_ctxm_mainmenu'), 'moreacts', 'after', true); | 392 rcm_contextmenu_register_command('ctxm_tb_label', rcmail_ctxm_label, $('#tb_label_ctxm_mainmenu'), 'moreacts', 'after', true); |
382 } | 393 }*/ |
383 | 394 |
384 // single message displayed? | 395 // single message displayed? |
385 if (window.tb_labels_for_message) | 396 if (window.tb_labels_for_message) |
386 { | 397 { |
387 var labelbox_parent = $('div.message-headers'); // larry skin | 398 var labelbox_parent = $('div.message-headers'); // larry skin |
397 ); | 408 ); |
398 } | 409 } |
399 | 410 |
400 // add roundcube events | 411 // add roundcube events |
401 rcmail.addEventListener('insertrow', function(event) { rcm_tb_label_insert(event.uid, event.row); }); | 412 rcmail.addEventListener('insertrow', function(event) { rcm_tb_label_insert(event.uid, event.row); }); |
402 | 413 |
403 rcmail.addEventListener('init', function(evt) { | 414 rcmail.addEventListener('init', function(evt) { |
404 // create custom button, JS method, broken layout in Firefox 9 using PHP method now | 415 // create custom button, JS method, broken layout in Firefox 9 using PHP method now |
405 /*var button = $('<A>').attr('href', '#').attr('id', 'tb_label_popuplink').attr('title', rcmail.gettext('label', 'thunderbird_labels')).html(''); | 416 /*var button = $('<A>').attr('href', '#').attr('id', 'tblabelpopuplink').attr('title', rcmail.gettext('label', 'thunderbird_labels')).html(''); |
406 | 417 |
407 button.bind('click', function(e) { | 418 button.bind('click', function(e) { |
408 rcmail.command('plugin.thunderbird_labels.rcm_tb_label_submenu', this); | 419 rcmail.command('plugin.thunderbird_labels.rcm_tb_label_submenu', this); |
409 return false; | 420 return false; |
410 }); | 421 }); |
411 | 422 |
412 // add and register | 423 // add and register |
413 rcmail.add_element(button, 'toolbar'); | 424 rcmail.add_element(button, 'toolbar'); |
414 rcmail.register_button('plugin.thunderbird_labels.rcm_tb_label_submenu', 'tb_label_popuplink', 'link'); | 425 rcmail.register_button('plugin.thunderbird_labels.rcm_tb_label_submenu', 'tblabelpopuplink', 'link'); |
415 */ | 426 */ |
416 //rcmail.register_command('plugin.thunderbird_labels.rcm_tb_label_submenu', rcm_tb_label_submenu, true); | 427 //rcmail.register_command('plugin.thunderbird_labels.rcm_tb_label_submenu', rcm_tb_label_submenu, true); |
417 rcmail.register_command('plugin.thunderbird_labels.rcm_tb_label_submenu', rcm_tb_label_submenu, rcmail.env.uid); | 428 rcmail.register_command('plugin.thunderbird_labels.rcm_tb_label_submenu', rcm_tb_label_submenu, rcmail.env.uid); |
418 | 429 |
419 // add event-listener to message list | 430 // add event-listener to message list |
420 if (rcmail.message_list) { | 431 if (rcmail.message_list) { |
421 rcmail.message_list.addEventListener('select', function(list){ | 432 rcmail.message_list.addEventListener('select', function(list){ |
422 rcmail.enable_command('plugin.thunderbird_labels.rcm_tb_label_submenu', list.get_selection().length > 0); | 433 rcmail.enable_command('plugin.thunderbird_labels.rcm_tb_label_submenu', list.get_selection().length > 0); |
423 }); | 434 }); |
435 rcmail.message_list.addEventListener('select', function(list) { | |
436 rcmail.enable_command('tblabeldoit',list.get_selection().length > 0); | |
437 }); | |
424 } | 438 } |
425 }); | 439 }); |
426 | 440 |
427 // -- add my submenu to roundcubes UI (for roundcube classic only?) | 441 // -- add my submenu to roundcubes UI (for roundcube classic only?) |
428 if (window.rcube_mail_ui) | 442 if (window.rcube_mail_ui) |
429 rcube_mail_ui.prototype.tb_label_popup_add = function() { | 443 rcube_mail_ui.prototype.tblabelpopup_add = function() { |
430 add = { | 444 add = { |
431 tb_label_popup: {id:'tb_label_popup'} | 445 tblabelpopup: {id:'tblabelpopup'} |
432 }; | 446 }; |
433 this.popups = $.extend(this.popups, add); | 447 this.popups = $.extend(this.popups, add); |
434 var obj = $('#'+this.popups.tb_label_popup.id); | 448 var obj = $('#'+this.popups.tblabelpopup.id); |
435 if (obj.length) | 449 if (obj.length) |
436 this.popups.tb_label_popup.obj = obj; | 450 this.popups.tblabelpopup.obj = obj; |
437 else | 451 else |
438 delete this.popups.tb_label_popup; | 452 delete this.popups.tblabelpopup; |
439 }; | 453 }; |
440 | 454 |
441 if (window.rcube_mail_ui) | 455 if (window.rcube_mail_ui) |
442 rcube_mail_ui.prototype.check_tb_popup = function() { | 456 rcube_mail_ui.prototype.check_tb_popup = function() { |
443 // larry skin doesn't have that variable, popup works automagically, return true | 457 // larry skin doesn't have that variable, popup works automagically, return true |
444 if (typeof this.popups == 'undefined') | 458 if (typeof this.popups == 'undefined') |
445 return true; | 459 return true; |
446 if (this.popups.tb_label_popup) | 460 if (this.popups.tblabelpopup) |
447 return true; | 461 return true; |
448 else | 462 else |
449 return false; | 463 return false; |
450 }; | 464 }; |
451 | 465 |