Просмотр исходного кода

Better code implementation for create_document

José Loguercio 9 лет назад
Родитель
Сommit
060762bdfa
2 измененных файлов с 11 добавлено и 21 удалено
  1. 8 18
      main/document/create_document.php
  2. 3 3
      main/inc/ajax/document.ajax.php

+ 8 - 18
main/document/create_document.php

@@ -52,15 +52,15 @@ $(document).ready(function() {
     });
 });
 
-$(document).on("click", ".dropdown-menu li a", function () {
-    var textValue = $(this).text();
+$(document).on("change", ".selectpicker", function () {
+    var dirValue = $(this).val();
     $.ajax({
         contentType: "application/x-www-form-urlencoded",
-        data: "textValue="+textValue,
-        url: "' . api_get_path(WEB_AJAX_PATH) . 'document.ajax.php?a=documentDestination",
+        data: "dirValue="+dirValue,
+        url: "' . api_get_path(WEB_AJAX_PATH) . 'document.ajax.php?a=document_destination",
         type: "POST",
         success: function(response) {
-            $("[name=\'textValue\']").val(response)
+            $("[name=\'dirValue\']").val(response)
         }
     });
 });
@@ -432,7 +432,7 @@ if (!$is_certificate_mode &&
 	}
 }
 
-$form->addHidden('textValue', '');
+$form->addHidden('dirValue', '');
 
 if ($is_certificate_mode) {
 	$form->addButtonCreate(get_lang('CreateCertificate'));
@@ -448,18 +448,8 @@ if ($form->validate()) {
 	$readonly = isset($values['readonly']) ? 1 : 0;
 	$values['title'] = trim($values['title']);
     
-    $textValue = $values['textValue'];
-    $homeDirectory = get_lang('HomeDirectory');
-    if ($textValue === $homeDirectory){
-        $dir = "/";
-    } else {
-        $posTextValue = strpos($textValue, '—');
-        $textValue = substr($textValue, ($posTextValue + 4));
-        foreach ($folder_titles as $dirValue => $dirText) {
-            if ($dirText === $textValue) {
-                $dir = $dirValue;
-            }
-        }
+    if (!empty($values['dirValue'])) {
+        $dir = $values['dirValue'];
     }
 
     if ($dir[strlen($dir) - 1] != '/') {

+ 3 - 3
main/inc/ajax/document.ajax.php

@@ -73,10 +73,10 @@ switch ($action) {
             );
         }
         break;
-    case 'documentDestination':
+    case 'document_destination':
         //obtained the bootstrap-select selected value via ajax
-        $textValue = isset($_POST['textValue']) ? $_POST['textValue'] : null;
-        echo $textValue;
+        $dirValue = isset($_POST['dirValue']) ? $_POST['dirValue'] : null;
+        echo $dirValue;
         break;
 }
 exit;