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
|
var questionIds = new Array();
|
25
|
questionIds[0] = questionId;
|
26
|
|
27
|
var documentObjects = new Array();
|
28
|
var index = 0;
|
29
|
if (submitFormObj.docid.length > 1) {
|
30
|
for (var i=0; i < submitFormObj.docid.length; i++) {
|
31
|
if (submitFormObj.docid[i].checked) {
|
32
|
var documentObject = new Object();
|
33
|
documentObject.docid = submitFormObj.docid[i].value;
|
34
|
|
35
|
for (var z = 0; z < submitFormObj[documentObject.docid].length; z++) {
|
36
|
questionIds[z] = submitFormObj[documentObject.docid][z].value;
|
37
|
}
|
38
|
|
39
|
documentObject.questionIds = questionIds;
|
40
|
documentObjects[index] = documentObject;
|
41
|
index++;
|
42
|
}
|
43
|
}
|
44
|
}
|
45
|
else {
|
46
|
//alert("submitFormObj.docid=" + submitFormObj.docid);
|
47
|
if (submitFormObj.docid.checked) {
|
48
|
var documentObject = new Object();
|
49
|
documentObject.docid = submitFormObj.docid.value;
|
50
|
|
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
|
155
|
if (formElement.name == "includeQuestions") {
|
156
|
continue;
|
157
|
}
|
158
|
|
159
|
//send the request
|
160
|
var myRequest = new Ajax.Request(
|
161
|
metacatURL,
|
162
|
{ method: 'post',
|
163
|
parameters: {
|
164
|
action: 'editcart',
|
165
|
operation: 'addfield',
|
166
|
field: formElement.name,
|
167
|
path: formElement.value},
|
168
|
evalScripts: true,
|
169
|
//onSuccess: function(transport) {alert('Selections saved: ' + operation); window.document.getElementById("iframeheaderclass").src=window.document.getElementById("iframeheaderclass").src;},
|
170
|
onFailure: function(transport) {alert('failure saving field: ' + formElement.name);}
|
171
|
});
|
172
|
count++;
|
173
|
}
|
174
|
}
|
175
|
|
176
|
window.document.getElementById("iframeheaderclass").src = window.document.getElementById("iframeheaderclass").src;
|
177
|
|
178
|
//alert(count + ' Field selections saved.');
|
179
|
|
180
|
return true;
|
181
|
|
182
|
}
|
183
|
|
184
|
/****************************************************************************
|
185
|
* Query Generation function
|
186
|
* @param docObjs is an Array of Objects with "docid" (String) and "questionIds" (Array) properties
|
187
|
* @param metadataObjs is an Array of Objects with "name" and "value" properties (both String)
|
188
|
* @return generated query string
|
189
|
*****************************************************************************/
|
190
|
function generateQuery(docObjs, metadataObjs) {
|
191
|
//alert("calling method");
|
192
|
|
193
|
//construct the assessment metadata attribute selection snippet
|
194
|
var metadataAttributes = "";
|
195
|
var index = 0;
|
196
|
for (var j=0; j < metadataObjs.length; j++) {
|
197
|
var metadataObj = metadataObjs[j];
|
198
|
|
199
|
metadataAttributes += "<attribute index=\"";
|
200
|
metadataAttributes += index;
|
201
|
metadataAttributes += "\">";
|
202
|
|
203
|
metadataAttributes += "<pathexpr label=\"";
|
204
|
metadataAttributes += metadataObj.name;
|
205
|
metadataAttributes += "\">";
|
206
|
metadataAttributes += metadataObj.value;
|
207
|
metadataAttributes += "</pathexpr>";
|
208
|
|
209
|
metadataAttributes += "</attribute>";
|
210
|
|
211
|
index++;
|
212
|
}//metadataObjs loop
|
213
|
|
214
|
|
215
|
//construct the begining of the query
|
216
|
var tempQuery =
|
217
|
"<?xml version=\"1.0\"?>"
|
218
|
+ "<dataquery>"
|
219
|
+ "<union>";
|
220
|
|
221
|
for (var i=0; i < docObjs.length; i++) {
|
222
|
|
223
|
var docId = docObjs[i].docid;
|
224
|
//alert("docId=" + docId);
|
225
|
|
226
|
//get the question ids for this question
|
227
|
var questionIds = docObjs[i].questionIds;
|
228
|
|
229
|
//alert("questionIds=" + questionIds);
|
230
|
|
231
|
//assemble the assessment metadata
|
232
|
var metadataAttributeSelection = "";
|
233
|
if (metadataAttributes.length > 0) {
|
234
|
metadataAttributeSelection =
|
235
|
"<datapackage id=\"" + docId + "\">"
|
236
|
+ "<entity id=\"" + docId + "\">"
|
237
|
+ metadataAttributes
|
238
|
+ "</entity>"
|
239
|
+ "</datapackage>";
|
240
|
}
|
241
|
|
242
|
//loop for each question item
|
243
|
for (var k=0; k < questionIds.length; k++) {
|
244
|
var questionId = questionIds[k];
|
245
|
|
246
|
tempQuery +=
|
247
|
"<query>"
|
248
|
//select the data
|
249
|
+ "<selection>"
|
250
|
+ "<datapackage id=\"" + docId + "\">"
|
251
|
+ "<entity index=\"0\">"
|
252
|
+ "<attribute index=\"0\"/>"
|
253
|
+ "<attribute index=\"1\"/>"
|
254
|
//omit student id attribute
|
255
|
+ "<attribute index=\"3\"/>"
|
256
|
+ "<attribute index=\"4\"/>"
|
257
|
+ "</entity>"
|
258
|
+ "</datapackage>";
|
259
|
|
260
|
//select the metadata
|
261
|
tempQuery += metadataAttributeSelection;
|
262
|
|
263
|
//select the question metadata
|
264
|
if (questionId.length > 0) {
|
265
|
tempQuery +=
|
266
|
"<datapackage id=\"" + questionId + "\">"
|
267
|
+ "<entity id=\"" + questionId + "\">"
|
268
|
+ "<attribute index=\"0\">"
|
269
|
+ "<pathexpr label=\"qId\">//assessment/section/item/@ident</pathexpr>"
|
270
|
+ "</attribute>"
|
271
|
+ "<attribute index=\"1\">"
|
272
|
+ "<pathexpr label=\"qTitle\">//assessment/section/item/@title</pathexpr>"
|
273
|
+ "</attribute>"
|
274
|
+ "<attribute index=\"2\">"
|
275
|
+ "<pathexpr label=\"qLabel\">//assessment/section/item/presentation/@label</pathexpr>"
|
276
|
+ "</attribute>"
|
277
|
+ "</entity>"
|
278
|
+ "</datapackage>";
|
279
|
}
|
280
|
|
281
|
tempQuery += "</selection>";
|
282
|
|
283
|
//join to the quesion "table"
|
284
|
if (questionId.length > 0) {
|
285
|
tempQuery +=
|
286
|
"<where>"
|
287
|
+ "<condition type=\"join\">"
|
288
|
+ "<left>"
|
289
|
+ "<datapackage id=\"" + docId + "\">"
|
290
|
+ "<entity index=\"0\">"
|
291
|
+ "<attribute index=\"1\"/>"
|
292
|
+ "</entity>"
|
293
|
+ "</datapackage>"
|
294
|
+ "</left>"
|
295
|
+ "<operator>=</operator>"
|
296
|
+ "<right>"
|
297
|
+ "<datapackage id=\"" + questionId + "\">"
|
298
|
+ "<entity id=\"" + questionId + "\">"
|
299
|
+ "<attribute index=\"0\">"
|
300
|
+ "<pathexpr label=\"qId\">//assessment/section/item/@ident</pathexpr>"
|
301
|
+ "</attribute>"
|
302
|
+ "</entity>"
|
303
|
+ "</datapackage>"
|
304
|
+ "</right>"
|
305
|
+ "</condition>"
|
306
|
+ "</where>";
|
307
|
}
|
308
|
|
309
|
tempQuery += "</query>";
|
310
|
|
311
|
} // for questionId loop
|
312
|
|
313
|
|
314
|
} //for docObjs loop
|
315
|
|
316
|
tempQuery +=
|
317
|
"</union>"
|
318
|
+ "</dataquery>";
|
319
|
|
320
|
//alert(tempQuery);
|
321
|
|
322
|
return tempQuery;
|
323
|
}
|
324
|
|
325
|
/**
|
326
|
* @param searchTerms - and object (hashtable) with, pay attention now:
|
327
|
keys are search values
|
328
|
* values are pathexprs
|
329
|
**/
|
330
|
function generateSearchString(searchTerms, operator, searchAssessments, searchAssessmentItems) {
|
331
|
var queryString =
|
332
|
"<pathquery version=\"1.2\">"
|
333
|
+"<querytitle>Web-Search</querytitle>";
|
334
|
|
335
|
/** assessments **/
|
336
|
if (searchAssessments) {
|
337
|
|
338
|
queryString +=
|
339
|
"<returndoctype>edml://ecoinformatics.org/edml</returndoctype>"
|
340
|
|
341
|
//assessment fields
|
342
|
+"<returnfield>assessment/duration</returnfield>"
|
343
|
+"<returnfield>assessment/@title</returnfield>"
|
344
|
+"<returnfield>assessment/@id</returnfield>"
|
345
|
+"<returnfield>lom/general/title/string</returnfield>"
|
346
|
+"<returnfield>lom/general/keyword/string</returnfield>"
|
347
|
+"<returnfield>individualName/surName</returnfield>"
|
348
|
+"<returnfield>organizationName</returnfield>"
|
349
|
|
350
|
+"<returnfield>assessmentItems/assessmentItem/assessmentItemId</returnfield>";
|
351
|
|
352
|
}
|
353
|
|
354
|
/** questions **/
|
355
|
if (searchAssessmentItems) {
|
356
|
queryString +=
|
357
|
"<returndoctype>http://www.imsglobal.org/xsd/ims_qtiasiv1p2</returndoctype>"
|
358
|
|
359
|
//question (qti) fields
|
360
|
+"<returnfield>item/@title</returnfield>"
|
361
|
+"<returnfield>item/@ident</returnfield>"
|
362
|
+"<returnfield>qtimetadata/qtimetadatafield/fieldlabel</returnfield>"
|
363
|
+"<returnfield>qtimetadata/qtimetadatafield/fieldentry</returnfield>"
|
364
|
//classification
|
365
|
+"<returnfield>fieldlabel</returnfield>"
|
366
|
+"<returnfield>fieldentry</returnfield>"
|
367
|
+"<returnfield>objectives/material/mattext</returnfield>"
|
368
|
//question content
|
369
|
+"<returnfield>presentation/flow/material/mattext</returnfield>"
|
370
|
+"<returnfield>response_label/@ident</returnfield>"
|
371
|
+"<returnfield>response_label/material/mattext</returnfield>";
|
372
|
}
|
373
|
|
374
|
queryString +=
|
375
|
"<querygroup operator=\"" + operator + "\">";
|
376
|
|
377
|
for (var i in searchTerms) {
|
378
|
var key = i;
|
379
|
var value = searchTerms[i];
|
380
|
queryString +=
|
381
|
"<queryterm searchmode=\"contains\" casesensitive=\"false\">";
|
382
|
if (key != "anyValue") {
|
383
|
queryString += "<pathexpr>" + key + "</pathexpr>";
|
384
|
}
|
385
|
queryString += "<value>" + value + "</value>";
|
386
|
queryString +="</queryterm>";
|
387
|
}
|
388
|
|
389
|
queryString +=
|
390
|
"</querygroup>"
|
391
|
+"</pathquery>";
|
392
|
|
393
|
return queryString;
|
394
|
|
395
|
}
|
396
|
|
397
|
|
398
|
function generateAssessmentSearchString(assessmentItemId) {
|
399
|
var query =
|
400
|
"<pathquery version='1.2'>"
|
401
|
+"<querytitle>Containing-Assessment-Search</querytitle>"
|
402
|
|
403
|
+"<returndoctype>edml://ecoinformatics.org/edml</returndoctype>"
|
404
|
|
405
|
+"<returnfield>assessment/@title</returnfield>"
|
406
|
+"<returnfield>assessment/@id</returnfield>"
|
407
|
+"<returnfield>assessment/duration</returnfield>"
|
408
|
+"<returnfield>lom/general/title/string</returnfield>"
|
409
|
+"<returnfield>lom/general/keyword/string</returnfield>"
|
410
|
+"<returnfield>individualName/surName</returnfield>"
|
411
|
+"<returnfield>organizationName</returnfield>"
|
412
|
|
413
|
+"<returnfield>assessmentItems/assessmentItem/assessmentItemId</returnfield>";
|
414
|
|
415
|
if (assessmentItemId.length > 0) {
|
416
|
query += "<querygroup operator='UNION'>";
|
417
|
|
418
|
//add the assessmentId if included
|
419
|
query +=
|
420
|
"<queryterm searchmode='contains' casesensitive='false'>"
|
421
|
+"<value>"
|
422
|
+ assessmentItemId
|
423
|
+"</value>"
|
424
|
+"<pathexpr>assessmentItemId</pathexpr>"
|
425
|
+"</queryterm>";
|
426
|
|
427
|
//close the query group
|
428
|
query +=
|
429
|
"</querygroup>";
|
430
|
}
|
431
|
|
432
|
query += "</pathquery>";
|
433
|
|
434
|
return query;
|
435
|
}
|
436
|
|
437
|
function generateAssessmentListString(assessmentIds) {
|
438
|
var query =
|
439
|
"<pathquery version='1.2'>"
|
440
|
+"<querytitle>Assessment-List</querytitle>"
|
441
|
|
442
|
+"<returndoctype>edml://ecoinformatics.org/edml</returndoctype>"
|
443
|
|
444
|
+"<returnfield>assessment/@title</returnfield>"
|
445
|
+"<returnfield>assessment/@id</returnfield>"
|
446
|
+"<returnfield>assessment/duration</returnfield>"
|
447
|
+"<returnfield>lom/general/title/string</returnfield>"
|
448
|
+"<returnfield>lom/general/keyword/string</returnfield>"
|
449
|
+"<returnfield>individualName/surName</returnfield>"
|
450
|
+"<returnfield>organizationName</returnfield>"
|
451
|
|
452
|
+"<returnfield>assessmentItems/assessmentItem/assessmentItemId</returnfield>";
|
453
|
|
454
|
if (assessmentIds.length > 0) {
|
455
|
query += "<querygroup operator='UNION'>";
|
456
|
|
457
|
//add the assessmentId if included
|
458
|
for (var i=0; i < assessmentIds.length; i++) {
|
459
|
query +=
|
460
|
"<queryterm searchmode='equals' casesensitive='false'>"
|
461
|
+"<value>"
|
462
|
+ assessmentIds[i]
|
463
|
+"</value>"
|
464
|
+"<pathexpr>@packageId</pathexpr>"
|
465
|
+"</queryterm>";
|
466
|
}
|
467
|
//close the query group
|
468
|
query +=
|
469
|
"</querygroup>";
|
470
|
}
|
471
|
|
472
|
query += "</pathquery>";
|
473
|
|
474
|
return query;
|
475
|
}
|
476
|
|
477
|
function callAjax(metacatURL, myQuery, qfmt, divId) {
|
478
|
|
479
|
//alert("calling ajax: " + metacatURL);
|
480
|
//alert("myQuery: " + myQuery);
|
481
|
|
482
|
//var myRequest = new Ajax.Request(
|
483
|
var myUpdate = new Ajax.Updater(
|
484
|
divId,
|
485
|
metacatURL,
|
486
|
{ method: 'post',
|
487
|
parameters: { action: 'squery', qformat: qfmt, query: myQuery},
|
488
|
evalScripts: true,
|
489
|
//onSuccess: function(transport) {alert('success: ' + transport.status);},
|
490
|
onFailure: function(transport) {alert('failure making ajax call');}
|
491
|
});
|
492
|
|
493
|
//alert("done calling ajax");
|
494
|
}
|