2011-05-10 01:07:36 +01:00
|
|
|
// XXX: Should I do crazy SN.X.Y.Z.A namespace instead?
|
|
|
|
var SN_WHITELIST = SN_WHITELIST || {};
|
|
|
|
|
2013-09-10 17:52:09 +01:00
|
|
|
SN_WHITELIST.updateButtons = function () {
|
2011-05-12 00:29:35 +01:00
|
|
|
$("ul > li > a.remove_row").show();
|
|
|
|
$("ul > li > a.add_row").hide();
|
|
|
|
|
2011-05-10 01:07:36 +01:00
|
|
|
var lis = $('ul > li > input[name^="username[]"]');
|
|
|
|
if (lis.length === 1) {
|
|
|
|
$("ul > li > a.remove_row").hide();
|
|
|
|
} else {
|
|
|
|
$("ul > li > a.remove_row:first").show();
|
|
|
|
}
|
2011-05-12 00:29:35 +01:00
|
|
|
$("ul > li > a.add_row:last").show();
|
2011-05-10 01:07:36 +01:00
|
|
|
};
|
|
|
|
|
2013-09-10 17:52:09 +01:00
|
|
|
SN_WHITELIST.resetRow = function (row) {
|
2011-05-10 01:07:36 +01:00
|
|
|
$("input", row).val('');
|
|
|
|
// Make sure the default domain is the first selection
|
|
|
|
$("select option:first", row).val();
|
|
|
|
$("a.remove_row", row).show();
|
|
|
|
};
|
|
|
|
|
2013-09-10 17:52:09 +01:00
|
|
|
SN_WHITELIST.addRow = function () {
|
2011-05-10 01:07:36 +01:00
|
|
|
var row = $(this).closest("li");
|
|
|
|
var newRow = row.clone();
|
2011-05-12 01:20:24 +01:00
|
|
|
$(row).find('a.add_row').hide();
|
2011-05-10 01:07:36 +01:00
|
|
|
SN_WHITELIST.resetRow(newRow);
|
2013-09-10 17:52:09 +01:00
|
|
|
$(newRow).insertAfter(row).show("blind", "fast", function () {
|
2011-05-10 01:07:36 +01:00
|
|
|
SN_WHITELIST.updateButtons();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2013-09-10 17:52:09 +01:00
|
|
|
SN_WHITELIST.removeRow = function () {
|
2011-05-12 00:00:35 +01:00
|
|
|
var that = this;
|
|
|
|
|
|
|
|
$("#confirm-dialog").dialog({
|
|
|
|
buttons : {
|
2013-09-10 17:52:09 +01:00
|
|
|
"Confirm" : function () {
|
2011-05-12 00:00:35 +01:00
|
|
|
$(this).dialog("close");
|
2013-09-10 17:52:09 +01:00
|
|
|
$(that).closest("li").hide("blind", "fast", function () {
|
2011-05-12 00:00:35 +01:00
|
|
|
$(this).remove();
|
|
|
|
SN_WHITELIST.updateButtons();
|
|
|
|
});
|
|
|
|
},
|
2013-09-10 17:52:09 +01:00
|
|
|
"Cancel" : function () {
|
2011-05-12 00:00:35 +01:00
|
|
|
$(this).dialog("close");
|
|
|
|
}
|
|
|
|
}
|
2011-05-10 01:07:36 +01:00
|
|
|
});
|
2011-05-12 00:00:35 +01:00
|
|
|
|
|
|
|
if ($(this).closest('li').find(':input[name^=username]').val()) {
|
|
|
|
$("#confirm-dialog").dialog("open");
|
|
|
|
} else {
|
2013-09-10 17:52:09 +01:00
|
|
|
$(that).closest("li").hide("blind", "fast", function () {
|
2011-05-12 00:00:35 +01:00
|
|
|
$(this).remove();
|
|
|
|
SN_WHITELIST.updateButtons();
|
|
|
|
});
|
|
|
|
}
|
2011-05-10 01:07:36 +01:00
|
|
|
};
|
|
|
|
|
2013-09-10 17:52:09 +01:00
|
|
|
$(document).ready(function () {
|
2011-05-12 00:00:35 +01:00
|
|
|
$("#confirm-dialog").dialog({
|
|
|
|
autoOpen: false,
|
|
|
|
modal: true
|
|
|
|
});
|
|
|
|
|
2013-09-10 17:52:09 +01:00
|
|
|
$(document).on('click', '.add_row', SN_WHITELIST.addRow);
|
|
|
|
$(document).on('click', '.remove_row', SN_WHITELIST.removeRow);
|
2011-05-12 00:29:35 +01:00
|
|
|
|
|
|
|
SN_WHITELIST.updateButtons();
|
2011-05-10 01:07:36 +01:00
|
|
|
});
|