whitelistinvite.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // XXX: Should I do crazy SN.X.Y.Z.A namespace instead?
  2. var SN_WHITELIST = SN_WHITELIST || {};
  3. SN_WHITELIST.updateButtons = function () {
  4. $("ul > li > a.remove_row").show();
  5. $("ul > li > a.add_row").hide();
  6. var lis = $('ul > li > input[name^="username[]"]');
  7. if (lis.length === 1) {
  8. $("ul > li > a.remove_row").hide();
  9. } else {
  10. $("ul > li > a.remove_row:first").show();
  11. }
  12. $("ul > li > a.add_row:last").show();
  13. };
  14. SN_WHITELIST.resetRow = function (row) {
  15. $("input", row).val('');
  16. // Make sure the default domain is the first selection
  17. $("select option:first", row).val();
  18. $("a.remove_row", row).show();
  19. };
  20. SN_WHITELIST.addRow = function () {
  21. var row = $(this).closest("li");
  22. var newRow = row.clone();
  23. $(row).find('a.add_row').hide();
  24. SN_WHITELIST.resetRow(newRow);
  25. $(newRow).insertAfter(row).show("blind", "fast", function () {
  26. SN_WHITELIST.updateButtons();
  27. });
  28. };
  29. SN_WHITELIST.removeRow = function () {
  30. var that = this;
  31. $("#confirm-dialog").dialog({
  32. buttons : {
  33. "Confirm" : function () {
  34. $(this).dialog("close");
  35. $(that).closest("li").hide("blind", "fast", function () {
  36. $(this).remove();
  37. SN_WHITELIST.updateButtons();
  38. });
  39. },
  40. "Cancel" : function () {
  41. $(this).dialog("close");
  42. }
  43. }
  44. });
  45. if ($(this).closest('li').find(':input[name^=username]').val()) {
  46. $("#confirm-dialog").dialog("open");
  47. } else {
  48. $(that).closest("li").hide("blind", "fast", function () {
  49. $(this).remove();
  50. SN_WHITELIST.updateButtons();
  51. });
  52. }
  53. };
  54. $(document).ready(function () {
  55. $("#confirm-dialog").dialog({
  56. autoOpen: false,
  57. modal: true
  58. });
  59. $(document).on('click', '.add_row', SN_WHITELIST.addRow);
  60. $(document).on('click', '.remove_row', SN_WHITELIST.removeRow);
  61. SN_WHITELIST.updateButtons();
  62. });