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