|
1 | | -// |
2 | | -// |
3 | | -// Updates ftp username dynamically, showing its prefix |
4 | 1 | App.Actions.WEB.update_ftp_username_hint = function(elm, hint) { |
5 | 2 | if (hint.trim() == '') { |
6 | 3 | $(elm).parent().find('.hint').html(''); |
7 | | - } |
8 | | - // remove prefix from value in order to eliminate duplicates |
| 4 | + } |
| 5 | + |
| 6 | + hint = hint.replace(/[^\w\d]/gi, ''); |
| 7 | + |
9 | 8 | if (hint.indexOf(GLOBAL.FTP_USER_PREFIX) == 0) { |
10 | 9 | hint = hint.slice(GLOBAL.FTP_USER_PREFIX.length, hint.length); |
11 | 10 | } |
12 | | - |
| 11 | + $(elm).parent().find('.v-ftp-user').val(hint); |
13 | 12 | $(elm).parent().find('.hint').text(GLOBAL.FTP_USER_PREFIX + hint); |
14 | 13 | } |
15 | 14 |
|
16 | | -// |
17 | | -// listener that triggers ftp user hint updating |
18 | 15 | App.Listeners.WEB.keypress_ftp_username = function() { |
19 | | - var ref = $('input[name="v_ftp_user"]'); |
20 | | - var current_val = ref.val(); |
21 | | - if (current_val.trim() != '') { |
22 | | - App.Actions.DB.update_ftp_username_hint(ref, current_val); |
23 | | - } |
24 | | - |
25 | | - ref.bind('keypress input', function(evt) { |
| 16 | + var ftp_user_inputs = $('.v-ftp-user'); |
| 17 | + $.each(ftp_user_inputs, function(i, ref) { |
| 18 | + var ref = $(ref); |
| 19 | + var current_val = ref.val(); |
| 20 | + if (current_val.trim() != '') { |
| 21 | + App.Actions.WEB.update_ftp_username_hint(ref, current_val); |
| 22 | + } |
| 23 | + |
| 24 | + ref.bind('keypress', function(evt) { |
| 25 | + clearTimeout(window.frp_usr_tmt); |
| 26 | + window.frp_usr_tmt = setTimeout(function() { |
| 27 | + var elm = $(evt.target); |
| 28 | + App.Actions.WEB.update_ftp_username_hint(elm, $(elm).val()); |
| 29 | + }, 100); |
| 30 | + }); |
| 31 | + }); |
| 32 | +} |
| 33 | + |
| 34 | +App.Listeners.WEB.keypress_domain_name = function() { |
| 35 | + $('#v_domain').bind('keypress', function(evt) { |
26 | 36 | clearTimeout(window.frp_usr_tmt); |
27 | 37 | window.frp_usr_tmt = setTimeout(function() { |
28 | | - var elm = $(evt.target); |
29 | | - App.Actions.WEB.update_ftp_username_hint(elm, $(elm).val()); |
| 38 | + //var elm = $(evt.target); |
| 39 | + //App.Actions.WEB.update_ftp_username_hint(elm, $(elm).val()); |
| 40 | + var domain = $('.ftp-path-prefix').text(GLOBAL.FTP_USER_PREPATH + '/' + $('#v_domain').val()); |
30 | 41 | }, 100); |
31 | 42 | }); |
32 | 43 | } |
33 | 44 |
|
| 45 | +// |
| 46 | +// |
| 47 | + |
| 48 | +App.Actions.WEB.update_ftp_path_hint = function(elm, hint) { |
| 49 | + if (hint.trim() == '') { |
| 50 | + $(elm).parent().find('.v-ftp-path-hint').html(''); |
| 51 | + } |
| 52 | + |
| 53 | + if (hint[0] != '/') { |
| 54 | + hint = '/' + hint; |
| 55 | + } |
| 56 | + hint = hint.replace(/\/(\/+)/g, '/'); |
| 57 | + |
| 58 | + $(elm).parent().find('.v-ftp-path-hint').text(hint); |
| 59 | +} |
| 60 | + |
| 61 | +App.Listeners.WEB.keypress_ftp_path = function() { |
| 62 | + var ftp_path_inputs = $('.v-ftp-path'); |
| 63 | + $.each(ftp_path_inputs, function(i, ref) { |
| 64 | + var ref = $(ref); |
| 65 | + var current_val = ref.val(); |
| 66 | + if (current_val.trim() != '') { |
| 67 | + App.Actions.WEB.update_ftp_path_hint(ref, current_val); |
| 68 | + } |
| 69 | + |
| 70 | + ref.bind('keypress', function(evt) { |
| 71 | + clearTimeout(window.frp_usr_tmt); |
| 72 | + window.frp_usr_tmt = setTimeout(function() { |
| 73 | + var elm = $(evt.target); |
| 74 | + App.Actions.WEB.update_ftp_path_hint(elm, $(elm).val()); |
| 75 | + }, 100); |
| 76 | + }); |
| 77 | + }); |
| 78 | +} |
| 79 | + |
| 80 | +// |
| 81 | +// |
| 82 | +App.Actions.WEB.add_ftp_user_form = function() { |
| 83 | + var ref = $('#templates').find('.ftptable').clone(true); |
| 84 | + var index = $('.data-col2 .ftptable').length + 1; |
| 85 | + |
| 86 | + ref.find('input').each(function(i, elm) { |
| 87 | + var attr_value = $(elm).attr('name').replace('%INDEX%', index); |
| 88 | + $(elm).attr('name', attr_value); |
| 89 | + }); |
| 90 | + |
| 91 | + ref.find('.ftp-user-number').text(index); |
| 92 | + |
| 93 | + $('.data-col2 .ftptable:last').after(ref); |
| 94 | + |
| 95 | + var index = 1; |
| 96 | + $('.data-col2 .ftp-user-number:visible').each(function(i, o) { |
| 97 | + $(o).text(index); |
| 98 | + index += 1; |
| 99 | + }); |
| 100 | +} |
| 101 | + |
| 102 | +App.Actions.WEB.remove_ftp_user = function(elm) { |
| 103 | + var ref = $(elm).parents('.ftptable'); |
| 104 | + ref.remove(); |
| 105 | + |
| 106 | + var index = 1; |
| 107 | + $('.data-col2 .ftp-user-number:visible').each(function(i, o) { |
| 108 | + $(o).text(index); |
| 109 | + index += 1; |
| 110 | + }); |
| 111 | + |
| 112 | + if ($('.ftptable-nrm:visible').length == 0) { |
| 113 | + $('.v-add-new-user').hide(); |
| 114 | + $('input[name="v_ftp"]').attr('checked', false); |
| 115 | + } |
| 116 | +} |
| 117 | + |
| 118 | + |
| 119 | +App.Actions.WEB.toggle_additional_ftp_accounts = function(elm) { |
| 120 | + if ($(elm).attr('checked')) { |
| 121 | + $('.ftptable-nrm, .v-add-new-user, .add-new-ftp-user-button').show(); |
| 122 | + $('.ftptable-nrm').each(function(i, elm) { |
| 123 | + var login = $(elm).find('.v-ftp-user'); |
| 124 | + if (login.val().trim() != '') { |
| 125 | + $(elm).find('.v-ftp-user-deleted').val(0); |
| 126 | + } |
| 127 | + }); |
| 128 | + } |
| 129 | + else { |
| 130 | + $('.ftptable-nrm, .v-add-new-user, .add-new-ftp-user-button').hide(); |
| 131 | + $('.ftptable-nrm').each(function(i, elm) { |
| 132 | + var login = $(elm).find('.v-ftp-user'); |
| 133 | + if (login.val().trim() != '') { |
| 134 | + $(elm).find('.v-ftp-user-deleted').val(1); |
| 135 | + } |
| 136 | + }); |
| 137 | + } |
| 138 | + |
| 139 | + if ($('.ftptable-nrm:visible').length == 0) { |
| 140 | + var ref = $('#templates').find('.ftptable').clone(true); |
| 141 | + var index = $('.data-col2 .ftptable').length + 1; |
| 142 | + |
| 143 | + ref.find('input').each(function(i, elm) { |
| 144 | + var attr_value = $(elm).attr('name').replace('%INDEX%', index); |
| 145 | + $(elm).attr('name', attr_value); |
| 146 | + }); |
| 147 | + |
| 148 | + ref.find('.ftp-user-number').text(index); |
| 149 | + |
| 150 | + $('.v-add-new-user').parent('tr').prev().find('td').html(ref); |
| 151 | + } |
| 152 | +} |
| 153 | + |
34 | 154 | // |
35 | 155 | // Page entry point |
36 | | -// Trigger listeners |
37 | 156 | App.Listeners.WEB.keypress_ftp_username(); |
| 157 | +App.Listeners.WEB.keypress_ftp_path(); |
| 158 | +App.Listeners.WEB.keypress_domain_name(); |
0 commit comments