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