Skip to content

Commit c50c7b2

Browse files
committed
Updated hints to handle native browser's paste events
Hint is update in case page is reloaded and value is set (in case of form errors) Hints are now using secure inserting into DOM avoiding xss Dns record hint added
1 parent 2981759 commit c50c7b2

File tree

6 files changed

+211
-84
lines changed

6 files changed

+211
-84
lines changed

web/js/pages/add.db.js

Lines changed: 54 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,70 @@
1+
//
2+
//
3+
// Updates database username dynamically, showing its prefix
14
App.Actions.DB.update_db_username_hint = function(elm, hint) {
2-
if (hint.trim() == '') {
3-
$(elm).parent().find('.hint').html('');
4-
}
5-
if (hint.indexOf(GLOBAL.DB_USER_PREFIX) == 0) {
6-
hint = hint.slice(GLOBAL.DB_USER_PREFIX.length, hint.length);
7-
}
8-
$(elm).parent().find('.hint').html(GLOBAL.DB_USER_PREFIX + hint);
5+
if (hint.trim() == '') {
6+
$(elm).parent().find('.hint').html('');
7+
}
8+
// remove prefix from value in order to eliminate duplicates
9+
if (hint.indexOf(GLOBAL.DB_USER_PREFIX) == 0) {
10+
hint = hint.slice(GLOBAL.DB_USER_PREFIX.length, hint.length);
11+
}
12+
13+
$(elm).parent().find('.hint').text(GLOBAL.DB_USER_PREFIX + hint);
914
}
1015

16+
//
17+
//
18+
// Updates database name dynamically, showing its prefix
1119
App.Actions.DB.update_db_databasename_hint = function(elm, hint) {
12-
if (hint.trim() == '') {
13-
$(elm).parent().find('.hint').html('');
14-
}
15-
if (hint.indexOf(GLOBAL.DB_DBNAME_PREFIX) == 0) {
16-
hint = hint.slice(GLOBAL.DB_DBNAME_PREFIX.length, hint.length);
17-
}
18-
$(elm).parent().find('.hint').html(GLOBAL.DB_DBNAME_PREFIX + hint);
20+
if (hint.trim() == '') {
21+
$(elm).parent().find('.hint').html('');
22+
}
23+
// remove prefix from value in order to eliminate duplicates
24+
if (hint.indexOf(GLOBAL.DB_DBNAME_PREFIX) == 0) {
25+
hint = hint.slice(GLOBAL.DB_DBNAME_PREFIX.length, hint.length);
26+
}
27+
$(elm).parent().find('.hint').text(GLOBAL.DB_DBNAME_PREFIX + hint);
1928
}
2029

30+
//
31+
// listener that triggers database user hint updating
2132
App.Listeners.DB.keypress_db_username = function() {
22-
$('input[name="v_dbuser"]').bind('keypress', function(evt) {
23-
clearTimeout(window.frp_usr_tmt);
24-
window.frp_usr_tmt = setTimeout(function() {
25-
var elm = $(evt.target);
26-
App.Actions.DB.update_db_username_hint(elm, $(elm).val());
27-
}, 100);
28-
});
33+
var ref = $('input[name="v_dbuser"]');
34+
var current_val = ref.val();
35+
if (current_val.trim() != '') {
36+
App.Actions.DB.update_db_username_hint(ref, current_val);
37+
}
38+
39+
ref.bind('keypress input', function(evt) {
40+
clearTimeout(window.frp_usr_tmt);
41+
window.frp_usr_tmt = setTimeout(function() {
42+
var elm = $(evt.target);
43+
App.Actions.DB.update_db_username_hint(elm, $(elm).val());
44+
}, 100);
45+
});
2946
}
3047

