Project

General

Profile

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
				documentObject.demographicData = submitFormObj[documentObject.docid + "demographicData"].value;
33
				
34
				var questionIds = new Array();
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.value != "") {
48
			var documentObject = new Object();
49
			documentObject.docid = submitFormObj.docid.value;
50
			documentObject.demographicData = submitFormObj[documentObject.docid + "demographicData"].value;
51
				
52
			var questionIds = new Array();
53
			if (submitFormObj[documentObject.docid].length > 1) {
54
				for (var z = 0; z < submitFormObj[documentObject.docid].length; z++) {
55
					questionIds[z] = submitFormObj[documentObject.docid][z].value;
56
				}
57
			}
58
			else {
59
				questionIds[0] = submitFormObj[documentObject.docid].value;
60
			}
61
			
62
			documentObject.questionIds = questionIds;
63
			documentObjects[0] = documentObject;
64
		}
65
	}
66
		
67
	var query = generateQuery(documentObjects, metadataObjs);
68
	
69
	submitFormObj.dataquery.value = query;
70
	
71
	return true;
72
		
73
}
74

    
75
/****************************************************************************
76
* Single Assessment download
77
* @param form containing the neceassary input items
78
* @return true/false for form submission
79
*****************************************************************************/
80
function assessmentSearch(submitFormObj) {
81

    
82
	//harvest the metadata fields we want to include
83
	var metadataObjs = new Array();
84
	var index = 0;
85
	for (var i=0; i < submitFormObj.length; i++) {
86
		var formElement = submitFormObj.elements[i];
87
		if (formElement.type == "checkbox" && formElement.checked) {
88
			//ignore certain other checkboxes, kind of a hack 
89
			if (formElement.name == "includeQuestions") {
90
				continue;
91
			}
92
			var metadataObj = new Object();
93
			metadataObj.name = formElement.name;
94
			metadataObj.value = formElement.value;
95
			metadataObjs[index] = metadataObj;
96
			index++;
97
		}
98
	}
99
	
100
	//var checkBox = document.getElementById("searchAll");
101
	var docId = submitFormObj.docid.value;
102
	//alert("docId=" + docId);
103
	
104
	//do we want question metadata?
105
	var includeQuestions = submitFormObj.includeQuestions.checked;
106
	var questionIds = new Array();
107
	questionIds[0] = "";
108
	
109
	if (includeQuestions) {
110
		if (submitFormObj.assessmentItemId.length > 1) {
111
			for (var i=0; i < submitFormObj.assessmentItemId.length; i++) {
112
				questionIds[i] = submitFormObj.assessmentItemId[i].value;
113
			}
114
		}
115
		else {
116
			questionIds[0] = submitFormObj.assessmentItemId.value;
117
		}
118
	}
119
	
120
	//set up the list of objects to pass to the query assembler, just one document
121
	var documentObjects = new Array();
122
	var documentObject = new Object();
123
	documentObject.docid = docId;
124
	documentObject.questionIds = questionIds;
125
	documentObjects[0] = documentObject;
126
	
127
	var query = generateQuery(documentObjects, metadataObjs);
128
	
129
	submitFormObj.dataquery.value = query;
130
	
131
	return true;
132
		
133
}
134

    
135
/****************************************************************************
136
* Save fields for the attribute maping
137
* @param formId containing the neceassary input items
138
* @return true/false for form submission
139
*****************************************************************************/
140
function saveFields(formId, metacatURL) {
141

    
142
	var submitFormObj = document.getElementById(formId);
143
	
144
	//send the request to clear
145
	var myRequest = new Ajax.Request(
146
	metacatURL,
147
	{	method: 'post',
148
		parameters: { 
149
			action: 'editcart', 
150
			operation: 'clearfields'},
151
		evalScripts: true, 
152
		//onSuccess: function(transport) {alert('success: ' + transport.status);},
153
		onFailure: function(transport) {alert('failure clearing fields');}
154
	 });
155
	
156
	//go through the check boxes and set the ones we want
157
	var count = 0;
158
	for (var i=0; i < submitFormObj.length; i++) {
159
		var formElement = submitFormObj.elements[i];
160
		if (formElement.type == "checkbox" && formElement.checked) {
161
			//ignore certain other checkboxes, kind of a hack, but it's javascript...
162
			if (formElement.name == "includeQuestions") {
163
				continue;
164
			}
165
			if (formElement.name == "docid") {
166
				continue;
167
			}
168
			
169
			//send the request
170
			var myRequest = new Ajax.Request(
171
			metacatURL,
172
			{	method: 'post',
173
				parameters: { 
174
					action: 'editcart', 
175
					operation: 'addfield', 
176
					field: formElement.name, 
177
					path: formElement.value},
178
				evalScripts: true, 
179
				onSuccess: function(transport) {
180
					//alert('Selections saved: ' + operation); 
181
					//refresh after the save
182
					if (document.getElementById("ajaxCartResults")) {
183
						window.location.reload();
184
					}
185
					else {
186
						window.document.getElementById("iframeheaderclass").src=window.document.getElementById("iframeheaderclass").src;
187
					}
188
				}, 
189
				onFailure: function(transport) {alert('failure saving field: ' + formElement.name);}
190
			 });
191
		 	count++;
192
		}
193
	}
194
	
195
	//window.document.getElementById("iframeheaderclass").src = window.document.getElementById("iframeheaderclass").src;
196
	
197
	//alert(count + ' Field selections saved.'); 
198
	
199
	return true;
200
		
201
}
202

    
203
/****************************************************************************
204
* Query Generation function
205
* @param docObjs is an Array of Objects with "docid" (String) and "questionIds" (Array) properties
206
* @param metadataObjs is an Array of Objects with "name" and "value" properties (both String)
207
* @return generated query string
208
*****************************************************************************/
209
function generateQuery(docObjs, metadataObjs) {
210
	//alert("calling method");
211
	
212
	//make parameters at some point
213
	var includeDemographicData = false;
214
	var questionMetadataCount = 2;
215
	var questionChoiceCount = 5;
216
	
217
	//construct the assessment metadata attribute selection snippet
218
	var metadataAttributes = "";
219
	var index = 0;
220
	for (var j=0; j < metadataObjs.length; j++) {
221
		var metadataObj = metadataObjs[j];
222
		
223
		metadataAttributes += "<attribute index=\"";
224
		metadataAttributes += index;
225
		metadataAttributes += "\">";
226
		
227
		metadataAttributes += "<pathexpr label=\"";
228
		metadataAttributes += metadataObj.name;
229
		metadataAttributes += "\">";
230
		metadataAttributes += metadataObj.value;
231
		metadataAttributes += "</pathexpr>";
232
		
233
		metadataAttributes += "</attribute>";
234
		
235
		index++;
236
	}//metadataObjs loop
237
	
238
	
239
	//construct the begining of the query
240
	var tempQuery = 
241
        "<?xml version=\"1.0\"?>"
242
        + "<dataquery>"
243
			+ "<union>";
244
			
245
	for (var i=0; i < docObjs.length; i++) {
246

    
247
		var docId = docObjs[i].docid;
248
		var containsDemographicData = docObjs[i].demographicData;
249
		//alert("containsDemographicData=" + containsDemographicData);
250
		
251
		//get the question ids for this question
252
		var questionIds = docObjs[i].questionIds;
253
	
254
		//alert("questionIds=" + questionIds);
255
		
256
		//assemble the assessment metadata
257
		var metadataAttributeSelection = "";
258
		if (metadataAttributes.length > 0) {
259
			metadataAttributeSelection =
260
				"<datapackage id=\"" + docId + "\">"
261
					+ "<entity id=\"" + docId + "\">"
262
						+ metadataAttributes
263
					+ "</entity>"
264
				+ "</datapackage>";
265
		}
266
				
267
		//loop for each question item
268
		for (var k=0; k < questionIds.length; k++) {
269
			var questionId = questionIds[k];
270
		
271
			tempQuery +=
272
			"<query>"
273
			+ "<selection>";
274
			
275
			//select the data
276
			tempQuery +=
277
				"<datapackage id=\"" + docId + "\">"
278
					+ "<entity index=\"0\">"
279
						+ "<attribute index=\"0\"/>"
280
						+ "<attribute index=\"1\"/>"
281
						//DO NOT omit student id attribute - used for transpose
282
						+ "<attribute index=\"2\"/>"
283
						+ "<attribute index=\"3\"/>"
284
						+ "<attribute index=\"4\"/>"
285
					+ "</entity>"
286
				+ "</datapackage>";
287
				
288
			//select the demographic data
289
			if (includeDemographicData) {
290
				if (containsDemographicData) {
291
					tempQuery +=
292
						"<datapackage id=\"" + docId + "\">"
293
							+ "<entity index=\"1\">"
294
								//omit student id attribute
295
								+ "<attribute index=\"1\"/>"
296
								+ "<attribute index=\"2\"/>"
297
								+ "<attribute index=\"3\"/>"
298
							+ "</entity>"
299
						+ "</datapackage>";	
300
				}
301
				else {
302
					tempQuery +=
303
						"<staticItem name=\"demographic_1\" value=\"\" />"
304
						+ "<staticItem name=\"demographic_2\" value=\"\" />"
305
						+ "<staticItem name=\"demographic_3\" value=\"\" />";
306
				}
307
			}
308
				
309
			//select the metadata
310
			tempQuery += metadataAttributeSelection;
311
	
312
			//select the question metadata						
313
			if (questionId.length > 0) {
314
				tempQuery +=
315
				"<datapackage id=\"" + questionId + "\">"
316
					+ "<entity id=\"" + questionId + "\">"
317
						+ "<attribute name=\"qId\">"
318
							+ "<pathexpr label=\"qId\">//assessment/section/item/@ident</pathexpr>"
319
						+ "</attribute>"
320
						+ "<attribute name=\"qTitle\">"
321
							+ "<pathexpr label=\"qTitle\">//assessment/section/item/@title</pathexpr>"
322
						+ "</attribute>"
323
						+ "<attribute name=\"qLabel\">"
324
							+ "<pathexpr label=\"qLabel\">//assessment/section/item/presentation/@label</pathexpr>"
325
						+ "</attribute>"
326
						+ "<attribute name=\"qPrompt\">"
327
							+ "<pathexpr label=\"qPrompt\">(//assessment/section/item/presentation/flow/response_lid/render_choice/material/mattext)|(//assessment/section/item/presentation/flow/response_str/material/mattext)</pathexpr>"
328
						+ "</attribute>";
329
				//control multiple choices
330
				for (var p = 1; p <= questionChoiceCount; p++) {
331
					tempQuery +=
332
						"<attribute name=\"qChoice_" + p + "\">"
333
							+ "<pathexpr label=\"qChoice_" + p + "\">//assessment/section/item/presentation/flow/response_lid/render_choice/flow_label/response_label/material/mattext</pathexpr>"
334
						+ "</attribute>";
335
				}
336
				//control multiple metadata fields
337
				for (var q = 1; q <= questionMetadataCount; q++) {
338
					tempQuery +=
339
						"<attribute name=\"qMetadataVocabulary_" + q +"\">"
340
							+ "<pathexpr label=\"qMetadataVocabulary_" + q +"\">//assessment/section/item/itemmetadata/qtimetadata/vocabulary</pathexpr>"
341
						+ "</attribute>"
342
						+ "<attribute name=\"qMetadataValue_" + q +"\">"
343
							+ "<pathexpr label=\"qMetadataValue_" + q +"\">//assessment/section/item/itemmetadata/qtimetadata/qtimetadatafield/fieldentry</pathexpr>"
344
						+ "</attribute>";
345
				}
346
				tempQuery +=
347
					"</entity>"
348
				+ "</datapackage>";
349
			}
350
				
351
			tempQuery += "</selection>";
352
			
353
			//join to the question "table"
354
			if (questionId.length > 0) {
355
				tempQuery +=
356
					"<where>"
357
						+ "<condition type=\"join\">"
358
							+ "<left>"
359
								+ "<datapackage id=\"" + docId + "\">"
360
									+ "<entity index=\"0\">"
361
										+ "<attribute index=\"1\"/>"
362
									+ "</entity>"
363
								+ "</datapackage>"
364
							+ "</left>"
365
							+ "<operator>=</operator>"
366
							+ "<right>"
367
								+ "<datapackage id=\"" + questionId + "\">"
368
									+ "<entity id=\"" + questionId + "\">"
369
										+ "<attribute name=\"qId\">"
370
											+ "<pathexpr label=\"qId\">//assessment/section/item/@ident</pathexpr>"
371
										+ "</attribute>"
372
									+ "</entity>"
373
								+ "</datapackage>"
374
							+ "</right>"
375
						+ "</condition>"
376
					+ "</where>";
377
			}
378
			
379
			tempQuery += "</query>";
380
		
381
		} // for questionId loop
382
		
383
	
384
	} //for docObjs loop
385
				 
386
	tempQuery +=
387
		 "</union>"	
388
		 + "</dataquery>";
389
	
390
	//alert(tempQuery);
391
             
392
    return tempQuery;
393
}
394

    
395
/**
396
*	@param searchTerms - and object (hashtable) with, pay attention now:
397
	keys are search values
398
*   values are pathexprs
399
**/
400
function generateSearchString(searchTerms, operator, searchAssessments, searchAssessmentItems) {
401
	var queryString = 
402
		"<pathquery version=\"1.2\">"
403
			+"<querytitle>Web-Search</querytitle>";
404
		
405
	/** assessments **/
406
	if (searchAssessments) {
407
	
408
		queryString +=
409
			"<returndoctype>edml://ecoinformatics.org/edml</returndoctype>"
410
			
411
			//assessment fields
412
               +"<returnfield>assessment/duration</returnfield>"
413
               +"<returnfield>assessment/title</returnfield>"
414
               +"<returnfield>assessment/@id</returnfield>"
415
               +"<returnfield>dataset/dataTable/entityName</returnfield>"
416
               +"<returnfield>lom/general/title/string</returnfield>"
417
               +"<returnfield>lom/general/keyword/string</returnfield>"
418
               +"<returnfield>individualName/surName</returnfield>"
419
               +"<returnfield>organizationName</returnfield>"
420
               
421
               +"<returnfield>assessmentItems/assessmentItem/assessmentItemId</returnfield>";
422
               
423
	}
424
						
425
	/** questions **/
426
	if (searchAssessmentItems) {
427
		queryString +=
428
			"<returndoctype>http://www.imsglobal.org/xsd/ims_qtiasiv1p2</returndoctype>"
429
			
430
			//question (qti) fields
431
			+"<returnfield>item/@title</returnfield>"
432
			+"<returnfield>item/@ident</returnfield>"
433
               +"<returnfield>qtimetadata/qtimetadatafield/fieldlabel</returnfield>"
434
               +"<returnfield>qtimetadata/qtimetadatafield/fieldentry</returnfield>"
435
			//classification
436
			+"<returnfield>fieldlabel</returnfield>"
437
			+"<returnfield>fieldentry</returnfield>"
438
			+"<returnfield>objectives/material/mattext</returnfield>"
439
			//question content
440
			+"<returnfield>presentation/flow/response_lid/render_choice/material/mattext</returnfield>"
441
			+"<returnfield>response_label/@ident</returnfield>"
442
			+"<returnfield>response_label/material/mattext</returnfield>";
443
	}		
444
    
445
    queryString +=
446
    	"<querygroup operator=\"" + operator + "\">";
447
                         
448
    for (var i in searchTerms) {
449
    	var key = i;
450
    	var value = searchTerms[i];
451
    	//only if we have a value  
452
    	if (value.length > 0) {                   
453
			queryString +=
454
				"<queryterm searchmode=\"contains\" casesensitive=\"false\">";
455
				if (key != "anyValue") {
456
					queryString += "<pathexpr>" + key + "</pathexpr>";
457
				}	
458
		      	queryString += "<value>" + value + "</value>";
459
		    queryString +="</queryterm>";
460
		}
461
    }
462
    
463
	queryString +=
464
		"</querygroup>"
465
	+"</pathquery>";
466
	
467
	return queryString;
468
				
469
}
470

    
471

    
472
function generateAssessmentSearchString(assessmentItemId) {
473
	var query = 
474
		"<pathquery version='1.2'>"
475
		     +"<querytitle>Containing-Assessment-Search</querytitle>"
476
		     
477
		     +"<returndoctype>edml://ecoinformatics.org/edml</returndoctype>"
478
		                           
479
                      +"<returnfield>assessment/title</returnfield>"
480
                      +"<returnfield>assessment/@id</returnfield>"
481
                      +"<returnfield>assessment/duration</returnfield>"
482
                      +"<returnfield>dataset/dataTable/entityName</returnfield>"
483
                      +"<returnfield>lom/general/title/string</returnfield>"
484
                      +"<returnfield>lom/general/keyword/string</returnfield>"
485
                      +"<returnfield>individualName/surName</returnfield>"
486
                      +"<returnfield>organizationName</returnfield>"
487
                      
488
                      +"<returnfield>assessmentItems/assessmentItem/assessmentItemId</returnfield>";
489
                      
490
		    if (assessmentItemId.length > 0) {
491
			    query += "<querygroup operator='UNION'>";
492
			    
493
			    //add the assessmentId if included
494
			    query +=
495
			     		"<queryterm searchmode='contains' casesensitive='false'>"
496
			                  +"<value>"
497
			                  + assessmentItemId
498
			                  +"</value>"
499
			                  +"<pathexpr>assessmentItemId</pathexpr>"
500
			          +"</queryterm>";
501
				
502
			    //close the query group      
503
			     query +=
504
			     "</querygroup>";
505
			}
506
			     
507
		query += "</pathquery>";
508
		
509
	return query;	
510
}
511

    
512
function generateAssessmentListString(assessmentIds) {
513
	var query = 
514
		"<pathquery version='1.2'>"
515
		     +"<querytitle>Assessment-List</querytitle>"
516
		     
517
		     +"<returndoctype>edml://ecoinformatics.org/edml</returndoctype>"
518
		                           
519
                      +"<returnfield>assessment/title</returnfield>"
520
                      +"<returnfield>assessment/@id</returnfield>"
521
                      +"<returnfield>assessment/duration</returnfield>"
522
           			  +"<returnfield>dataset/dataTable/entityName</returnfield>"
523
                      +"<returnfield>lom/general/title/string</returnfield>"
524
                      +"<returnfield>lom/general/keyword/string</returnfield>"
525
                      +"<returnfield>individualName/surName</returnfield>"
526
                      +"<returnfield>organizationName</returnfield>"
527
                      
528
                      +"<returnfield>assessmentItems/assessmentItem/assessmentItemId</returnfield>";
529
                      
530
		    if (assessmentIds.length > 0) {
531
			    query += "<querygroup operator='UNION'>";
532
			    
533
			    //add the assessmentId if included
534
			    for (var i=0; i < assessmentIds.length; i++) {
535
				    query +=
536
				     		"<queryterm searchmode='equals' casesensitive='false'>"
537
				                  +"<value>"
538
				                  + assessmentIds[i]
539
				                  +"</value>"
540
				                  +"<pathexpr>@packageId</pathexpr>"
541
				          +"</queryterm>";
542
				}
543
			    //close the query group      
544
			     query +=
545
			     "</querygroup>";
546
			}
547
			     
548
		query += "</pathquery>";
549
		
550
	return query;	
551
}
552

    
553
function callAjax(metacatURL, myQuery, qfmt, divId) {
554
														
555
	//alert("calling ajax: " + metacatURL);
556
	//alert("myQuery: " + myQuery);
557
	
558
	//var myRequest = new Ajax.Request(
559
	var myUpdate = new Ajax.Updater(
560
		divId,
561
		metacatURL,
562
		{	method: 'post',
563
			parameters: { action: 'squery', qformat: qfmt, query: myQuery},
564
			evalScripts: true, 
565
			//onSuccess: function(transport) {alert('success: ' + transport.status);},
566
			onFailure: function(transport) {alert('failure making ajax call');}
567
		 });
568
		 
569
	 //alert("done calling ajax");
570
}
571
function getIframeDocument(iframeId) {
572
	//look up the document
573
	var iframe = window.document.getElementById(iframeId);
574
	var doc = null;
575
	if (iframe.contentDocument) {
576
		doc = iframe.contentDocument;
577
	}
578
	else {
579
		doc = iframe.contentWindow.document;
580
	}
581
	return doc;
582
}
(22-22/22)