diff --git a/www/themes/new/css/datatables_custom.css b/www/themes/new/css/datatables_custom.css index fa50a08c5..973704430 100644 --- a/www/themes/new/css/datatables_custom.css +++ b/www/themes/new/css/datatables_custom.css @@ -495,3 +495,14 @@ color: #DDD; background-color: #222; } + +/* Highlight rows that are marked via the checkbox column */ +table.dataTable tbody tr.row-marked, +table.display tbody tr.row-marked { + background-color: #e8f2ff !important; +} + +table.dataTable tbody tr.row-marked td, +table.display tbody tr.row-marked td { + background-color: #e8f2ff !important; +} diff --git a/www/themes/new/js/scripts.js b/www/themes/new/js/scripts.js index 22a3f86c2..1a5d590e2 100644 --- a/www/themes/new/js/scripts.js +++ b/www/themes/new/js/scripts.js @@ -133,9 +133,76 @@ $(function() { $("body").css("overflow", "visible"); }); - -}); + /* Toggle background for rows that are marked via checkboxes */ + var markedRowTableIds = [ + "angebote", + "angeboteinbearbeitung", + "auftraege", + "auftraegeoffene", + "auftraegeoffeneauto", + "auftraegeinbearbeitung", + "rechnungen", + "rechnungenoffene", + "rechnungeninbearbeitung", + "lieferscheine", + "lieferscheineoffene", + "lieferscheineinbearbeitung", + "mahnwesen_list" + ]; + + function markSelectedRows($table) { + $table.find("tbody tr").each(function(){ + var $row = $(this); + var isChecked = $row.find('input[type="checkbox"]:checked').length > 0; + $row.toggleClass("row-marked", isChecked); + }); + } + + function isMarkedTable($table){ + var id = $table.attr("id"); + return id && markedRowTableIds.indexOf(id) !== -1; + } + + function bindMarkedRowHighlight(selector) { + var $table = selector instanceof jQuery ? selector : $(selector); + + if(!$table.length || !isMarkedTable($table)){ + return; + } + + if($table.data("rowMarkedBound")){ + markSelectedRows($table); + return; + } + + $table.data("rowMarkedBound", true); + + var refresh = function(){ + markSelectedRows($table); + }; + + $table.on("change", "tbody input[type=\"checkbox\"]", refresh); + $table.on("draw.dt", refresh); + refresh(); + } + + function refreshMarkedRowTables(){ + markedRowTableIds.forEach(function(id){ + bindMarkedRowHighlight("#" + id); + }); + } + + refreshMarkedRowTables(); + + $(document).on("init.dt", function(e, settings){ + bindMarkedRowHighlight($(settings.nTable)); + }); + $(document).on("change", "#auswahlalle", function(){ + window.setTimeout(refreshMarkedRowTables, 0); + }); + +});