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:
parent
f98d8f7fc5
commit
76219b025b
|
@ -362,35 +362,25 @@
|
|||
var $tr = $(this);
|
||||
var $table = $tr.closest('table.multiselect');
|
||||
var data = self.icinga.ui.getSelectionKeys($table);
|
||||
var multisel = $table.hasClass('multiselect');
|
||||
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.preventDefault();
|
||||
|
||||
if (icinga.events.handleExternalTarget($tr)) {
|
||||
// link handled externally
|
||||
return false;
|
||||
}
|
||||
if (multisel && !data) {
|
||||
icinga.logger.error('A table with multiselection must define the attribute "data-icinga-multiselect-data"');
|
||||
if (!data) {
|
||||
icinga.logger.error('multiselect table has no data-icinga-multiselect-data');
|
||||
return;
|
||||
}
|
||||
if (multisel && !url) {
|
||||
icinga.logger.error('A table with multiselection must define the attribute "data-icinga-multiselect-url"');
|
||||
if (!url) {
|
||||
icinga.logger.error('multiselect table has no data-icinga-multiselect-url');
|
||||
return;
|
||||
}
|
||||
|
||||
// update selection
|
||||
if ((event.ctrlKey || event.metaKey) && multisel) {
|
||||
if (event.ctrlKey || event.metaKey) {
|
||||
icinga.ui.toogleTableRowSelection($tr);
|
||||
// multi selection
|
||||
} else if (event.shiftKey && multisel) {
|
||||
} else if (event.shiftKey) {
|
||||
// range selection
|
||||
icinga.ui.addTableRowRangeSelection($tr);
|
||||
} else {
|
||||
|
@ -400,28 +390,27 @@
|
|||
// focus only the current table.
|
||||
icinga.ui.focusTable($table[0]);
|
||||
|
||||
// update url
|
||||
var $target = self.getLinkTargetFor($tr);
|
||||
if (multisel) {
|
||||
var $trs = $table.find('tr[href].active');
|
||||
if ($trs.length > 1) {
|
||||
var queries = [];
|
||||
var selectionData = icinga.ui.getSelectionSetData($trs, data);
|
||||
var query = icinga.ui.selectionDataToQuery(selectionData, data, icinga);
|
||||
icinga.loader.loadUrl(url + '?' + query, $target);
|
||||
icinga.ui.storeSelectionData(selectionData);
|
||||
} else if ($trs.length === 1) {
|
||||
// display a single row
|
||||
icinga.loader.loadUrl($tr.attr('href'), $target);
|
||||
icinga.ui.storeSelectionData($tr.attr('href'));
|
||||
} else {
|
||||
// display nothing
|
||||
icinga.loader.loadUrl('#');
|
||||
icinga.ui.storeSelectionData(null);
|
||||
}
|
||||
} else {
|
||||
|
||||
var $trs = $table.find('tr[href].active');
|
||||
if ($trs.length > 1) {
|
||||
var selectionData = icinga.ui.getSelectionSetData($trs, data);
|
||||
var query = icinga.ui.selectionDataToQuery(selectionData);
|
||||
icinga.loader.loadUrl(url + '?' + query, $target);
|
||||
icinga.ui.storeSelectionData(selectionData);
|
||||
} else if ($trs.length === 1) {
|
||||
// display a single row
|
||||
$tr = $trs.first();
|
||||
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;
|
||||
},
|
||||
|
||||
|
@ -441,6 +430,14 @@
|
|||
var formerUrl;
|
||||
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
|
||||
if (href.match(remote)) {
|
||||
return true;
|
||||
|
|
Loading…
Reference in New Issue