diff --git a/shrine-webclient/src/main/html/js-i2b2/cells/plugins/MedCo/MedCo_QryTool.js b/shrine-webclient/src/main/html/js-i2b2/cells/plugins/MedCo/MedCo_QryTool.js index 312f27107..bff7eed4d 100644 --- a/shrine-webclient/src/main/html/js-i2b2/cells/plugins/MedCo/MedCo_QryTool.js +++ b/shrine-webclient/src/main/html/js-i2b2/cells/plugins/MedCo/MedCo_QryTool.js @@ -1,322 +1,323 @@ var currId = 0; // to give a unique id to the panels i2b2.MedCo.QT = {}; // ------ initialize the controller ------ i2b2.MedCo.QT.ctrlr = {}; i2b2.MedCo.QT.ctrlr.init = function(){ // Initialization of the query tool. var num_panels = 3; // start with 3 panels // // ------ (re-)initialize the model ------ // i2b2.MedCo.QT.model = {}; // i2b2.MedCo.QT.model.panels = new Array(); // // // ------ (re-)initialize the view ------ // i2b2.MedCo.QT.view = {}; // i2b2.MedCo.QT.view.panels = new Array(); i2b2.MedCo.QT.panels = []; for (var i=0; i < num_panels; i++) { i2b2.MedCo.QT.ctrlr.appendPanel() } } i2b2.MedCo.QT.ctrlr.appendPanel = function(){ // Each element (row) visualized on a panel is bound either to a concept (which can // be either sensitive or non-sensitive) or to a list of variant ids (always sensitive). // create a new panel, add it to the list of panels and bind to it model, view and controller var panel = {} i2b2.MedCo.QT.panels.push(panel); // ------ initialize the model of the panel ------ panel.model = { "exclude": false, // indicates whether the panel is excluded or not "group": i2b2.MedCo.QT.panels.length-1, // indicates the group id of the panel (starting from 0) "content": [] // contains a list of {"sensitive": bool, "values"=[ list of concepts/variant ids bound to i-th row of the panel ]} }; // ------ initialize the view of the panel ------ panel.view = document.createElement("div"); panel.view.className = 'MedCo-QueryPanel'; // add the panel to the visualized list of panels document.getElementById("MedCo-QueryPanels").appendChild(panel.view); panel.view.innerHTML = "
" + "
"+ "Clear" + "
"+ "
Group "+ 1 + "
" + "
" + "
" + "
" + // "
" + "
" + // "
" + "
" + "Exclude" + "
" + "
" + "
" + "
"; // create and add the div for the dropped concepts var conceptsView = panel.view.getElementsByClassName('MedCo-QueryPanelConcepts')[0]; i2b2.sdx.Master.AttachType(conceptsView.id , 'CONCPT', {dropTarget: true}); i2b2.sdx.Master.setHandlerCustom(conceptsView.id, 'CONCPT', 'DropHandler', function (sdxData) {panel.ctrlr.doDrop(sdxData);}); // var panels = document.getElementById("MedCo-QueryPanels") // // create the HTML of the panel and return the respective object // create and append the three elements (header, options, concepts div) // var paneldiv = document.createElement("div"); // paneldiv.className = 'MedCo-QueryPanel' // panels.appendChild(paneldiv) // // // create and fill header // var header = document.createElement("div"); // header.className = 'MedCo-QueryPanelHeader'; // // var temp = document.createElement("div"); // temp.className = 'delete'; // header.appendChild(temp) // var temp1 = document.createElement("a"); // temp1.onclick = panel.delete; // temp.appendChild(temp1) // var temp2 = document.createElement("img") // temp2.src ="js-i2b2/cells/CRC/assets/QryTool_b_clear.gif" // temp2.alt = "Clear" // temp1.appendChild(temp2) // // temp = document.createElement("div"); // temp.className = 'groupId'; // temp.innerText = 'Group ' + panel.group; // header.appendChild(temp) // // // create and fill options // var options = document.createElement("div"); // options.className ='MedCo-QueryPanelOptions'; // // temp = document.createElement("div"); // temp.className = 'date'; // options.appendChild(temp) // // temp = document.createElement("div"); // temp.className = 'occur'; // options.appendChild(temp) // // temp = document.createElement("div"); // panel.exclude = false // temp.className = 'exclude'; // temp.onclick = function () { // // underline the text in the botton // temp.style.textDecoration = temp.style.textDecoration=="underline"? "none":"underline" // // // mark the panel as excluded // panel.exclude = !panel.exclude; // // // update the concepts visualization // var conceptsDiv = conceptsView.getElementsByClassName("sdxDefaultCONCPT") // if (panel.exclude) { // // insert "NOT" in front of the concepts in the div // // //  NOT  // for (var i = 0; i < conceptsDiv.length; i++) { // conceptsDiv[i].insertBefore(notTemplate.cloneNode(true), conceptsDiv[i].firstChild); // } // } // else{ // // remove the "NOT" in front of the concepts in the div // for (var i = 0; i < conceptsDiv.length; i++){ // conceptsDiv[i].removeChild(conceptsDiv[i].getElementsByClassName("itemExclude")[0]) // } // } // } // options.appendChild(temp) // temp1 = document.createElement("a") // temp1.title = "Exclude records matching this group's criteria..." // temp1.text = "Exclude" // temp.appendChild(temp1) // // // create and add the div for the dropped concepts // var conceptsView = document.createElement("div"); // conceptsView.className = 'MedCo-QueryPanelConcepts'; // conceptsView.id = "MedCo-QueryPanel" + (id++) // i2b2.sdx.Master.AttachType(conceptsView.id, 'CONCPT', {dropTarget: true}); // i2b2.sdx.Master.setHandlerCustom(conceptsView.id, 'CONCPT', 'DropHandler', function (sdxData) {panel.doDrop(sdxData);}); // paneldiv.appendChild(header) // paneldiv.appendChild(options) // paneldiv.appendChild(conceptsView) /* Instantiate a ContextMenu for this panel*/ YAHOO.util.Event.onContentReady(conceptsView.id, function () { var conceptContextMenu = new YAHOO.widget.ContextMenu( conceptsView.id+"ContextMenu", { trigger: document.getElementById(conceptsView.id).childNodes, itemdata: ["Delete"], lazyload: true } ); // whenever the content of the panel changes, update the trigger property $(conceptsView.id).on("DOMSubtreeModified",function(){ conceptContextMenu.cfg.setProperty("trigger", document.getElementById(conceptsView.id).childNodes); }); function onContextMenuClick(p_sType, p_aArgs) { //p_aArgs[1]: MenuItem instance that was the target of the "click" event. var oItem = p_aArgs[1], // The MenuItem that was clicked oTarget = this.contextEventTarget, oLI; if (oItem) { // todo: also verify the class (sdxDefaultCONCPT)? oLI = oTarget.nodeName.toUpperCase() == "DIV" ? oTarget : YAHOO.util.Dom.getAncestorByClassName(oTarget, "sdxDefaultCONCPT"); switch (oItem.index) { case 0: // Delete // remove the concept from the view and from the model - var panel = document.getElementById(conceptsView.id) - panel.removeChild(oLI) - i2b2.MedCo.QT.panels.model.content.splice(Array.from(panel.children).indexOf(oLI), 1) + var panel_view = document.getElementById(conceptsView.id) + var index = Array.from(panel_view.children).indexOf(oLI) + panel.model.content.splice(index, 1) + panel_view.removeChild(oLI) break; // add here other cases if there are more menu items } } } // "render" event handler for the ewe context menu function onContextMenuRender(p_sType, p_aArgs) { // Add a "click" event handler to the ewe context menu this.subscribe("click", onContextMenuClick); } conceptContextMenu.subscribe("render", onContextMenuRender); // a bit rude bug fix... (hide menu when clicking on the panel) document.getElementById(conceptsView.id).onclick = function () {conceptContextMenu.hide.call(conceptContextMenu)} }); panel.view.appendConcept = function (concept, output){ var conceptDiv = "
" + ((panel.model.exclude) ? "NOT" : "") + "" + concept + ((output)? (" (...)") : "") + "
"; var conceptPanelId = panel.view.getElementsByClassName('MedCo-QueryPanelConcepts')[0].id; var conceptPanel =document.getElementById(conceptPanelId) conceptPanel.innerHTML += conceptDiv; return conceptPanel.lastChild }; // ------ initialize the controller ------ panel.ctrlr = {}; panel.ctrlr.doDrop = function (sdxData) { var concept = sdxData[0]; // only interested in first record // CHECK: some useful functions: // alert(i2b2.h.getXNodeVal(sdxData.origData.xmlOrig, "level")) // alert(Object.getOwnPropertyNames(sdxData.origData)); // optimization to prevent requerying the hive for new results if the input dataset has not changed // i2b2.ExampTabs.model.dirtyResultsData = true; // check whether to show a popup or directly append the concept switch(concept.sdxInfo.sdxDisplayName) { case "Gene Name": i2b2.MedCo.popups.ByGene.show(panel.model.group); return; case "Protein Position": i2b2.MedCo.popups.ByProteinPosition.show(panel.model.group); return; case "Variant Name": i2b2.MedCo.popups.ByVariantName.show(panel.model.group); return; } // check if the concept is sensitive var keyval = concept.sdxInfo.sdxKeyValue; var sensitive = !keyval.includes("nonsensitive") && !keyval.includes("non-sensitive"); var conceptModel = sensitive ? concept.origData.basecode.split(":")[1] : (concept.origData.key).replace(/ NOT  // for (var i = 0; i < conceptsDiv.length; i++) { // conceptsDiv[i].insertBefore(notTemplate.cloneNode(true), conceptsDiv[i].firstChild); // } // } // else{ // // remove the "NOT" in front of the concepts in the div // for (var i = 0; i < conceptsDiv.length; i++){ // conceptsDiv[i].removeChild(conceptsDiv[i].getElementsByClassName("itemExclude")[0]) // } // } // } } panel.ctrlr.remove = function(){ alert("remove") } }; \ No newline at end of file