easier direct editing of list items
[sgn.git] / js / CXGN / secretary.js
blob35af49f6e50a451662bc5e4be76822f6c93c1573
1 /** NOTICE ** This is a DEPRECATED module, hence the lower-case file-name.  I will eventually move everything here-in to separate modules.  This will allow for a graceful transition to well-factored code **/
4 /**
5 ************** Misc Secretary Functions ***********************************HEADER************************
6 **/
8 function getSel() {
9         var txt = '';
10         var foundIn = '';
11         document.getElementById('selectedblastp').innerHTML = "";
12         document.getElementById('selectedblastnfull').innerHTML = "";
13         document.getElementById('selectedblastncds').innerHTML = "";
14         
15         if (window.getSelection)
16         {
17                 txt = window.getSelection();
18                 foundIn = 'window.getSelection()';
19         }
20         else if (document.getSelection)
21         {
22                 txt = document.getSelection();
23                 foundIn = 'document.getSelection()';
24         }
25         else if (document.selection)
26         {
27                 txt = document.selection.createRange().text;
28                 foundIn = 'document.selection.createRange()';
29         }
30         else return false;
31         //fixtxt = txt.replace(/<br>/ig, "");
32         var fixtxt = new String(txt);
34         fixtxt = fixtxt.replace(/\W/ig, "");
35         if (fixtxt.match(/^[A-Z]+$/)) {
36                 return fixtxt;
37         }
38         else return false;
41 function selectedblastp(selection){
42       HTML = "<a class='external' href='http://www.ncbi.nlm.nih.gov/blast/Blast.cgi?CMD=Put&QUERY=" + selection + "&DATABASE=nr&PROGRAM=blastp&FILTER=L&HITLIST_SZE=500'>Perform BLASTP on Selection (" + selection.length + " aa)</a>";
43       document.getElementById('selectedblastp').innerHTML = HTML;
47 function selectedblastnfull(selection){
48       HTML = "<a class='external' href='http://www.ncbi.nlm.nih.gov/blast/Blast.cgi?CMD=Put&QUERY=" + selection + "&DATABASE=nr&PROGRAM=blastn&FILTER=L&HITLIST_SZE=500'>Perform BLASTN on Selection (" + selection.length + " bp)</a>";
49       document.getElementById('selectedblastnfull').innerHTML = HTML;
52 function selectedblastncds(selection){
53       HTML = "<a class='external' href='http://www.ncbi.nlm.nih.gov/blast/Blast.cgi?CMD=Put&QUERY=" + selection + "&DATABASE=nr&PROGRAM=blastn&FILTER=L&HITLIST_SZE=500'>Perform BLASTN on Selection (" + selection.length + " bp)</a>";
54       document.getElementById('selectedblastncds').innerHTML = HTML;
58 function closebox(boxID) {
59         document.getElementById(boxID).style.display="none";
60         return false;
63 /** Only works on <span> tags for a given class name, currently alters the following properties:
64 ***** color, backgroundColor, border, fontWeight  **/
65 function classAlter(className, styleProperty, styleValue) {
66         for (i=0;i<document.getElementsByTagName("span").length; i++) {
67                 if (document.getElementsByTagName("span").item(i).className == className){
68                         document.getElementsByTagName("span").item(i).style[styleProperty] = styleValue;
69                 }
70                 if(1 == 0){  //change back if thing above doesn't work
71                         if(styleProperty == "color"){
72                                 document.getElementsByTagName("span").item(i).style.color = styleValue;
73                         }
74                         else if(styleProperty == "backgroundColor"){
75                                 document.getElementsByTagName("span").item(i).style.backgroundColor = styleValue;
76                         }
77                         else if(styleProperty == "border"){
78                                 document.getElementsByTagName("span").item(i).style.border = styleValue;
79                         }
80                         else if(styleProperty == "fontWeight"){
81                                 document.getElementsByTagName("span").item(i).style.fontWeight = styleValue;
82                         }
83                 }       
84         }
87 /* Must match value in class highlightColor of the css file
89 var searchHighlightColor = "#c9c9ff";
90 var searchHighlight = 0;
92 //Ensures that cookie object is instantiated, as well as Highlight Toggle-dependent functions
93 function prepareSearchHighlight(){
94         if(Cookie){
95                 if(UserPrefs.get('searchHighlight')){
96                         searchHighlight = UserPrefs.get('searchHighlight');
97                 }
98         }
99         //Ok, this may look weird.  What we are doing is priming browser cache by calling the toggle function, which calls the classAlter function
100         // and iterates through all of the <span> tags.  Therefore, the switches occur more quickly when the user first clicks the button.
101         if (searchHighlight == 1){ 
102                 searchHighlight = 0; 
103                 toggleSearchHighlight();  //this will set searchHighlight back to 1, don't worry ;) 
104         }
105         else{
106                 searchHighlight = 1;
107                 toggleSearchHighlight();
108         }
111 function toggleSearchHighlight(nocookieset){
112         if(searchHighlight){
113                 classAlter("searchHighlight", "backgroundColor", "white");
114                 document.getElementById("highlightSelector").style.display = "inline";
115                 document.getElementById("unhighlightSelector").style.display = "none";
116                 searchHighlight = 0;
117                 UserPrefs.set('searchHighlight', 0);
118                 if(!nocookieset) UserPrefs.setCookie();
119         }
120         else {
121                 classAlter("searchHighlight", "backgroundColor", searchHighlightColor);
122                 document.getElementById("highlightSelector").style.display = "none";
123                 document.getElementById("unhighlightSelector").style.display = "inline";
124                 searchHighlight = 1;
125                 UserPrefs.set('searchHighlight', 1);
126                 if(!nocookieset) UserPrefs.setCookie();
127         }
131 ************** Secretary Database Query Functions *********************HEADER*****************************
135 var selectTextColorBg = "#771111"; //background color of active text
136 var selectTextColor = "#332277";  //color of unselected checkbox text
138 var joiners = new Array();
140 for(var i=0; i<10; i++) joiners.push("AND");
142 function selectModify(num, type){
144         if(type=='rem'){
145                 document.getElementById("condcontainer" + num).style.display = "none";
146                 document.getElementById("selrem" + num).style.display = "none";
147                 if(num<10) document.getElementById("seladd" + num).style.display = "none";
148                 document.getElementById("seladd" + (num-1)).style.display = "inline";
149                 if (num > 1) document.getElementById("selrem" + (num-1)).style.display = "inline";
150                 document.getElementById("condvar"+num).value="";
151                 document.getElementById("condop"+num).value="=";
152                 document.getElementById("condoperand"+num).value="";
153         }
154         if(type=='add'){
155                 if(num<10) document.getElementById("condcontainer" + (num+1)).style.display="inline";
156                 if(num<10) document.getElementById("selrem" + (num+1)).style.display="inline";
157                 if(num<9) document.getElementById("seladd" + (num+1)).style.display="inline";
158                 document.getElementById("seladd" + num).style.display="none";
159                 if(num>0) document.getElementById("selrem" + num).style.display="none"
160         }
163 function selectSwitch(value, item){
164         box = document.getElementById("cb." + value);
165         text = document.getElementById("text." + value);
166         
167         if(item){
168                 box = document.getElementById("cb." + value + "." + item);
169                 text = document.getElementById("text." + value + "." + item);
170         }
171         if(box.checked) {
172                 box.checked = false;
173                 text.style.backgroundColor = "white";
174                 text.style.color = selectTextColor;
175                 text.style.fontWeight = "normal";
176         }
177         else {
178                 box.checked = true;
179                 text.style.backgroundColor = selectTextColorBg; 
180                 text.style.color = "white";
181                 text.style.fontWeight = "bold";
183                 if(value != "COUNT"){
184                                 document.getElementById("cb.COUNT").checked = false;
185                                 text = document.getElementById("text.COUNT");
186                                 text.style.color = "#332277"
187                                 text.style.backgroundColor = "white";
188                                 text.style.fontWeight = "normal";
189                 }
190         }
195 function cbColorSwitch(value, item){
196         
197         box = document.getElementById("cb." + value);
198         text = document.getElementById("text." + value);
199         
200         if(item){
201                 box = document.getElementById("cb." + value + "." + item);
202                 text = document.getElementById("text." + value + "." + item);
203         }
206         if(!box.checked) {
207                 text.style.backgroundColor = "white";
208                 text.style.color = selectTextColor;
209                 text.style.fontWeight = "normal";
210         }
211         else {
212                 text.style.backgroundColor = selectTextColorBg;
213                 text.style.color = "white";
214                 text.style.fontWeight = "bold";
215         }
219 function switchJoin(id){
220         joinercontent = document.getElementById("joinercontent"+id);
221         formjoiner = document.getElementById("formjoiner" + id);
222         if (joinercontent.innerHTML=="AND"){
223                 joinercontent.innerHTML="OR";
224                 joiners[id-1] = "OR";
225                 formjoiner.value = "OR";
226         }
227         else{
228                 joinercontent.innerHTML="AND";
229                 joiners[id-1] = "AND";
230                 formjoiner.value = "AND";
231         }
234 function switchParen(id){
235         formparen = document.getElementById("formparen"+id);
236         parencontent = document.getElementById("parencontent"+id);
237         jointop = document.getElementById("jointop"+id);
238         joinbottom = document.getElementById("joinbottom"+id);
240         if(formparen.value=='0'){
241                 formparen.value=1;
242                 parencontent.innerHTML = "<span style='color:#442277'>(Unjoin)</span>";
243                 jointop.innerHTML="";
244                 joinbottom.innerHTML="";
245         }
246         else{
247                 formparen.value=0;
248                 parencontent.innerHTML = "(Join)";
249                 jointop.innerHTML="<br>";
250                 joinbottom.innerHTML="<br>";
251         }
255 function variableChange(id){
256         variable = document.getElementById("condvar" + id);
257         operator = document.getElementById("condop" + id);
258         type = variable.value.charAt(0);
259         if(type=="f" || type=="i") operator.value = ">";
260         else if(type=="r") operator.value = "REGEXP";
261         else if(type=="t") operator.value = "FULLTEXT";
264 function chartTypeChange(){
265         ctype = document.getElementById("charttype");
266         pie_opt = document.getElementById("pie_options");
267         bar_opt = document.getElementById("bar_options");
268         if(ctype.value==''){
269                 pie_opt.style.display = "none";
270                 bar_opt.style.display = "none";
271         }
272         else if(ctype.value=="pie"){
273                 pie_opt.style.display = "block";
274                 bar_opt.style.display = "none";
275         }
276         else{
277                 pie_opt.style.display = "none";
278                 bar_opt.style.display = "block";
279         }
282 var num=0;
283 var live=1;
284 var last=3;
286 function killAnimateDots(){
287         live = 0;
290 function animateDots(){
291         num = num+1;
292         if(num>3) num = 0;
293         last = num - 1;
294         if(last<0) last = 3;
295         
296         document.getElementById("dots"+last).style.display="none";
297         document.getElementById("dots"+num).style.display="inline";
298         
299         if(live) setTimeout("animateDots()", 500); 
303 function closeBox(name){
304         document.getElementById(name+"_hide").style.display="none";     
305         document.getElementById(name+"_show").style.display="inline";
306         document.getElementById(name+"_table").style.display="none";
307         document.getElementById(name+"_box").style.borderColor="#555555";
308         document.getElementById(name+"_header").style.backgroundColor="#555555";
311 function openBox(name){
312         document.getElementById(name+"_hide").style.display="inline";   
313         document.getElementById(name+"_show").style.display="none";
314         document.getElementById(name+"_table").style.display="inline";
316         var activeColor = "";
317         if(name=="chart") activeColor = "#444499";
318         else if(name=="select") activeColor = "#770000";
319         else if(name=="cond") activeColor = "#551155";
321         document.getElementById(name+"_box").style.borderColor = activeColor;
322         document.getElementById(name+"_header").style.backgroundColor = activeColor;
327 *************** Hotlist Functions ***************************HEADER****************************************
330 function RequestWaitIndicator(waitElementId) {
331                 
332         RequestWaitIndicator.numWaits += 1;
333         this.id = "RWI:" + RequestWaitIndicator.numWaits;
334         RequestWaitIndicator.waitHash[this.id] = 1;     
335         this.waitElementId = waitElementId;     
336         setTimeout("RequestWaitIndicator.displayElement('" + this.id + "', '" + this.waitElementId + "')", 1000);
337         
338         this.stopWait = function () {
339                 RequestWaitIndicator.waitHash[this.id] = 0;
340                 Effects.hideElement(waitElementId);
341         }
343 RequestWaitIndicator.numWaits = 0;
344 RequestWaitIndicator.waitHash = {};
345 RequestWaitIndicator.displayElement = function (waitId, elementId) {
346         if (RequestWaitIndicator.waitHash[waitId]){
347                 Effects.showElement(elementId);
348         }
353 ********* User account related functions ****************HEADER************************************************
358 var http_request = false;
360 function makeRequest(url, parameters, type) {
362       http_request = false;
364       if (window.XMLHttpRequest) { // Mozilla, Safari,...
365          http_request = new XMLHttpRequest();
366          if (http_request.overrideMimeType) {
367             http_request.overrideMimeType('text/xml');
368          }
369       } else if (window.ActiveXObject) { // IE
370          try {
371             http_request = new ActiveXObject("Msxml2.XMLHTTP");
372          } catch (e) {
373             try {
374                http_request = new ActiveXObject("Microsoft.XMLHTTP");
375             } catch (e) {}
376          }
377       }
378         if (!http_request) {
379              //print("<!--Async XML Request Failed-->");
380          return false;
381       }
382       if (type=='username') http_request.onreadystatechange = alertContentsName;
383       http_request.open('GET', url + parameters, true);
384       http_request.send(null);
385           return true;
388 function alertContentsName() {
389       if (http_request.readyState == 4) {
390          if (http_request.status == 200) {
391             check_name_response(http_request.responseText);
392                 return true;
393          }
394           else return true;
395       }
396       else return false;
397    }
400 function check_password(password){
401         if(password==""){
402                 document.getElementById('quickwarning').innerHTML = "&nbsp;";
403                 document.getElementById('choosepw').style.color= "black"; 
404     }
405         else if(password.length < 7){
406                 document.getElementById('quickwarning').innerHTML = "Password must be at least 7 characters long";
407                 document.getElementById('choosepw').style.color= "#dd4444"; 
408         }
409         else {
410                 document.getElementById('quickwarning').innerHTML = "&nbsp;";
411                 document.getElementById('choosepw').style.color = "black";
412         }
415 function check_password_match(passwordrep){
416         password = document.cf.password.value;
417         if(passwordrep=="" || password.length==0){
418                 document.getElementById('quickwarning').innerHTML = "&nbsp;"
419                 document.getElementById('confirmpw').style.color = "black";
420         }
421         else if(passwordrep != password){
422                 document.getElementById('quickwarning').innerHTML = "Repeated password doesn't match";
423                 document.getElementById('confirmpw').style.color = "#dd4444";
424         }
425         else{
426                 document.getElementById('quickwarning').innerHTML = "&nbsp;";
427                 document.getElementById('confirmpw').style.color = "black";
428         }
433 function check_name(username){
434   if(username==""){
435         document.getElementById('quickwarning').innerHTML = "&nbsp;";         
436         document.getElementById('chooseuname').style.color = "black";
437         document.getElementById('uname_available').style.display = "none";
438         document.getElementById('uname_taken').style.display = "none";
439   }
440   else if(username.length < 7){
441         document.getElementById('quickwarning').firstChild.nodeValue = "Username must be at least 7 characters long";
442         document.getElementById('chooseuname').style.color = "#dd4444";
443         document.getElementById('uname_available').style.display = "none";
444         document.getElementById('uname_taken').style.display = "none";
445   }
446   else  {
447         document.getElementById('quickwarning').innerHTML = "&nbsp;";
448         document.getElementById('chooseuname').style.color = "black";
449         makeRequest('scraps/check_name_avail.pl', '?username=' + username, 'username');
450   }
453 function check_email(email){
455   var ereg = /^[^@]+@[^@]+$/; 
456   if(email==""){
457         document.getElementById('quickwarning').innerHTML = "&nbsp;";         
458         document.getElementById('chooseemail').style.color = "black";
459   }
460   else if(!email.match(ereg)){
461         document.getElementById('quickwarning').innerHTML = "E-mail not of the form: name@address";
462         document.getElementById('chooseemail').style.color = "#dd4444";
463   
464   }
465   else  {
466         document.getElementById('quickwarning').innerHTML = "&nbsp;";
467         document.getElementById('chooseemail').style.color = "black";
468   }
471 function check_name_response(response){
472         if (response=='1') {
473                 document.getElementById('uname_available').style.display = "inline";
474                 document.getElementById('uname_taken').style.display = "none";
475         }
476         else if(response=='0') {
477                 document.getElementById('uname_available').style.display = "none";
478                 document.getElementById('uname_taken').style.display = "inline";
479         }
480         else {
481                 document.getElementById('uname_available').style.display = "none";
482                 document.getElementById('uname_taken').style.display = "none";
483         }
487 function hide_warning(){
488         document.getElementById('login_warning').style.display="none";
491 function new_user(){
492         document.getElementById('login_box').style.display="none";
493         document.getElementById('createaccount_box').style.display="block";
494         document.getElementById('newuname').focus();
495         return false;
498 function hide_create(){
499         document.getElementById("createaccount_box").style.display="none";
500         document.getElementById("userbar_container").style.display="block"; 
501         document.getElementById("login_warning").style.display="none";
502         return false;
505 function hide_login(){
506         document.getElementById("login_box").style.display="none"; 
507         document.getElementById("userbar_container").style.display="block"; 
508         document.getElementById("login_warning").style.display="none";
509         return false;
512 function show_login(){
513         document.getElementById("login_box").style.display="block"; 
514         document.getElementById("userbar_container").style.display="none"; 
515         document.getElementById("uname").focus(); 
516         document.getElementById("login_warning").style.display="none";
517         return false;
522 /** 
523 **** List Functions ****************************HEADER**********************************************************
525 var http_request_mylistpage = false;
526 var workinglist = "";
528 var lastAction = "";
529 var lastList = "";
530 var lastNewList = "";
533 function makeRequestMylist(url, parameters, type, list) {
535           workinglist = list;
536       http_request_mylistpage = false;
538       if (window.XMLHttpRequest) { // Mozilla, Safari,...
539          http_request_mylistpage = new XMLHttpRequest();
540          if (http_request_mylistpage.overrideMimeType) {
541             http_request_mylistpage.overrideMimeType('text/xml');
542          }
543       } else if (window.ActiveXObject) { // IE
544          try {
545             http_request_mylistpage = new ActiveXObject("Msxml2.XMLHTTP");
546          } catch (e) {
547             try {
548                http_request_mylistpage = new ActiveXObject("Microsoft.XMLHTTP");
549             } catch (e) {}
550          }
551       }
552       if (!http_request_mylistpage) {
553                  return false;
554       }
555       if (type=='alterlist') http_request_mylistpage.onreadystatechange = alertContentsList;
556       if (type=='FASTA') http_request_mylistpage.onreadystatechange = alertContentsFASTA;
557       http_request_mylistpage.open('GET', url + parameters, true);
558       http_request_mylistpage.send(null);
559           return true;
563 function alertContentsList() {
564       if (http_request_mylistpage.readyState == 4) {
565          if (http_request_mylistpage.status == 200) {
566             mylist_response(http_request_mylistpage.responseText);
567             return true;
568          }
569          else return true;
570       }
571       else return false;
572    }
574 function alertContentsFASTA(list){
575       if (http_request_mylistpage.readyState == 4) {
576          if (http_request_mylistpage.status == 200) {
577             fasta_response(http_request_mylistpage.responseText);
578             return true;
579          }
580          else return true;
581       }
582       else return false;
583    }
586 function createFASTA(type, list) {
587         document.getElementById(list+'_fetch').style.display='inline';
588         document.getElementById(list+'_cleartool').style.display="none";
589         document.getElementById(list+'_createfastalinks').style.display="none";
590         if(type!="full" && type!="cds" && type!="prot" && type!="cdna") type="full";
592         var RequestURL = "fastacreate.php?user=<?php echo $username?>&type=" + type + "&list="+list; 
593         makeRequestMylist(RequestURL, "", "FASTA", list);               
597 function fasta_response(output) {
598         var list = workinglist;
599         document.getElementById(list+"_FASTAbox").value = output;               
600         document.getElementById(list+"_FASTAholder").style.display="block";
601         document.getElementById(list+"_fetch").style.display='none';
602         document.getElementById(list+"_cleartool").style.display="inline";
603         document.getElementById(list+"_createfastalinks").style.display = "inline";
606 function undoLast(){
607         var action;
608         if(lastAction=="add") action = "remove";
609         else if(lastAction=="remove") action = "add";
611         alterList()
616 function alterList(newlist, action, list){      
617         
618         lastAction = action;
619         lastList = list;
620         lastNewList = newlist;
622         var RequestURL = "alterlist.php?user=<?php echo $username?>&md5pass=<?php echo $password?>";
623         RequestURL += "&list="+list+"&newlist=" + newlist + "&action=" + action;
624         makeRequestMylist(RequestURL, "", "alterlist", list);   
627 var clear_reload = 0;
628 function clearList(list){
629         
630         RequestURL = "alterlist.php?user=<?php echo $username?>&md5pass=<?php echo $password?>";
631         RequestURL += "&list="+list+"&clear=1";
632         makeRequestMylist(RequestURL, "", "alterlist", list);
633         clear_reload = 1;
636 function alterLink(id, action, list){
637         
638         if(action=="add") HTML = "<a href='#' onclick='alterList(\"" + id + "\", \"add\", \""+list+"\"); alterLink(\"" + id + "\", \"remove\", \""+list+"\"); return false;' style='text-decoration:none'>[ <img src='/img/hotlist_add.png' border=0 align='absmiddle'> Re-Add ]</a>";
639         else if (action=="remove") HTML = "<a href='#' onclick='alterList(\"" + id + "\", \"remove\", \""+list+"\"); alterLink(\"" + id + "\", \"add\", \""+list+"\"); return false;' style='text-decoration:none'>[ <img src='/img/hotlist_remove.png' border=0 align='absmiddle'> Remove ]</a>";
640         document.getElementById(list + "_" + id).innerHTML = HTML;
644 function mylist_response(output){
646         var list = workinglist;
647         output = output.toString();
648         
649         if (output.charAt(0) == 'q'){
651         output = output.substring(1);
652         listsize = output * 1;
653         if(list=="hotlist") document.getElementById('hlsize').firstChild.nodeValue = listsize;
654     document.getElementById(list+"_headercount").innerHTML = listsize + " Genes";       
655         if(listsize==0 && clear_reload==1) window.location.reload();
656         clear_reload = 0;
657         }
658         
659