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

webclient.js-i2b2.cells.WORK.WORK_ctrlr_general.js Maven / Gradle / Ivy

console.group('Load & Execute component file: WORK > ctrl > general');
console.time('execute time');


// main plugin handler
i2b2.WORK.visible = false;
i2b2.WORK.ctrlr.main = {};


i2b2.WORK.ctrlr.main._generateRefreshList = function(tvTargets) {
	// this function is used to generate a list of treenodes that need to be refreshed
	// it's primary goal is to prevent errors caused by trying to refresh a child
	// who does not exist after it's parent has been refreshed
	if (!tvTargets.length) { return []; }

	var i1, i2, tNode, aNode, isDone, wasChanged;
	// ALGORITHM: pick a node, climb tree and see if ancestor node is in nodes list that was passed,
	// if ancestor is found, select that as our new working node and remove the previously selected
	// node, repeat.  Exit when algorithm has been applied to all nodes in the list.
	for (i1=0; i1');

	var varInput = {
		rename_text: newName,
		rename_target_id: pn.sdxInfo.sdxKeyValue,
		result_wait_time: 180
	};
	i2b2.WORK.ajax.renameChild("WORK:Workplace", varInput, scopedCallback);
};


i2b2.WORK.ctrlr.main.Delete = function(target_node, options) { 
	var nd = target_node.data.i2b2_SDX;
	if (!options) { options = {}; }
	if (!options.silent) {
		var nodeTitle = getHtmlText($(target_node.data.nodeid).select("DIV")[0]);
		nodeTitle = String(nodeTitle).strip();
		if (nd.origData.encapType == "FOLDER") {
			var go = confirm('Are you sure you want to delete the folder "'+nodeTitle+'" and all of it\'s contents?');
		} else {
			var go = confirm('Are you sure you want to delete "'+nodeTitle+'"?');
		}
		if (!go) { return false; }
	}

	if (options.callback) {
		var scopedCallback = options.callback;
	} else {
		// create callback GUI update routine
		var scopedCallback = new i2b2_scopedCallback();
		scopedCallback.scope = target_node;
		scopedCallback.callback = function(results) {
			i2b2.WORK.view.main.queryResponse = results.msgResponse;
			i2b2.WORK.view.main.queryRequest = results.msgRequest;
			if (results.error) {
				alert("An error occurred while trying to delete the selected item!");
			} else {
				this.tree.removeNode(this, true);
			}
		}
	}
	var varInput = {
		delete_target_id: nd.sdxInfo.sdxKeyValue, 
		result_wait_time: 180
	};
	i2b2.WORK.ajax.deleteChild("WORK:Workplace", varInput, scopedCallback);
}


i2b2.WORK.ctrlr.main.Annotate = function(target_node) { 
	var nd = target_node.data.i2b2_SDX;
	if (Object.isUndefined(nd)) {
		console.error("The target node does not have SDX data attached.");
		return false;
	}
	var origAnno = nd.origData.annotation;
	if (!origAnno) { origAnno = ''; }
	else {
		var eachLine = origAnno.split('\n');
		if(eachLine.length > 1){ // an annotation was found
			var tempAnno = '';
			for(var i = 1, l = eachLine.length; i < l; i++) {
				tempAnno += eachLine[i];
			}
			origAnno = tempAnno;
		} else {
			origAnno = '';
		}
	}
	var newAnno = prompt('Change this work item\'s annotation to:', origAnno);
	if (!newAnno || newAnno==origAnno) { return false; }

	// create callback display routine
	var scopedCallback = new i2b2_scopedCallback();
	scopedCallback.scope = target_node;
	scopedCallback.callback = function(results) {
		i2b2.WORK.view.main.queryResponse = results.msgResponse;
		i2b2.WORK.view.main.queryRequest = results.msgRequest;
		if (results.error) {
			alert("An error occurred while trying to annotate the selected item!");
		} else {
			// GUI refresh is not needed
			//this.data.i2b2_SDX.origData.annotation = newAnno;
			i2b2.WORK.view.main.refreshTree();
		}
	}
	var pn = target_node.data.i2b2_SDX;
	var varInput = {
		annotation_text: newAnno, 
		annotation_target_id: pn.sdxInfo.sdxKeyValue,
		result_wait_time: 180
	};
	i2b2.WORK.ajax.annotateChild("WORK:Workplace", varInput, scopedCallback);
};




i2b2.WORK.ctrlr.main.HandleDrop = function(sdxDropped) {
	var ddm = YAHOO.util.DDM;
	var trgtEl = ddm.getBestMatch(ddm.interactionInfo.drop);
	var trgtElID = trgtEl.id
	var yuiTV = YAHOO.widget.TreeView.findTreeByChildDiv(trgtElID);
	var trgtNode = yuiTV.getNodeByProperty("nodeid", trgtElID);
	var trgtSdx = trgtNode.data.i2b2_SDX;
	for (var i=0; i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy