From e66a77e5601842a855963a25c3f4e229969c3392 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak <alec@alec.pl> Date: Sun, 17 Aug 2014 03:11:56 -0400 Subject: [PATCH] Fix contacts list update after adding/deleting/moving a contact (#1490028, #1490033) --- program/js/treelist.js | 72 ++++++++++++++++++++++++++++++++--- 1 files changed, 65 insertions(+), 7 deletions(-) diff --git a/program/js/treelist.js b/program/js/treelist.js index 1e60617..3a13602 100644 --- a/program/js/treelist.js +++ b/program/js/treelist.js @@ -46,6 +46,7 @@ scroll_speed: 20, save_state: false, keyboard: true, + tabexit: true, check_droptarget: function(node) { return !node.virtual; } }, p || {}); @@ -68,6 +69,8 @@ tree_state, ui_droppable, ui_draggable, + draggable_opts, + droppable_opts, list_id = (container.attr('id') || p.id_prefix || '0'), me = this; @@ -91,6 +94,8 @@ this.get_item = get_item; this.get_node = get_node; this.get_selection = get_selection; + this.is_search = is_search; + this.reset_search = reset_search; /////// startup code (constructor) @@ -470,7 +475,7 @@ /** * */ - function reset() + function reset(keep_content) { select(''); @@ -478,7 +483,24 @@ indexbyid = {}; drag_active = false; - container.html(''); + if (keep_content) { + if (draggable_opts) { + if (ui_draggable) + draggable('destroy'); + draggable(draggable_opts); + } + + if (droppable_opts) { + if (ui_droppable) + droppable('destroy'); + droppable(droppable_opts); + } + + update_data(); + } + else { + container.html(''); + } reset_search(); } @@ -501,11 +523,17 @@ var li, sli; if (!node.virtual && !node.deleted && String(node.text).toLowerCase().indexOf(q) >= 0 && hits.indexOf(node.id) < 0) { li = id2dom(node.id); + + // skip already filtered nodes + if (li.data('filtered')) + return; + sli = $('<li>') .attr('id', li.attr('id') + '--xsR') .attr('class', li.attr('class')) .addClass('searchresult__') - .append(li.children().first().clone(true, true)) + // append all elements like links and inputs, but not sub-trees + .append(li.children(':not(div.treetoggle,ul)').clone(true, true)) .appendTo(container); hits.push(node.id); } @@ -544,7 +572,7 @@ searchfield.val(''); $(container).children('li.searchresult__').remove(); - $(container).children('li').show(); + $(container).children('li').filter(function() { return !$(this).data('filtered'); }).show(); search_active = false; @@ -553,6 +581,14 @@ if (selection) select(selection); + } + + /** + * + */ + function is_search() + { + return search_active; } /** @@ -775,7 +811,7 @@ var target = e.target || {}, keyCode = rcube_event.get_keycode(e); - if (!has_focus || target.nodeName == 'INPUT' || target.nodeName == 'TEXTAREA' || target.nodeName == 'SELECT') + if (!has_focus || target.nodeName == 'INPUT' && keyCode != 38 && keyCode != 40 || target.nodeName == 'TEXTAREA' || target.nodeName == 'SELECT') return true; switch (keyCode) { @@ -801,7 +837,7 @@ return false; case 9: // Tab - if (p.keyboard) { + if (p.keyboard && p.tabexit) { // jump to last/first item to move focus away from the treelist widget by tab var limit = rcube_event.get_modifier(e) == SHIFT_KEY ? 'first' : 'last'; focus_noscroll(container.find('li[role=treeitem]:has(a)')[limit]().find('a:'+limit)); @@ -1043,6 +1079,16 @@ { if (!opts) opts = {}; + if ($.type(opts) == 'string') { + if (opts == 'destroy') { + ui_droppable = null; + } + $('li:not(.virtual)', container).droppable(opts); + return this; + } + + droppable_opts = opts; + var my_opts = $.extend({ greedy: true, tolerance: 'pointer', @@ -1070,7 +1116,7 @@ opts.over(e, ui); }; - $(selector ? selector : 'li:not(.virtual)', container).droppable(my_opts); + $('li:not(.virtual)', container).droppable(my_opts); return this; } @@ -1084,11 +1130,23 @@ { if (!opts) opts = {}; + if ($.type(opts) == 'string') { + if (opts == 'destroy') { + ui_draggable = null; + } + $('li:not(.virtual)', container).draggable(opts); + return this; + } + + draggable_opts = opts; + var my_opts = $.extend({ appendTo: 'body', + revert: 'invalid', iframeFix: true, addClasses: false, cursorAt: {left: -20, top: 5}, + create: function(e, ui) { ui_draggable = ui; }, helper: function(e) { return $('<div>').attr('id', 'rcmdraglayer') .text($.trim($(e.target).first().text())); -- Gitblit v1.9.1