/****************************************************************************
* Multiple Assessment download
* @param form containing the neceassary input items
* @return true/false for form submission
*****************************************************************************/
function multipleAssessmentSearch(submitFormObj, fieldFormObj) {
//alert("submitFormObj=" + submitFormObj);
//harvest the metadata fields we want to include
var metadataObjs = new Array();
var index = 0;
for (var i=0; i < fieldFormObj.length; i++) {
var formElement = fieldFormObj.elements[i];
var metadataObj = new Object();
metadataObj.name = formElement.name;
metadataObj.value = formElement.value;
metadataObjs[index] = metadataObj;
index++;
}
//TODO option for all questions vs. just one
//var questionId = submitFormObj.questionId.value;
//alert("questionId=" + questionId);
var documentObjects = new Array();
var index = 0;
if (submitFormObj.docid.length > 1) {
for (var i=0; i < submitFormObj.docid.length; i++) {
if (submitFormObj.docid[i].value != "") {
var documentObject = new Object();
documentObject.docid = submitFormObj.docid[i].value;
documentObject.demographicData = submitFormObj[documentObject.docid + "demographicData"].value;
var questionIds = new Array();
for (var z = 0; z < submitFormObj[documentObject.docid].length; z++) {
questionIds[z] = submitFormObj[documentObject.docid][z].value;
}
documentObject.questionIds = questionIds;
documentObjects[index] = documentObject;
index++;
}
}
}
else {
//alert("submitFormObj.docid=" + submitFormObj.docid);
if (submitFormObj.docid.value != "") {
var documentObject = new Object();
documentObject.docid = submitFormObj.docid.value;
documentObject.demographicData = submitFormObj[documentObject.docid + "demographicData"].value;
var questionIds = new Array();
if (submitFormObj[documentObject.docid].length > 1) {
for (var z = 0; z < submitFormObj[documentObject.docid].length; z++) {
questionIds[z] = submitFormObj[documentObject.docid][z].value;
}
}
else {
questionIds[0] = submitFormObj[documentObject.docid].value;
}
documentObject.questionIds = questionIds;
documentObjects[0] = documentObject;
}
}
var itemMetadataCount = submitFormObj.metadataCount.value;
var query = generateQuery(documentObjects, metadataObjs, itemMetadataCount);
submitFormObj.dataquery.value = query;
return true;
}
/****************************************************************************
* Single Assessment download
* @param form containing the neceassary input items
* @return true/false for form submission
*****************************************************************************/
function assessmentSearch(submitFormObj) {
//harvest the metadata fields we want to include
var metadataObjs = new Array();
var index = 0;
for (var i=0; i < submitFormObj.length; i++) {
var formElement = submitFormObj.elements[i];
if (formElement.type == "checkbox" && formElement.checked) {
//ignore certain other checkboxes, kind of a hack
if (formElement.name == "includeQuestions") {
continue;
}
var metadataObj = new Object();
metadataObj.name = formElement.name;
metadataObj.value = formElement.value;
metadataObjs[index] = metadataObj;
index++;
}
}
//var checkBox = document.getElementById("searchAll");
var docId = submitFormObj.docid.value;
//alert("docId=" + docId);
//do we want question metadata?
var includeQuestions = submitFormObj.includeQuestions.checked;
var questionIds = new Array();
questionIds[0] = "";
if (includeQuestions) {
if (submitFormObj.assessmentItemId.length > 1) {
for (var i=0; i < submitFormObj.assessmentItemId.length; i++) {
questionIds[i] = submitFormObj.assessmentItemId[i].value;
}
}
else {
questionIds[0] = submitFormObj.assessmentItemId.value;
}
}
//set up the list of objects to pass to the query assembler, just one document
var documentObjects = new Array();
var documentObject = new Object();
documentObject.docid = docId;
documentObject.questionIds = questionIds;
documentObjects[0] = documentObject;
var query = generateQuery(documentObjects, metadataObjs);
submitFormObj.dataquery.value = query;
return true;
}
/****************************************************************************
* Save fields for the attribute maping
* @param formId containing the neceassary input items
* @return true/false for form submission
*****************************************************************************/
function saveFields(formId, metacatURL) {
var submitFormObj = document.getElementById(formId);
//send the request to clear
var myRequest = new Ajax.Request(
metacatURL,
{ method: 'post',
parameters: {
action: 'editcart',
operation: 'clearfields'},
evalScripts: true,
//onSuccess: function(transport) {alert('success: ' + transport.status);},
onFailure: function(transport) {alert('failure clearing fields');}
});
//go through the check boxes and set the ones we want
var count = 0;
for (var i=0; i < submitFormObj.length; i++) {
var formElement = submitFormObj.elements[i];
if (formElement.type == "checkbox" && formElement.checked) {
//ignore certain other checkboxes, kind of a hack, but it's javascript...
if (formElement.name == "includeQuestions") {
continue;
}
if (formElement.name == "docid") {
continue;
}
//send the request
var myRequest = new Ajax.Request(
metacatURL,
{ method: 'post',
parameters: {
action: 'editcart',
operation: 'addfield',
field: formElement.name,
path: formElement.value},
evalScripts: true,
onSuccess: function(transport) {
//alert('Selections saved: ' + operation);
//refresh after the save
if (document.getElementById("ajaxCartResults")) {
window.location.reload();
}
else {
window.document.getElementById("iframeheaderclass").src=window.document.getElementById("iframeheaderclass").src;
}
},
onFailure: function(transport) {alert('failure saving field: ' + formElement.name);}
});
count++;
}
}
//window.document.getElementById("iframeheaderclass").src = window.document.getElementById("iframeheaderclass").src;
//alert(count + ' Field selections saved.');
return true;
}
/****************************************************************************
* Query Generation function
* @param docObjs is an Array of Objects with "docid" (String) and "questionIds" (Array) properties
* @param metadataObjs is an Array of Objects with "name" and "value" properties (both String)
* @return generated query string
*****************************************************************************/
function generateQuery(docObjs, metadataObjs, itemMetadataCount) {
//alert("calling method");
//make parameters at some point
var includeDemographicData = false;
var questionMetadataCount = 2;
if (itemMetadataCount) {
questionMetadataCount = itemMetadataCount;
}
var questionChoiceCount = 5;
//construct the assessment metadata attribute selection snippet
var metadataAttributes = "";
var index = 0;
for (var j=0; j < metadataObjs.length; j++) {
var metadataObj = metadataObjs[j];
metadataAttributes += "";
metadataAttributes += "";
metadataAttributes += metadataObj.value;
metadataAttributes += "";
metadataAttributes += "";
index++;
}//metadataObjs loop
//construct the begining of the query
var tempQuery =
""
+ ""
+ "";
for (var i=0; i < docObjs.length; i++) {
var docId = docObjs[i].docid;
var containsDemographicData = docObjs[i].demographicData;
//alert("containsDemographicData=" + containsDemographicData);
//get the question ids for this question
var questionIds = docObjs[i].questionIds;
//alert("questionIds=" + questionIds);
//assemble the assessment metadata
var metadataAttributeSelection = "";
if (metadataAttributes.length > 0) {
metadataAttributeSelection =
""
+ ""
+ metadataAttributes
+ ""
+ "";
}
//loop for each question item
for (var k=0; k < questionIds.length; k++) {
var questionId = questionIds[k];
tempQuery +=
""
+ "";
//select the data
tempQuery +=
""
+ ""
+ ""
+ ""
//DO NOT omit student id attribute - used for transpose
+ ""
+ ""
+ ""
// the external response file
+ ""
+ ""
+ "";
//select the demographic data
if (includeDemographicData) {
if (containsDemographicData) {
tempQuery +=
""
+ ""
//omit student id attribute
+ ""
+ ""
+ ""
+ ""
+ "";
}
else {
tempQuery +=
""
+ ""
+ "";
}
}
//select the metadata
tempQuery += metadataAttributeSelection;
//select the question metadata
if (questionId.length > 0) {
tempQuery +=
""
+ ""
+ ""
+ "//assessment/section/item/@ident"
+ ""
+ ""
+ "//assessment/section/item/@title"
+ ""
+ ""
+ "//assessment/section/item/presentation/@label"
+ ""
+ ""
+ "(//assessment/section/item/presentation/flow/response_lid/render_choice/material/mattext)|(//assessment/section/item/presentation/flow/response_str/material/mattext)|(//assessment/section/item/presentation/flow/material/mattext)"
+ "";
//control multiple choices
for (var p = 1; p <= questionChoiceCount; p++) {
tempQuery +=
""
+ "//assessment/section/item/presentation/flow/response_lid/render_choice/flow_label/response_label/material/mattext"
+ "";
}
//at least one metadata field
tempQuery +=
""
+ "//assessment/section/item/itemmetadata/qtimetadata/vocabulary"
+ ""
+ ""
+ "//assessment/section/item/itemmetadata/qtimetadata/qtimetadatafield/fieldentry"
+ "";
//control multiple metadata fields
for (var q = 2; q <= questionMetadataCount; q++) {
tempQuery +=
""
+ "//assessment/section/item/itemmetadata/qtimetadata/vocabulary"
+ ""
+ ""
+ "//assessment/section/item/itemmetadata/qtimetadata/qtimetadatafield/fieldentry"
+ "";
}
tempQuery +=
""
+ "";
}
tempQuery += "";
//join to the question "table"
if (questionId.length > 0) {
tempQuery +=
""
+ ""
+ ""
+ ""
+ ""
+ ""
+ ""
+ ""
+ ""
+ "="
+ ""
+ ""
+ ""
+ ""
+ "//assessment/section/item/@ident"
+ ""
+ ""
+ ""
+ ""
+ ""
+ "";
}
tempQuery += "";
} // for questionId loop
} //for docObjs loop
tempQuery +=
""
+ "";
//alert(tempQuery);
return tempQuery;
}
/**
* @param searchTerms - and object (hashtable) with, pay attention now:
keys are search values
* values are pathexprs
**/
function generateSearchString(
searchTerms,
assessmentItemIds,
operator,
searchAssessments,
searchAssessmentItems) {
var queryString =
""
+"Web-Search";
/** assessments **/
if (searchAssessments) {
queryString +=
"edml://ecoinformatics.org/edml"
//assessment fields
+"assessment/duration"
+"assessment/title"
+"assessment/@id"
+"dataset/dataTable/entityName"
+"lom/general/title/string"
+"lom/general/keyword/string"
+"individualName/surName"
+"organizationName"
+"assessmentItems/assessmentItem/assessmentItemId";
}
/** questions **/
if (searchAssessmentItems) {
queryString +=
"http://www.imsglobal.org/xsd/ims_qtiasiv1p2"
//question (qti) fields
+"item/@title"
+"item/@ident"
+"qtimetadata/qtimetadatafield/fieldlabel"
+"qtimetadata/qtimetadatafield/fieldentry"
//classification
+"fieldlabel"
+"fieldentry"
+"objectives/material/mattext"
//question content
+"presentation/flow/response_lid/render_choice/material/mattext"
+"response_label/@ident"
+"response_label/material/mattext";
}
// a query group for search terms
var termQueryString = "";
termQueryString +=
"";
for (var i in searchTerms) {
var key = i;
var value = searchTerms[i];
//only if we have a value
if (value.length > 0) {
termQueryString +=
"";
if (key != "anyValue") {
termQueryString += "" + key + "";
}
termQueryString += "" + value + "";
termQueryString +="";
}
}
termQueryString += "";
// querygroup for assessmentItemIds
var itemQueryString = "";
if (assessmentItemIds) {
//the pathexpr
var pathexpr = "assessmentItems/assessmentItem/assessmentItemId";
// a query group for search terms
itemQueryString +=
"";
for (var i in assessmentItemIds) {
var itemId = assessmentItemIds[i];
//only if we have a value
if (itemId.length > 0) {
itemQueryString +=
"";
if (key != "anyValue") {
itemQueryString += "" + pathexpr + "";
}
itemQueryString += "" + itemId + "";
itemQueryString +="";
}
}
itemQueryString += "";
}
//combine the various conditions
queryString +=
"";
queryString += termQueryString;
queryString += itemQueryString;
queryString += "";
//end the pathquery
queryString += "";
return queryString;
}
function generateAssessmentSearchString(assessmentItemId) {
var query =
""
+"Containing-Assessment-Search"
+"edml://ecoinformatics.org/edml"
+"assessment/duration"
+"assessment/title"
+"assessment/@id"
+"dataset/dataTable/entityName"
+"lom/general/title/string"
+"lom/general/keyword/string"
+"individualName/surName"
+"organizationName"
+"assessmentItems/assessmentItem/assessmentItemId";
if (assessmentItemId.length > 0) {
query += "";
//add the assessmentId if included
query +=
""
+""
+ assessmentItemId
+""
+"assessmentItemId"
+"";
//close the query group
query +=
"";
}
query += "";
return query;
}
function generateAssessmentListString(assessmentIds) {
var query =
""
+"Assessment-List"
+"edml://ecoinformatics.org/edml"
+"assessment/title"
+"assessment/@id"
+"assessment/duration"
+"dataset/dataTable/entityName"
+"lom/general/title/string"
+"lom/general/keyword/string"
+"individualName/surName"
+"organizationName"
+"assessmentItems/assessmentItem/assessmentItemId";
if (assessmentIds.length > 0) {
query += "";
//add the assessmentId if included
for (var i=0; i < assessmentIds.length; i++) {
query +=
""
+""
+ assessmentIds[i]
+""
+"@packageId"
+"";
}
//close the query group
query +=
"";
}
query += "";
return query;
}
function callAjax(metacatURL, myQuery, qfmt, divId, callback) {
//alert("calling ajax: " + metacatURL);
//alert("myQuery: " + myQuery);
//var myRequest = new Ajax.Request(
var myUpdate = new Ajax.Updater(
divId,
metacatURL,
{ method: 'post',
parameters: { action: 'squery', qformat: qfmt, query: myQuery},
evalScripts: true,
onComplete: callback,
onFailure: function(transport) {alert('failure making ajax call');}
});
//alert("done calling ajax");
}
function getIframeDocument(iframeId) {
//look up the document
var iframe = window.document.getElementById(iframeId);
var doc = null;
if (iframe.contentDocument) {
doc = iframe.contentDocument;
}
else {
doc = iframe.contentWindow.document;
}
return doc;
}