From 1a3f4f5c2aaa0329ba28f11bf15a294358307341 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Fri, 16 Jan 2015 16:47:53 +0100 Subject: [PATCH] Feature #3471: Deleted elements from tables can now be deselected --- src/sunstone/public/js/sunstone.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/sunstone/public/js/sunstone.js b/src/sunstone/public/js/sunstone.js index 17118d13a7..edfef7b60c 100644 --- a/src/sunstone/public/js/sunstone.js +++ b/src/sunstone/public/js/sunstone.js @@ -7329,14 +7329,31 @@ function setupResourceTableSelect(section, context_id, options) { $(section).on("click", '#selected_ids_row_'+context_id+' span.fa.fa-times', function() { var row_id = $(this).parent("span").attr('row_id'); + var found = false; + // TODO: improve preformance, linear search $.each(dataTable_select.fnGetData(), function(index, row){ if(row[options.id_index] == row_id){ + found = true; row_click(dataTable_select.fnGetNodes(index), row); return false; } }); + if (!found){ + var ids = $('#selected_ids_row_'+context_id, section).data("ids"); + delete ids[row_id]; + $('#selected_ids_row_'+context_id+' span[row_id="'+row_id+'"]', section).remove(); + + if ($.isEmptyObject(ids)){ + $('#selected_resource_multiple_'+context_id, section).hide(); + $('#select_resource_multiple_'+context_id, section).show(); + } else { + $('#selected_resource_multiple_'+context_id, section).show(); + $('#select_resource_multiple_'+context_id, section).hide(); + } + } + }); } else{