3 * Function used in locus_display.pl
4 * @author Naama Menda <nm249@cornell.edu>
8 JSAN.use('MochiKit.DOM');
9 JSAN.use('MochiKit.Visual');
10 JSAN.use('MochiKit.Async');
12 JSAN.use('CXGN.Effects');
13 JSAN.use('CXGN.Phenome.Tools');
17 //update the registry input box when an option is selected. Not sure if we should do this or not
18 updateRegistryInput: function() {
19 var select_box = MochiKit.DOM.getElement('registry_select');
20 for (i=0; i < select_box.length; i++){
21 if(select_box.options[i].selected) {
22 MochiKit.DOM.getElement('associate_registry_button').disabled = false;
27 //Make an ajax response that finds all the registries with names or symbols like the current value of the registry input
28 getRegistries: function(str) {
30 var select = MochiKit.DOM.getElement('registry_select');
32 MochiKit.DOM.getElement('associate_registry_button').disabled = true;
34 var d = new MochiKit.Async.doSimpleXMLHttpRequest("registry_browser.pl", {registry_name: str});
35 d.addCallbacks(this.updateRegistrySelect);
39 //Parse the ajax response and update the registry select box accordingly
40 updateRegistrySelect: function(request) {
41 var select = MochiKit.DOM.getElement('registry_select');
42 MochiKit.DOM.getElement('associate_registry_button').disabled = true;
43 var responseText = request.responseText;
44 var responseArray = responseText.split("|");
46 //the last element of the array is empty. Dont want this in the select box
48 select.length = responseArray.length;
49 for (i=0; i < responseArray.length; i++) {
50 var registryObject = responseArray[i].split("*");
51 select[i].value = registryObject[0];
52 if (typeof(registryObject[1]) != "undefined"){
53 select[i].text = registryObject[1];
58 //Make an ajax response that associates the selected registry with this locus
59 associateRegistry: function(locus_id, sp_person_id) {
60 var registry_id = MochiKit.DOM.getElement('registry_select').value;
61 var d = new MochiKit.Async.doSimpleXMLHttpRequest("associate_registry.pl", {registry_id: registry_id, locus_id: locus_id, sp_person_id: sp_person_id});
62 d.addCallbacks(Tools.reloadPage);
66 //Make an ajax response that adds a registry to the database and associates it with this locus
67 addRegistry: function(locus_id, sp_person_id) {
68 var registry_name = MochiKit.DOM.getElement('registry_name').value;
69 var registry_symbol = MochiKit.DOM.getElement('registry_symbol').value;
70 var registry_description = MochiKit.DOM.getElement('registry_description').value;
72 if(registry_symbol == ""){
73 MochiKit.DOM.getElement("add_registry_button").disabled=false;
74 alert("You must enter a symbol for the new registry");
76 }else if(registry_name == ""){
77 MochiKit.DOM.getElement("add_registry_button").disabled=false;
78 alert("You must enter a name for the new registry");
81 var d = new MochiKit.Async.doSimpleXMLHttpRequest("add_registry.pl", {registry_symbol: registry_symbol, registry_name: registry_name, registry_description: registry_description, sp_person_id: sp_person_id, locus_id: locus_id});
82 d.addCallbacks(this.registry_exists);
85 //create an alert if the ajax request for adding a registry finds that the registry already exists
86 registry_exists: function(request) {
87 if(request.responseText == "already exists"){
88 alert('That registry already exists');
90 this.associateRegistry();
94 addRegistryView: function() {
95 Effects.hideElement('registry_search');
96 Effects.showElement('registry_add');
99 searchRegistries: function() {
100 Effects.showElement('registry_search');
101 Effects.hideElement('registry_add');
104 //Logic on when to enable the add registry button
105 enableButton: function() {
106 var registry_name = MochiKit.DOM.getElement('registry_name').value;
107 var registry_symbol = MochiKit.DOM.getElement('registry_symbol').value;
108 if(registry_symbol != "" && registry_name != ""){
109 MochiKit.DOM.getElement("add_registry_button").disabled=false;
112 MochiKit.DOM.getElement("add_registry_button").disabled=true;
116 //Make an ajax request that finds all the alleles related to the currently selected individual
117 getAlleles: function(locus_id) {
118 MochiKit.DOM.getElement("associate_individual_button").disabled=false;
119 var individual_id = MochiKit.DOM.getElement('individual_select').value;
120 var d = new MochiKit.Async.doSimpleXMLHttpRequest("allele_browser.pl", {locus_id: locus_id, individual_id: individual_id});
121 d.addCallbacks(this.updateAlleleSelect);
124 //Parse the ajax response to update the allele select box
125 updateAlleleSelect: function(request) {
126 var select = MochiKit.DOM.getElement('allele_select');
127 var responseText = request.responseText;
128 var responseArray = responseText.split("|");
129 //the last element of the array is empty. Dont want this in the select box
132 select.length = responseArray.length;
133 for (i=0; i < responseArray.length; i++) {
134 var registryObject = responseArray[i].split("*");
135 select[i].value = registryObject[0];
136 if (typeof(registryObject[1]) != "undefined"){
137 select[i].text = registryObject[1];
140 select[i].text = registryObject[0];
141 select[i].value = null;
144 if(responseArray.length > 1){
145 Effects.showElement('alleleSelect');
148 Effects.hideElement('alleleSelect');
153 associateAllele: function(sp_person_id, allele_id) {
154 // locus page does not call this function with an allele_id
155 // allele page calls the function with the page object_id
156 if (!allele_id) { allele_id = $('allele_select').value; }
157 var individual_id = $('individual_select').value;
159 new Ajax.Request("associate_allele.pl", {
160 parameters: {allele_id: allele_id, individual_id: individual_id, sp_person_id: sp_person_id},
161 onSuccess: function(response) {
162 var json = response.responseText;
163 MochiKit.Logging.log("associateAllele response: " , json);
164 var x = eval ("("+json+")");
165 MochiKit.Logging.log("associateAllele response: " , json);
166 if (x.error) { alert(x.error); }
167 else { Tools.reloadPage(); }
173 //Make an ajax request to find all the individuals with a name like the current value of of the accession name input box
174 getIndividuals: function(str, locus_id) {
177 var select = MochiKit.DOM.getElement('individual_select');
179 MochiKit.DOM.getElement('associate_individual_button').disabled = true;
182 var d = new MochiKit.Async.doSimpleXMLHttpRequest("individual_browser.pl", {individual_name: str, locus_id: locus_id, type: type});
183 d.addCallbacks(this.updateIndividualsSelect);
187 //Make an ajax request to find all the individuals with a name like the current value of of the accession name input box
188 getAlleleIndividuals: function(str, allele_id) {
189 var type = 'browse_allele';
191 var select = $('individual_select');
193 $('associate_individual_button').disabled = true;
196 new Ajax.Request("individual_browser.pl", {parameters: {individual_name: str, allele_id: allele_id, type: type}, onSuccess: this.updateIndividualsSelect});
200 //Parse the ajax response to update the individuals select box
201 updateIndividualsSelect: function(request) {
202 var select = MochiKit.DOM.getElement('individual_select');
203 MochiKit.DOM.getElement('associate_individual_button').disabled = true;
205 var responseText = request.responseText;
206 var responseArray = responseText.split("|");
207 //last element of array is empty. dont want this in select box
210 select.length = responseArray.length;
211 for (i=0; i < responseArray.length; i++) {
212 var individualObject = responseArray[i].split("*");
213 select[i].value = individualObject[0];
214 if (typeof(individualObject[1]) != "undefined"){
215 select[i].text = individualObject[1];
218 select[i].text = individualObject[0];
219 select[i].value = null;
226 getEvidenceWith: function(locus_id) {
227 var type = 'evidence_with';
228 var evidence_with_id = $('evidence_with_select').value;
229 new Ajax.Request('evidence_browser.pl', {parameters:
230 {type: type, locus_id: locus_id}, onSuccess:this.updateEvidenceWithSelect});
233 updateEvidenceWithSelect: function(request) {
234 var select = $('evidence_with_select');
236 var responseText = request.responseText;
237 var responseArray = responseText.split("|");
238 //the last element of the array is empty. Dont want this in the select box
240 responseArray.unshift("*--Optional: select an evidence identifier--");
243 select.length = responseArray.length;
244 for (i=0; i < responseArray.length; i++) {
245 var evidenceWithObject = responseArray[i].split("*");
246 select[i].value = evidenceWithObject[0];
247 select[i].text = evidenceWithObject[1];
252 getReference: function(locus_id) {
254 var type = 'reference';
255 var reference_id = $('reference_select').value;
256 new Ajax.Request('evidence_browser.pl', { parameters:
257 {type: type, locus_id: locus_id}, onSuccess: this.updateReferenceSelect });
258 MochiKit.Logging.log("Locus.js getReference is calling UpdateReferenceSelect with locus_id", locus_id);
261 updateReferenceSelect: function(request) {
262 var select = $('reference_select');
264 var responseText = request.responseText;
265 var responseArray = responseText.split("|");
266 //the last element of the array is empty. Dont want this in the select box
268 responseArray.unshift("*--Optional: select supporting reference --");
271 select.length = responseArray.length;
272 for (i=0; i < responseArray.length; i++) {
273 var referenceObject = responseArray[i].split("*");
274 select[i].value = referenceObject[0];
275 select[i].text = referenceObject[1];
278 /////////////////////////
279 //MOVED TO LocusPage!!!!!!!!!!!!!!!!!!
280 ////////////////////////////////////////////
282 //Make an ajax response that associates the selected ontology term with this locus
283 associateOntology: function(locus_id, sp_person_id) {
284 if (this.isVisible('cvterm_list')) {
285 var dbxref_id = $('cvterm_list_select').value;
286 MochiKit.Logging.log("Locus.js: cvterm_list_select.dbxfref_id=...", dbxref_id);
288 var dbxref_id = $('ontology_select').value;
289 MochiKit.Logging.log("Locus.js: ontology_select.dbxfref_id=...", dbxref_id);
292 var relationship_id = $('relationship_select').value;
293 var evidence_code_id = $('evidence_code_select').value;
294 var evidence_description_id = $('evidence_description_select').value;
295 var evidence_with_id = $('evidence_with_select').value;
296 var reference_id = $('reference_select').value;
298 new Ajax.Request('associate_ontology_term.pl', { parameters:
299 {type: type, object_id: locus_id, dbxref_id: dbxref_id, sp_person_id: sp_person_id, relationship_id: relationship_id, evidence_code_id: evidence_code_id, evidence_description_id: evidence_description_id, evidence_with_id: evidence_with_id, reference_id: reference_id}, onSuccess: this.ontologyResponse });
303 ontologyResponse: function(response) {
304 var responseText = response.responseText;
305 if (responseText) { alert(responseText); }
307 MochiKit.Logging.log("about to reload page...", response );
308 window.location.reload();
316 toggleAssociateRegistry: function()
318 MochiKit.Visual.toggle('associateRegistryForm', 'blind');
322 //#####################################LOCUS RELATIONSHIPS
324 getLocusReference: function(locus_id) {
326 var type = 'reference';
327 var reference_id = $('locus_reference_select').value;
328 new Ajax.Request('evidence_browser.pl', { parameters:
329 {type: type, locus_id: locus_id}, onSuccess: this.updateLocusReferenceSelect });
330 MochiKit.Logging.log("Locus.js getLocusReference is calling UpdateReferenceSelect with locus_id", locus_id);
333 updateLocusReferenceSelect: function(request) {
334 var select = $('locus_reference_select');
336 var responseText = request.responseText;
337 var responseArray = responseText.split("|");
338 //the last element of the array is empty. Dont want this in the select box
340 responseArray.unshift("*--Optional: select supporting reference --");
343 select.length = responseArray.length;
344 for (i=0; i < responseArray.length; i++) {
345 var referenceObject = responseArray[i].split("*");
346 select[i].value = referenceObject[0];
347 select[i].text = referenceObject[1];
351 getLocusRelationship: function() {
352 //MochiKit.DOM.getElement("associate_locus_button").disabled=false;
353 var type = 'locus_relationship';
354 var locus_relationship_id = MochiKit.DOM.getElement('locus_relationship_select').value;
355 var d = new MochiKit.Async.doSimpleXMLHttpRequest("locus_browser.pl", {type: type} );
356 d.addCallbacks(this.updateLocusRelationshipSelect);
359 updateLocusRelationshipSelect: function(request) {
360 var select = MochiKit.DOM.getElement('locus_relationship_select');
362 var responseText = request.responseText;
363 var responseArray = responseText.split("|");
364 //the last element of the array is empty. Dont want this in the select box
367 select.length = responseArray.length;
368 for (i=0; i < responseArray.length; i++)
370 var locusRelationshipObject = responseArray[i].split("*");
372 select[i].value = locusRelationshipObject[0];
373 if (typeof(locusRelationshipObject[1]) != "undefined"){
374 select[i].text = locusRelationshipObject[1];
377 select[i].text = locusRelationshipObject[0];
378 select[i].value = null;
383 getLocusEvidenceCode: function() {
384 //MochiKit.DOM.getElement("associate_locus_button").disabled=false;
385 var type = 'locus_evidence_code';
386 var locus_evidence_code_id = MochiKit.DOM.getElement('locus_evidence_code_select').value;
387 var d = new MochiKit.Async.doSimpleXMLHttpRequest("locus_browser.pl", {type: type} );
388 d.addCallbacks(this.updateLocusEvidenceCodeSelect);
391 updateLocusEvidenceCodeSelect: function(request) {
392 var select = MochiKit.DOM.getElement('locus_evidence_code_select');
394 var responseText = request.responseText;
395 var responseArray = responseText.split("|");
396 //the last element of the array is empty. Dont want this in the select box
398 responseArray.unshift("*--please select an evidence code--");
400 select.length = responseArray.length;
402 for (i=0; i < responseArray.length; i++) {
403 var locusevidenceCodeObject = responseArray[i].split("*");
405 select[i].value = locusevidenceCodeObject[0];
406 select[i].text = locusevidenceCodeObject[1];
408 //document.evidence_code_select.options[i] = new Option(evidenceCodeObject[0], evidenceCodeObject[1]);
414 //#####################################
417 //Make an ajax response that finds all the unigenes with unigene ids like the current value of the unigene id input
418 getUnigenes: function(unigene_id, locus_id) {
419 if(unigene_id.length==0){
420 var select = MochiKit.DOM.getElement('unigene_select');
422 MochiKit.DOM.getElement('associate_unigene_button').disabled = true;
425 new Ajax.Request('unigene_browser.pl', { parameters:
426 {type: type, locus_id: locus_id, unigene_id: unigene_id},
427 onSuccess: this.updateUnigeneSelect });
431 //Parse the ajax response and update the unigene select box accordingly
432 updateUnigeneSelect: function(response) {
433 var select = MochiKit.DOM.getElement('unigene_select');
434 //MochiKit.DOM.getElement('associate_unigene_button').disabled = true;
435 var json = response.responseText;
436 var x = eval ("("+json+")");
437 //var responseText = request.responseText;
438 var responseArray = x.response.split("|");
440 //the last element of the array is empty. Dont want this in the select box
443 select.length = responseArray.length;
444 for (i=0; i < responseArray.length; i++) {
445 var unigeneObject = responseArray[i].split("*");
447 select[i].value = unigeneObject[0];
448 if (typeof(unigeneObject[1]) != "undefined"){
449 select[i].text = unigeneObject[1];
455 //Make an ajax response that obsoletes the selected individual-allele association
456 obsoleteIndividualAllele: function(individual_allele_id) {
457 var type= 'obsolete';
458 new Ajax.Request('individual_browser.pl', {parameters:
459 {type: type, individual_allele_id: individual_allele_id}, onSuccess: Tools.reloadPage });
461 //Make an ajax response that finds all loci with names/synonyms/symbols like the current value of the locus input
462 getMergeLocus: function(str, object_id) {
464 var select = MochiKit.DOM.getElement('locus_merge');
466 $('associate_locus_button').disabled = true;
468 var type = 'browse locus';
469 var organism = $('common_name').value;
470 new Ajax.Request("locus_browser.pl", {parameters:
471 {type: type, locus_name: str,object_id: object_id, organism: organism}, onSuccess: this.updateLocusSelect }); }
474 //Parse the ajax response and update the locus select box accordingly
475 updateLocusSelect: function(request) {
476 var select = $('locus_list');
477 $('merge_locus_button').disabled = true;
479 var responseText = request.responseText;
480 var responseArray = responseText.split("|");
482 //the last element of the array is empty. Dont want this in the select box
485 select.length = responseArray.length;
486 for (i=0; i < responseArray.length; i++) {
487 var locusObject = responseArray[i].split("*");
489 select[i].value = locusObject[0];
490 if (typeof(locusObject[1]) != "undefined"){
491 select[i].text = locusObject[1];
496 //Logic on when to enable the merge locus button
497 enableMergeButton: function() {
498 MochiKit.DOM.getElement("merge_locus_button").disabled=false;
501 //make an ajax response to merge locus x with the current locus
502 mergeLocus: function(locus_id) {
503 var merged_locus_id = MochiKit.DOM.getElement('locus_list').value;
504 new Ajax.Request('merge_locus.pl', {
505 parameters: { merged_locus_id: merged_locus_id, locus_id: locus_id},
506 onSuccess: function(response) {
507 var json = response.responseText;
508 var x = eval ("("+json+")");
509 MochiKit.Logging.log("mergeLocus response: " , json);
510 if (x.error) { alert(x.error); }
511 else { window.location.reload() ; }
517 toggleVisible:function(elem){
518 MochiKit.DOM.toggleElementClass("invisible", elem);
519 MochiKit.Logging.log("toggling visible element : " , elem);
522 makeVisible: function(elem) {
523 MochiKit.DOM.removeElementClass(elem, "invisible");
524 MochiKit.DOM.addElementClass(elem, "visible");
528 makeInvisible: function(elem) {
529 MochiKit.DOM.removeElementClass(elem, "visible");
530 MochiKit.DOM.addElementClass(elem, "invisible");
533 isVisible: function(elem) {
534 // you may also want to check for
535 // getElement(elem).style.display == "none"
536 MochiKit.Logging.log("testing isVisible", elem);
537 if (MochiKit.DOM.hasElementClass(elem, "invisible")) {
538 MochiKit.Logging.log("this element is invisible: ", elem);
539 }else if (MochiKit.DOM.hasElementClass(elem, "visible")) {
540 MochiKit.Logging.log("this element is visible: ", elem);
541 }else { MochiKit.Logging.log("this element does not have a visible/invisible element set: ", elem); }
543 return MochiKit.DOM.hasElementClass(elem, "visible") ;
548 searchCvterms: function() {
549 Effects.showElement('ontology_search');
550 Effects.hideElement('cvterm_list');
551 this.makeVisible('ontology_search');
552 this.makeInvisible('cvterm_list');
555 getCvtermsList: function(locus_id) {
556 Effects.showElement('cvterm_list');
557 Effects.hideElement('ontology_search');
558 this.makeInvisible('ontology_search');
559 this.makeVisible('cvterm_list');
561 new Ajax.Request("/phenome/locus_page/get_locus_cvterms.pl", {
562 parameters: {locus_id: locus_id },
563 onSuccess: function(response) {
564 var json = response.responseText;
565 var x = eval ("("+json+")");
566 MochiKit.Logging.log("getCvtermsList response: " , json);
567 if (x.error) { alert(x.error); }
569 var select = MochiKit.DOM.getElement('cvterm_list_select');
571 //first count the # of hash keys. Need to declare first the length of the select menu
572 for (key in x) keyCount++;
573 select.length = keyCount;
575 //now populate the select list from the hash. Need to iterate over the hash keys again...
577 for (dbxref_id in x) {
578 select[i].value = dbxref_id;
579 select[i].text = x[dbxref_id];
588 //make an ajax response to add a dbxref to the locus
589 addLocusDbxref: function(locus_id, dbxref_id) {
590 //var dbxref_id = $('dbxref_id').value;
592 var validate = $(dbxref_id).value;
594 new Ajax.Request('/phenome/add_dbxref.pl', {parameters:
595 { type: type, object_id: locus_id, dbxref_id: dbxref_id, validate: validate}, onSuccess:Tools.reloadPage} );