Project

General

Profile

1 4288 leinfelder
/****************************************************************************
2
* Multiple Assessment download
3
* @param form containing the neceassary input items
4
* @return true/false for form submission
5
*****************************************************************************/
6 4387 leinfelder
function multipleAssessmentSearch(submitFormObj, fieldFormObj) {
7 4377 leinfelder
8
	//alert("submitFormObj=" + submitFormObj);
9 4288 leinfelder
	//harvest the metadata fields we want to include
10
	var metadataObjs = new Array();
11
	var index = 0;
12 4387 leinfelder
	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 4288 leinfelder
	}
20 4267 leinfelder
21 4288 leinfelder
	//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 4290 leinfelder
	var index = 0;
29 4377 leinfelder
	if (submitFormObj.docid.length > 1) {
30
		for (var i=0; i < submitFormObj.docid.length; i++) {
31
			if (submitFormObj.docid[i].checked) {
32 4290 leinfelder
				var documentObject = new Object();
33 4377 leinfelder
				documentObject.docid = submitFormObj.docid[i].value;
34 4290 leinfelder
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 4288 leinfelder
		}
44
	}
45
	else {
46 4377 leinfelder
		//alert("submitFormObj.docid=" + submitFormObj.docid);
47
		if (submitFormObj.docid.checked) {
48 4290 leinfelder
			var documentObject = new Object();
49 4377 leinfelder
			documentObject.docid = submitFormObj.docid.value;
50 4290 leinfelder
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 4288 leinfelder
		}
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 4267 leinfelder
	var docId = submitFormObj.docid.value;
95 4273 leinfelder
	//alert("docId=" + docId);
96 4267 leinfelder
97 4281 leinfelder
	//do we want question metadata?
98 4282 leinfelder
	var includeQuestions = submitFormObj.includeQuestions.checked;
99 4281 leinfelder
	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 4288 leinfelder
	//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 4281 leinfelder
120 4288 leinfelder
	var query = generateQuery(documentObjects, metadataObjs);
121
122
	submitFormObj.dataquery.value = query;
123
124
	return true;
125
126
}
127
128
/****************************************************************************
129 4387 leinfelder
* 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 4411 leinfelder
			//ignore certain other checkboxes, kind of a hack, but it's javascript...
155 4387 leinfelder
			if (formElement.name == "includeQuestions") {
156
				continue;
157
			}
158 4411 leinfelder
			if (formElement.name == "docid") {
159
				continue;
160
			}
161 4387 leinfelder
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 4411 leinfelder
				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 4387 leinfelder
				onFailure: function(transport) {alert('failure saving field: ' + formElement.name);}
183
			 });
184
		 	count++;
185
		}
186
	}
187
188 4411 leinfelder
	//window.document.getElementById("iframeheaderclass").src = window.document.getElementById("iframeheaderclass").src;
189 4387 leinfelder
190 4388 leinfelder
	//alert(count + ' Field selections saved.');
191 4387 leinfelder
192
	return true;
193
194
}
195
196
/****************************************************************************
197 4288 leinfelder
* 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 4267 leinfelder
	var metadataAttributes = "";
207
	var index = 0;
208 4288 leinfelder
	for (var j=0; j < metadataObjs.length; j++) {
209
		var metadataObj = metadataObjs[j];
210 4267 leinfelder
211 4288 leinfelder
		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 4267 leinfelder
233 4288 leinfelder
	for (var i=0; i < docObjs.length; i++) {
234
235
		var docId = docObjs[i].docid;
236 4377 leinfelder
		//alert("docId=" + docId);
237 4288 leinfelder
238
		//get the question ids for this question
239
		var questionIds = docObjs[i].questionIds;
240 4267 leinfelder
241 4377 leinfelder
		//alert("questionIds=" + questionIds);
242 4288 leinfelder
243
		//assemble the assessment metadata
244
		var metadataAttributeSelection = "";
245
		if (metadataAttributes.length > 0) {
246
			metadataAttributeSelection =
247 4267 leinfelder
				"<datapackage id=\"" + docId + "\">"
248
					+ "<entity id=\"" + docId + "\">"
249
						+ metadataAttributes
250
					+ "</entity>"
251
				+ "</datapackage>";
252 4288 leinfelder
		}
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 4267 leinfelder
275 4288 leinfelder
			//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 4281 leinfelder
295 4288 leinfelder
			//join to the quesion "table"
296
			if (questionId.length > 0) {
297 4281 leinfelder
				tempQuery +=
298 4288 leinfelder
					"<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 4281 leinfelder
328 4288 leinfelder
	tempQuery +=
329
		 "</union>"
330
		 + "</dataquery>";
331
332 4377 leinfelder
	//alert(tempQuery);
333 4288 leinfelder
334
    return tempQuery;
335 4290 leinfelder
}
336
337 4364 leinfelder
/**
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 4290 leinfelder
	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 4364 leinfelder
386
    queryString +=
387
    	"<querygroup operator=\"" + operator + "\">";
388
389
    for (var i in searchTerms) {
390
    	var key = i;
391
    	var value = searchTerms[i];
392
		queryString +=
393
			"<queryterm searchmode=\"contains\" casesensitive=\"false\">";
394
			if (key != "anyValue") {
395
				queryString += "<pathexpr>" + key + "</pathexpr>";
396
			}
397
	      	queryString += "<value>" + value + "</value>";
398
	    queryString +="</queryterm>";
399
    }
400
401 4290 leinfelder
	queryString +=
402 4364 leinfelder
		"</querygroup>"
403 4290 leinfelder
	+"</pathquery>";
404
405
	return queryString;
406
407
}
408
409
410
function generateAssessmentSearchString(assessmentItemId) {
411
	var query =
412
		"<pathquery version='1.2'>"
413
		     +"<querytitle>Containing-Assessment-Search</querytitle>"
414
415
		     +"<returndoctype>edml://ecoinformatics.org/edml</returndoctype>"
416
417
                      +"<returnfield>assessment/@title</returnfield>"
418
                      +"<returnfield>assessment/@id</returnfield>"
419
                      +"<returnfield>assessment/duration</returnfield>"
420
                      +"<returnfield>lom/general/title/string</returnfield>"
421
                      +"<returnfield>lom/general/keyword/string</returnfield>"
422
                      +"<returnfield>individualName/surName</returnfield>"
423
                      +"<returnfield>organizationName</returnfield>"
424
425
                      +"<returnfield>assessmentItems/assessmentItem/assessmentItemId</returnfield>";
426
427
		    if (assessmentItemId.length > 0) {
428
			    query += "<querygroup operator='UNION'>";
429
430
			    //add the assessmentId if included
431
			    query +=
432
			     		"<queryterm searchmode='contains' casesensitive='false'>"
433
			                  +"<value>"
434
			                  + assessmentItemId
435
			                  +"</value>"
436
			                  +"<pathexpr>assessmentItemId</pathexpr>"
437
			          +"</queryterm>";
438
439
			    //close the query group
440
			     query +=
441
			     "</querygroup>";
442
			}
443
444
		query += "</pathquery>";
445
446
	return query;
447
}
448
449 4363 leinfelder
function generateAssessmentListString(assessmentIds) {
450
	var query =
451
		"<pathquery version='1.2'>"
452
		     +"<querytitle>Assessment-List</querytitle>"
453
454
		     +"<returndoctype>edml://ecoinformatics.org/edml</returndoctype>"
455
456
                      +"<returnfield>assessment/@title</returnfield>"
457
                      +"<returnfield>assessment/@id</returnfield>"
458
                      +"<returnfield>assessment/duration</returnfield>"
459
                      +"<returnfield>lom/general/title/string</returnfield>"
460
                      +"<returnfield>lom/general/keyword/string</returnfield>"
461
                      +"<returnfield>individualName/surName</returnfield>"
462
                      +"<returnfield>organizationName</returnfield>"
463
464
                      +"<returnfield>assessmentItems/assessmentItem/assessmentItemId</returnfield>";
465
466
		    if (assessmentIds.length > 0) {
467
			    query += "<querygroup operator='UNION'>";
468
469
			    //add the assessmentId if included
470
			    for (var i=0; i < assessmentIds.length; i++) {
471
				    query +=
472
				     		"<queryterm searchmode='equals' casesensitive='false'>"
473
				                  +"<value>"
474
				                  + assessmentIds[i]
475
				                  +"</value>"
476
				                  +"<pathexpr>@packageId</pathexpr>"
477
				          +"</queryterm>";
478
				}
479
			    //close the query group
480
			     query +=
481
			     "</querygroup>";
482
			}
483
484
		query += "</pathquery>";
485
486
	return query;
487
}
488
489 4377 leinfelder
function callAjax(metacatURL, myQuery, qfmt, divId) {
490 4290 leinfelder
491
	//alert("calling ajax: " + metacatURL);
492
	//alert("myQuery: " + myQuery);
493
494
	//var myRequest = new Ajax.Request(
495
	var myUpdate = new Ajax.Updater(
496 4377 leinfelder
		divId,
497 4290 leinfelder
		metacatURL,
498
		{	method: 'post',
499
			parameters: { action: 'squery', qformat: qfmt, query: myQuery},
500
			evalScripts: true,
501
			//onSuccess: function(transport) {alert('success: ' + transport.status);},
502
			onFailure: function(transport) {alert('failure making ajax call');}
503
		 });
504
505
	 //alert("done calling ajax");
506 4267 leinfelder
}