diff --git a/plugins/kolab_tags/kolab_tags.js b/plugins/kolab_tags/kolab_tags.js index 222fdf95..f189d28d 100644 --- a/plugins/kolab_tags/kolab_tags.js +++ b/plugins/kolab_tags/kolab_tags.js @@ -1,808 +1,848 @@ /** * 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 (rcmail.task == 'mail') { 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) { 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('*'); }); // 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); }); } } }); var tagsfilter = [], tag_selector_element, tag_form_data, tag_form_save_func, reset_css = {color: '', backgroundColor: ''}; // fills tag cloud with tags list function load_tags() { var ul = $('#taglist'), clickable = rcmail.message_list; $.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.enable_command('reset-tags', tagsfilter.length && clickable); } function add_tag_element(list, tag, clickable) { // @todo: .append('') var element = $('
  • ').text(tag.name).data('tag', tag.uid).appendTo(list); if (clickable) { element.click(function(e) { var item = $(this), tagid = item.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) { item.addClass('selected'); tag_set_color(item, t); tagsfilter.push(tagid); } else if (shift) { item.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; }) } return element; } 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', click: function() { if (tag_form_save()) $(this).dialog('close'); } }, { text: rcmail.gettext('cancel'), click: function() { $(this).dialog('close'); } }], { width: 400, modal: true, 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 = [ $('').val(rcmail.gettext('kolab_tags.add')) .click(function() { tag_form_dialog(); }), $('').val(rcmail.gettext('kolab_tags.edit')) .attr('disabled', true) .click(function() { tag_form_dialog((select.val())[0]); }), $('').val(rcmail.gettext('kolab_tags.delete')) .attr('disabled', true) .click(function() { $.each(select.val() || [], function(i, v) { $('option[value="' + v + '"]', select).remove(); delete tag_form_data.update[v]; delete tag_form_data.add[v]; if (!/^temp/.test(v)) tag_form_data['delete'].push(v); }); $(this).prop('disabled', true); }) ]; select.on('change', function() { var selected = $(this).val() || []; buttons[1].attr('disabled', selected.length != 1); buttons[2].attr('disabled', selected.length == 0); }); $.each(rcmail.env.tags, function(i, v) { $('