Changeset 2459
- Timestamp:
- 12/04/09 13:17:08 (2 years ago)
- Location:
- disease_book
- Files:
-
- 2 added
- 5 edited
-
WebContent/generated-res/scripts/ontologymrefinput.js (modified) (2 diffs)
-
WebContent/generated-res/scripts/ontologyxrefinput.js (modified) (5 diffs)
-
WebContent/testAjax.html (added)
-
generated/java/syndromebooktest/ui/SyndromeHtmlForm.java (modified) (3 diffs)
-
handwritten/java/myservlet/MyServlet.java (modified) (1 diff)
-
handwritten/java/plugin/SyndromeHtmlForm.java (added)
-
syndromebooktest_db.xml (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
disease_book/WebContent/generated-res/scripts/ontologymrefinput.js
r2425 r2459 17 17 } 18 18 19 function omref_addInput(name, xrefEntity, xrefField, xrefLabel, container)19 function omref_addInput(name, xrefEntity, xrefField, xrefLabel, xrefDescription, container) 20 20 { 21 mref_addInput(name, xrefEntity, xrefField, xrefLabel, null, container);21 mref_addInput(name, xrefEntity, xrefField, xrefLabel, null, xrefDescription, container); 22 22 } 23 23 24 function omref_addInput(name, xrefEntity, xrefField, xrefLabel, xrefFilters, container) {24 function omref_addInput(name, xrefEntity, xrefField, xrefLabel, xrefFilters, xrefDescription, container) { 25 25 //only add if the previous select has an option selected 26 26 var lastSelect = mref_getLastSelect(container); … … 41 41 selectInput.onfocus = function(e) 42 42 { 43 showOntologyXrefInput(selectInput, xrefEntity, xrefField, xrefLabel, xrefFilters );43 showOntologyXrefInput(selectInput, xrefEntity, xrefField, xrefLabel, xrefFilters, xrefDescription); 44 44 return false; 45 45 } -
disease_book/WebContent/generated-res/scripts/ontologyxrefinput.js
r2425 r2459 1 function showOntologyXrefInput(input, xref_entity, xref_field, xref_label) {1 function showOntologyXrefInput(input, xref_entity, xref_field, xref_label) { 2 2 showXrefInput(input, xref_entity, xref_field, xref_label, null); 3 3 } 4 4 5 function showOntologyXrefInput(input, xref_entity, xref_field, xref_label, xref_filters) { 5 function showOntologyXrefInput(input, xref_entity, xref_field, xref_label, 6 xref_filters, xref_description) { 6 7 var id = input.id + "_" + input.form.name; 7 8 8 //hide previously open div 9 if (window.xrefInputDiv && window.xrefInputDiv.id != id) 10 { 11 //alert("hiding "+window.xrefInputDiv.id); 9 // hide previously open div 10 if (window.xrefInputDiv && window.xrefInputDiv.id != id) { 11 // alert("hiding "+window.xrefInputDiv.id); 12 12 window.xrefInputDiv.style.display = "none"; 13 13 } 14 14 15 // create if not exists15 // create if not exists 16 16 if (document.getElementById(id) == null) { 17 //alert("create"); 18 var myInput = new OntologyXrefInput(input, xref_entity, xref_field, xref_label, xref_filters); 19 window.xrefInputDiv = myInput.xrefDiv; 20 } 21 else 22 { 17 // alert("create"); 18 var myInput = new OntologyXrefInput(input, xref_entity, xref_field, 19 xref_label, xref_filters, xref_description); 20 window.xrefInputDiv = myInput.xrefDiv; 21 } else { 23 22 window.xrefInputDiv = document.getElementById(id); 24 25 //hide if shown, 26 if (window.xrefInputDiv.style.display == "block") 27 { 23 24 // hide if shown, 25 if (window.xrefInputDiv.style.display == "block") { 28 26 window.xrefInputDiv.style.display = "none"; 29 27 input.focus(); 30 28 input.blur(); 31 29 } 32 // else show 33 else 34 { 30 // else show 31 else { 35 32 window.xrefInputDiv.style.display = "block"; 36 33 input.focus(); 37 input.blur(); 34 input.blur(); 38 35 searchbox = xrefInputDiv.getElementsByTagName("input")[0]; 39 searchbox.focus(); 40 } 41 } 42 } 43 44 //constructor 45 function OntologyXrefInput(input, xref_entity, xref_field, xref_label, xref_filters) { 46 //alert("constructor"); 47 this.init(input, xref_entity, xref_field, xref_label, xref_filters); 48 } 49 50 //define class prototype 51 OntologyXrefInput.prototype = { 52 init : function(input, xref_entity, xref_field, xref_label, xref_filters) { 53 //alert("init"); 36 searchbox.focus(); 37 } 38 } 39 } 40 41 // constructor 42 function OntologyXrefInput(input, xref_entity, xref_field, xref_label, 43 xref_filters, xref_description) { 44 // alert("constructor"); 45 this.init(input, xref_entity, xref_field, xref_label, xref_filters, xref_description); 46 } 47 48 // define class prototype 49 OntologyXrefInput.prototype = { 50 init : function(input, xref_entity, xref_field, xref_label, xref_filters, xref_description) { 51 // alert("init"); 54 52 this.input = input; 55 53 56 54 this.xref_entity = xref_entity; 57 55 this.xref_field = xref_field; 58 56 this.xref_label = xref_label; 59 57 this.xref_filters = xref_filters; 60 61 //create the xref div 58 this.xref_description = xref_description; 59 60 // create the xref div 62 61 this.xrefDiv = document.createElement("div"); 63 62 this.xrefDiv.className = "xrefinput"; 64 63 this.xrefDiv.style.display = "block"; 65 64 this.xrefDiv.id = input.id + "_" + input.form.name; 66 67 // add the div as child of the input65 66 // add the div as child of the input 68 67 this.input.parentNode.insertBefore(this.xrefDiv, this.input.nextSibling); 69 this.xrefDiv.setAttribute("XrefInputObject", this); // ???70 71 // add the search box68 this.xrefDiv.setAttribute("XrefInputObject", this); // ??? 69 70 // add the search box 72 71 this.searchLabel = document.createElement("label"); 73 72 this.searchLabel.appendChild(document.createTextNode("search:")); … … 76 75 this.xrefDiv.appendChild(this.searchInput); 77 76 this.searchInput.focus(); 78 77 79 78 this.xrefDiv.appendChild(document.createElement("br")); 80 79 81 // initialize with current selection if any80 // initialize with current selection if any 82 81 this.xrefDiv.value = this.input.value; 83 if(this.input.options.length > 0) 84 { 82 if (this.input.options.length > 0) { 85 83 this.searchInput.value = this.input.options[0].text; 86 } 87 88 89 //add a handler to the search box to update select when changed 84 } 85 86 // add a handler to the search box to update select when changed 90 87 var _this = this; 91 this.addEvent(this.searchInput, " keyup", function(e) {88 this.addEvent(this.searchInput, "mouseover", function(e) { 92 89 _this.reload(); 93 94 //if only one option auto-select 95 if(_this.selectInput.options.length == 1) 96 { 97 _this.selectInput.options[0].style.background = "blue"; 98 _this.selectInput.options[0].style.color = "white"; 99 } 100 101 //on 'enter' and if only one option, choose that 102 if( (e.which == 13 || e.keyCode == 13) && _this.selectInput.options.length == 1) 103 { 104 _this.selectInput.selectedIndex = 0; 105 _this.select(_this); 106 return; 107 } 108 //on 'esc' close dialog 109 if(e.which == 27) 110 { 111 _this.xrefDiv.style.display = "none"; 112 } 113 }); 114 115 //add the select box 116 this.selectInput = document.createElement("select"); 117 //this.selectInput.multiple = "true"; 118 90 91 // if only one option auto-select 92 if (_this.selectInput.options.length == 1) { 93 _this.selectInput.options[0].style.background = "blue"; 94 _this.selectInput.options[0].style.color = "white"; 95 } 96 97 // on 'enter' and if only one option, choose that 98 if ((e.which == 13 || e.keyCode == 13) 99 && _this.selectInput.options.length == 1) { 100 _this.selectInput.selectedIndex = 0; 101 _this.select(_this); 102 return; 103 } 104 // on 'esc' close dialog 105 if (e.which == 27) { 106 _this.xrefDiv.style.display = "none"; 107 } 108 }); 109 110 // add the select box 111 this.selectInput = document.createElement("select"); 112 // this.selectInput.multiple = "true"; 113 119 114 this.selectInput.style.width = "100%"; 120 115 this.xrefDiv.appendChild(this.selectInput); 121 116 122 // add handler so the input is updated when clicking one select option123 var _this = this; 117 // add handler so the input is updated when clicking one select option 118 var _this = this; 124 119 this.addEvent(this.selectInput, "click", function(e) { 125 120 _this.select(_this); 126 }); 127 121 }); 122 128 123 this.reload(); 129 124 this.searchInput.focus(); 130 125 }, 131 /*Copy the current selected item to 'input' and close dialog*/ 132 select : function(_this) 133 { 134 if(_this.selectInput.options.length > 0) 135 { 136 //alert("clicked option "+ _this.selectInput.options[_this.selectInput.selectedIndex].value); 137 _this.input.options[0].value = _this.selectInput.options[_this.selectInput.selectedIndex].value; 138 _this.input.options[0].text = _this.selectInput.options[_this.selectInput.selectedIndex].text; 139 _this.xrefDiv.style.display = "none"; 140 } 141 }, 142 /* reload function*/ 126 /* Copy the current selected item to 'input' and close dialog */ 127 select : function(_this) { 128 if (_this.selectInput.options.length > 0) { 129 // alert("clicked option "+ 130 // _this.selectInput.options[_this.selectInput.selectedIndex].value); 131 _this.input.options[0].value = _this.selectInput.options[_this.selectInput.selectedIndex].value; 132 _this.input.options[0].text = _this.selectInput.options[_this.selectInput.selectedIndex].text; 133 _this.xrefDiv.style.display = "none"; 134 } 135 }, 136 /* reload function */ 143 137 reload : function() { 144 //alert("reload"); 145 146 //load the select box contents via AJAX 147 var url = "xref/find?xref_entity="+this.xref_entity+"&xref_field="+this.xref_field+"&xref_label="+this.xref_label+"&xref_label_search="+this.searchInput.value; 148 if(this.xref_filters != null) url += "&xref_filters="+this.xref_filters; 149 //alert(url); 138 // alert("reload"); 139 140 // load the select box contents via AJAX 141 var url = "xref/find?xref_entity=" + this.xref_entity + "&xref_field=" 142 + this.xref_field + "&xref_label=" + this.xref_label 143 + "&xref_label_search=" + this.searchInput.value; 144 if (this.xref_filters != null) 145 url += "&xref_filters=" + this.xref_filters; 146 // alert(url); 150 147 151 148 // branch for native XMLHttpRequest object … … 153 150 154 151 req = false; 155 if (window.XMLHttpRequest && !(window.ActiveXObject)) //NOT IE152 if (window.XMLHttpRequest && !(window.ActiveXObject)) // NOT IE 156 153 { 157 154 req = new XMLHttpRequest(); 158 } 159 else if (window.ActiveXObject) { 155 } else if (window.ActiveXObject) { 160 156 req = new ActiveXObject("Microsoft.XMLHTTP"); 161 157 } … … 163 159 if (req) { 164 160 req.onreadystatechange = function(e) { 165 // only if req shows "complete" 161 // only if req shows "complete" 166 162 if (req.readyState == 4) { 167 // only if "OK" 168 if (req.status == 200) {169 // ...processing statements go here...170 var options = eval('(' + req.responseText + ')');171 _this.redrawOptions(options);172 } else {173 alert("There was a problem retrieving the XML data:\n"174 + req.statusText);175 }176 }163 // only if "OK" 164 if (req.status == 200) { 165 // ...processing statements go here... 166 var options = eval('(' + req.responseText + ')'); 167 _this.redrawOptions(options); 168 } else { 169 alert("There was a problem retrieving the XML data:\n" 170 + req.statusText); 171 } 172 } 177 173 }; 178 174 req.open("GET", url, true); … … 180 176 } 181 177 }, 182 getDescriptionForOntology : function(ontology_id) { 183 //using http://localhost:8080/molgenis_distro/ontology_description?id=2 184 //load the select box contents via AJAX 185 var url = "ontology_description?id="+ontology_id; 186 187 // branch for native XMLHttpRequest object 188 this.result = "null"; 189 var _this = this; 190 191 req = false; 192 if (window.XMLHttpRequest && !(window.ActiveXObject)) //NOT IE 193 { 194 req = new XMLHttpRequest(); 195 } 196 else if (window.ActiveXObject) { 197 req = new ActiveXObject("Microsoft.XMLHTTP"); 198 } 199 200 201 if (req) { 202 req.onreadystatechange = function(e) { 203 // only if req shows "complete" 204 if (req.readyState == 4) { 205 // only if "OK" 206 if (req.status == 200) { 207 // ...processing statements go here... 208 _this.result = req.responseText; 209 210 } else { 211 alert("There was a problem retrieving the XML data:\n" 212 + req.statusText); 213 } 214 } 215 }; 216 req.open("GET", url, true); 217 req.send(""); 218 } 219 return this.result; 178 getDescriptionForOntology : function(ontology_id, option) { 179 // using http://localhost:8080/molgenis_distro/ontology_description?id=ontology_id 180 // load the select box contents via AJAX 181 182 var div = document.getElementById('container'); 183 var req="n/a"; 184 var handleSuccess = function(o) { 185 YAHOO.log("The success handler was called. tId: " + o.tId + ".", 186 "info", "example"); 187 if (o.responseText !== undefined) { 188 option.title = o.responseText; 189 req = o.responseText ; 190 } 191 } 192 var handleFailure = function(o) { 193 alert("F"); 194 YAHOO.log("The failure handler was called. tId: " + o.tId + ".", 195 "info", "example"); 196 if (o.responseText !== undefined) { 197 div.innerHTML = o.tId; 198 div.innerHTML += o.status; 199 div.innerHTML += o.statusText; 200 } 201 } 202 var callback = { 203 success : handleSuccess, 204 failure : handleFailure//, 205 // argument : { 206 // foo : "foo", 207 // bar : "bar" 208 // } 209 } 210 var sUrl = "http://localhost:8080/molgenis_distro/ontology_description?entity="+this.xref_description+"&id="; 211 //function makeRequest(){ 212 var myInput = YAHOO.util.Dom.get('myInput'); 213 var request = YAHOO.util.Connect.asyncRequest('GET', sUrl + ontology_id, 214 callback); 215 YAHOO.log("Initiating request; tId: " + request.tId + ".", "info", 216 "example"); 217 //} 220 218 }, 221 219 redrawOptions : function(options) { 222 //remove existing options this.selectInput.options; 223 for (i = this.selectInput.options.length - 1; i >=0; i--) 224 { 220 // remove existing options this.selectInput.options; 221 for (i = this.selectInput.options.length - 1; i >= 0; i--) { 225 222 this.selectInput.removeChild(this.selectInput.options[i]); 226 223 } 227 224 228 //add empty option to set 'null' when search is empty 229 if(this.searchInput.value == "") 230 { 225 // add empty option to set 'null' when search is empty 226 if (this.searchInput.value == "") { 231 227 this.selectInput.appendChild(document.createElement("option")); 232 } 233 234 // add the current options228 } 229 230 // add the current options 235 231 for ( var i in options) { 236 232 var option = document.createElement("option"); 237 233 238 // add the value234 // add the value 239 235 option.value = i; 240 option.title = this.getDescriptionForOntology(i);241 242 // add option to select box236 this.getDescriptionForOntology(i, option); 237 238 // add option to select box 243 239 this.selectInput.appendChild(option); 244 240 245 option.text = options[i]; 246 } 247 248 // resize select to fit241 option.text = options[i]; 242 } 243 244 // resize select to fit 249 245 this.selectInput.size = options.length <= 10 ? options.length : 10; 250 246 }, 251 handleAjax: function(e) { 252 //alert("render"); 253 // only if req shows "complete" 254 if (req.readyState == 4) 255 { 256 // only if "OK" 257 if (req.status == 200) 258 { 259 var options = eval('(' + req.responseText + ')'); 260 this.redrawOptions(options); 261 } else 262 { 247 handleAjax : function(e) { 248 // alert("render"); 249 // only if req shows "complete" 250 if (req.readyState == 4) { 251 // only if "OK" 252 if (req.status == 200) { 253 var options = eval('(' + req.responseText + ')'); 254 this.redrawOptions(options); 255 } else { 263 256 alert("There was a problem retrieving the XML data:\n" 264 257 + req.statusText); 265 } 266 } 267 }, 268 /*helper function to add events for both IE and FF in one call 269 @obj = the oject to add the event ont 270 @eventname = name of the event minus the 'on', e.g. 'click' means 'onclick' 271 @func = the function to be called if this event happens 258 } 259 } 260 }, 261 /* 262 * helper function to add events for both IE and FF in one call @obj = the oject 263 * to add the event ont @eventname = name of the event minus the 'on', e.g. 264 * 'click' means 'onclick' @func = the function to be called if this event 265 * happens 272 266 */ 273 267 addEvent : function(obj, eventname, func) { 274 // alert(eventname);268 // alert(eventname); 275 269 if (navigator.userAgent.match(/MSIE/)) { 276 270 obj.attachEvent("on" + eventname, func); -
disease_book/generated/java/syndromebooktest/ui/SyndromeHtmlForm.java
r2425 r2459 73 73 input.setXrefField("id"); 74 74 input.setXrefLabel("term"); 75 input.setXrefDescription("OntologyTerm"); 75 76 //initialize the OntologyTerm.term of current record 76 77 input.setValueLabels(entity.getOntologyLabels()); … … 253 254 //GenesTested: Field(entity=Syndrome, name=GenesTested, type=mref[Gene->id], mref_name=Syndrome_GenesTested, mref_localid=Syndrome, mref_remoteid=Gene, xref_label=GeneName, auto=false, nillable=true, readonly=false, default=) 254 255 { 255 MrefInput input = newMrefInput("genesTested",entity.getGenesTested());256 OntologyMrefInput input = new OntologyMrefInput("genesTested",entity.getGenesTested()); 256 257 input.setLabel("GenesTested"); 257 258 input.setDescription("GenesTested"); … … 261 262 input.setXrefField("id"); 262 263 input.setXrefLabel("geneName"); 264 input.setXrefDescription("Gene"); 263 265 //initialize the Gene.GeneName of current record 264 266 input.setValueLabels(entity.getGenesTestedLabels()); 265 267 inputs.add(input); 266 } 268 } 267 269 //FreeText: Field(entity=Syndrome, name=FreeText, type=text, auto=false, nillable=true, readonly=false, default=) 268 270 { -
disease_book/handwritten/java/myservlet/MyServlet.java
r2425 r2459 13 13 import org.molgenis.util.Tuple; 14 14 15 import syndromebooktest.Gene; 15 16 import syndromebooktest.OntologyTerm; 16 17 17 import app.servlet.MolgenisServlet; 18 18 19 19 public class MyServlet extends MolgenisServlet { 20 20 21 @Override22 public void service(HttpServletRequest request, HttpServletResponse response)23 throws IOException, ServletException {24 // TODO Auto-generated method stub21 @Override 22 public void service(HttpServletRequest request, HttpServletResponse response) 23 throws IOException, ServletException { 24 // TODO Auto-generated method stub 25 25 26 27 logger.debug("MyServlet run"); 28 29 //ontology_description?id=1 30 String path = request.getRequestURI(); 31 if(path != null && path.contains("/ontology_description")) 32 { 33 Tuple r; 34 35 try 36 { 37 r = new HttpServletRequestTuple(request); 38 int id = r.getInt("id"); 39 //get description from db and write as text 40 Database db = getDatabase(); 41 List<OntologyTerm> result = db.query(OntologyTerm.class).equals("id",id).find(); 42 43 if(result.size()>0) 44 { 45 PrintWriter writer = response.getWriter(); 46 writer.println(result.get(0).getDescription()); 47 writer.close(); 26 logger.debug("MyServlet run2"); 27 28 // ontology_description?id=1 29 String path = request.getRequestURI(); 30 if (path != null && path.contains("/ontology_description")) { 31 Tuple r; 32 33 try { 34 r = new HttpServletRequestTuple(request); 35 int id = r.getInt("id"); 36 // value is 'OntologyTerm' or 'Gene' 37 String entity = r.getString("entity"); 38 // get description from db and write as text 39 Database db = getDatabase(); 40 if (entity.equals("OntologyTerm")) { 41 List<OntologyTerm> result = db.query(OntologyTerm.class) 42 .equals("id", id).find(); 43 44 if (result.size() > 0) { 45 PrintWriter writer = response.getWriter(); 46 writer.println(result.get(0).getDescription()); 47 writer.close(); 48 } 49 } else if (entity.equals("Gene")) { 50 List<Gene> result = db.query(Gene.class).equals("id", id) 51 .find(); 52 53 if (result.size() > 0) { 54 PrintWriter writer = response.getWriter(); 55 writer.println(result.get(0).getGeneDescription()); 56 writer.close(); 57 } 58 } 59 60 } catch (Exception e) { 61 // TODO Auto-generated catch block 62 e.printStackTrace(); 48 63 } 49 50 51 } catch (Exception e) { 52 // TODO Auto-generated catch block 53 e.printStackTrace(); 64 65 } else { 66 super.service(request, response); 54 67 } 55 56 68 } 57 else 58 { 59 super.service(request, response); 60 } 69 61 70 } 62 63 } -
disease_book/syndromebooktest_db.xml
r2425 r2459 22 22 23 23 <entity name="Syndrome"> 24 <field name=" id" type="xref" xref_field="Login.user_id"24 <field name="user_id" type="xref" xref_field="Login.user_id" 25 25 xref_label="loginname" /> 26 26 <field name="Syndrome_id" type="autoid" />
Note: See TracChangeset
for help on using the changeset viewer.