Fix more selection bugs, implement new selection on schedule table

This commit is contained in:
Duncan Sommerville 2015-08-18 18:45:55 -04:00
parent e7367c3374
commit 63f9403b11
2 changed files with 61 additions and 7 deletions

View File

@ -914,6 +914,7 @@ var AIRTIME = (function(AIRTIME) {
var tr = $(this).parent(); var tr = $(this).parent();
if (flagForDeselection) { if (flagForDeselection) {
flagForDeselection = false; flagForDeselection = false;
$previouslySelected = undefined;
mod.deselectItem(tr); mod.deselectItem(tr);
} else { } else {
mod.checkItem(tr); mod.checkItem(tr);

View File

@ -782,8 +782,8 @@ var AIRTIME = (function(AIRTIME){
"bScrollCollapseY": false "bScrollCollapseY": false
}); });
$sbTable.find("tbody").on("mousedown", "tr:not(.sb-header, .sb-footer, .sb-past, .sb-empty, :has(td.dataTables_empty))", function(ev) { $sbTable.find("tbody").on("mousedown", "tr:not(.sb-header, .sb-footer, .sb-past, .sb-empty, :has(td.dataTables_empty)) > td.sb-checkbox", function(ev) {
var $tr = $(this), var $tr = $(this).parent(),
// Get the ID of the selected row // Get the ID of the selected row
$rowId = $tr.attr("id"); $rowId = $tr.attr("id");
@ -807,6 +807,7 @@ var AIRTIME = (function(AIRTIME){
}); });
} }
} }
$tr.addClass(SB_SELECTED_CLASS); $tr.addClass(SB_SELECTED_CLASS);
$tr.find(".sb-checkbox > input").prop('checked', true); $tr.find(".sb-checkbox > input").prop('checked', true);
} else { } else {
@ -818,16 +819,68 @@ var AIRTIME = (function(AIRTIME){
$previouslySelected = $tr; $previouslySelected = $tr;
}); });
$sbTable.find("tbody").on("click", "tr:not(.sb-header, .sb-footer, .sb-past, .sb-empty, :has(td.dataTables_empty))", function(ev) { $sbTable.find("tbody").on("mousedown", "tr:not(.sb-header, .sb-footer, .sb-past, .sb-empty, :has(td.dataTables_empty)) > td:not(.sb-checkbox)", function(ev) {
var $tr = $(this).parent(),
// Get the ID of the selected row
$rowId = $tr.attr("id");
if (!$tr.hasClass(SB_SELECTED_CLASS)) {
if (ev.shiftKey && $previouslySelected !== undefined) {
if ($previouslySelected.attr("id") == $rowId) {
return;
}
// If the selected row comes before the previously selected row,
// we want to select previous rows, otherwise we select next
if ($previouslySelected.prevAll("#" + $rowId).length !== 0) {
$previouslySelected.prevUntil($tr).each(function (i, el) {
$(el).addClass(SB_SELECTED_CLASS);
$(el).find(".sb-checkbox > input").prop('checked', true);
});
} else {
$previouslySelected.nextUntil($tr).each(function (i, el) {
$(el).addClass(SB_SELECTED_CLASS);
$(el).find(".sb-checkbox > input").prop('checked', true);
});
}
} else if (!ev.ctrlKey) {
mod.selectNone();
}
$tr.addClass(SB_SELECTED_CLASS);
$tr.find(".sb-checkbox > input").prop('checked', true);
} else if (ev.ctrlKey) {
$tr.removeClass(SB_SELECTED_CLASS);
$tr.find(".sb-checkbox > input").prop('checked', false);
}
selectedRows = $("." + SB_SELECTED_CLASS);
// Remember this row so we can properly multiselect
$previouslySelected = $tr;
});
$sbTable.find("tbody").on("click", "tr:not(.sb-header, .sb-footer, .sb-past, .sb-empty, :has(td.dataTables_empty)) > td.sb-checkbox", function() {
var tr = $(this).parent();
if (flagForDeselection) { if (flagForDeselection) {
flagForDeselection = false; flagForDeselection = false;
$(this).removeClass(SB_SELECTED_CLASS); $previouslySelected = undefined;
$(this).find(".sb-checkbox > input").prop('checked', false); tr.removeClass(SB_SELECTED_CLASS);
tr.find(".sb-checkbox > input").prop('checked', false);
} else { } else {
$(this).find(".sb-checkbox > input").prop('checked', true); tr.find(".sb-checkbox > input").prop('checked', true);
}
selectedRows = $("." + SB_SELECTED_CLASS);
});
$sbTable.find("tbody").on("click", "tr:not(.sb-header, .sb-footer, .sb-past, .sb-empty, :has(td.dataTables_empty)) > td:not(.sb-checkbox)", function(e) {
var tr = $(this).parent();
if (!(e.shiftKey || e.ctrlKey)) {
mod.selectNone();
tr.addClass(SB_SELECTED_CLASS);
tr.find(".sb-checkbox > input").prop('checked', true);
$previouslySelected = tr;
} }
selectedRows = $("." + SB_SELECTED_CLASS); selectedRows = $("." + SB_SELECTED_CLASS);
mod.checkToolBarIcons();
}); });
//begin context menu initialization. //begin context menu initialization.