3 ///////////////////////////////////////////////////////////////////////////
5 // NOTICE OF COPYRIGHT //
7 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
8 // http://moodle.com //
10 // Copyright (C) 1999 onwards 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');
36 var sequenceField
= document
.getElementById('menusequence');
37 var enumField
= document
.getElementById('menuenum');
39 /// Register the rest of events
40 if (typeField
.addEventListener
) {
42 typeField
.addEventListener('change', transformForm
, false);
43 sequenceField
.addEventListener('change', transformForm
, false);
44 enumField
.addEventListener('change', transformForm
, false);
47 typeField
.attachEvent('onchange', transformForm
);
48 sequenceField
.attachEvent('onchange', transformForm
);
49 enumField
.attachEvent('onchange', transformForm
);
54 * This function controls all modifications to perform when any field changes
56 function transformForm(event
) {
58 /// Initialize all the needed variables
59 var typeField
= document
.getElementById('menutype');
60 var lengthField
= document
.getElementById('length');
61 var decimalsField
= document
.getElementById('decimals');
62 var unsignedField
= document
.getElementById('menuunsigned');
63 var notnullField
= document
.getElementById('menunotnull');
64 var sequenceField
= document
.getElementById('menusequence');
65 var enumField
= document
.getElementById('menuenum');
66 var enumvaluesField
= document
.getElementById('enumvalues');
67 var defaultField
= document
.getElementById('default');
69 var lengthTip
= document
.getElementById('lengthtip');
70 var decimalsTip
= document
.getElementById('decimalstip');
72 /// Initially, enable everything
73 decimalsField
.disabled
= false;
74 unsignedField
.disabled
= false;
75 notnullField
.disabled
= false;
76 sequenceField
.disabled
= false;
77 enumField
.disabled
= false;
78 enumvaluesField
.disabled
= false;
79 defaultField
.disabled
= false;
81 /// Based on enum, disable some items
82 if (enumField
.value
== '0') {
83 enumvaluesField
.disabled
= true;
84 enumvaluesField
.value
= '';
87 /// Based on sequence, disable some items
88 if (sequenceField
.value
== '1') {
89 unsignedField
.disabled
= true;
90 unsignedField
.value
= '1';
91 notnullField
.disabled
= true;
92 notnullField
.value
= '1';
93 defaultField
.disabled
= true;
94 defaultField
.value
= '';
95 enumField
.disabled
= true;
96 enumField
.value
= '0';
97 enumvaluesField
.disabled
= true;
98 enumvaluesField
.value
= '';
102 /// Based on type, disable some items
103 switch (typeField
.value
) {
104 case '1': // XMLDB_TYPE_INTEGER
105 lengthTip
.innerHTML
= ' 1...20';
106 decimalsTip
.innerHTML
= '';
107 decimalsField
.disabled
= true;
108 decimalsField
.value
= '';
109 enumField
.disabled
= true;
110 enumField
.value
= '0';
111 enumvaluesField
.disabled
= true;
112 enumvaluesField
.value
= '';
114 case '2': // XMLDB_TYPE_NUMBER
115 lengthTip
.innerHTML
= ' 1...20';
116 decimalsTip
.innerHTML
= ' 0...length or empty';
117 enumField
.disabled
= true;
118 enumField
.value
= '0';
119 enumvaluesField
.disabled
= true;
120 enumvaluesField
.value
= '';
122 case '3': // XMLDB_TYPE_FLOAT
123 lengthTip
.innerHTML
= ' 1...20 or empty';
124 decimalsTip
.innerHTML
= ' 0...length or empty';
125 enumField
.disabled
= true;
126 enumField
.value
= '0';
127 enumvaluesField
.disabled
= true;
128 enumvaluesField
.value
= '';
130 case '4': // XMLDB_TYPE_CHAR
131 lengthTip
.innerHTML
= ' 1...255';
132 decimalsTip
.innerHTML
= '';
133 decimalsField
.disabled
= true;
134 decimalsField
.value
= '';
135 unsignedField
.disabled
= true;
136 unsignedField
.value
= '0';
137 sequenceField
.disabled
= true;
138 sequenceField
.value
= '0';
140 case '5': // XMLDB_TYPE_TEXT
141 lengthTip
.innerHTML
= ' small, medium, big';
142 decimalsTip
.innerHTML
= '';
143 decimalsField
.disabled
= true;
144 decimalsField
.value
= '';
145 unsignedField
.disabled
= true;
146 unsignedField
.value
= '0';
147 sequenceField
.disabled
= true;
148 sequenceField
.value
= '0';
149 defaultField
.disabled
= true;
150 defaultField
.value
= '';
152 case '6': // XMLDB_TYPE_BINARY
153 lengthTip
.innerHTML
= ' small, medium, big';
154 decimalsTip
.innerHTML
= '';
155 decimalsField
.disabled
= true;
156 decimalsField
.value
= '';
157 unsignedField
.disabled
= true;
158 unsignedField
.value
= '0';
159 sequenceField
.disabled
= true;
160 sequenceField
.value
= '0';
161 enumField
.disabled
= true;
162 enumField
.value
= '0';
163 enumvaluesField
.disabled
= true;
164 enumvaluesField
.value
= '';
165 defaultField
.disabled
= true;
166 defaultField
.value
= '';
168 case '7': // XMLDB_TYPE_DATETIME
169 lengthTip
.innerHTML
= '';
170 lengthField
.disabled
= true;
171 lengthField
.value
= '';
172 decimalsTip
.innerHTML
= '';
173 decimalsField
.disabled
= true;
174 decimalsField
.value
= '';
175 unsignedField
.disabled
= true;
176 unsignedField
.value
= '0';
177 sequenceField
.disabled
= true;
178 sequenceField
.value
= '0';
179 enumField
.disabled
= true;
180 enumField
.value
= '0';
181 enumvaluesField
.disabled
= true;
182 enumvaluesField
.value
= '';
183 defaultField
.disabled
= true;
184 defaultField
.value
= '';