Skip to content

Commit 393d97f

Browse files
committed
Multiple FTP Account Support
1 parent 0797ddf commit 393d97f

File tree

3 files changed

+262
-32
lines changed

3 files changed

+262
-32
lines changed

web/js/pages/add.web.js

Lines changed: 139 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,158 @@
1-
//
2-
//
3-
// Updates ftp username dynamically, showing its prefix
41
App.Actions.WEB.update_ftp_username_hint = function(elm, hint) {
52
if (hint.trim() == '') {
63
$(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+
98
if (hint.indexOf(GLOBAL.FTP_USER_PREFIX) == 0) {
109
hint = hint.slice(GLOBAL.FTP_USER_PREFIX.length, hint.length);
1110
}
12-
11+
$(elm).parent().find('.v-ftp-user').val(hint);
1312
$(elm).parent().find('.hint').text(GLOBAL.FTP_USER_PREFIX + hint);
1413
}
1514

16-
//
17-
// listener that triggers ftp user hint updating
1815
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) {
2636
clearTimeout(window.frp_usr_tmt);
2737
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());
3041
}, 100);
3142
});
3243
}
3344

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+
34154
//
35155
// Page entry point
36-
// Trigger listeners
37156
App.Listeners.WEB.keypress_ftp_username();
157+
App.Listeners.WEB.keypress_ftp_path();
158+
App.Listeners.WEB.keypress_domain_name();

web/js/pages/edit.web.js

Lines changed: 120 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,138 @@
11
App.Actions.WEB.update_ftp_username_hint = function(elm, hint) {
22
if (hint.trim() == '') {
33
$(elm).parent().find('.hint').html('');
4-
}
4+
}
5+
6+
hint = hint.replace(/[^\w\d]/gi, '');
7+
58
if (hint.indexOf(GLOBAL.FTP_USER_PREFIX) == 0) {
69
hint = hint.slice(GLOBAL.FTP_USER_PREFIX.length, hint.length);
710
}
11+
$(elm).parent().find('.v-ftp-user').val(hint);
812
$(elm).parent().find('.hint').text(GLOBAL.FTP_USER_PREFIX + hint);
913
}
1014

1115
App.Listeners.WEB.keypress_ftp_username = function() {
12-
var ref = $('input[name="v_ftp_user"]');
13-
var current_val = ref.val();
14-
if (current_val.trim() != '') {
15-
App.Actions.DB.update_ftp_username_hint(ref, current_val);
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+
//
35+
//
36+
37+
App.Actions.WEB.update_ftp_path_hint = function(elm, hint) {
38+
if (hint.trim() == '') {
39+
$(elm).parent().find('.v-ftp-path-hint').html('');
40+
}
41+
42+
if (hint[0] != '/') {
43+
hint = '/' + hint;
44+
}
45+
46+
hint = hint.replace(/\/(\/+)/g, '/');
47+
48+
$(elm).parent().find('.v-ftp-path-hint').text(hint);
49+
}
50+
51+
App.Listeners.WEB.keypress_ftp_path = function() {
52+
var ftp_path_inputs = $('.v-ftp-path');
53+
$.each(ftp_path_inputs, function(i, ref) {
54+
var ref = $(ref);
55+
var current_val = ref.val();
56+
if (current_val.trim() != '') {
57+
App.Actions.WEB.update_ftp_path_hint(ref, current_val);
58+
}
59+
60+
ref.bind('keypress', function(evt) {
61+
clearTimeout(window.frp_usr_tmt);
62+
window.frp_usr_tmt = setTimeout(function() {
63+
var elm = $(evt.target);
64+
App.Actions.WEB.update_ftp_path_hint(elm, $(elm).val());
65+
}, 100);
66+
});
67+
});
68+
}
69+
70+
//
71+
//
72+
App.Actions.WEB.add_ftp_user_form = function() {
73+
var ref = $('#templates').find('.ftptable').clone(true);
74+
var index = $('.data-col2 .ftptable').length + 1;
75+
76+
ref.find('input').each(function(i, elm) {
77+
var attr_value = $(elm).attr('name').replace('%INDEX%', index);
78+
$(elm).attr('name', attr_value);
79+
});
80+
81+
ref.find('.ftp-user-number').text(index);
82+
83+
$('.data-col2 .ftptable:last').after(ref);
84+
85+
var index = 1;
86+
$('.data-col2 .ftp-user-number:visible').each(function(i, o) {
87+
$(o).text(index);
88+
index += 1;
89+
});
90+
}
91+
92+
App.Actions.WEB.remove_ftp_user = function(elm) {
93+
var ref = $(elm).parents('.ftptable');
94+
ref.find('.v-ftp-user-deleted').val('1');
95+
if (ref.find('.v-ftp-user-is-new').val() == 1) {
96+
ref.remove();
97+
return true;
1698
}
99+
ref.removeClass('ftptable-nrm');
100+
ref.hide();
17101

18-
ref.bind('keypress', function(evt) {
19-
clearTimeout(window.frp_usr_tmt);
20-
window.frp_usr_tmt = setTimeout(function() {
21-
var elm = $(evt.target);
22-
App.Actions.WEB.update_ftp_username_hint(elm, $(elm).val());
23-
}, 100);
102+
var index = 1;
103+
$('.data-col2 .ftp-user-number:visible').each(function(i, o) {
104+
$(o).text(index);
105+
index += 1;
24106
});
107+
108+
if ($('.ftptable-nrm:visible').length == 0) {
109+
$('.add-new-ftp-user-button').hide();
110+
$('input[name="v_ftp"]').attr('checked', false);
111+
}
112+
}
113+
114+
App.Actions.WEB.toggle_additional_ftp_accounts = function(elm) {
115+
if ($(elm).attr('checked')) {
116+
$('.ftptable-nrm, .v-add-new-user, .add-new-ftp-user-button').show();
117+
$('.ftptable-nrm').each(function(i, elm) {
118+
var login = $(elm).find('.v-ftp-user');
119+
if (login.val().trim() != '') {
120+
$(elm).find('.v-ftp-user-deleted').val(0);
121+
}
122+
});
123+
}
124+
else {
125+
$('.ftptable-nrm, .v-add-new-user, .add-new-ftp-user-button').hide();
126+
$('.ftptable-nrm').each(function(i, elm) {
127+
var login = $(elm).find('.v-ftp-user');
128+
if (login.val().trim() != '') {
129+
$(elm).find('.v-ftp-user-deleted').val(1);
130+
}
131+
});
132+
}
25133
}
26134

27135
//
28136
// Page entry point
29137
App.Listeners.WEB.keypress_ftp_username();
138+
App.Listeners.WEB.keypress_ftp_path();

web/js/templates.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ var Templator = function()
6666
{
6767
'undefined' == typeof App.Templates._indexes[key] ? App.Templates._indexes[key] = {} : false;
6868
'undefined' == typeof App.Templates._indexes[key][ref_key] ?
69-
App.Templates._indexes[key][ref_key] = {} : false;
69+
App.Templates._indexes[key][ref_key] = {} : false;
7070

7171
jQuery(tpl).each(function(index, o) {
7272
if (':' == o.charAt(0)) {
@@ -84,8 +84,8 @@ var Templator = function()
8484

8585
Templator.getTemplate = function(ns, key){
8686
return [
87-
App.Templates._indexes[ns][key],
88-
App.Templates.html[ns][key].slice(0)
87+
App.Templates._indexes[ns][key],
88+
App.Templates.html[ns][key].slice(0)
8989
];
9090
}
9191
// init templator

0 commit comments

Comments
 (0)