/
admin_core.js
352 lines (304 loc) · 10.4 KB
/
admin_core.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
$(document).ready(function(){
setupAllTabs();
if(typeof(userdateformat) !== 'undefined')
{
$(".popupdate").datepicker({ dateFormat: userdateformat,
showOn: 'button',
changeYear: true,
changeMonth: true,
duration: 'fast'
}, $.datepicker.regional[userlanguage]);
$(".popupdatetime").datepicker({ dateFormat: userdateformat+' 00:00',
showOn: 'button',
changeYear: true,
changeMonth: true,
duration: 'fast'
}, $.datepicker.regional[userlanguage]);
}
// Loads the tooltips for the toolbars
$('img[alt]').each(function() {
if($(this).attr('alt') != '')
{
$(this).qtip({
style: { name: 'cream',
tip:true,
color:'#111111',
border: {
width: 1,
radius: 5,
color: '#EADF95'}
},
position: { adjust: {
screen: true, scroll:true },
corner: {
target: 'bottomRight'}
},
show: {effect: { length:50}}
});
}
});
if ($('#showadvancedattributes').length>0) updatequestionattributes();
$('#showadvancedattributes').click(function(){
$('#showadvancedattributes').hide();
$('#hideadvancedattributes').show();
$('#advancedquestionsettingswrapper').animate({
"height": "toggle", "opacity": "toggle"
});
})
$('#hideadvancedattributes').click(function(){
$('#showadvancedattributes').show();
$('#hideadvancedattributes').hide();
$('#advancedquestionsettingswrapper').animate({
"height": "toggle", "opacity": "toggle"
});
})
$('#question_type').change(updatequestionattributes);
});
//We have form validation and other stuff..
function updatequestionattributes()
{
$('.loader').show();
$('#advancedquestionsettings').html('');
$('#advancedquestionsettings').load('admin.php?action=ajaxquestionattributes',{qid:$('#qid').val(),
question_type:$('#question_type').val(),
sid:$('#sid').val()
}, function(){
// Loads the tooltips for the toolbars
// Loads the tooltips for the toolbars
$('.loader').hide();
$('label[title]').qtip({
style: { name: 'cream',
tip: true,
color:'#111111',
border: {
width: 1,
radius: 5,
color: '#EADF95'}
},
position: { adjust: {
screen: true, scroll:true },
corner: {
target: 'bottomRight'}
},
show: {effect: { length:50}}
});}
);
}
function validatefilename (form, strmessage )
{
if (form.the_file.value == "") {
alert( strmessage );
form.the_file.focus();
return false ;
}
return true ;
}
// If the length of the element's string is 0 then display helper message
function isEmpty(elem, helperMsg)
{
if(elem.value.length == 0){
alert(helperMsg);
elem.focus(); // set the focus to this input
return false;
}
return true;
}
function codeCheck(prefix, elementcount, helperMsg)
{
var i, j;
var X = new Array();
for (i=0; i<=elementcount; i++) {
j = document.getElementById(prefix+i);
if (j != undefined)
{
j.value=trim(j.value);
X.push(j.value);
}
}
if (arrHasDupes(X))
{
alert(helperMsg);
return false;
}
return true;
}
function arrHasDupes( A ) { // finds any duplicate array elements using the fewest possible comparison
var i, j, n;
n=A.length;
// to ensure the fewest possible comparisons
for (i=0; i<n; i++) { // outer loop uses each item i at 0 through n
for (j=i+1; j<n; j++) { // inner loop only compares items j at i+1 to n
if (A[i]==A[j]) return true;
} }
return false;
}
// (c) 2006 Simon Wunderlin, License: GPL, hacks want to be free ;)
// This fix forces Firefox to fire the onchange event if someone changes select box with cursor keys
function ev_gecko_select_keyup_ev(Ev) {
// prevent tab, alt, ctrl keys from fireing the event
if (Ev.keyCode && (Ev.keyCode == 1 || Ev.keyCode == 9 ||
Ev.keyCode == 16 || Ev.altKey || Ev.ctrlKey))
return true;
Ev.target.onchange();
return true;
}
function init_gecko_select_hack() {
var selects = document.getElementsByTagName("SELECT");
for(i=0; i<selects.length; i++)
selects.item(i).addEventListener("keyup", ev_gecko_select_keyup_ev, false);
return true;
}
function getkey(e)
{
if (window.event) return window.event.keyCode;
else
if (e) return e.which;
else return null;
}
function goodchars(e, goods)
{
var key, keychar;
key = getkey(e);
if (key == null) return true;
// get character
keychar = String.fromCharCode(key);
keychar = keychar.toLowerCase();
goods = goods.toLowerCase();
// check goodkeys
if (goods.indexOf(keychar) != -1)
return true;
// control keys
if ( key==null || key==0 || key==8 || key==9 || key==27 )
return true;
// else return false
return false;
}
function trim(stringToTrim) {
return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function DoAdd()
{
if (document.getElementById("available_languages").selectedIndex>-1)
{
var strText = document.getElementById("available_languages").options[document.getElementById("available_languages").selectedIndex].text;
var strId = document.getElementById("available_languages").options[document.getElementById("available_languages").selectedIndex].value;
AddItem(document.getElementById("additional_languages"), strText, strId);
RemoveItem(document.getElementById("available_languages"), document.getElementById("available_languages").selectedIndex);
sortSelect(document.getElementById("additional_languages"));
UpdateLanguageIDs();
}
}
function DoRemove(minItems,strmsg)
{
var strText = document.getElementById("additional_languages").options[document.getElementById("additional_languages").selectedIndex].text;
var strId = document.getElementById("additional_languages").options[document.getElementById("additional_languages").selectedIndex].value;
if (document.getElementById("additional_languages").options.length>minItems)
{
AddItem(document.getElementById("available_languages"), strText, strId);
RemoveItem(document.getElementById("additional_languages"), document.getElementById("additional_languages").selectedIndex);
sortSelect(document.getElementById("available_languages"));
UpdateLanguageIDs();
}
else
if (strmsg!=''){alert(strmsg);}
}
function AddItem(objListBox, strText, strId)
{
var newOpt;
newOpt = document.createElement("OPTION");
newOpt = new Option(strText,strId);
newOpt.id = strId;
objListBox.options[objListBox.length]=newOpt;
}
function RemoveItem(objListBox, strId)
{
if (strId > -1)
objListBox.options[strId]=null;
}
function GetItemIndex(objListBox, strId)
{
for (var i = 0; i < objListBox.children.length; i++)
{
var strCurrentValueId = objListBox.children[i].id;
if (strId == strCurrentValueId)
{
return i;
}
}
return -1;
}
function UpdateLanguageIDs(mylangs,confirmtxt)
{
document.getElementById("languageids").value = '';
var lbBox = document.getElementById("additional_languages");
for (var i = 0; i < lbBox.options.length; i++)
{
document.getElementById("languageids").value = document.getElementById("languageids").value + lbBox.options[i].value+ ' ';
}
if (mylangs)
{
if (checklangs(mylangs))
{
return true;
} else
{
return confirm(confirmtxt);
}
}
}
function compareText (option1, option2) {
return option1.text < option2.text ? -1 :
option1.text > option2.text ? 1 : 0;
}
function compareValue (option1, option2) {
return option1.value < option2.value ? -1 :
option1.value > option2.value ? 1 : 0;
}
function compareTextAsFloat (option1, option2) {
var value1 = parseFloat(option1.text);
var value2 = parseFloat(option2.text);
return value1 < value2 ? -1 :
value1 > value2 ? 1 : 0;
}
function compareValueAsFloat (option1, option2) {
var value1 = parseFloat(option1.value);
var value2 = parseFloat(option2.value);
return value1 < value2 ? -1 :
value1 > value2 ? 1 : 0;
}
function sortSelect (select, compareFunction) {
if (!compareFunction)
compareFunction = compareText;
var options = new Array (select.options.length);
for (var i = 0; i < options.length; i++)
options[i] =
new Option (
select.options[i].text,
select.options[i].value,
select.options[i].defaultSelected,
select.options[i].selected
);
options.sort(compareFunction);
select.options.length = 0;
for (var i = 0; i < options.length; i++)
select.options[i] = options[i];
}
function checklangs(mylangs)
{
selObject=document.getElementById("additional_languages");
var found;
for (x = 0; x < mylangs.length; x++)
{
found = 0;
for (i=0;i<selObject.options.length;i++)
{
if(selObject.options[i].value == mylangs[x])
{
found = 1;
break;
}
}
if (found == 0) { return false; }
}
return true;
}