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