48+
//
49+
// listener that triggers database name hint updating
3150
App.Listeners.DB.keypress_db_databasename = function() {
32-
$('input[name="v_database"]').bind('keypress', function(evt) {
33-
clearTimeout(window.frp_dbn_tmt);
34-
window.frp_dbn_tmt = setTimeout(function() {
35-
var elm = $(evt.target);
36-
App.Actions.DB.update_db_databasename_hint(elm, $(elm).val());
37-
}, 100);
38-
});
51+
var ref = $('input[name="v_database"]');
52+
var current_val = ref.val();
53+
if (current_val.trim() != '') {
54+
App.Actions.DB.update_db_databasename_hint(ref, current_val);
55+
}
56+
57+
ref.bind('keypress input', function(evt) {
58+
clearTimeout(window.frp_dbn_tmt);
59+
window.frp_dbn_tmt = setTimeout(function() {
60+
var elm = $(evt.target);
61+
App.Actions.DB.update_db_databasename_hint(elm, $(elm).val());
62+
}, 100);
63+
});
3964
}
4065

4166
//
4267
// Page entry point
68+
// Trigger listeners
4369
App.Listeners.DB.keypress_db_username();
4470
App.Listeners.DB.keypress_db_databasename();

web/js/pages/add.dns.record.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
//
2+
//
3+
// Updates database dns record dynamically, showing its full domain path
4+
App.Actions.DB.update_dns_record_hint = function(elm, hint) {
5+
// clean hint
6+
if (hint.trim() == '') {
7+
$(elm).parent().find('.hint').html('');
8+
}
9+
10+
// set domain name without rec in case of @ entries
11+
if (hint == '@') {
12+
hint = '';
13+
}
14+
15+
// dont show pregix if domain name = rec value
16+
if (hint == GLOBAL.DNS_REC_PREFIX || hint + '.' == GLOBAL.DNS_REC_PREFIX) {
17+
hint = '';
18+
}
19+
20+
// add dot at the end if needed
21+
if (hint != '' && hint.slice(-1) != '.') {
22+
hint += '.';
23+
}
24+
25+
$(elm).parent().find('.hint').text(hint + GLOBAL.DNS_REC_PREFIX);
26+
}
27+
28+
//
29+
// listener that triggers dns record name hint updating
30+
App.Listeners.DB.keypress_dns_rec_entry = function() {
31+
var ref = $('input[name="v_rec"]');
32+
var current_rec = ref.val();
33+
if (current_rec.trim() != '') {
34+
App.Actions.DB.update_dns_record_hint(ref, current_rec);
35+
}
36+
37+
ref.bind('keypress input', function(evt) {
38+
clearTimeout(window.frp_usr_tmt);
39+
window.frp_usr_tmt = setTimeout(function() {
40+
var elm = $(evt.target);
41+
App.Actions.DB.update_dns_record_hint(elm, $(elm).val());
42+
}, 100);
43+
});
44+
}
45+
46+
//
47+
// Page entry point
48+
// Trigger listeners
49+
App.Listeners.DB.keypress_dns_rec_entry();

web/js/pages/add.web.js

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,37 @@
1+
//
2+
//
3+
// Updates ftp username dynamically, showing its prefix
14
App.Actions.WEB.update_ftp_username_hint = function(elm, hint) {
2-
if (hint.trim() == '') {
3-
$(elm).parent().find('.hint').html('');
4-
}
5-
if (hint.indexOf(GLOBAL.FTP_USER_PREFIX) == 0) {
6-
hint = hint.slice(GLOBAL.FTP_USER_PREFIX.length, hint.length);
7-
}
8-
$(elm).parent().find('.hint').html(GLOBAL.FTP_USER_PREFIX + hint);
5+
if (hint.trim() == '') {
6+
$(elm).parent().find('.hint').html('');
7+
}
8+
// remove prefix from value in order to eliminate duplicates
9+
if (hint.indexOf(GLOBAL.FTP_USER_PREFIX) == 0) {
10+
hint = hint.slice(GLOBAL.FTP_USER_PREFIX.length, hint.length);
11+
}
12+
13+
$(elm).parent().find('.hint').text(GLOBAL.FTP_USER_PREFIX + hint);
914
}
1015

