edit_dns_rec.js 1.2 KB

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