All Downloads are FREE. Search and download functionalities are using the official Maven repository.

webclient.js-i2b2.cells.CRC.CRC_view_Find.js Maven / Gradle / Ivy

/**
 * @projectDescription	View controller for the Find viewport. (CRC's "previous queries" window)
 * @inherits 	i2b2.CRC.view
 * @namespace	i2b2.CRC.view.find
 * @author		Nick Benik, Griffin Weber MD PhD
 * @version 	1.3
 * ----------------------------------------------------------------------------------------
 * updated 9-15-08: RC4 launch [Nick Benik] 
 */
console.group('Load & Execute component file: CRC > view > Find');
console.time('execute time');


// create and save the screen objects
i2b2.CRC.view.find = new i2b2Base_cellViewController(i2b2.CRC, 'find');
i2b2.CRC.view.find.visible = false;
// define the option functions
// ================================================================================================== //
i2b2.CRC.view.find.showOptions = function(subScreen){
	if (!this.modalOptions) {
		var handleSubmit = function(){
			// submit value(s)
			if (this.submit()) {
				$('HISTMaxQryDisp').style.border = "2px inset";
				if ($('HISTsortOrderASC').checked) {
					tmpValue = 'ASC';
				}
				else {
					tmpValue = 'DESC';
				}
				i2b2.CRC.view['find'].params.sortOrder = tmpValue;
				if ($('HISTsortByNAME').checked) {
					tmpValue = 'NAME';
				}
				else {
					tmpValue = 'DATE';
				}
				i2b2.CRC.view['find'].params.sortBy = tmpValue;
				tmpValue = parseInt($('HISTMaxQryDisp').value, 10);
				i2b2.CRC.view['find'].params.maxQueriesDisp = tmpValue;
				// requery the find list
				i2b2.CRC.ctrlr.find.Refresh();
			}
		}
		var handleCancel = function(){
			this.cancel();
		}
		this.modalOptions = new YAHOO.widget.SimpleDialog("optionsFind", {
			width: "400px",
			fixedcenter: true,
			constraintoviewport: true,
			modal: true,
			zindex: 700,
			buttons: [{
				text: "OK",
				handler: handleSubmit,
				isDefault: true
			}, {
				text: "Cancel",
				handler: handleCancel
			}]
		});
		$('optionsFind').show();
		this.modalOptions.validate = function(){
			// now process the form data
			var tmpValue = parseInt($('HISTMaxQryDisp').value, 10);
			var value = $('HISTMaxQryDisp').value;
			if(!isNaN(value) && parseInt(Number(value)) == value && !isNaN(parseInt(value, 10)) && value >=0){
				$('HISTMaxQryDisp').style.border = "2px inset";
				return true;
			} else {
				alert("The max number of Queries must be a whole number larger then zero.");
				$('HISTMaxQryDisp').style.border = "2px inset red";
				return false;
			}
		};
		this.modalOptions.render(document.body);
	} 
	this.modalOptions.show();
	// load settings
	if (this.params.sortOrder=="ASC") {
		$('HISTsortOrderASC').checked = true;
	} else {
		$('HISTsortOrderDESC').checked = true;
	}
	if (this.params.sortBy=="NAME") {
		$('HISTsortByNAME').checked = true;
	} else {
		$('HISTsortByDATE').checked = true;
	}
	$('HISTMaxQryDisp').value = this.params.maxQueriesDisp;		
}

// ================================================================================================== //
i2b2.CRC.view.find.ToggleNode = function(divTarg, divTreeID) {
	// get the i2b2 data from the yuiTree node
	var tvTree = YAHOO.widget.TreeView.getTree(divTreeID);
	var tvNode = tvTree.getNodeByProperty('nodeid', divTarg.id);
	tvNode.toggle();
}





// ================================================================================================== //
i2b2.CRC.view.find.PopulateQueryMasters = function(dm_ptr, dm_name, options) {
	var thisview = i2b2.CRC.view.find;
	// clear the data first
	var tvTree = i2b2.CRC.view.find.yuiTree;
	var tvRoot = tvTree.getRoot();
	tvTree.removeChildren(tvRoot);
	tvTree.locked = false;
	
	// sort by the options
	if (Object.isUndefined(options)) { var options = {}; }
	if (!options.sortBy) { options.sortBy = 'DATE'; }
	if (!options.sortOrder) { options.sortBy = 'DESC'; }
	if (options.sortBy=='NAME') {
		var compareAttrib = 'name';
	} else {
		var compareAttrib = 'created';
	}
	if (options.sortOrder=='ASC') {
		var reverseSort = false;
	} else {
		var reverseSort = true;
	}

	// NEW SORT METHOD USING prototype Enumerators
	var QM_sortVal = function(rec) {
		var hash_key = rec[0]; 
		var sdxExtObj = rec[1];
		var cl_compareAttrib = compareAttrib;  // <---- closure var
		var t = sdxExtObj.origData[cl_compareAttrib];
		if (cl_compareAttrib=="created") {
			// proper date handling (w/improper handling for latest changes to output format)
			var sd = t.toUpperCase();
			if (sd.indexOf('Z') != -1 || sd.indexOf('T') != -1) {
				t = t.toLowerCase();
			} else {
				t = Date.parse(t);
			}
		} else {
			t = String(t.toLowerCase() );
		}
		return t;
	};
	var sortFinal = i2b2.CRC.model.QueryMasters.sortBy(QM_sortVal);
	// reverse if needed
	if (reverseSort) { sortFinal.reverse(true); }
	
	// populate the Query Masters into the treeview
	for (var i=0; i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy