Jaap Marcus 5 лет назад
Родитель
Сommit
97e68fc4cc
3 измененных файлов с 56 добавлено и 5 удалено
  1. 3 5
      web/add/dns/index.php
  2. 49 0
      web/js/pages/edit_dns_rec.js
  3. 4 0
      web/templates/admin/edit_dns_rec.html

+ 3 - 5
web/add/dns/index.php

@@ -123,15 +123,14 @@ if (!empty($_POST['ok_rec'])) {
     $v_val = escapeshellarg($_POST['v_val']);
     $v_val = escapeshellarg($_POST['v_val']);
     $v_priority = escapeshellarg($_POST['v_priority']);
     $v_priority = escapeshellarg($_POST['v_priority']);
     $v_ttl = escapeshellarg($_POST['v_ttl']);
     $v_ttl = escapeshellarg($_POST['v_ttl']);
-
     // Add dns record
     // Add dns record
     if (empty($_SESSION['error_msg'])) {
     if (empty($_SESSION['error_msg'])) {
         exec (HESTIA_CMD."v-add-dns-record ".$user." ".$v_domain." ".$v_rec." ".$v_type." ".$v_val." ".$v_priority." '' false ".$v_ttl, $output, $return_var);
         exec (HESTIA_CMD."v-add-dns-record ".$user." ".$v_domain." ".$v_rec." ".$v_type." ".$v_val." ".$v_priority." '' false ".$v_ttl, $output, $return_var);
         check_return_code($return_var,$output);
         check_return_code($return_var,$output);
-        unset($output);
-        $v_type = $_POST['v_type'];
+        unset($output);   
     }
     }
-
+    $v_type = $_POST['v_type'];
+    
     // Flush field values on success
     // Flush field values on success
     if (empty($_SESSION['error_msg'])) {
     if (empty($_SESSION['error_msg'])) {
         $_SESSION['ok_msg'] = __('DNS_RECORD_CREATED_OK',htmlentities($_POST['v_rec']),htmlentities($_POST['v_domain']));
         $_SESSION['ok_msg'] = __('DNS_RECORD_CREATED_OK',htmlentities($_POST['v_rec']),htmlentities($_POST['v_domain']));
@@ -179,7 +178,6 @@ if (empty($_GET['domain'])) {
     render_page($user, $TAB, 'add_dns');
     render_page($user, $TAB, 'add_dns');
 } else {
 } else {
     // Display body for dns record
     // Display body for dns record
-
     $v_domain = $_GET['domain'];
     $v_domain = $_GET['domain'];
     render_page($user, $TAB, 'add_dns_rec');
     render_page($user, $TAB, 'add_dns_rec');
 }
 }

+ 49 - 0
web/js/pages/edit_dns_rec.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 = '';
+    }
+
+    // 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();

+ 4 - 0
web/templates/admin/edit_dns_rec.html

@@ -73,6 +73,7 @@
                                 <td>
                                 <td>
                                   <input type="text" size="20" class="vst-input" name="v_rec" value="<?=htmlentities(trim($v_rec, "'"))?>">
                                   <input type="text" size="20" class="vst-input" name="v_rec" value="<?=htmlentities(trim($v_rec, "'"))?>">
                                   <input type="hidden" name="v_record_id" value="<?=htmlentities($v_record_id)?>">
                                   <input type="hidden" name="v_record_id" value="<?=htmlentities($v_record_id)?>">
+                                  <small class="hint"></small>
                                 </td>
                                 </td>
                             </tr>
                             </tr>
                             <tr>
                             <tr>
@@ -156,3 +157,6 @@
             </table>
             </table>
         </form>
         </form>
     </div>
     </div>
+    <script>
+        GLOBAL.DNS_REC_PREFIX = <?=json_encode($_GET['domain'])?>;
+    </script>