Mercurial > hg > rc1
changeset 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 | 4b2bc456ce42 |
children | e097905863b9 |
files | plugins/thunderbird_labels/skins/larry/tb_label.css plugins/thunderbird_labels/tb_label.js plugins/thunderbird_labels/thunderbird_labels.php |
diffstat | 3 files changed, 181 insertions(+), 149 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/thunderbird_labels/skins/larry/tb_label.css Thu Jan 18 07:54:45 2018 -0500 +++ b/plugins/thunderbird_labels/skins/larry/tb_label.css Sun Jan 28 11:32:20 2018 -0500 @@ -6,7 +6,7 @@ * CSS is Based on a patch for roundcube 0.3 I found a long time ago */ -#tb_label_popuplink { +#tblabelpopuplink { background-image: url(thunderbird_32.png); /*background-repeat: repeat;*/ background-position: 50% 0px; @@ -16,13 +16,13 @@ margin: 0px 5px 0px 5px; } -#tb_label_popup +#tblabelpopup { width: auto; position: absolute; } -#tb_label_popup a.active +#tblabelpopup a.active { color: inherit; /* fix for firefox */ }
--- a/plugins/thunderbird_labels/tb_label.js Thu Jan 18 07:54:45 2018 -0500 +++ b/plugins/thunderbird_labels/tb_label.js Sun Jan 28 11:32:20 2018 -0500 @@ -14,14 +14,14 @@ if (typeof rcmail_ui == "undefined") rcmail_ui = UI; if (!rcmail_ui.check_tb_popup()) - rcmail_ui.tb_label_popup_add(); + rcmail_ui.tblabelpopup_add(); // Show the popup menu with tags // -- skin larry vs classic if (typeof rcmail_ui.show_popupmenu == "undefined") - rcmail_ui.show_popup('tb_label_popup'); + rcmail_ui.show_popup('tblabelpopup'); else - rcmail_ui.show_popupmenu('tb_label_popup'); + rcmail_ui.show_popupmenu('tblabelpopup'); return false; } @@ -82,12 +82,12 @@ // -- create sensible popup, using roundcubes internals if (!rcmail_ui.check_tb_popup()) - rcmail_ui.tb_label_popup_add(); + rcmail_ui.tblabelpopup_add(); // -- skin larry vs classic if (typeof rcmail_ui.show_popupmenu == "undefined") - rcmail_ui.show_popup('tb_label_popup'); + rcmail_ui.show_popup('tblabelpopup'); else - rcmail_ui.show_popupmenu('tb_label_popup'); + rcmail_ui.show_popupmenu('tblabelpopup'); return false; } @@ -209,124 +209,127 @@ } } +function tblabeldoit(props,obj,event) { + var toggle_label = props; + var toggle_label_no = parseInt(toggle_label.replace('label', '')); + var label_name = rcmail.env.tb_label_custom_labels[toggle_label_no]; + var hasParm = rcmail.env.tb_label_parm_labels[toggle_label_no]; + var selection = rcm_tb_label_get_selection(); + + if (!selection.length) + return; + + var from = toggle_label_no; + var to = toggle_label_no; + var unset_all = false; + // special case flag 0 means remove all flags + if (toggle_label_no == 0) + { + from = 1; + to = rcmail.env.tb_max_label; + ; + unset_all = true; + } + for (i = from; i <= to; i++) + { + toggle_label = 'label' + i; + toggle_label_no = i; + // compile list of unflag and flag msgs and then send command + // Thunderbird modifies multiple message flags like it did the first in the selection + // e.g. first message has flag1, you click flag1, every message select loses flag1, the ones not having flag1 don't get it! + var first_toggle_mode = 'on'; + if (rcmail.env.messages) + { + var first_message = rcmail.env.messages[selection[0]]; + if (first_message.flags + && jQuery.inArray(toggle_label_no, + first_message.flags.tb_labels) >= 0 + ) + first_toggle_mode = 'off'; + else + first_toggle_mode = 'on'; + } + else // single message display + { + // flag already set? + if (jQuery.inArray(toggle_label_no, + tb_labels_for_message) >= 0) + first_toggle_mode = 'off'; + } + if (hasParm && first_toggle_mode == 'on') { + var dates=prompt("Booking dates in form d/m-d/m : ","25/7-1/8"); + if (dates!=null){ + toggle_label+='_'+dates; + } + else { + return; + } + } + var flag_uids = []; + var unflag_uids = []; + jQuery.each(selection, function (idx, uid) { + // message list not available (example: in detailview) + if (!rcmail.env.messages) + { + if (first_toggle_mode == 'on') + flag_uids.push(uid); + else + unflag_uids.push(uid); + // make sure for unset all there is the single message id + if (unset_all && unflag_uids.length == 0) + unflag_uids.push(uid); + return; + } + var message = rcmail.env.messages[uid]; + if (message.flags + && jQuery.inArray(toggle_label_no, + message.flags.tb_labels) >= 0 + ) + { + if (first_toggle_mode == 'off') + unflag_uids.push(uid); + } + else + { + if (first_toggle_mode == 'on') + flag_uids.push(uid); + } + }); + + if (unset_all) + flag_uids = []; + + // skip sending flags to backend that are not set anywhere + if (flag_uids.length == 0 + && unflag_uids.length == 0) + continue; + + var str_flag_uids = flag_uids.join(','); + var str_unflag_uids = unflag_uids.join(','); + + var lock = rcmail.set_busy(true, 'loading'); + // call PHP set_flags to set the flags in IMAP server + 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); + + // remove/add classes and tb labels from messages in JS + rcm_tb_label_flag_msgs(flag_uids, toggle_label_no); + rcm_tb_label_unflag_msgs(unflag_uids, toggle_label_no); + } +} + function rcm_tb_label_init_onclick() { var max_id = rcmail.env.tb_max_label; for (i = 0; i <= max_id ; i++) { // find the "HTML a tags" of tb-label submenus - var cur_a = $('#tb_label_popup li.label' + i +' a'); + var cur_a = $('#tblabelpopup li.label' + i +' a'); // TODO check if click event is defined instead of unbinding? cur_a.unbind('click'); - cur_a.click(function() { - var toggle_label = $(this).parent().attr('class'); - var toggle_label_no = parseInt(toggle_label.replace('label', '')); - var label_name = rcmail.env.tb_label_custom_labels[toggle_label_no]; - var hasParm = rcmail.env.tb_label_parm_labels[toggle_label_no]; - var selection = rcm_tb_label_get_selection(); - - if (!selection.length) - return; - - var from = toggle_label_no; - var to = toggle_label_no; - var unset_all = false; - // special case flag 0 means remove all flags - if (toggle_label_no == 0) - { - from = 1; - to = rcmail.env.tb_max_label; -; - unset_all = true; - } - for (i = from; i <= to; i++) - { - toggle_label = 'label' + i; - toggle_label_no = i; - // compile list of unflag and flag msgs and then send command - // Thunderbird modifies multiple message flags like it did the first in the selection - // e.g. first message has flag1, you click flag1, every message select loses flag1, the ones not having flag1 don't get it! - var first_toggle_mode = 'on'; - if (rcmail.env.messages) - { - var first_message = rcmail.env.messages[selection[0]]; - if (first_message.flags - && jQuery.inArray(toggle_label_no, - first_message.flags.tb_labels) >= 0 - ) - first_toggle_mode = 'off'; - else - first_toggle_mode = 'on'; - } - else // single message display - { - // flag already set? - if (jQuery.inArray(toggle_label_no, - tb_labels_for_message) >= 0) - first_toggle_mode = 'off'; - } - if (hasParm && first_toggle_mode == 'on') { - var dates=prompt("Booking dates in form d/m-d/m : ","25/7-1/8"); - if (dates!=null){ - toggle_label+='_'+dates; - } - else { - return; - } - } - var flag_uids = []; - var unflag_uids = []; - jQuery.each(selection, function (idx, uid) { - // message list not available (example: in detailview) - if (!rcmail.env.messages) - { - if (first_toggle_mode == 'on') - flag_uids.push(uid); - else - unflag_uids.push(uid); - // make sure for unset all there is the single message id - if (unset_all && unflag_uids.length == 0) - unflag_uids.push(uid); - return; - } - var message = rcmail.env.messages[uid]; - if (message.flags - && jQuery.inArray(toggle_label_no, - message.flags.tb_labels) >= 0 - ) - { - if (first_toggle_mode == 'off') - unflag_uids.push(uid); - } - else - { - if (first_toggle_mode == 'on') - flag_uids.push(uid); - } - }); - - if (unset_all) - flag_uids = []; - - // skip sending flags to backend that are not set anywhere - if (flag_uids.length == 0 - && unflag_uids.length == 0) - continue; - - var str_flag_uids = flag_uids.join(','); - var str_unflag_uids = unflag_uids.join(','); - - var lock = rcmail.set_busy(true, 'loading'); - // call PHP set_flags to set the flags in IMAP server - 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); - - // remove/add classes and tb labels from messages in JS - rcm_tb_label_flag_msgs(flag_uids, toggle_label_no); - rcm_tb_label_unflag_msgs(unflag_uids, toggle_label_no); - } - }); + cur_a.attr('onclick',"rcmail.command('tblabeldoit','label"+i+"',this,event)"); } + rcmail.register_command('tblabeldoit',function(props,obj,event) {tblabeldoit(props,obj,event);}); } function rcmail_ctxm_label(command, el, pos) @@ -340,7 +343,7 @@ if (!selection.length && rcmail.env.uid) rcmail.message_list.select_row(rcmail.env.uid); - var cur_a = $('#tb_label_popup li.label' + rcmail.tb_label_no +' a'); + var cur_a = $('#tblabelpopup li.label' + rcmail.tb_label_no +' a'); if (cur_a) { cur_a.click(); @@ -366,7 +369,7 @@ if ((k > 47 && k < 58) || (k > 95 && k < 106)) { var label_no = k % 48; - var cur_a = $('#tb_label_popup li.label' + label_no + ' a'); + var cur_a = $('#tblabelpopup li.label' + label_no + ' a'); if (cur_a) { @@ -375,11 +378,19 @@ } }); } - + rcmail.addEventListener('contextmenu_init', function(menu) { + // identify the folder list context menu + if (menu.menu_name == 'messagelist') { + var mc = menu.menu_source.length; // BREAK HERE + //.push({label: 'Labels', command: 'folders', props: '', classes: 'managefolders'}); } + } + } + ); // if exists add contextmenu entries - if (window.rcm_contextmenu_register_command) { + /*if (window.rcm_contextmenu_register_command) { + [Doesn't exist -- HST] rcm_contextmenu_register_command('ctxm_tb_label', rcmail_ctxm_label, $('#tb_label_ctxm_mainmenu'), 'moreacts', 'after', true); - } + }*/ // single message displayed? if (window.tb_labels_for_message) @@ -399,10 +410,10 @@ // add roundcube events rcmail.addEventListener('insertrow', function(event) { rcm_tb_label_insert(event.uid, event.row); }); - + rcmail.addEventListener('init', function(evt) { // create custom button, JS method, broken layout in Firefox 9 using PHP method now - /*var button = $('<A>').attr('href', '#').attr('id', 'tb_label_popuplink').attr('title', rcmail.gettext('label', 'thunderbird_labels')).html(''); + /*var button = $('<A>').attr('href', '#').attr('id', 'tblabelpopuplink').attr('title', rcmail.gettext('label', 'thunderbird_labels')).html(''); button.bind('click', function(e) { rcmail.command('plugin.thunderbird_labels.rcm_tb_label_submenu', this); @@ -411,7 +422,7 @@ // add and register rcmail.add_element(button, 'toolbar'); - rcmail.register_button('plugin.thunderbird_labels.rcm_tb_label_submenu', 'tb_label_popuplink', 'link'); + rcmail.register_button('plugin.thunderbird_labels.rcm_tb_label_submenu', 'tblabelpopuplink', 'link'); */ //rcmail.register_command('plugin.thunderbird_labels.rcm_tb_label_submenu', rcm_tb_label_submenu, true); rcmail.register_command('plugin.thunderbird_labels.rcm_tb_label_submenu', rcm_tb_label_submenu, rcmail.env.uid); @@ -421,21 +432,24 @@ rcmail.message_list.addEventListener('select', function(list){ rcmail.enable_command('plugin.thunderbird_labels.rcm_tb_label_submenu', list.get_selection().length > 0); }); + rcmail.message_list.addEventListener('select', function(list) { + rcmail.enable_command('tblabeldoit',list.get_selection().length > 0); + }); } - }); + }); // -- add my submenu to roundcubes UI (for roundcube classic only?) if (window.rcube_mail_ui) - rcube_mail_ui.prototype.tb_label_popup_add = function() { + rcube_mail_ui.prototype.tblabelpopup_add = function() { add = { - tb_label_popup: {id:'tb_label_popup'} + tblabelpopup: {id:'tblabelpopup'} }; this.popups = $.extend(this.popups, add); - var obj = $('#'+this.popups.tb_label_popup.id); + var obj = $('#'+this.popups.tblabelpopup.id); if (obj.length) - this.popups.tb_label_popup.obj = obj; + this.popups.tblabelpopup.obj = obj; else - delete this.popups.tb_label_popup; + delete this.popups.tblabelpopup; }; if (window.rcube_mail_ui) @@ -443,7 +457,7 @@ // larry skin doesn't have that variable, popup works automagically, return true if (typeof this.popups == 'undefined') return true; - if (this.popups.tb_label_popup) + if (this.popups.tblabelpopup) return true; else return false;
--- a/plugins/thunderbird_labels/thunderbird_labels.php Thu Jan 18 07:54:45 2018 -0500 +++ b/plugins/thunderbird_labels/thunderbird_labels.php Sun Jan 28 11:32:20 2018 -0500 @@ -44,7 +44,7 @@ $this->add_hook('messages_list', array($this, 'read_flags')); $this->add_hook('message_load', array($this, 'read_single_flags')); $this->add_hook('template_object_messageheaders', array($this, 'color_headers')); - $this->add_hook('render_page', array($this, 'tb_label_popup')); + $this->add_hook('render_page', array($this, 'tblabelpopup')); $this->include_stylesheet($this->local_skin_path() . '/tb_label.css'); $this->name = get_class($this); @@ -55,20 +55,35 @@ } $this->message_tb_labels = array(); + # This builds the toolbar button, but + # it's also used by the ctxtmenu initialisation + # contextmenu.js:rcube_context_menu to build + # the context menu, and that somehow + # ends up with display: none??? + # Bother, missed it, it's before this.container.show + # Afeter ul.appendnd -- inside menu.show on 307 + # 567? Yes -- that's calling 'hide', but overriding + # doesn't fix :-( + rcube::write_log('lab','add_button'); $this->add_button( array( - 'command' => 'plugin.thunderbird_labels.rcm_tb_label_submenu', - 'id' => 'tb_label_popuplink', + #'command' => 'plugin.thunderbird_labels.rcm_tb_label_submenu', + 'name' => 'tblabellink', + 'id' => 'tblabelpopuplink', + #'domain' => $this->ID, + 'type' => 'link', + 'class' => 'button tblabel', + 'label' => $this->gettext('tb_label_button_label'), 'title' => 'tb_label_button_title', - 'domain' => $this->ID, - 'type' => 'link', - 'content' => $this->gettext('tb_label_button_label'), - 'class' => 'button buttonPas disabled', - 'classact' => 'button', + 'onclick' => "UI.toggle_popup('tblabelpopup',event);return false", + 'aria-haspopup' => true, + 'aria-expanded' => false, + 'aria-owns' => 'plugin.thunderbird_labels.rcm_tb_label_submenu-menu' + #'classact' => 'listbutton add', ), 'toolbar' ); - + // JS function "set_flags" => PHP function "set_flags" $this->register_action('plugin.thunderbird_labels.set_flags', array($this, 'set_flags')); @@ -80,10 +95,10 @@ { if ($this->rc->action == 'list') $this->add_hook('render_mailboxlist', array($this, 'show_tb_label_contextmenu')); - #rcube::write_log('lab','ctxt: '.$this->rc->action); + rcube::write_log('lab','ctxt: '.$this->rc->action); } else { - #rcube::write_log('lab','no ctxt'); + rcube::write_log('lab','no ctxt'); } } elseif ($this->rc->task == 'settings') @@ -264,17 +279,19 @@ } public function show_tb_label_contextmenu($args) + # never called? { #$this->api->output->add_label('copymessage.copyingmessage'); - #rcube::write_log('lab',"stblc"); $li = html::tag('li', array('class' => 'submenu'), '<span>'.rcube::Q($this->gettext('tb_label_contextmenu_title')).'</span>' . $this->_gen_label_submenu($args, 'tb_label_ctxm_submenu')); $out .= html::tag('ul', array('id' => 'tb_label_ctxm_mainmenu'), $li); + rcube::write_log('lab',"stblc $out"); $this->api->output->add_footer(html::div(array('style' => 'display: none;'), $out)); } private function _gen_label_submenu($args, $id) + # never called? { $out = ''; $custom_labels = $this->rc->config->get('tb_label_custom_labels'); @@ -513,21 +530,22 @@ $this->api->output->send(); } - function tb_label_popup() + function tblabelpopup() { $custom_labels = $this->rc->config->get('tb_label_custom_labels'); $max_id = $this->rc->config->get('tb_max_label'); - $out = '<div id="tb_label_popup" class="popupmenu"> + $out = '<div id="tblabelpopup" class="popupmenu"> <ul class="toolbarmenu">'; for ($i = 0; $i <= $max_id; $i++) { $separator = ($i == 0)? ' separator_below' :''; - $out .= '<li class="label'.$i.$separator.'"><a href="#" class="active">'.$i.' '.$custom_labels[$i].'</a></li>'; + $out .= '<li class="label'.$i.$separator.'"><a href="#" id="tblabel'.$i.'" class="active">'.$i.' '.$custom_labels[$i].'</a></li>'; } $out .= '</ul> </div>'; - $this->rc->output->add_gui_object('tb_label_popup_obj', 'tb_label_popup'); - $this->rc->output->add_footer($out); + $this->rc->output->add_gui_object('tblabelpopup_obj', 'tblabelpopup'); + rcube::write_log('lab',"tblp $out"); + $this->rc->output->add_footer($out); } }