|
| 1 | +// |
| 2 | +// |
| 3 | +// Updates database username dynamically, showing its prefix |
1 | 4 | 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); |
9 | 14 | } |
10 | 15 |
|
| 16 | +// |
| 17 | +// |
| 18 | +// Updates database name dynamically, showing its prefix |
11 | 19 | 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); |
19 | 28 | } |
20 | 29 |
|
| 30 | +// |
| 31 | +// listener that triggers database user hint updating |
21 | 32 | 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 | + }); |
29 | 46 | } |
30 | 47 |
|
| 48 | +// |
| 49 | +// listener that triggers database name hint updating |
31 | 50 | 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 | + }); |
39 | 64 | } |
40 | 65 |
|
41 | 66 | // |
42 | 67 | // Page entry point |
| 68 | +// Trigger listeners |
43 | 69 | App.Listeners.DB.keypress_db_username(); |
44 | 70 | App.Listeners.DB.keypress_db_databasename(); |
0 commit comments