diff --git a/plugins/kolab_tags/kolab_tags.js b/plugins/kolab_tags/kolab_tags.js index df2f6df3..e999b177 100644 --- a/plugins/kolab_tags/kolab_tags.js +++ b/plugins/kolab_tags/kolab_tags.js @@ -1,1269 +1,1269 @@ /** * Kolab Tags plugin * * @author Aleksander Machniak * * @licstart The following is the entire license notice for the * JavaScript code in this file. * * Copyright (C) 2014, Kolab Systems AG * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . * * @licend The above is the entire license notice * for the JavaScript code in this file. */ window.rcmail && rcmail.addEventListener('init', function() { if (/^(mail|notes|tasks)$/.test(rcmail.task)) { var msg_view = rcmail.env.action == 'show' || rcmail.env.action == 'preview'; if (!msg_view && rcmail.env.action) { return; } // load tags cloud if (rcmail.gui_objects.taglist) { // Tags for kolab_notes plugin have to be initialized via an event if (rcmail.task == 'notes' && !window.kolabnotes) { rcmail.addEventListener('kolab-notes-init', load_tags); } else { load_tags(); } } // display tags in message subject (message window) if (msg_view) { rcmail.enable_command('tag-add', true); rcmail.enable_command('tag-remove', 'tag-remove-all', rcmail.env.tags.length); message_tags(rcmail.env.message_tags); } // register events related to messages list if (rcmail.message_list) { rcmail.addEventListener('listupdate', message_list_update_tags); rcmail.addEventListener('requestsearch', search_request); rcmail.addEventListener('requestlist', search_request); rcmail.message_list.addEventListener('select', function(o) { message_list_select(o); }); } // register commands rcmail.register_command('manage-tags', function() { manage_tags(); }, true); rcmail.register_command('reset-tags', function() { reset_tags(); }); rcmail.register_command('tag-add', function(props, obj, event) { tag_add(props, obj, event); }); rcmail.register_command('tag-remove', function(props, obj, event) { tag_remove(props, obj, event); }); rcmail.register_command('tag-remove-all', function() { tag_remove('*'); }); // Disable tag functionality in contextmenu in Roundcube < 1.4 if (!rcmail.env.rcversion) { rcmail.addEventListener('menu-open', function(e) { if (e.name == 'rcm_markmessagemenu') { $.each(['add', 'remove', 'remove-all'], function() { $('a.cmd_tag-' + this).parent().hide(); }); } }); } // Set activation state for contextmenu entries related with tags management else { rcmail.addEventListener('contextmenu_init', function(menu) { if (menu.menu_name == 'folderlist') { menu.addEventListener('activate', function(p) { if (p.command == 'manage-tags') { return true; } if (p.command == 'reset-tags') { return !!(tagsfilter.length && main_list_widget()); } }); } }); } // ajax response handler rcmail.addEventListener('plugin.kolab_tags', update_tags); // select current messages list filter, this need to be done here // because we modify $_SESSION['search_filter'] if (rcmail.env.search_filter_selected && rcmail.gui_objects.search_filter) { $(rcmail.gui_objects.search_filter).val(rcmail.env.search_filter_selected) // update selection in decorated select .filter('.decorated').each(function() { var title = $('option:selected', this).text(); $('a.menuselector span', $(this).parent()).text(title); }); } // Allow other plugins to update tags list rcmail.addEventListener('kolab-tags-counts', update_counts) .addEventListener('kolab-tags-refresh', refresh_tags); } }); var tag_selector_element, tag_form_data, tag_form_save_func, tagsfilter = [], tagscounts = [], reset_css = {color: '', backgroundColor: ''}; function main_list_widget() { if (rcmail.task == 'mail' && rcmail.message_list) return rcmail.message_list; if (rcmail.task == 'notes' && rcmail.noteslist) return rcmail.noteslist; if (rcmail.task == 'tasks' && rcmail.gui_objects.resultlist) return rcmail.gui_objects.resultlist; } // fills tag cloud with tags list function load_tags() { var ul = $('#taglist'), clickable = !!main_list_widget(); $.each(rcmail.env.tags, function(i, tag) { var li = add_tag_element(ul, tag, clickable); // remember default color/bg of unselected tag element if (!i) tag_css = li.css(['color', 'background-color']); if (rcmail.env.selected_tags && $.inArray(String(tag.uid), rcmail.env.selected_tags) > -1) { li.addClass('selected'); tag_set_color(li, tag); tagsfilter.push(String(tag.uid)); } }); rcmail.triggerEvent('kolab-tags-update', {}); rcmail.enable_command('reset-tags', tagsfilter.length && clickable); } function add_tag_element(list, tag, clickable) { var element = $('
  • ').attr('class', tag_class_name(tag)) .text(tag.name).data('tag', tag.uid) .append('') .appendTo(list); if (clickable) { element.click(function(e) { var tagid = element.data('tag'); if (!tagid) return false; // reset selection on regular clicks var index = $.inArray(tagid, tagsfilter), shift = e.shiftKey || e.ctrlKey || e.metaKey, t = tag_find(tagid); if (!shift) { if (tagsfilter.length > 1) index = -1; $('li', list).removeClass('selected').css(reset_css); tagsfilter = []; } // add tag to the filter if (index < 0) { element.addClass('selected'); tag_set_color(element, t); tagsfilter.push(tagid); } else if (shift) { element.removeClass('selected').css(reset_css); tagsfilter.splice(index, 1); } apply_tags_filter(); // clear text selection in IE after shift+click if (shift && document.selection) document.selection.empty(); e.preventDefault(); return false; }); if (!$('html.touch').length) { element.draggable({ addClasses: false, cursor: 'default', cursorAt: {left: -10}, revert: 'invalid', revertDuration: 300, helper: tag_draggable_helper, start: tag_draggable_start, appendTo: 'body' }); } } return element; } function update_counts(p) { $('#taglist > li').each(function(i,li) { var elem = $(li), tagid = elem.data('tag'), tag = tag_find(tagid); count = tag && p.counter ? p.counter[tag.name] : ''; elem.children('.count').text(count ? count : ''); }); tagscounts = p.counter; } function manage_tags() { // display it as popup rcmail.tags_popup = rcmail.show_popup_dialog( '
    ', rcmail.gettext('kolab_tags.tags'), [{ text: rcmail.gettext('save'), 'class': 'mainaction save', click: function() { if (tag_form_save()) $(this).dialog('close'); } }, { text: rcmail.gettext('cancel'), 'class': 'cancel', click: function() { $(this).dialog('close'); } }], { width: 400, modal: true, classes: {'ui-dialog-content': 'formcontent'}, closeOnEscape: true, close: function(e, ui) { $(this).remove(); } } ); tag_form_data = {add: {}, 'delete': [], update: {}}; tag_form_save_func = null; var form = $('#tagsform'), select = $('select', form), buttons = [ $('