-
Notifications
You must be signed in to change notification settings - Fork 988
/
admin_core.js
769 lines (687 loc) · 23.1 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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
/*
* JavaScript functions for LimeSurvey administrator
*
* This file is part of LimeSurvey
* Copyright (C) 2007-2013 The LimeSurvey Project Team / Carsten Schmitz
* All rights reserved.
* License: GNU/GPL License v2 or later, see LICENSE.php
* LimeSurvey is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/
$(document).ready(function(){
initializeAjaxProgress();
tableCellAdapters();
if(typeof(userdateformat) !== 'undefined')
{
$(".popupdate").each(function(i,e) {
format=$('#dateformat'+e.name).val();
if(!format) format = userdateformat;
$(e).datepicker({ dateFormat: format,
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]);
}
$(".sf-menu").superfish({speed: 'fast'});
doToolTip();
$('button,input[type=submit],input[type=button],input[type=reset],.button').button();
$('button,input[type=submit],input[type=button],input[type=reset],.button').addClass("limebutton");
$(".progressbar").each(function(){
var pValue = parseInt($(this).attr('name'));
$(this).progressbar({
value: pValue
});
if (pValue > 85){
$("div",$(this)).css({ 'background': 'Red' });
}
$("div",this).html(pValue + "%");
});
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);
$('#MinimizeGroupWindow').click(function(){
$('#groupdetails').hide();
});
$('#MaximizeGroupWindow').click(function(){
$('#groupdetails').show();
});
$('#tabs').tabs();
$('.tab-nav').tabs();
$(".flashmessage").each(function() {
$(this).notify().notify('create','themeroller',{},{custom:true,
speed: 500,
expires: 5000
});
});
if ($("#question_type").not('.none').length > 0 && $("#question_type").attr('type')!='hidden'){
/*
$("#question_type").msDropDown({
'on' : {
'create' :qTypeDropdownInit
}
});
*/
qTypeDropdownInit();
$("#question_type").change(function(event){
var selected_value = qDescToCode[''+$("#question_type_child .selected").text()];
OtherSelection(selected_value);
});
}
$("#question_type.none").change(function(event){
var selected_value = $("#question_type").val();
OtherSelection(selected_value);
});
});
function qTypeDropdownInit()
{
$(document).ready(function () {
$("#question_type option").each(function(index,element){
$(element).qtip({
style: {
classes: 'qtip-questiontype'
},
content: getToolTip($(element).text()),
position: {
my : 'top left',
at: 'top right',
target: $('label[for=question_type]'),
viewport: $(window),
adjust: {
x: 20
}
}
});
});
});
$(document).ready(function() {
$('body').on('mouseenter mouseleave', 'li.questionType', function(e) {
if (e.type = 'mouseenter')
{
// Hide all others if we show a new one.
$('#question_type option').qtip('hide');
$($(e.currentTarget).data().select2Data.element).qtip('option', 'position.target', $(e.currentTarget)).qtip('show');
}
else
{
$($(e.currentTarget).data().select2Data.element).qtip('hide');
}
});
});
}
var aToolTipData = {
};
var qDescToCode;
var qCodeToInfo;
function getToolTip(type){
var code = qDescToCode[''+type];
var multiple = 0;
if (code=='S') multiple = 2;
if (code == ":") code = "COLON";
else if(code == "|") code = "PIPE";
else if(code == "*") code = "EQUATION";
if (multiple > 0){
returnval = '';
for(i=1;i<=multiple;i++){
returnval = returnval + "<img src='" + imgurl + "/screenshots/"+code+i+".png' /><br /><br />";
}
return returnval;
}
return "<img src='" + imgurl + "/screenshots/"+code+".png' />";
}
//We have form validation and other stuff..
function updatequestionattributes()
{
$('.loader').show();
$('#advancedquestionsettings').html('');
var selected_value = qDescToCode[''+$("#question_type_child .selected").text()];
if (selected_value==undefined) selected_value = $("#question_type").val();
$('#advancedquestionsettings').load(attr_url,{qid:$('#qid').val(),
question_type:selected_value,
sid:$('#sid').val(),
'YII_CSRF_TOKEN':yii_csrf
}, 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 ;
}
function doToolTip()
{
// ToolTip on menu
$(".sf-menu li").each(function() {
tipcontent=$(this).children("a").children("img").attr('alt');
if(tipcontent && tipcontent!=""){
$(this).qtip({
content: {
text: tipcontent
},
style: {
classes: "qtip-light qtip-rounded"
},
position: {
my: 'bottom left',
at: "top right"
}
});
}
});
$(".sf-menu a > img[alt]").removeAttr("alt");
$("a").each(function() {
tipcontent=$(this).children("img").attr('alt');
if(!tipcontent){tipcontent=$(this).attr('title');}
if(tipcontent && tipcontent!=""){
$(this).qtip({
content: {
text: tipcontent
},
style: {
classes: "qtip-light qtip-rounded"
},
position: {
viewport: $(window),
at: 'bottom right'
}
});
}
});
$("a > img[alt]").removeAttr("alt");
// Call the popuptip hover rel attribute
$('.popuptip').each(function(){
if($(this).attr('rel')){
htmlcontent=$(this).html();
tiptarget=$("#"+$(this).attr('rel'));
//if($("#"+$(this).attr('rel')).find('img').length==1){ tiptarget=$("#"+$(this).attr('rel')).find('img');}
tiptarget.qtip({
content: {
text: htmlcontent
},
style: {
classes: "qtip-light qtip-rounded"
},
position: {
at: "bottom center",
my: "top center"
},
hide: {
fixed: true,
delay: 500,
event: "mouseout"
}
});
$("#"+$(this).attr('rel')).find("img").removeAttr("alt"); // Remove children img attr alt, the default tooltip can apply.
}
});
// On label
$('label[title]').each(function() {
if($(this).attr('title') != '')
{
$(this).qtip({
style: {
classes: "qtip-cream qtip-rounded"
},
position: {
viewport: $(window),
at: "bottom right"
}
});
}
});
// Loads the tooltips on image
$('img[alt],input[src]').each(function() {
if($(this).attr('alt') != ''){
$(this).qtip({
content: {
attr: "alt"
},
style: {
classes: "qtip-light qtip-rounded"
},
position: {
viewport: $(window),
at: "bottom right"
},
hide: {
event: "mouseout"
}
});
}
});
//Still used ?
$('.tipme').each(function() {
if($(this).attr('alt') != '')
{
$(this).qtip(
{
content: {
attr: 'alt'
},
style: {
classes: "qtip-cream qtip-rounded"
},
position: {
viewport: $(window),
at: 'top right',
tooltip: 'bottom left'
}
});
}
});
}
// If the length of the element's string is 0 then display helper message
function isEmpty(elem, helperMsg)
{
if($.trim(elem.value).length == 0){
alert(helperMsg);
elem.focus(); // set the focus to this input
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() {
return true;
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;
}
function isset( variable )
{
return( typeof( variable ) != 'undefined' );
}
String.prototype.splitCSV = function(sep) {
for (var foo = this.split(sep = sep || ","), x = foo.length - 1, tl; x >= 0; x--) {
if (foo[x].replace(/"\s+$/, '"').charAt(foo[x].length - 1) == '"') {
if ((tl = foo[x].replace(/^\s+"/, '"')).length > 1 && tl.charAt(0) == '"') {
foo[x] = foo[x].replace(/^\s*"|"\s*$/g, '').replace(/""/g, '"');
} else if (x) {
foo.splice(x - 1, 2, [foo[x - 1], foo[x]].join(sep));
} else foo = foo.shift().split(sep).concat(foo);
} else foo[x].replace(/""/g, '"');
}return foo;
};
// This is a helper function to extract the question ID from a DOM ID element
function removechars(strtoconvert){
return strtoconvert.replace(/[-a-zA-Z_]/g,"");
}
function htmlspecialchars (string, quote_style, charset, double_encode) {
// Convert special characters to HTML entities
//
// version: 1109.2015
// discuss at: http://phpjs.org/functions/htmlspecialchars // + original by: Mirek Slugen
// + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// + bugfixed by: Nathan
// + bugfixed by: Arno
// + revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) // + bugfixed by: Brett Zamir (http://brett-zamir.me)
// + input by: Ratheous
// + input by: Mailfaker (http://www.weedem.fr/)
// + reimplemented by: Brett Zamir (http://brett-zamir.me)
// + input by: felix // + bugfixed by: Brett Zamir (http://brett-zamir.me)
// % note 1: charset argument not supported
// * example 1: htmlspecialchars("<a href='test'>Test</a>", 'ENT_QUOTES');
// * returns 1: '<a href='test'>Test</a>'
// * example 2: htmlspecialchars("ab\"c'd", ['ENT_NOQUOTES', 'ENT_QUOTES']); // * returns 2: 'ab"c'd'
// * example 3: htmlspecialchars("my "&entity;" is still here", null, null, false);
// * returns 3: 'my "&entity;" is still here'
var optTemp = 0,
i = 0, noquotes = false;
if (typeof quote_style === 'undefined' || quote_style === null) {
quote_style = 2;
}
string = string.toString(); if (double_encode !== false) { // Put this first to avoid double-encoding
string = string.replace(/&/g, '&');
}
string = string.replace(/</g, '<').replace(/>/g, '>');
var OPTS = {
'ENT_NOQUOTES': 0,
'ENT_HTML_QUOTE_SINGLE': 1,
'ENT_HTML_QUOTE_DOUBLE': 2,
'ENT_COMPAT': 2, 'ENT_QUOTES': 3,
'ENT_IGNORE': 4
};
if (quote_style === 0) {
noquotes = true; }
if (typeof quote_style !== 'number') { // Allow for a single string or an array of string flags
quote_style = [].concat(quote_style);
for (i = 0; i < quote_style.length; i++) {
// Resolve string input to bitwise e.g. 'ENT_IGNORE' becomes 4
if (OPTS[quote_style[i]] === 0) {
noquotes = true;
}
else if (OPTS[quote_style[i]]) {
optTemp = optTemp | OPTS[quote_style[i]]; }
}
quote_style = optTemp;
}
if (quote_style & OPTS.ENT_HTML_QUOTE_SINGLE) { string = string.replace(/'/g, ''');
}
if (!noquotes) {
string = string.replace(/"/g, '"');
}
return string;
}
jQuery.fn.center = function () {
this.css("position","absolute");
this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");
this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
return this;
}
// Fix broken substr function with negative start value (in older IE)
if ('ab'.substr(-1) != 'b') {
String.prototype.substr = function(substr) {
return function(start, length) {
if (start < 0) start = this.length + start;
return substr.call(this, start, length);
}
}(String.prototype.substr);
}
/**
* Yii CSRF protection divs breaks this script so this function moves the
* hidden CSRF field out of the div and remove it if needed
*
*/
function removeCSRFDivs()
{
$('input[name=YII_CSRF_TOKEN]').each(function(){
parent = $(this).parent();
grandfather = $(parent).parent();
grandfather.append(this);
parent.remove();
});
}
function initializeAjaxProgress()
{
$('#ajaxprogress').dialog({
'modal' : true,
'closeOnEscape' : false,
'title' : $('#ajaxprogress').attr('title'),
'autoOpen' : false,
'minHeight': 0,
'resizable': false
});
$('#ajaxprogress').bind('ajaxStart', function()
{
$(this).dialog('open');
});
$('#ajaxprogress').bind('ajaxStop', function()
{
$(this).dialog('close');
});
}
/**
* Adapt cell to have a click on cell do a click on input:radio or input:checkbox (if unique)
* Using delegate the can be outside document.ready
*/
function tableCellAdapters()
{
$('table.activecell').delegate('tbody td input:checkbox,tbody td input:radio,tbody td label,tbody th input:checkbox,tbody th input:radio,tbody th label',"click", function(e) {
e.stopPropagation();
});
$('table.activecell').delegate('tbody td,tbody th',"click", function() {
if($(this).find("input:radio,input:checkbox").length==1)
{
$(this).find("input:radio").click();
$(this).find("input:radio").triggerHandler("click");
$(this).find("input:checkbox").click();
$(this).find("input:checkbox").triggerHandler("click");
}
});
}
/**
* sendPost : create a form, fill with param and submit
*
* @param {string} action
* @param {} checkcode : deprecated
* @param {array} arrayparam
* @param {array} arrayval
*
* TODO : use $.post
*/
function sendPost(myaction,checkcode,arrayparam,arrayval)
{
var myform = document.createElement('form');
document.body.appendChild(myform);
myform.action =myaction;
myform.method = 'POST';
for (i=0;i<arrayparam.length;i++)
{
addHiddenElement(myform,arrayparam[i],arrayval[i])
}
if(typeof csrfToken =="string")
{
addHiddenElement(myform,'YII_CSRF_TOKEN',csrfToken);
}
// Maybe submit only if csrfToken is string
myform.submit();
}
function addHiddenElement(theform,thename,thevalue)
{
var myel = document.createElement('input');
myel.type = 'hidden';
myel.name = thename;
theform.appendChild(myel);
myel.value = thevalue;
return myel;
}