From c50c7b26753e1081c2a6fd2acb7527cf6b1cd914 Mon Sep 17 00:00:00 2001 From: "very-twi@github.com" Date: Wed, 12 Feb 2014 12:08:23 +0200 Subject: [PATCH] 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 --- web/js/pages/add.db.js | 82 ++++++++++++++++++---------- web/js/pages/add.dns.record.js | 49 +++++++++++++++++ web/js/pages/add.web.js | 42 +++++++++----- web/js/pages/edit.db.js | 82 ++++++++++++++++++---------- web/js/pages/edit.web.js | 34 +++++++----- web/templates/admin/add_dns_rec.html | 6 ++ 6 files changed, 211 insertions(+), 84 deletions(-) create mode 100644 web/js/pages/add.dns.record.js diff --git a/web/js/pages/add.db.js b/web/js/pages/add.db.js index 9c122219..c0f36fc9 100644 --- a/web/js/pages/add.db.js +++ b/web/js/pages/add.db.js @@ -1,44 +1,70 @@ +// +// +// Updates database username dynamically, showing its prefix App.Actions.DB.update_db_username_hint = function(elm, hint) { - if (hint.trim() == '') { - $(elm).parent().find('.hint').html(''); - } - if (hint.indexOf(GLOBAL.DB_USER_PREFIX) == 0) { - hint = hint.slice(GLOBAL.DB_USER_PREFIX.length, hint.length); - } - $(elm).parent().find('.hint').html(GLOBAL.DB_USER_PREFIX + hint); + if (hint.trim() == '') { + $(elm).parent().find('.hint').html(''); + } + // remove prefix from value in order to eliminate duplicates + if (hint.indexOf(GLOBAL.DB_USER_PREFIX) == 0) { + hint = hint.slice(GLOBAL.DB_USER_PREFIX.length, hint.length); + } + + $(elm).parent().find('.hint').text(GLOBAL.DB_USER_PREFIX + hint); } +// +// +// Updates database name dynamically, showing its prefix App.Actions.DB.update_db_databasename_hint = function(elm, hint) { - if (hint.trim() == '') { - $(elm).parent().find('.hint').html(''); - } - if (hint.indexOf(GLOBAL.DB_DBNAME_PREFIX) == 0) { - hint = hint.slice(GLOBAL.DB_DBNAME_PREFIX.length, hint.length); - } - $(elm).parent().find('.hint').html(GLOBAL.DB_DBNAME_PREFIX + hint); + if (hint.trim() == '') { + $(elm).parent().find('.hint').html(''); + } + // remove prefix from value in order to eliminate duplicates + if (hint.indexOf(GLOBAL.DB_DBNAME_PREFIX) == 0) { + hint = hint.slice(GLOBAL.DB_DBNAME_PREFIX.length, hint.length); + } + $(elm).parent().find('.hint').text(GLOBAL.DB_DBNAME_PREFIX + hint); } +// +// listener that triggers database user hint updating App.Listeners.DB.keypress_db_username = function() { - $('input[name="v_dbuser"]').bind('keypress', function(evt) { - clearTimeout(window.frp_usr_tmt); - window.frp_usr_tmt = setTimeout(function() { - var elm = $(evt.target); - App.Actions.DB.update_db_username_hint(elm, $(elm).val()); - }, 100); - }); + var ref = $('input[name="v_dbuser"]'); + var current_val = ref.val(); + if (current_val.trim() != '') { + App.Actions.DB.update_db_username_hint(ref, current_val); + } + + ref.bind('keypress input', function(evt) { + clearTimeout(window.frp_usr_tmt); + window.frp_usr_tmt = setTimeout(function() { + var elm = $(evt.target); + App.Actions.DB.update_db_username_hint(elm, $(elm).val()); + }, 100); + }); } +// +// listener that triggers database name hint updating App.Listeners.DB.keypress_db_databasename = function() { - $('input[name="v_database"]').bind('keypress', function(evt) { - clearTimeout(window.frp_dbn_tmt); - window.frp_dbn_tmt = setTimeout(function() { - var elm = $(evt.target); - App.Actions.DB.update_db_databasename_hint(elm, $(elm).val()); - }, 100); - }); + var ref = $('input[name="v_database"]'); + var current_val = ref.val(); + if (current_val.trim() != '') { + App.Actions.DB.update_db_databasename_hint(ref, current_val); + } + + ref.bind('keypress input', function(evt) { + clearTimeout(window.frp_dbn_tmt); + window.frp_dbn_tmt = setTimeout(function() { + var elm = $(evt.target); + App.Actions.DB.update_db_databasename_hint(elm, $(elm).val()); + }, 100); + }); } // // Page entry point +// Trigger listeners App.Listeners.DB.keypress_db_username(); App.Listeners.DB.keypress_db_databasename(); diff --git a/web/js/pages/add.dns.record.js b/web/js/pages/add.dns.record.js new file mode 100644 index 00000000..d3141807 --- /dev/null +++ b/web/js/pages/add.dns.record.js @@ -0,0 +1,49 @@ +// +// +// Updates database dns record dynamically, showing its full domain path +App.Actions.DB.update_dns_record_hint = function(elm, hint) { + // clean hint + if (hint.trim() == '') { + $(elm).parent().find('.hint').html(''); + } + + // set domain name without rec in case of @ entries + if (hint == '@') { + hint = ''; + } + + // dont show pregix if domain name = rec value + if (hint == GLOBAL.DNS_REC_PREFIX || hint + '.' == GLOBAL.DNS_REC_PREFIX) { + hint = ''; + } + + // add dot at the end if needed + if (hint != '' && hint.slice(-1) != '.') { + hint += '.'; + } + + $(elm).parent().find('.hint').text(hint + GLOBAL.DNS_REC_PREFIX); +} + +// +// listener that triggers dns record name hint updating +App.Listeners.DB.keypress_dns_rec_entry = function() { + var ref = $('input[name="v_rec"]'); + var current_rec = ref.val(); + if (current_rec.trim() != '') { + App.Actions.DB.update_dns_record_hint(ref, current_rec); + } + + ref.bind('keypress input', function(evt) { + clearTimeout(window.frp_usr_tmt); + window.frp_usr_tmt = setTimeout(function() { + var elm = $(evt.target); + App.Actions.DB.update_dns_record_hint(elm, $(elm).val()); + }, 100); + }); +} + +// +// Page entry point +// Trigger listeners +App.Listeners.DB.keypress_dns_rec_entry(); diff --git a/web/js/pages/add.web.js b/web/js/pages/add.web.js index 36f59982..8b06b14a 100644 --- a/web/js/pages/add.web.js +++ b/web/js/pages/add.web.js @@ -1,23 +1,37 @@ +// +// +// Updates ftp username dynamically, showing its prefix App.Actions.WEB.update_ftp_username_hint = function(elm, hint) { - if (hint.trim() == '') { - $(elm).parent().find('.hint').html(''); - } - if (hint.indexOf(GLOBAL.FTP_USER_PREFIX) == 0) { - hint = hint.slice(GLOBAL.FTP_USER_PREFIX.length, hint.length); - } - $(elm).parent().find('.hint').html(GLOBAL.FTP_USER_PREFIX + hint); + if (hint.trim() == '') { + $(elm).parent().find('.hint').html(''); + } + // remove prefix from value in order to eliminate duplicates + if (hint.indexOf(GLOBAL.FTP_USER_PREFIX) == 0) { + hint = hint.slice(GLOBAL.FTP_USER_PREFIX.length, hint.length); + } + + $(elm).parent().find('.hint').text(GLOBAL.FTP_USER_PREFIX + hint); } +// +// listener that triggers ftp user hint updating App.Listeners.WEB.keypress_ftp_username = function() { - $('input[name="v_ftp_user"]').bind('keypress', function(evt) { - clearTimeout(window.frp_usr_tmt); - window.frp_usr_tmt = setTimeout(function() { - var elm = $(evt.target); - App.Actions.WEB.update_ftp_username_hint(elm, $(elm).val()); - }, 100); - }); + var ref = $('input[name="v_ftp_user"]'); + var current_val = ref.val(); + if (current_val.trim() != '') { + App.Actions.DB.update_ftp_username_hint(ref, current_val); + } + + ref.bind('keypress input', function(evt) { + clearTimeout(window.frp_usr_tmt); + window.frp_usr_tmt = setTimeout(function() { + var elm = $(evt.target); + App.Actions.WEB.update_ftp_username_hint(elm, $(elm).val()); + }, 100); + }); } // // Page entry point +// Trigger listeners App.Listeners.WEB.keypress_ftp_username(); diff --git a/web/js/pages/edit.db.js b/web/js/pages/edit.db.js index 9c122219..c0f36fc9 100644 --- a/web/js/pages/edit.db.js +++ b/web/js/pages/edit.db.js @@ -1,44 +1,70 @@ +// +// +// Updates database username dynamically, showing its prefix App.Actions.DB.update_db_username_hint = function(elm, hint) { - if (hint.trim() == '') { - $(elm).parent().find('.hint').html(''); - } - if (hint.indexOf(GLOBAL.DB_USER_PREFIX) == 0) { - hint = hint.slice(GLOBAL.DB_USER_PREFIX.length, hint.length); - } - $(elm).parent().find('.hint').html(GLOBAL.DB_USER_PREFIX + hint); + if (hint.trim() == '') { + $(elm).parent().find('.hint').html(''); + } + // remove prefix from value in order to eliminate duplicates + if (hint.indexOf(GLOBAL.DB_USER_PREFIX) == 0) { + hint = hint.slice(GLOBAL.DB_USER_PREFIX.length, hint.length); + } + + $(elm).parent().find('.hint').text(GLOBAL.DB_USER_PREFIX + hint); } +// +// +// Updates database name dynamically, showing its prefix App.Actions.DB.update_db_databasename_hint = function(elm, hint) { - if (hint.trim() == '') { - $(elm).parent().find('.hint').html(''); - } - if (hint.indexOf(GLOBAL.DB_DBNAME_PREFIX) == 0) { - hint = hint.slice(GLOBAL.DB_DBNAME_PREFIX.length, hint.length); - } - $(elm).parent().find('.hint').html(GLOBAL.DB_DBNAME_PREFIX + hint); + if (hint.trim() == '') { + $(elm).parent().find('.hint').html(''); + } + // remove prefix from value in order to eliminate duplicates + if (hint.indexOf(GLOBAL.DB_DBNAME_PREFIX) == 0) { + hint = hint.slice(GLOBAL.DB_DBNAME_PREFIX.length, hint.length); + } + $(elm).parent().find('.hint').text(GLOBAL.DB_DBNAME_PREFIX + hint); } +// +// listener that triggers database user hint updating App.Listeners.DB.keypress_db_username = function() { - $('input[name="v_dbuser"]').bind('keypress', function(evt) { - clearTimeout(window.frp_usr_tmt); - window.frp_usr_tmt = setTimeout(function() { - var elm = $(evt.target); - App.Actions.DB.update_db_username_hint(elm, $(elm).val()); - }, 100); - }); + var ref = $('input[name="v_dbuser"]'); + var current_val = ref.val(); + if (current_val.trim() != '') { + App.Actions.DB.update_db_username_hint(ref, current_val); + } + + ref.bind('keypress input', function(evt) { + clearTimeout(window.frp_usr_tmt); + window.frp_usr_tmt = setTimeout(function() { + var elm = $(evt.target); + App.Actions.DB.update_db_username_hint(elm, $(elm).val()); + }, 100); + }); } +// +// listener that triggers database name hint updating App.Listeners.DB.keypress_db_databasename = function() { - $('input[name="v_database"]').bind('keypress', function(evt) { - clearTimeout(window.frp_dbn_tmt); - window.frp_dbn_tmt = setTimeout(function() { - var elm = $(evt.target); - App.Actions.DB.update_db_databasename_hint(elm, $(elm).val()); - }, 100); - }); + var ref = $('input[name="v_database"]'); + var current_val = ref.val(); + if (current_val.trim() != '') { + App.Actions.DB.update_db_databasename_hint(ref, current_val); + } + + ref.bind('keypress input', function(evt) { + clearTimeout(window.frp_dbn_tmt); + window.frp_dbn_tmt = setTimeout(function() { + var elm = $(evt.target); + App.Actions.DB.update_db_databasename_hint(elm, $(elm).val()); + }, 100); + }); } // // Page entry point +// Trigger listeners App.Listeners.DB.keypress_db_username(); App.Listeners.DB.keypress_db_databasename(); diff --git a/web/js/pages/edit.web.js b/web/js/pages/edit.web.js index 36f59982..fc9be3fc 100644 --- a/web/js/pages/edit.web.js +++ b/web/js/pages/edit.web.js @@ -1,21 +1,27 @@ App.Actions.WEB.update_ftp_username_hint = function(elm, hint) { - if (hint.trim() == '') { - $(elm).parent().find('.hint').html(''); - } - if (hint.indexOf(GLOBAL.FTP_USER_PREFIX) == 0) { - hint = hint.slice(GLOBAL.FTP_USER_PREFIX.length, hint.length); - } - $(elm).parent().find('.hint').html(GLOBAL.FTP_USER_PREFIX + hint); + if (hint.trim() == '') { + $(elm).parent().find('.hint').html(''); + } + if (hint.indexOf(GLOBAL.FTP_USER_PREFIX) == 0) { + hint = hint.slice(GLOBAL.FTP_USER_PREFIX.length, hint.length); + } + $(elm).parent().find('.hint').text(GLOBAL.FTP_USER_PREFIX + hint); } App.Listeners.WEB.keypress_ftp_username = function() { - $('input[name="v_ftp_user"]').bind('keypress', function(evt) { - clearTimeout(window.frp_usr_tmt); - window.frp_usr_tmt = setTimeout(function() { - var elm = $(evt.target); - App.Actions.WEB.update_ftp_username_hint(elm, $(elm).val()); - }, 100); - }); + var ref = $('input[name="v_ftp_user"]'); + var current_val = ref.val(); + if (current_val.trim() != '') { + App.Actions.DB.update_ftp_username_hint(ref, current_val); + } + + ref.bind('keypress', function(evt) { + clearTimeout(window.frp_usr_tmt); + window.frp_usr_tmt = setTimeout(function() { + var elm = $(evt.target); + App.Actions.WEB.update_ftp_username_hint(elm, $(elm).val()); + }, 100); + }); } // diff --git a/web/templates/admin/add_dns_rec.html b/web/templates/admin/add_dns_rec.html index 44024745..a90e7dda 100644 --- a/web/templates/admin/add_dns_rec.html +++ b/web/templates/admin/add_dns_rec.html @@ -56,6 +56,7 @@ @@ -116,3 +117,8 @@ + + +