]> git.mjollnir.org Git - moodle.git/commitdiff
Minor changes to improve behaviour of selections.
authorstronk7 <stronk7>
Mon, 25 Sep 2006 22:53:39 +0000 (22:53 +0000)
committerstronk7 <stronk7>
Mon, 25 Sep 2006 22:53:39 +0000 (22:53 +0000)
admin/xmldb/actions/view_table_php/view_table_php.class.php
admin/xmldb/actions/view_table_php/view_table_php.js

index ffaaafd3572062f21cc7299650d24a5bb0e696b9..2780f499ac5b16e44542c26a234e662572293db7 100644 (file)
@@ -43,7 +43,11 @@ class view_table_php extends XMLDBAction {
             'selectfieldkeyindex' => 'xmldb',
             'view' => 'xmldb',
             'table' => 'xmldb',
+            'selectonecommand' => 'xmldb',
             'selectonefieldkeyindex' => 'xmldb',
+            'mustselectonefield' => 'xmldb',
+            'mustselectonekey' => 'xmldb',
+            'mustselectoneindex' => 'xmldb',
             'back' => 'xmldb'
         ));
     }
@@ -97,6 +101,7 @@ class view_table_php extends XMLDBAction {
         $commandparam = optional_param('command', 'add_field', PARAM_PATH);
         $origfieldkeyindexparam = optional_param('fieldkeyindex', $defaultfieldkeyindex, PARAM_PATH);
         $fieldkeyindexparam = preg_replace('/[fki]#/i', '', $origfieldkeyindexparam); ///Strip the initials
+        $fieldkeyindexinitial = substr($origfieldkeyindexparam, 0, 1); //To know what we have selected
 
     /// The back to edit xml button
         $b = ' <p align="center" class="buttons">';
@@ -107,22 +112,27 @@ class view_table_php extends XMLDBAction {
     /// The table currently being edited
         $o .= '<h3 class="main">' . $this->str['table'] . ': ' . s($tableparam) . '</h3>';
 
+    /// To indent the menu selections
+        $optionspacer = '&nbsp;&nbsp;&nbsp;';
+
     /// Calculate the popup of commands
-        $commands = array('add_field',
-                         'drop_field',
-                         'rename_field (not imp!)',
-                         'change_field_type (not imp!)',
-                         'change_field_precision',
-                         'change_field_unsigned',
-                         'change_field_notnull',
-                         'change_field_sequence (not imp!)',
-                         'change_field_enum (not imp!)',
-                         'change_field_default');
+        $commands = array('Fields',
+                         $optionspacer . 'add_field',
+                         $optionspacer . 'drop_field',
+                         $optionspacer . 'rename_field (not imp!)',
+                         $optionspacer . 'change_field_type (not imp!)',
+                         $optionspacer . 'change_field_precision',
+                         $optionspacer . 'change_field_unsigned',
+                         $optionspacer . 'change_field_notnull',
+                         $optionspacer . 'change_field_sequence (not imp!)',
+                         $optionspacer . 'change_field_enum (not imp!)',
+                         $optionspacer . 'change_field_default',
+                         'Keys',
+                         'Indexes');
         foreach ($commands as $command) {
-            $popcommands[$command] = str_replace('_', ' ', $command);
+            $popcommands[str_replace($optionspacer, '', $command)] = str_replace('_', ' ', $command);
         }
     /// Calculate the popup of fields/keys/indexes
-        $optionspacer = '&nbsp;&nbsp;&nbsp;';
         if ($fields) {
             $popfields['fieldshead'] = 'Fields';
             foreach ($fields as $field) {
@@ -158,29 +168,60 @@ class view_table_php extends XMLDBAction {
     /// Check we have selected some field/key/index from the popup
         if ($fieldkeyindexparam == 'fieldshead' || $fieldkeyindexparam == 'keyshead' || $fieldkeyindexparam == 'indexeshead') {
             $o.= s($this->str['selectonefieldkeyindex']);
-         } else {
+    /// Check we have selected some command from the popup
+        } else if ($commandparam == 'Fields' || $commandparam == 'Keys' || $commandparam == 'Indexes') {
+            $o.= s($this->str['selectonecommand']);
+        } else {
         /// Based on current params, call the needed function
             switch ($commandparam) {
                 case 'add_field':
-                    $o.= s($this->add_field_php($structure, $tableparam, $fieldkeyindexparam));
+                    if ($fieldkeyindexinitial == 'f') { //Only if we have got one field
+                        $o.= s($this->add_field_php($structure, $tableparam, $fieldkeyindexparam));
+                    } else {
+                        $o.= $this->str['mustselectonefield'];
+                    }
                     break;
                 case 'drop_field':
-                    $o.= s($this->drop_field_php($structure, $tableparam, $fieldkeyindexparam));
+                    if ($fieldkeyindexinitial == 'f') { //Only if we have got one field
+                        $o.= s($this->drop_field_php($structure, $tableparam, $fieldkeyindexparam));
+                    } else {
+                        $o.= $this->str['mustselectonefield'];
+                    }
                     break;
                 case 'rename_field':
-                    $o.= s($this->rename_field_php($structure, $tableparam, $fieldkeyindexparam));
+                    if ($fieldkeyindexinitial == 'f') { //Only if we have got one field
+                        $o.= s($this->rename_field_php($structure, $tableparam, $fieldkeyindexparam));
+                    } else {
+                        $o.= $this->str['mustselectonefield'];
+                    }
                     break;
                 case 'change_field_precision':
-                    $o.= s($this->change_field_precision_php($structure, $tableparam, $fieldkeyindexparam));
+                    if ($fieldkeyindexinitial == 'f') { //Only if we have got one field
+                        $o.= s($this->change_field_precision_php($structure, $tableparam, $fieldkeyindexparam));
+                    } else {
+                        $o.= $this->str['mustselectonefield'];
+                    }
                     break;
                 case 'change_field_unsigned':
-                    $o.= s($this->change_field_unsigned_php($structure, $tableparam, $fieldkeyindexparam));
+                    if ($fieldkeyindexinitial == 'f') { //Only if we have got one field
+                        $o.= s($this->change_field_unsigned_php($structure, $tableparam, $fieldkeyindexparam));
+                    } else {
+                        $o.= $this->str['mustselectonefield'];
+                    }
                     break;
                 case 'change_field_notnull':
-                    $o.= s($this->change_field_notnull_php($structure, $tableparam, $fieldkeyindexparam));
+                    if ($fieldkeyindexinitial == 'f') { //Only if we have got one field
+                        $o.= s($this->change_field_notnull_php($structure, $tableparam, $fieldkeyindexparam));
+                    } else {
+                        $o.= $this->str['mustselectonefield'];
+                    }
                     break;
                 case 'change_field_default':
-                    $o.= s($this->change_field_default_php($structure, $tableparam, $fieldkeyindexparam));
+                    if ($fieldkeyindexinitial == 'f') { //Only if we have got one field
+                        $o.= s($this->change_field_default_php($structure, $tableparam, $fieldkeyindexparam));
+                    } else {
+                        $o.= $this->str['mustselectonefield'];
+                    }
                     break;
             }
         }
index 1fb1d888bfe0ce4619a2a8730c54110e0bbde6aa..071f08678bd7ad2dc7f791e16499987827ec1ea2 100644 (file)
     }
 
 /**
- * This function disables some elements from the fields/keys/indexes drop down
+ * This function disables some elements from the command and from the fields/keys/indexes drop downs
  */
 function disablePopupHeads() {
+    var popup = document.getElementById("menucommand");
+    var i = popup.length;
+    while (i--) {
+        option = popup[i];
+        if (option.value == "Fields" || option.value == "Keys" || option.value == "Indexes") {
+            popup[i].disabled = true;
+        }
+    }
     var popup = document.getElementById("menufieldkeyindex");
     var i = popup.length;
     while (i--) {