Changeset 2459


Ignore:
Timestamp:
12/04/09 13:17:08 (2 years ago)
Author:
mswertz
Message:

Added description as OntologyMrefInput? to enable description on pulldowns.

Location:
disease_book
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • disease_book/WebContent/generated-res/scripts/ontologymrefinput.js

    r2425 r2459  
    1717} 
    1818 
    19 function omref_addInput(name, xrefEntity, xrefField, xrefLabel, container) 
     19function omref_addInput(name, xrefEntity, xrefField, xrefLabel, xrefDescription, container) 
    2020{ 
    21         mref_addInput(name, xrefEntity, xrefField, xrefLabel, null, container); 
     21        mref_addInput(name, xrefEntity, xrefField, xrefLabel, null, xrefDescription, container); 
    2222} 
    2323 
    24 function omref_addInput(name, xrefEntity, xrefField, xrefLabel, xrefFilters, container) {        
     24function omref_addInput(name, xrefEntity, xrefField, xrefLabel, xrefFilters, xrefDescription, container) {       
    2525        //only add if the previous select has an option selected 
    2626        var lastSelect = mref_getLastSelect(container);  
     
    4141                selectInput.onfocus = function(e) 
    4242                { 
    43                         showOntologyXrefInput(selectInput, xrefEntity, xrefField, xrefLabel, xrefFilters); 
     43                        showOntologyXrefInput(selectInput, xrefEntity, xrefField, xrefLabel, xrefFilters, xrefDescription); 
    4444                        return false; 
    4545                } 
  • disease_book/WebContent/generated-res/scripts/ontologyxrefinput.js

    r2425 r2459  
    1 function showOntologyXrefInput(input, xref_entity, xref_field, xref_label){ 
     1function showOntologyXrefInput(input, xref_entity, xref_field, xref_label) { 
    22        showXrefInput(input, xref_entity, xref_field, xref_label, null); 
    33} 
    44 
    5 function showOntologyXrefInput(input, xref_entity, xref_field, xref_label, xref_filters) { 
     5function showOntologyXrefInput(input, xref_entity, xref_field, xref_label, 
     6                xref_filters, xref_description) { 
    67        var id = input.id + "_" + input.form.name; 
    78 
    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); 
    1212                window.xrefInputDiv.style.display = "none"; 
    1313        } 
    1414 
    15         //create if not exists 
     15        // create if not exists 
    1616        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 { 
    2322                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") { 
    2826                        window.xrefInputDiv.style.display = "none"; 
    2927                        input.focus(); 
    3028                        input.blur(); 
    3129                } 
    32                 // else show  
    33                 else 
    34                 { 
     30                // else show 
     31                else { 
    3532                        window.xrefInputDiv.style.display = "block"; 
    3633                        input.focus(); 
    37                         input.blur();                    
     34                        input.blur(); 
    3835                        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 
     42function 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 
     49OntologyXrefInput.prototype = { 
     50        init : function(input, xref_entity, xref_field, xref_label, xref_filters, xref_description) { 
     51                // alert("init"); 
    5452        this.input = input; 
    55          
     53 
    5654        this.xref_entity = xref_entity; 
    5755        this.xref_field = xref_field; 
    5856        this.xref_label = xref_label; 
    5957        this.xref_filters = xref_filters; 
    60  
    61         //create the xref div 
     58        this.xref_description = xref_description; 
     59 
     60        // create the xref div 
    6261        this.xrefDiv = document.createElement("div"); 
    6362        this.xrefDiv.className = "xrefinput"; 
    6463        this.xrefDiv.style.display = "block"; 
    6564        this.xrefDiv.id = input.id + "_" + input.form.name; 
    66          
    67         //add the div as child of the input 
     65 
     66        // add the div as child of the input 
    6867        this.input.parentNode.insertBefore(this.xrefDiv, this.input.nextSibling); 
    69         this.xrefDiv.setAttribute("XrefInputObject", this); //??? 
    70  
    71         //add the search box 
     68        this.xrefDiv.setAttribute("XrefInputObject", this); // ??? 
     69 
     70        // add the search box 
    7271        this.searchLabel = document.createElement("label"); 
    7372        this.searchLabel.appendChild(document.createTextNode("search:")); 
     
    7675        this.xrefDiv.appendChild(this.searchInput); 
    7776        this.searchInput.focus(); 
    78          
     77 
    7978        this.xrefDiv.appendChild(document.createElement("br")); 
    8079 
    81         //initialize with current selection if any  
     80        // initialize with current selection if any 
    8281        this.xrefDiv.value = this.input.value; 
    83         if(this.input.options.length > 0) 
    84         { 
     82        if (this.input.options.length > 0) { 
    8583                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 
    9087        var _this = this; 
    91         this.addEvent(this.searchInput, "keyup", function(e) { 
     88        this.addEvent(this.searchInput, "mouseover", function(e) { 
    9289                _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 
    119114        this.selectInput.style.width = "100%"; 
    120115        this.xrefDiv.appendChild(this.selectInput); 
    121116 
    122         //add handler so the input is updated when clicking one select option 
    123         var _this = this;        
     117        // add handler so the input is updated when clicking one select option 
     118        var _this = this; 
    124119        this.addEvent(this.selectInput, "click", function(e) { 
    125120                _this.select(_this); 
    126         });      
    127          
     121        }); 
     122 
    128123        this.reload(); 
    129124        this.searchInput.focus(); 
    130125}, 
    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 */ 
     127select : 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 */ 
    143137reload : 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); 
    150147 
    151148        // branch for native XMLHttpRequest object 
     
    153150 
    154151        req = false; 
    155         if (window.XMLHttpRequest  && !(window.ActiveXObject)) //NOT IE 
     152        if (window.XMLHttpRequest && !(window.ActiveXObject)) // NOT IE 
    156153        { 
    157154                req = new XMLHttpRequest(); 
    158         } 
    159         else if (window.ActiveXObject) { 
     155        } else if (window.ActiveXObject) { 
    160156                req = new ActiveXObject("Microsoft.XMLHTTP"); 
    161157        } 
     
    163159        if (req) { 
    164160                req.onreadystatechange = function(e) { 
    165                         // only if req shows "complete"  
     161                        // only if req shows "complete" 
    166162                        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                        } 
    177173                }; 
    178174                req.open("GET", url, true); 
     
    180176        } 
    181177}, 
    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; 
     178getDescriptionForOntology : 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        //} 
    220218}, 
    221219redrawOptions : 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--) { 
    225222                this.selectInput.removeChild(this.selectInput.options[i]); 
    226223        } 
    227224 
    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 == "") { 
    231227                this.selectInput.appendChild(document.createElement("option")); 
    232         }        
    233          
    234         //add the current options 
     228        } 
     229 
     230        // add the current options 
    235231        for ( var i in options) { 
    236232                var option = document.createElement("option"); 
    237233 
    238                 //add the value 
     234                // add the value 
    239235                option.value = i; 
    240                 option.title = this.getDescriptionForOntology(i); 
    241  
    242                 //add option to select box 
     236                this.getDescriptionForOntology(i, option); 
     237 
     238                // add option to select box 
    243239                this.selectInput.appendChild(option); 
    244240 
    245                 option.text = options[i];        
    246         } 
    247          
    248         //resize select to fit 
     241                option.text = options[i]; 
     242        } 
     243 
     244        // resize select to fit 
    249245        this.selectInput.size = options.length <= 10 ? options.length : 10; 
    250246}, 
    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                         { 
     247handleAjax : 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 { 
    263256                        alert("There was a problem retrieving the XML data:\n" 
    264257                                        + 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 
    272266 */ 
    273267addEvent : function(obj, eventname, func) { 
    274         //alert(eventname); 
     268        // alert(eventname); 
    275269        if (navigator.userAgent.match(/MSIE/)) { 
    276270                obj.attachEvent("on" + eventname, func); 
  • disease_book/generated/java/syndromebooktest/ui/SyndromeHtmlForm.java

    r2425 r2459  
    7373                        input.setXrefField("id"); 
    7474                        input.setXrefLabel("term"); 
     75                        input.setXrefDescription("OntologyTerm"); 
    7576                        //initialize the OntologyTerm.term of current record 
    7677                        input.setValueLabels(entity.getOntologyLabels());  
     
    253254                //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=) 
    254255                { 
    255                         MrefInput input = new MrefInput("genesTested",entity.getGenesTested()); 
     256                        OntologyMrefInput input = new OntologyMrefInput("genesTested",entity.getGenesTested()); 
    256257                        input.setLabel("GenesTested"); 
    257258                        input.setDescription("GenesTested"); 
     
    261262                        input.setXrefField("id"); 
    262263                        input.setXrefLabel("geneName"); 
     264                        input.setXrefDescription("Gene"); 
    263265                        //initialize the Gene.GeneName of current record 
    264266                        input.setValueLabels(entity.getGenesTestedLabels());  
    265267                        inputs.add(input); 
    266                 } 
     268                }        
    267269                //FreeText: Field(entity=Syndrome, name=FreeText, type=text, auto=false, nillable=true, readonly=false, default=) 
    268270                { 
  • disease_book/handwritten/java/myservlet/MyServlet.java

    r2425 r2459  
    1313import org.molgenis.util.Tuple; 
    1414 
     15import syndromebooktest.Gene; 
    1516import syndromebooktest.OntologyTerm; 
    16  
    1717import app.servlet.MolgenisServlet; 
    1818 
    1919public class MyServlet extends MolgenisServlet { 
    2020 
    21 @Override 
    22 public void service(HttpServletRequest request, HttpServletResponse response) 
    23                 throws IOException, ServletException { 
    24         // TODO Auto-generated method stub 
     21        @Override 
     22        public void service(HttpServletRequest request, HttpServletResponse response) 
     23                        throws IOException, ServletException { 
     24                // TODO Auto-generated method stub 
    2525 
    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(); 
    4863                        } 
    49                          
    50                          
    51                 } catch (Exception e) { 
    52                         // TODO Auto-generated catch block 
    53                         e.printStackTrace(); 
     64 
     65                } else { 
     66                        super.service(request, response); 
    5467                } 
    55                  
    5668        } 
    57         else 
    58         { 
    59                 super.service(request, response); 
    60         } 
     69 
    6170} 
    62          
    63 } 
  • disease_book/syndromebooktest_db.xml

    r2425 r2459  
    2222         
    2323<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" 
    2525                        xref_label="loginname" /> 
    2626                <field name="Syndrome_id" type="autoid" /> 
Note: See TracChangeset for help on using the changeset viewer.