3 ///////////////////////////////////////////////////////////////////////////
5 // NOTICE OF COPYRIGHT //
7 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
8 // http://moodle.com //
10 // Copyright (C) 2001-3001 Martin Dougiamas http://dougiamas.com //
11 // (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com //
13 // This program is free software; you can redistribute it and/or modify //
14 // it under the terms of the GNU General Public License as published by //
15 // the Free Software Foundation; either version 2 of the License, or //
16 // (at your option) any later version. //
18 // This program is distributed in the hope that it will be useful, //
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
21 // GNU General Public License for more details: //
23 // http://www.gnu.org/copyleft/gpl.html //
25 ///////////////////////////////////////////////////////////////////////////
28 /// Register the needed events
31 /// Adjust the form on load
34 /// Get the required fields
35 var typeField = document.getElementById('menutype');
37 /// Register the rest of events
38 if (typeField.addEventListener) {
40 typeField.addEventListener('change', transformForm, false);
43 typeField.attachEvent('onchange', transformForm);
48 * This function controls all modifications to perform when any field changes
50 function transformForm(event) {
52 /// Initialize all the needed variables
53 var typeField = document.getElementById('menutype');
54 var fieldsField = document.getElementById('fields');
55 var reftableField = document.getElementById('reftable');
56 var reffieldsField = document.getElementById('reffields');
58 /// Initially, enable everything
59 typeField.disabled = false;
60 fieldsField.disabled = false;
61 reftableField.disabled = false;
62 reffieldsField.disabled = false;
64 /// Based on type, disable some items
65 switch (typeField.value) {
66 case '1': // XMLDB_KEY_PRIMARY
67 case '2': // XMLDB_KEY_UNIQUE
68 reftableField.disabled = true;
69 reftableField.value = '';
70 reffieldsField.disabled = true;
71 reffieldsField.value = '';
73 case '3': // XMLDB_KEY_FOREIGN
74 case '5': // XMLDB_KEY_FOREIGN_UNIQUE