16+
//
17+
// listener that triggers ftp user hint updating
1118
App.Listeners.WEB.keypress_ftp_username = function() {
12-
$('input[name="v_ftp_user"]').bind('keypress', function(evt) {
13-
clearTimeout(window.frp_usr_tmt);
14-
window.frp_usr_tmt = setTimeout(function() {
15-
var elm = $(evt.target);
16-
App.Actions.WEB.update_ftp_username_hint(elm, $(elm).val());
17-
}, 100);
18-
});
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) {
26+
clearTimeout(window.frp_usr_tmt);
27+
window.frp_usr_tmt = setTimeout(function() {
28+
var elm = $(evt.target);
29+
App.Actions.WEB.update_ftp_username_hint(elm, $(elm).val());
30+
}, 100);
31+
});
1932
}
2033

2134
//
2235
// Page entry point
36+
// Trigger listeners
2337
App.Listeners.WEB.keypress_ftp_username();

web/js/pages/edit.db.js

Lines changed: 54 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,70 @@
1+
//
2+
//
3+
// Updates database username dynamically, showing its prefix
14
App.Actions.DB.update_db_username_hint = function(elm, hint) {
2-
if (hint.trim() == '') {
3-
$(elm).parent().find('.hint').html('');
4-
}
5-
if (hint.indexOf(GLOBAL.DB_USER_PREFIX) == 0) {
6-
hint = hint.slice(GLOBAL.DB_USER_PREFIX.length, hint.length);
7-
}
8-
$(elm).parent().find('.hint').html(GLOBAL.DB_USER_PREFIX + hint);
5+
if (hint.trim() == '') {
6+
$(elm).parent().find('.hint').html('');
7+
}
8+
// remove prefix from value in order to eliminate duplicates
9+
if (hint.indexOf(GLOBAL.DB_USER_PREFIX) == 0) {
10+
hint = hint.slice(GLOBAL.DB_USER_PREFIX.length, hint.length);
11+
}
12+
13+
$(elm).parent().find('.hint').text(GLOBAL.DB_USER_PREFIX + hint);
914
}
1015

16+
//
17+
//
18+
// Updates database name dynamically, showing its prefix
1119
App.Actions.DB.update_db_databasename_hint = function(elm, hint) {
12-
if (hint.trim() == '') {
13-
$(elm).parent().find('.hint').html('');
14-
}
15-
if (hint.indexOf(GLOBAL.DB_DBNAME_PREFIX) == 0) {
16-
hint = hint.slice(GLOBAL.DB_DBNAME_PREFIX.length, hint.length);
17-
}
18-
$(elm).parent().find('.hint').html(GLOBAL.DB_DBNAME_PREFIX + hint);
20+
if (hint.trim() == '') {
21+
$(elm).parent().find('.hint').html('');
22+
}
23+
// remove prefix from value in order to eliminate duplicates
24+
if (hint.indexOf(GLOBAL.DB_DBNAME_PREFIX) == 0) {
25+
hint = hint.slice(GLOBAL.DB_DBNAME_PREFIX.length, hint.length);
26+
}
27+
$(elm).parent().find('.hint').text(GLOBAL.DB_DBNAME_PREFIX + hint);
1928
}
2029

30+
//
31+
// listener that triggers database user hint updating
2132
App.Listeners.DB.keypress_db_username = function() {
22-
$('input[name="v_dbuser"]').bind('keypress', function(evt) {
23-
clearTimeout(window.frp_usr_tmt);
24-
window.frp_usr_tmt = setTimeout(function() {
25-
var elm = $(evt.target);
26-
App.Actions.DB.update_db_username_hint(elm, $(elm).val());
27-
}, 100);
28-
});
33+
var ref = $('input[name="v_dbuser"]');
34+
var current_val = ref.val();
35+
if (current_val.trim() != '') {
36+
App.Actions.DB.update_db_username_hint(ref, current_val);
37+
}
38+
39+
ref.bind('keypress input', function(evt) {
40+
clearTimeout(window.frp_usr_tmt);
41+
window.frp_usr_tmt = setTimeout(function() {
42+
var elm = $(evt.target);
43+
App.Actions.DB.update_db_username_hint(elm, $(elm).val());
44+
}, 100);
45+
});
2946
}
3047

