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
			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
		}
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
	var docId = submitFormObj.docid.value;
97
	//alert("docId=" + docId);
98
	
99
	//do we want question metadata?
100
	var includeQuestions = submitFormObj.includeQuestions.checked;
101
	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
	//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
	
122
	var query = generateQuery(documentObjects, metadataObjs);
123
	
124
	submitFormObj.dataquery.value = query;
125
	
126
	return true;
127
		
128
}
129

    
130
/****************************************************************************
131
* 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
			//ignore certain other checkboxes, kind of a hack, but it's javascript...
157
			if (formElement.name == "includeQuestions") {
158
				continue;
159
			}
160
			if (formElement.name == "docid") {
161
				continue;
162
			}
163
			
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
				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
				onFailure: function(transport) {alert('failure saving field: ' + formElement.name);}
185
			 });
186
		 	count++;
187
		}
188
	}
189
	
190
	//window.document.getElementById("iframeheaderclass").src = window.document.getElementById("iframeheaderclass").src;
191
	
192
	//alert(count + ' Field selections saved.'); 
193
	
194
	return true;
195
		
196
}
197

    
198
/****************************************************************************
199
* 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
	var metadataAttributes = "";
209
	var index = 0;
210
	for (var j=0; j < metadataObjs.length; j++) {
211
		var metadataObj = metadataObjs[j];
212
		
213
		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
			
235
	for (var i=0; i < docObjs.length; i++) {
236

    
237
		var docId = docObjs[i].docid;
238
		var containsDemographicData = docObjs[i].demographicData;
239
		//alert("containsDemographicData=" + containsDemographicData);
240
		
241
		//get the question ids for this question
242
		var questionIds = docObjs[i].questionIds;
243
	
244
		//alert("questionIds=" + questionIds);
245
		
246
		//assemble the assessment metadata
247
		var metadataAttributeSelection = "";
248
		if (metadataAttributes.length > 0) {
249
			metadataAttributeSelection =
250
				"<datapackage id=\"" + docId + "\">"
251
					+ "<entity id=\"" + docId + "\">"
252
						+ metadataAttributes
253
					+ "</entity>"
254
				+ "</datapackage>";
255
		}
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
			+ "<selection>";
264
			
265
			//select the data
266
			tempQuery +=
267
				"<datapackage id=\"" + docId + "\">"
268
					+ "<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
			//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
			else {
290
				tempQuery +=
291
					"<staticItem name=\"demographic_1\" value=\"\" />"
292
					+ "<staticItem name=\"demographic_2\" value=\"\" />"
293
					+ "<staticItem name=\"demographic_3\" value=\"\" />";
294
			}
295
				
296
			//select the metadata
297
			tempQuery += metadataAttributeSelection;
298
	
299
			//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
			
319
			//join to the question "table"
320
			if (questionId.length > 0) {
321
				tempQuery +=
322
					"<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
				 
352
	tempQuery +=
353
		 "</union>"	
354
		 + "</dataquery>";
355
	
356
	//alert(tempQuery);
357
             
358
    return tempQuery;
359
}
360

    
361
/**
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
	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
               +"<returnfield>assessment/title</returnfield>"
380
               +"<returnfield>assessment/@id</returnfield>"
381
               +"<returnfield>dataset/dataTable/entityName</returnfield>"
382
               +"<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
    
411
    queryString +=
412
    	"<querygroup operator=\"" + operator + "\">";
413
                         
414
    for (var i in searchTerms) {
415
    	var key = i;
416
    	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
    }
428
    
429
	queryString +=
430
		"</querygroup>"
431
	+"</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
                      +"<returnfield>assessment/title</returnfield>"
446
                      +"<returnfield>assessment/@id</returnfield>"
447
                      +"<returnfield>assessment/duration</returnfield>"
448
                      +"<returnfield>dataset/dataTable/entityName</returnfield>"
449
                      +"<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
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
                      +"<returnfield>assessment/title</returnfield>"
486
                      +"<returnfield>assessment/@id</returnfield>"
487
                      +"<returnfield>assessment/duration</returnfield>"
488
           			  +"<returnfield>dataset/dataTable/entityName</returnfield>"
489
                      +"<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
function callAjax(metacatURL, myQuery, qfmt, divId) {
520
														
521
	//alert("calling ajax: " + metacatURL);
522
	//alert("myQuery: " + myQuery);
523
	
524
	//var myRequest = new Ajax.Request(
525
	var myUpdate = new Ajax.Updater(
526
		divId,
527
		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
}
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
}
(21-21/21)