edit_dns_rec.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. const domain = $('input[name="v_domain"]').val();
  7. if (hint.trim() == '') {
  8. $(elm).parent().find('.hint').text('');
  9. }
  10. // set domain name without rec in case of @ entries
  11. if (hint == '@') {
  12. hint = '';
  13. }
  14. // dont show prefix if domain name = rec value
  15. if (hint == domain) {
  16. hint = '';
  17. }
  18. // add dot at the end if needed
  19. if (hint != '' && hint.slice(-1) != '.') {
  20. hint += '.';
  21. }
  22. $(elm)
  23. .parent()
  24. .find('.hint')
  25. .text(hint + domain);
  26. };
  27. //
  28. // listener that triggers dns record name hint updating
  29. App.Listeners.DB.keypress_dns_rec_entry = function () {
  30. var ref = $('input[name="v_rec"]');
  31. var current_rec = ref.val();
  32. if (current_rec.trim() != '') {
  33. App.Actions.DB.update_dns_record_hint(ref, current_rec);
  34. }
  35. ref.bind('keypress input', function (evt) {
  36. clearTimeout(window.frp_usr_tmt);
  37. window.frp_usr_tmt = setTimeout(function () {
  38. var elm = $(evt.target);
  39. App.Actions.DB.update_dns_record_hint(elm, $(elm).val());
  40. }, 100);
  41. });
  42. };
  43. //
  44. // Page entry point
  45. // Trigger listeners
  46. App.Listeners.DB.keypress_dns_rec_entry();