48+
//
49+
// listener that triggers database name hint updating
3150
App.Listeners.DB.keypress_db_databasename = function() {
32-
$('input[name="v_database"]').bind('keypress', function(evt) {
33-
clearTimeout(window.frp_dbn_tmt);
34-
window.frp_dbn_tmt = setTimeout(function() {
35-
var elm = $(evt.target);
36-
App.Actions.DB.update_db_databasename_hint(elm, $(elm).val());
37-
}, 100);
38-
});
51+
var ref = $('input[name="v_database"]');
52+
var current_val = ref.val();
53+
if (current_val.trim() != '') {
54+
App.Actions.DB.update_db_databasename_hint(ref, current_val);
55+
}
56+
57+
ref.bind('keypress input', function(evt) {
58+
clearTimeout(window.frp_dbn_tmt);
59+
window.frp_dbn_tmt = setTimeout(function() {
60+
var elm = $(evt.target);
61+
App.Actions.DB.update_db_databasename_hint(elm, $(elm).val());
62+
}, 100);
63+
});
3964
}
4065

4166
//
4267
// Page entry point
68+
// Trigger listeners
4369
App.Listeners.DB.keypress_db_username();
4470
App.Listeners.DB.keypress_db_databasename();

web/js/pages/edit.web.js

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
11
App.Actions.WEB.update_ftp_username_hint = function(elm, hint) {
2-
if (hint.trim() == '') {
3-
$(elm).parent().find('.hint').html('');
4-
}
5-
if (hint.indexOf(GLOBAL.FTP_USER_PREFIX) == 0) {
6-
hint = hint.slice(GLOBAL.FTP_USER_PREFIX.length, hint.length);
7-
}
8-
$(elm).parent().find('.hint').html(GLOBAL.FTP_USER_PREFIX + hint);
2+
if (hint.trim() == '') {
3+
$(elm).parent().find('.hint').html('');
4+
}
5+
if (hint.indexOf(GLOBAL.FTP_USER_PREFIX) == 0) {
6+
hint = hint.slice(GLOBAL.FTP_USER_PREFIX.length, hint.length);
7+
}
8+
$(elm).parent().find('.hint').text(GLOBAL.FTP_USER_PREFIX + hint);
99
}
1010

1111
App.Listeners.WEB.keypress_ftp_username = function() {
12-
$('input[name="v_ftp_user"]').bind('keypress', function(evt) {
13-
clearTimeout(window.frp_usr_tmt);
14-
window.frp_usr_tmt = setTimeout(function() {
15-
var elm = $(evt.target);
16-
App.Actions.WEB.update_ftp_username_hint(elm, $(elm).val());
17-
}, 100);
18-
});
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+
}
17+
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);
24+
});
1925
}
2026

2127
//

web/templates/admin/add_dns_rec.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
<tr>
5757
<td>
5858
<input type="text" size="20" class="vst-input" name="v_rec" <?php if (!empty($v_rec)) echo "value=".$v_rec; ?>>
59+
<small class="hint"></small>
5960
</td>
6061
</tr>
6162
<tr>
@@ -116,3 +117,8 @@
116117
</tr>
117118
</table>
118119
</form>
120+
121+
<script type="text/javascript">
122+
GLOBAL.DNS_REC_PREFIX = '<?php echo $_GET['domain']; ?>';
123+
</script>
124+
<script type="text/javascript" src="/js/pages/add.dns.record.js"></script>

0 commit comments

Comments
 (0)