/
updateset.js
353 lines (266 loc) · 9.91 KB
/
updateset.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
$(document).ready(function(){
if ($(".answertable tbody").children().length == 0)
add_label(undefined);
$(".btnaddanswer").live('click',add_label);
$(".btndelanswer").live('click',del_label);
$('#neweditlblset0 .answertable tbody').sortable({
update:sort_complete,
distance:2
});
$('#quickadd').dialog({autoOpen: false,
modal: true,
width:600,
title: $("#quickadd").attr('name')});
$('.btnquickadd').live('click',function(){
$('#quickadd').dialog('open');
});
$('#btnqacancel').click(function(){
$('#quickadd').dialog('close');
});
$('#btnqareplace').click(quickaddfunction);
$('#btnqainsert').click(quickaddfunction);
$("#mainform").submit(function(event,ui){
if (code_duplicates_check()==false) return false;
var dataToSend = {};
dataToSend['langs'] = [];
dataToSend['codelist'] = [];
$("#tabs>form>div").each(function(divindex,divelement){
var div_language = $(".lslanguage",divelement).val();
if (typeof(div_language)!="undefined")
dataToSend['langs'].push(div_language);
});
$("tbody>tr",$("#tabs>form>div:first")).each(function(trindex,trelement){
var tr_code = $(trelement).attr('id');
tr_code=tr_code.substr(3);
dataToSend['codelist'].push(tr_code);
dataToSend[tr_code] = {
code: $("#code_"+tr_code).val(),
assessmentvalue: $("#assessmentvalue_"+tr_code).val()
};
$(dataToSend['langs']).each(function(i,e){
dataToSend[tr_code]['text_'+e] = $("[name=title_"+e+"_"+tr_code+"]").val();
});
});
$("input[name=dataToSend]").remove();
var encodedData = htmlspecialchars(js2php(dataToSend));
$("#mainform").append("<input type='hidden' name='dataToSend' value='"+encodedData+"' />");
});
fix_highlighting();
});
function quickaddfunction(){
var lsreplace = false;
if ($(this).attr('id') == 'btnqareplace'){
lsreplace=true;
}
if (lsreplace){
$(".answertable tbody>tr").remove();
}
lsrows=$('#quickaddarea').val().split("\n");
var seperatorchar="\t";
if (lsrows[0].indexOf("\t")==-1){
seperatorchar=';'
}
$(lsrows).each(function(index,element){
code = undefined;
params = element.split(seperatorchar);
k = 0;
if (params.length > $(".lslanguage").length){
code = params[0].replace(/[^a-zA-Z 0-9]+/g,'').substr(0,5);
i++;
}
if (index!=0 || (!lsreplace && $("#tabs>div:not(:last) tbody>tr").length > 0)){
event = {};
event.target = $(".btnaddanswer:last");
var retcode = add_label(event);
}
else{
var retcode = add_label();
}
if (typeof(code)!="undefined")
$("#code_"+retcode).val(code);
$(".lslanguage").each(function(){
$("input[name=title_"+$(this).val()+"_"+retcode+"]").val(params[k]);
k++;
});
});
$("#quickaddarea").html('');
$('#quickadd').dialog('close');
}
function check_onsubmit(element){
var onsub = $(element).attr('onsubmit');
var code = onsub.substr(6,onsub.length);
return eval(code);
}
function sort_complete(event, ui){
var newposition = ($(ui.item).parent().children().index($(ui.item)));
var item = ui.item;
var position = ui.position;
var originalposition = ui.originalPosition;
if (originalposition.top > position.top) newposition = newposition - 1;
$("#tabs div:not(:first) [name="+$(item).attr('name')+"]").each(function(index,element){
var backup = "<tr id='row"+$(item).attr('name')+"'>"+$(element).html()+"</tr>";
if (newposition >= 0)
$($(element).parent().children()[newposition]).after(backup);
else
$(element).parent().prepend(backup);
$(element).remove();
});
fix_highlighting();
}
function add_label(event)
{
if(event!=undefined)
{
if ($(this).closest('tr').find('.codeval').size()>0)
{
next_code=getNextCode($(this).closest('tr').find('.codeval').val());
}
else
{
next_code='L001';
}
while ($('.answertable').find('input[value="'+next_code+'"]').length>0 && next_code!=$(this).closest('tr').find('.codeval').val())
{
next_code=getNextCode(next_code);
}
}
else
{
next_code='L001';
}
var html = createNewLabelTR(true,true);
if (typeof(event)=="undefined")
var row_id = -1;
else
var row_id = ($(event.target).parent().parent().parent().children().index($(event.target).parent().parent()));
var randomid = 'new' + Math.floor(Math.random()*1111111);
html = str_replace("###assessmentval###",'0',html);
html = str_replace("###codeval###",next_code,html);
html = str_replace("###next###",randomid,html);
html = str_replace("###lang###",$("#tabs div:first .lslanguage").val(),html);
if (typeof(event) == "undefined")
$("#tabs div:first tbody").append(html);
else
$(event.target).parent().parent().after(html);
html = createNewLabelTR(true,false);
html = str_replace("###assessmentval###",'0',html);
html = str_replace("###codeval###",next_code,html);
html = str_replace("###next###",randomid,html);
$("#tabs div:not(:first)").each(function(index,element){
var temp_html = str_replace("###lang###",$(".lslanguage",element).val(),html);
if (row_id >= 0){
$($("tbody",element).children()[row_id]).after(temp_html);
}
else
$(".answertable tbody",$(element)).append(temp_html);
});
$("tr[name="+randomid+"]").hide().fadeIn(1000);
fix_highlighting();
return randomid;
}
function del_label(event){
var id = $(event.target).parent().parent().attr('id');
$("#"+id).remove();
fix_highlighting();
if ($(".answertable tbody").children().length == 0)
add_label(undefined);
}
function fix_highlighting(){
$("tbody tr").removeClass("highlight");
$("tbody tr:even").addClass("highlight");
}
function createNewLabelTR(alternate,first){
x = "<tr ";
if (alternate)
x = x + "class= 'highlight' ";
x = x + "style = 'white-space: nowrap;' id='row###next###'>";
if (!first)
x = x + "<td>###codeval###</td><td>###assessmentval###</td>";
else
x = x + "<td><img src=" + sImageURL + "handle.png></td><td>"
+ "<input type='hidden' class='hiddencode' value='###codeval###' />"
+ "<input type='text' class='codeval' value='###codeval###' name='code_###next###' id='code_###next###' size='6' maxlength='5' >"
+ "</td><td>"
+ "<input type=\"text\" class='assessmentval' value=\"###assessmentval###\" name=\"assessmentvalue_###next###\" id=\"assessmentvalue_###next###\" style=\"text-align: right;\" size=\"6\" maxlength=\"5\" >";
x = x + "<td><input name=\"title_###lang###_###next###\" type=\"text\" value=\"\" size=\"80\" maxlength=\"3000\" >"+
"<a title=\"\" id=\"title_###lang###_###next###_ctrl\" href=\"javascript:start_popup_editor('title_###lang###_###next###','[Label:](###lang###)','','','','editlabel','labels')\">"+
"<img height=\"16\" border=\"0\" width=\"16\" src=" + sImageURL + "edithtmlpopup.png name=\"title_###lang###_###next###_popupctrlena\" id=\"title_###lang###_###next###_popupctrlena\" alt=\"\">"+
"<img height=\"16\" border=\"0\" align=\"top\" width=\"16\" style=\"display: none;\" src=" + sImageURL + "edithtmlpopup_disabled.png name=\"title_###lang###_###next###_popupctrldis\" id=\"title_###lang###_###next###_popupctrldis\" alt=\"Give focus to the HTML editor popup window\"></a></td>";
if (first)
x = x + "<td style=\"text-align: center;\"><img class=\"btnaddanswer\" src=" + sImageURL + "addanswer.png><img class=\"btndelanswer\" src=" + sImageURL + "deleteanswer.png></td>";
x = x + "</tr>";
return x;
}
function str_replace (search, replace, subject, count) {
var i = 0, j = 0, temp = '', repl = '', sl = 0, fl = 0,
f = [].concat(search),
r = [].concat(replace),
s = subject,
ra = r instanceof Array, sa = s instanceof Array;
s = [].concat(s);
if (count) {
this.window[count] = 0;
}
for (i=0, sl=s.length; i < sl; i++) {
if (s[i] === '') {
continue;
}
for (j=0, fl=f.length; j < fl; j++) {
temp = s[i]+'';
repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0];
s[i] = (temp).split(f[j]).join(repl);
if (count && s[i] !== temp) {
this.window[count] += (temp.length-s[i].length)/f[j].length;}
}
}
return sa ? s : s[0];
}
function getNextCode(sourcecode)
{
i=1;
found=true;
foundnumber=-1;
while (i<=sourcecode.length && found)
{
found=is_numeric(sourcecode.substr(-i));
if (found)
{
foundnumber=sourcecode.substr(-i);
i++;
}
}
if (foundnumber==-1)
{
return(sourcecode);
}
else
{
foundnumber++;
foundnumber=foundnumber+'';
result=sourcecode.substr(0,sourcecode.length-foundnumber.length)+foundnumber;
return(result);
}
}
function code_duplicates_check()
{
var codearray=[];
$('#tabs>form>div:first input.codeval').each(function(){
sValue=$.trim($(this).val());
$(this).val(sValue);
codearray.push(sValue);
})
if ($.inArray('other', codearray)!=-1)
{
alert(otherisreserved);
return false;
}
if (arrHasDupes(codearray))
{
alert(duplicatelabelcode);
return false;
}
return true;
}
function is_numeric (mixed_var) {
return (typeof(mixed_var) === 'number' || typeof(mixed_var) === 'string') && mixed_var !== '' && !isNaN(mixed_var);
}