js/events: multiple multiselect fixes

* Removed obsolete checks (event is only triggered for multiselect tables)
* allows deselecting last row, closing "detail view"
* fix bug when unselecting one of two rows, it used to keep the wrong one
* play nice with other involved non-row-level links
This commit is contained in:
Thomas Gelf 2014-06-20 13:43:18 +02:00
parent f98d8f7fc5
commit 76219b025b

View File

@ -362,35 +362,25 @@
var $tr = $(this); var $tr = $(this);
var $table = $tr.closest('table.multiselect'); var $table = $tr.closest('table.multiselect');
var data = self.icinga.ui.getSelectionKeys($table); var data = self.icinga.ui.getSelectionKeys($table);
var multisel = $table.hasClass('multiselect');
var url = $table.data('icinga-multiselect-url'); var url = $table.data('icinga-multiselect-url');
// When the selection points to a link, select the closest row
if ($tr.prop('tagName').toLowerCase() === 'a') {
$tr = $tr.closest('tr').first();
}
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
if (icinga.events.handleExternalTarget($tr)) { if (!data) {
// link handled externally icinga.logger.error('multiselect table has no data-icinga-multiselect-data');
return false;
}
if (multisel && !data) {
icinga.logger.error('A table with multiselection must define the attribute "data-icinga-multiselect-data"');
return; return;
} }
if (multisel && !url) { if (!url) {
icinga.logger.error('A table with multiselection must define the attribute "data-icinga-multiselect-url"'); icinga.logger.error('multiselect table has no data-icinga-multiselect-url');
return; return;
} }
// update selection // update selection
if ((event.ctrlKey || event.metaKey) && multisel) { if (event.ctrlKey || event.metaKey) {
icinga.ui.toogleTableRowSelection($tr); icinga.ui.toogleTableRowSelection($tr);
// multi selection // multi selection
} else if (event.shiftKey && multisel) { } else if (event.shiftKey) {
// range selection // range selection
icinga.ui.addTableRowRangeSelection($tr); icinga.ui.addTableRowRangeSelection($tr);
} else { } else {
@ -400,28 +390,27 @@
// focus only the current table. // focus only the current table.
icinga.ui.focusTable($table[0]); icinga.ui.focusTable($table[0]);
// update url
var $target = self.getLinkTargetFor($tr); var $target = self.getLinkTargetFor($tr);
if (multisel) {
var $trs = $table.find('tr[href].active'); var $trs = $table.find('tr[href].active');
if ($trs.length > 1) { if ($trs.length > 1) {
var queries = []; var selectionData = icinga.ui.getSelectionSetData($trs, data);
var selectionData = icinga.ui.getSelectionSetData($trs, data); var query = icinga.ui.selectionDataToQuery(selectionData);
var query = icinga.ui.selectionDataToQuery(selectionData, data, icinga); icinga.loader.loadUrl(url + '?' + query, $target);
icinga.loader.loadUrl(url + '?' + query, $target); icinga.ui.storeSelectionData(selectionData);
icinga.ui.storeSelectionData(selectionData); } else if ($trs.length === 1) {
} else if ($trs.length === 1) { // display a single row
// display a single row $tr = $trs.first();
icinga.loader.loadUrl($tr.attr('href'), $target);
icinga.ui.storeSelectionData($tr.attr('href'));
} else {
// display nothing
icinga.loader.loadUrl('#');
icinga.ui.storeSelectionData(null);
}
} else {
icinga.loader.loadUrl($tr.attr('href'), $target); icinga.loader.loadUrl($tr.attr('href'), $target);
icinga.ui.storeSelectionData($tr.attr('href'));
} else {
// display nothing
if ($target.attr('id') === 'col2') {
icinga.ui.layout1col();
}
icinga.ui.storeSelectionData(null);
} }
return false; return false;
}, },
@ -441,6 +430,14 @@
var formerUrl; var formerUrl;
var remote = /^(?:[a-z]+:)\/\//; var remote = /^(?:[a-z]+:)\/\//;
// Ignore clicks on multiselect table inner links while key pressed
if ((event.ctrlKey || event.metaKey || event.shiftKey) &&
! $a.is('tr[href]') && $a.closest('table.multiselect').length > 0 &&
$a.closest('tr[href]').length > 0)
{
return self.rowSelected.call($a.closest('tr[href]'), event);
}
// Let remote links pass through // Let remote links pass through
if (href.match(remote)) { if (href.match(remote)) {
return true; return true;