Unify some datatable utility code

This commit is contained in:
emanuele-f 2016-12-19 13:15:33 +01:00 committed by Simone Mainardi
parent 6db583f373
commit 79ac40b5fe
4 changed files with 52 additions and 29 deletions

46
httpdocs/js/datatable_utils.js vendored Normal file
View file

@ -0,0 +1,46 @@
// 2016 - ntop.org
function datatableRemoveEmptyRow(table) {
$("tbody tr.emptyRow", $(table)).remove();
}
function datatableAddEmptyRow(table, empty_str) {
$("tbody", $(table)).html('<tr class="emptyRow"><td colspan="3"><i>' + empty_str + '</i></td></tr>');
}
function datatableIsEmpty(table) {
return $("tr:not(.emptyRow)", $(table)).length == 1;
}
function datatableGetByForm(form) {
return $("table", $("#dt-top-details", $(form)).parent())
}
function datatableUndoAddRow(new_row, empty_str, bt_to_enable) {
if (bt_to_enable)
$(bt_to_enable).removeAttr("disabled");
var form = $(new_row).closest("form");
$(new_row).remove();
aysUpdateForm(form);
var dt = datatableGetByForm(form);
if (datatableIsEmpty(dt))
datatableAddEmptyRow(dt, empty_str);
}
function datatableForEachRow(table, callbacks) {
$("tr:not(:first)", table).each(function(row_i) {
if(typeof callbacks === 'function') {
callbacks.bind(this)(row_i);
} else {
var i;
for (i=0; i<callbacks.length; i++)
callbacks[i].bind(this)(row_i);
}
});
}
function datatableAddDeleteButtonCallback(td_idx, callback_str, label) {
$("td:nth-child("+td_idx+")", $(this)).html('<a href="javascript:void(0)" class="add-on" onclick="' + callback_str + '" role="button"><span class="label label-danger">' + label + '</span></a>');
}