1
|
/****************************************************************************
|
2
|
* Multiple Assessment download
|
3
|
* @param form containing the neceassary input items
|
4
|
* @return true/false for form submission
|
5
|
*****************************************************************************/
|
6
|
function multipleAssessmentSearch(submitFormObj, fieldFormObj) {
|
7
|
|
8
|
//alert("submitFormObj=" + submitFormObj);
|
9
|
//harvest the metadata fields we want to include
|
10
|
var metadataObjs = new Array();
|
11
|
var index = 0;
|
12
|
for (var i=0; i < fieldFormObj.length; i++) {
|
13
|
var formElement = fieldFormObj.elements[i];
|
14
|
var metadataObj = new Object();
|
15
|
metadataObj.name = formElement.name;
|
16
|
metadataObj.value = formElement.value;
|
17
|
metadataObjs[index] = metadataObj;
|
18
|
index++;
|
19
|
}
|
20
|
|
21
|
//TODO option for all questions vs. just one
|
22
|
//var questionId = submitFormObj.questionId.value;
|
23
|
//alert("questionId=" + questionId);
|
24
|
|
25
|
var documentObjects = new Array();
|
26
|
var index = 0;
|
27
|
if (submitFormObj.docid.length > 1) {
|
28
|
for (var i=0; i < submitFormObj.docid.length; i++) {
|
29
|
if (submitFormObj.docid[i].value != "") {
|
30
|
var documentObject = new Object();
|
31
|
documentObject.docid = submitFormObj.docid[i].value;
|
32
|
|
33
|
var questionIds = new Array();
|
34
|
for (var z = 0; z < submitFormObj[documentObject.docid].length; z++) {
|
35
|
questionIds[z] = submitFormObj[documentObject.docid][z].value;
|
36
|
}
|
37
|
|
38
|
documentObject.questionIds = questionIds;
|
39
|
documentObjects[index] = documentObject;
|
40
|
index++;
|
41
|
}
|
42
|
}
|
43
|
}
|
44
|
else {
|
45
|
//alert("submitFormObj.docid=" + submitFormObj.docid);
|
46
|
if (submitFormObj.docid.value != "") {
|
47
|
var documentObject = new Object();
|
48
|
documentObject.docid = submitFormObj.docid.value;
|
49
|
|
50
|
var questionIds = new Array();
|
51
|
for (var z = 0; z < submitFormObj[documentObject.docid].length; z++) {
|
52
|
questionIds[z] = submitFormObj[documentObject.docid][z].value;
|
53
|
}
|
54
|
|
55
|
documentObject.questionIds = questionIds;
|
56
|
documentObjects[0] = documentObject;
|
57
|
}
|
58
|
}
|
59
|
|
60
|
var query = generateQuery(documentObjects, metadataObjs);
|
61
|
|
62
|
submitFormObj.dataquery.value = query;
|
63
|
|
64
|
return true;
|
65
|
|
66
|
}
|
67
|
|
68
|
/****************************************************************************
|
69
|
* Single Assessment download
|
70
|
* @param form containing the neceassary input items
|
71
|
* @return true/false for form submission
|
72
|
*****************************************************************************/
|
73
|
function assessmentSearch(submitFormObj) {
|
74
|
|
75
|
//harvest the metadata fields we want to include
|
76
|
var metadataObjs = new Array();
|
77
|
var index = 0;
|
78
|
for (var i=0; i < submitFormObj.length; i++) {
|
79
|
var formElement = submitFormObj.elements[i];
|
80
|
if (formElement.type == "checkbox" && formElement.checked) {
|
81
|
//ignore certain other checkboxes, kind of a hack
|
82
|
if (formElement.name == "includeQuestions") {
|
83
|
continue;
|
84
|
}
|
85
|
var metadataObj = new Object();
|
86
|
metadataObj.name = formElement.name;
|
87
|
metadataObj.value = formElement.value;
|
88
|
metadataObjs[index] = metadataObj;
|
89
|
index++;
|
90
|
}
|
91
|
}
|
92
|
|
93
|
//var checkBox = document.getElementById("searchAll");
|
94
|
var docId = submitFormObj.docid.value;
|
95
|
//alert("docId=" + docId);
|
96
|
|
97
|
//do we want question metadata?
|
98
|
var includeQuestions = submitFormObj.includeQuestions.checked;
|
99
|
var questionIds = new Array();
|
100
|
questionIds[0] = "";
|
101
|
|
102
|
if (includeQuestions) {
|
103
|
if (submitFormObj.assessmentItemId.length > 1) {
|
104
|
for (var i=0; i < submitFormObj.assessmentItemId.length; i++) {
|
105
|
questionIds[i] = submitFormObj.assessmentItemId[i].value;
|
106
|
}
|
107
|
}
|
108
|
else {
|
109
|
questionIds[0] = submitFormObj.assessmentItemId.value;
|
110
|
}
|
111
|
}
|
112
|
|
113
|
//set up the list of objects to pass to the query assembler, just one document
|
114
|
var documentObjects = new Array();
|
115
|
var documentObject = new Object();
|
116
|
documentObject.docid = docId;
|
117
|
documentObject.questionIds = questionIds;
|
118
|
documentObjects[0] = documentObject;
|
119
|
|
120
|
var query = generateQuery(documentObjects, metadataObjs);
|
121
|
|
122
|
submitFormObj.dataquery.value = query;
|
123
|
|
124
|
return true;
|
125
|
|
126
|
}
|
127
|
|
128
|
/****************************************************************************
|
129
|
* Save fields for the attribute maping
|
130
|
* @param formId containing the neceassary input items
|
131
|
* @return true/false for form submission
|
132
|
*****************************************************************************/
|
133
|
function saveFields(formId, metacatURL) {
|
134
|
|
135
|
var submitFormObj = document.getElementById(formId);
|
136
|
|
137
|
//send the request to clear
|
138
|
var myRequest = new Ajax.Request(
|
139
|
metacatURL,
|
140
|
{ method: 'post',
|
141
|
parameters: {
|
142
|
action: 'editcart',
|
143
|
operation: 'clearfields'},
|
144
|
evalScripts: true,
|
145
|
//onSuccess: function(transport) {alert('success: ' + transport.status);},
|
146
|
onFailure: function(transport) {alert('failure clearing fields');}
|
147
|
});
|
148
|
|
149
|
//go through the check boxes and set the ones we want
|
150
|
var count = 0;
|
151
|
for (var i=0; i < submitFormObj.length; i++) {
|
152
|
var formElement = submitFormObj.elements[i];
|
153
|
if (formElement.type == "checkbox" && formElement.checked) {
|
154
|
//ignore certain other checkboxes, kind of a hack, but it's javascript...
|
155
|
if (formElement.name == "includeQuestions") {
|
156
|
continue;
|
157
|
}
|
158
|
if (formElement.name == "docid") {
|
159
|
continue;
|
160
|
}
|
161
|
|
162
|
//send the request
|
163
|
var myRequest = new Ajax.Request(
|
164
|
metacatURL,
|
165
|
{ method: 'post',
|
166
|
parameters: {
|
167
|
action: 'editcart',
|
168
|
operation: 'addfield',
|
169
|
field: formElement.name,
|
170
|
path: formElement.value},
|
171
|
evalScripts: true,
|
172
|
onSuccess: function(transport) {
|
173
|
//alert('Selections saved: ' + operation);
|
174
|
//refresh after the save
|
175
|
if (document.getElementById("ajaxCartResults")) {
|
176
|
window.location.reload();
|
177
|
}
|
178
|
else {
|
179
|
window.document.getElementById("iframeheaderclass").src=window.document.getElementById("iframeheaderclass").src;
|
180
|
}
|
181
|
},
|
182
|
onFailure: function(transport) {alert('failure saving field: ' + formElement.name);}
|
183
|
});
|
184
|
count++;
|
185
|
}
|
186
|
}
|
187
|
|
188
|
//window.document.getElementById("iframeheaderclass").src = window.document.getElementById("iframeheaderclass").src;
|
189
|
|
190
|
//alert(count + ' Field selections saved.');
|
191
|
|
192
|
return true;
|
193
|
|
194
|
}
|
195
|
|
196
|
/****************************************************************************
|
197
|
* Query Generation function
|
198
|
* @param docObjs is an Array of Objects with "docid" (String) and "questionIds" (Array) properties
|
199
|
* @param metadataObjs is an Array of Objects with "name" and "value" properties (both String)
|
200
|
* @return generated query string
|
201
|
*****************************************************************************/
|
202
|
function generateQuery(docObjs, metadataObjs) {
|
203
|
//alert("calling method");
|
204
|
|
205
|
//construct the assessment metadata attribute selection snippet
|
206
|
var metadataAttributes = "";
|
207
|
var index = 0;
|
208
|
for (var j=0; j < metadataObjs.length; j++) {
|
209
|
var metadataObj = metadataObjs[j];
|
210
|
|
211
|
metadataAttributes += "<attribute index=\"";
|
212
|
metadataAttributes += index;
|
213
|
metadataAttributes += "\">";
|
214
|
|
215
|
metadataAttributes += "<pathexpr label=\"";
|
216
|
metadataAttributes += metadataObj.name;
|
217
|
metadataAttributes += "\">";
|
218
|
metadataAttributes += metadataObj.value;
|
219
|
metadataAttributes += "</pathexpr>";
|
220
|
|
221
|
metadataAttributes += "</attribute>";
|
222
|
|
223
|
index++;
|
224
|
}//metadataObjs loop
|
225
|
|
226
|
|
227
|
//construct the begining of the query
|
228
|
var tempQuery =
|
229
|
"<?xml version=\"1.0\"?>"
|
230
|
+ "<dataquery>"
|
231
|
+ "<union>";
|
232
|
|
233
|
for (var i=0; i < docObjs.length; i++) {
|
234
|
|
235
|
var docId = docObjs[i].docid;
|
236
|
//alert("docId=" + docId);
|
237
|
|
238
|
//get the question ids for this question
|
239
|
var questionIds = docObjs[i].questionIds;
|
240
|
|
241
|
//alert("questionIds=" + questionIds);
|
242
|
|
243
|
//assemble the assessment metadata
|
244
|
var metadataAttributeSelection = "";
|
245
|
if (metadataAttributes.length > 0) {
|
246
|
metadataAttributeSelection =
|
247
|
"<datapackage id=\"" + docId + "\">"
|
248
|
+ "<entity id=\"" + docId + "\">"
|
249
|
+ metadataAttributes
|
250
|
+ "</entity>"
|
251
|
+ "</datapackage>";
|
252
|
}
|
253
|
|
254
|
//loop for each question item
|
255
|
for (var k=0; k < questionIds.length; k++) {
|
256
|
var questionId = questionIds[k];
|
257
|
|
258
|
tempQuery +=
|
259
|
"<query>"
|
260
|
//select the data
|
261
|
+ "<selection>"
|
262
|
+ "<datapackage id=\"" + docId + "\">"
|
263
|
+ "<entity index=\"0\">"
|
264
|
+ "<attribute index=\"0\"/>"
|
265
|
+ "<attribute index=\"1\"/>"
|
266
|
//omit student id attribute
|
267
|
+ "<attribute index=\"3\"/>"
|
268
|
+ "<attribute index=\"4\"/>"
|
269
|
+ "</entity>"
|
270
|
+ "</datapackage>";
|
271
|
|
272
|
//select the metadata
|
273
|
tempQuery += metadataAttributeSelection;
|
274
|
|
275
|
//select the question metadata
|
276
|
if (questionId.length > 0) {
|
277
|
tempQuery +=
|
278
|
"<datapackage id=\"" + questionId + "\">"
|
279
|
+ "<entity id=\"" + questionId + "\">"
|
280
|
+ "<attribute index=\"0\">"
|
281
|
+ "<pathexpr label=\"qId\">//assessment/section/item/@ident</pathexpr>"
|
282
|
+ "</attribute>"
|
283
|
+ "<attribute index=\"1\">"
|
284
|
+ "<pathexpr label=\"qTitle\">//assessment/section/item/@title</pathexpr>"
|
285
|
+ "</attribute>"
|
286
|
+ "<attribute index=\"2\">"
|
287
|
+ "<pathexpr label=\"qLabel\">//assessment/section/item/presentation/@label</pathexpr>"
|
288
|
+ "</attribute>"
|
289
|
+ "</entity>"
|
290
|
+ "</datapackage>";
|
291
|
}
|
292
|
|
293
|
tempQuery += "</selection>";
|
294
|
|
295
|
//join to the quesion "table"
|
296
|
if (questionId.length > 0) {
|
297
|
tempQuery +=
|
298
|
"<where>"
|
299
|
+ "<condition type=\"join\">"
|
300
|
+ "<left>"
|
301
|
+ "<datapackage id=\"" + docId + "\">"
|
302
|
+ "<entity index=\"0\">"
|
303
|
+ "<attribute index=\"1\"/>"
|
304
|
+ "</entity>"
|
305
|
+ "</datapackage>"
|
306
|
+ "</left>"
|
307
|
+ "<operator>=</operator>"
|
308
|
+ "<right>"
|
309
|
+ "<datapackage id=\"" + questionId + "\">"
|
310
|
+ "<entity id=\"" + questionId + "\">"
|
311
|
+ "<attribute index=\"0\">"
|
312
|
+ "<pathexpr label=\"qId\">//assessment/section/item/@ident</pathexpr>"
|
313
|
+ "</attribute>"
|
314
|
+ "</entity>"
|
315
|
+ "</datapackage>"
|
316
|
+ "</right>"
|
317
|
+ "</condition>"
|
318
|
+ "</where>";
|
319
|
}
|
320
|
|
321
|
tempQuery += "</query>";
|
322
|
|
323
|
} // for questionId loop
|
324
|
|
325
|
|
326
|
} //for docObjs loop
|
327
|
|
328
|
tempQuery +=
|
329
|
"</union>"
|
330
|
+ "</dataquery>";
|
331
|
|
332
|
//alert(tempQuery);
|
333
|
|
334
|
return tempQuery;
|
335
|
}
|
336
|
|
337
|
/**
|
338
|
* @param searchTerms - and object (hashtable) with, pay attention now:
|
339
|
keys are search values
|
340
|
* values are pathexprs
|
341
|
**/
|
342
|
function generateSearchString(searchTerms, operator, searchAssessments, searchAssessmentItems) {
|
343
|
var queryString =
|
344
|
"<pathquery version=\"1.2\">"
|
345
|
+"<querytitle>Web-Search</querytitle>";
|
346
|
|
347
|
/** assessments **/
|
348
|
if (searchAssessments) {
|
349
|
|
350
|
queryString +=
|
351
|
"<returndoctype>edml://ecoinformatics.org/edml</returndoctype>"
|
352
|
|
353
|
//assessment fields
|
354
|
+"<returnfield>assessment/duration</returnfield>"
|
355
|
+"<returnfield>assessment/@title</returnfield>"
|
356
|
+"<returnfield>assessment/@id</returnfield>"
|
357
|
+"<returnfield>lom/general/title/string</returnfield>"
|
358
|
+"<returnfield>lom/general/keyword/string</returnfield>"
|
359
|
+"<returnfield>individualName/surName</returnfield>"
|
360
|
+"<returnfield>organizationName</returnfield>"
|
361
|
|
362
|
+"<returnfield>assessmentItems/assessmentItem/assessmentItemId</returnfield>";
|
363
|
|
364
|
}
|
365
|
|
366
|
/** questions **/
|
367
|
if (searchAssessmentItems) {
|
368
|
queryString +=
|
369
|
"<returndoctype>http://www.imsglobal.org/xsd/ims_qtiasiv1p2</returndoctype>"
|
370
|
|
371
|
//question (qti) fields
|
372
|
+"<returnfield>item/@title</returnfield>"
|
373
|
+"<returnfield>item/@ident</returnfield>"
|
374
|
+"<returnfield>qtimetadata/qtimetadatafield/fieldlabel</returnfield>"
|
375
|
+"<returnfield>qtimetadata/qtimetadatafield/fieldentry</returnfield>"
|
376
|
//classification
|
377
|
+"<returnfield>fieldlabel</returnfield>"
|
378
|
+"<returnfield>fieldentry</returnfield>"
|
379
|
+"<returnfield>objectives/material/mattext</returnfield>"
|
380
|
//question content
|
381
|
+"<returnfield>presentation/flow/material/mattext</returnfield>"
|
382
|
+"<returnfield>response_label/@ident</returnfield>"
|
383
|
+"<returnfield>response_label/material/mattext</returnfield>";
|
384
|
}
|
385
|
|
386
|
queryString +=
|
387
|
"<querygroup operator=\"" + operator + "\">";
|
388
|
|
389
|
for (var i in searchTerms) {
|
390
|
var key = i;
|
391
|
var value = searchTerms[i];
|
392
|
//only if we have a value
|
393
|
if (value.length > 0) {
|
394
|
queryString +=
|
395
|
"<queryterm searchmode=\"contains\" casesensitive=\"false\">";
|
396
|
if (key != "anyValue") {
|
397
|
queryString += "<pathexpr>" + key + "</pathexpr>";
|
398
|
}
|
399
|
queryString += "<value>" + value + "</value>";
|
400
|
queryString +="</queryterm>";
|
401
|
}
|
402
|
}
|
403
|
|
404
|
queryString +=
|
405
|
"</querygroup>"
|
406
|
+"</pathquery>";
|
407
|
|
408
|
return queryString;
|
409
|
|
410
|
}
|
411
|
|
412
|
|
413
|
function generateAssessmentSearchString(assessmentItemId) {
|
414
|
var query =
|
415
|
"<pathquery version='1.2'>"
|
416
|
+"<querytitle>Containing-Assessment-Search</querytitle>"
|
417
|
|
418
|
+"<returndoctype>edml://ecoinformatics.org/edml</returndoctype>"
|
419
|
|
420
|
+"<returnfield>assessment/@title</returnfield>"
|
421
|
+"<returnfield>assessment/@id</returnfield>"
|
422
|
+"<returnfield>assessment/duration</returnfield>"
|
423
|
+"<returnfield>lom/general/title/string</returnfield>"
|
424
|
+"<returnfield>lom/general/keyword/string</returnfield>"
|
425
|
+"<returnfield>individualName/surName</returnfield>"
|
426
|
+"<returnfield>organizationName</returnfield>"
|
427
|
|
428
|
+"<returnfield>assessmentItems/assessmentItem/assessmentItemId</returnfield>";
|
429
|
|
430
|
if (assessmentItemId.length > 0) {
|
431
|
query += "<querygroup operator='UNION'>";
|
432
|
|
433
|
//add the assessmentId if included
|
434
|
query +=
|
435
|
"<queryterm searchmode='contains' casesensitive='false'>"
|
436
|
+"<value>"
|
437
|
+ assessmentItemId
|
438
|
+"</value>"
|
439
|
+"<pathexpr>assessmentItemId</pathexpr>"
|
440
|
+"</queryterm>";
|
441
|
|
442
|
//close the query group
|
443
|
query +=
|
444
|
"</querygroup>";
|
445
|
}
|
446
|
|
447
|
query += "</pathquery>";
|
448
|
|
449
|
return query;
|
450
|
}
|
451
|
|
452
|
function generateAssessmentListString(assessmentIds) {
|
453
|
var query =
|
454
|
"<pathquery version='1.2'>"
|
455
|
+"<querytitle>Assessment-List</querytitle>"
|
456
|
|
457
|
+"<returndoctype>edml://ecoinformatics.org/edml</returndoctype>"
|
458
|
|
459
|
+"<returnfield>assessment/@title</returnfield>"
|
460
|
+"<returnfield>assessment/@id</returnfield>"
|
461
|
+"<returnfield>assessment/duration</returnfield>"
|
462
|
+"<returnfield>lom/general/title/string</returnfield>"
|
463
|
+"<returnfield>lom/general/keyword/string</returnfield>"
|
464
|
+"<returnfield>individualName/surName</returnfield>"
|
465
|
+"<returnfield>organizationName</returnfield>"
|
466
|
|
467
|
+"<returnfield>assessmentItems/assessmentItem/assessmentItemId</returnfield>";
|
468
|
|
469
|
if (assessmentIds.length > 0) {
|
470
|
query += "<querygroup operator='UNION'>";
|
471
|
|
472
|
//add the assessmentId if included
|
473
|
for (var i=0; i < assessmentIds.length; i++) {
|
474
|
query +=
|
475
|
"<queryterm searchmode='equals' casesensitive='false'>"
|
476
|
+"<value>"
|
477
|
+ assessmentIds[i]
|
478
|
+"</value>"
|
479
|
+"<pathexpr>@packageId</pathexpr>"
|
480
|
+"</queryterm>";
|
481
|
}
|
482
|
//close the query group
|
483
|
query +=
|
484
|
"</querygroup>";
|
485
|
}
|
486
|
|
487
|
query += "</pathquery>";
|
488
|
|
489
|
return query;
|
490
|
}
|
491
|
|
492
|
function callAjax(metacatURL, myQuery, qfmt, divId) {
|
493
|
|
494
|
//alert("calling ajax: " + metacatURL);
|
495
|
//alert("myQuery: " + myQuery);
|
496
|
|
497
|
//var myRequest = new Ajax.Request(
|
498
|
var myUpdate = new Ajax.Updater(
|
499
|
divId,
|
500
|
metacatURL,
|
501
|
{ method: 'post',
|
502
|
parameters: { action: 'squery', qformat: qfmt, query: myQuery},
|
503
|
evalScripts: true,
|
504
|
//onSuccess: function(transport) {alert('success: ' + transport.status);},
|
505
|
onFailure: function(transport) {alert('failure making ajax call');}
|
506
|
});
|
507
|
|
508
|
//alert("done calling ajax");
|
509
|
}
|
510
|
function getIframeDocument(iframeId) {
|
511
|
//look up the document
|
512
|
var iframe = window.document.getElementById(iframeId);
|
513
|
var doc = null;
|
514
|
if (iframe.contentDocument) {
|
515
|
doc = iframe.contentDocument;
|
516
|
}
|
517
|
else {
|
518
|
doc = iframe.contentWindow.document;
|
519
|
}
|
520
|
return doc;
|
521
|
}
|