Use JS array instead of JSON object when creating lists of items for quick actions, respect all pages

master
andryyy 2017-04-27 20:11:05 +02:00
parent 25e6339940
commit c29923d77a
1 changed files with 12 additions and 10 deletions

View File

@ -237,7 +237,7 @@ $(document).ready(function() {
$.each(data, function (i, item) { $.each(data, function (i, item) {
item.action = '<div class="btn-group">' + item.action = '<div class="btn-group">' +
'<a href="/edit.php?alias=' + encodeURI(item.address) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' + '<a href="/edit.php?alias=' + encodeURI(item.address) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
'<a href="/remove.php?alias=' + encodeURI(item.address) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-pencil"></span> ' + lang.remove + '</a>' + '<a href="/delete.php?alias=' + encodeURI(item.address) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-pencil"></span> ' + lang.remove + '</a>' +
'</div>'; '</div>';
item.chkbox = '<input type="checkbox" class="alias_item" name="sel_aliases" value="' + item.address + '" />'; item.chkbox = '<input type="checkbox" class="alias_item" name="sel_aliases" value="' + item.address + '" />';
if (item.is_catch_all == 1) { if (item.is_catch_all == 1) {
@ -273,7 +273,7 @@ $(document).ready(function() {
} }
}); });
var selected_aliases = {}; var selected_aliases = [];
$(document).on('click', 'tr', function(e) { $(document).on('click', 'tr', function(e) {
if (e.target.type == "checkbox") { if (e.target.type == "checkbox") {
@ -284,22 +284,24 @@ $(document).ready(function() {
} }
}); });
$(document).on('change', 'input[name=sel_aliases]', function() { $(document).on('change', 'input[name=sel_aliases]:checkbox', function() {
selected_aliases = {}; if ($(this).is(':checked')) {
$('input[name=sel_aliases]:checked').each(function(i) { selected_aliases.push($(this).val());
selected_aliases[i] = ($(this).val()); }
}); else {
selected_aliases.splice($.inArray($(this).val(), selected_aliases),1);
}
}); });
$(document).on('click', '#select_all_aliases', function(e) { $(document).on('click', '#select_all_aliases', function(e) {
e.preventDefault(); e.preventDefault();
var alias_chkbxs = $("input[name=sel_aliases]:visible"); var alias_chkbxs = $("input[name=sel_aliases]");
alias_chkbxs.prop("checked", !alias_chkbxs.prop("checked")).change(); alias_chkbxs.prop("checked", !alias_chkbxs.prop("checked")).change();
}); });
$(document).on('click', '#activate_selected_alias', function(e) { $(document).on('click', '#activate_selected_alias', function(e) {
e.preventDefault(); e.preventDefault();
if (Object.keys(selected_aliases).length !== 0) { if (selected_aliases.length !== 0) {
$.ajax({ $.ajax({
type: "POST", type: "POST",
dataType: "json", dataType: "json",