aboutsummaryrefslogtreecommitdiff
path: root/web/javascript/dhtml.js
blob: 52676ac80e09f05f38190c0849c7a6f1f6dad380 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
/**
 * These are REALLY simple serialisation tools meant for simple Hash-like
objects in the for key=val
 */
var PrefUtils = {
  deserialize:function(inStr){
    return eval('('+inStr+')');
  },
  serialize:function(inObj){
    var buf = '{';
    var cma = '';
    var quote = "'";
    for (i in inObj){
      if (typeof i == 'string'){
        buf += cma + quote + i + quote + " : " 
          + quote +inObj[i]+ quote;
          cma = ',';
      }
    }
    buf += '}';
    return buf;
  },
  testCookie:function(){
    setCookie('cookieTest', 'cookieTest', 1);
    var cookieTest = getCookie('cookieTest');
    delCookie('cookieTest');
    if (cookieTest) return true;
    else return false;
  },
  form2Cookie:function(thisForm, cookieName){
    if (!this.testCookie()){
      alert("You need to enable Cookie in your browser!");
    }
    else{
      var pref = getCookie(cookieName);
      var options = this.deserialize(pref);
      if(!options){
  	  options = new Array();
      }/**/
      for( var x = 0; thisForm.elements[x]; x++ ) {
  	  if( thisForm.elements[x].type ) {
  	    var oE = thisForm.elements[x]; 
  	    var oT = oE.type.toLowerCase();
  	    if( oT == 'text' || oT == 'textarea' || oT == 'select-one' ) {
  	      options[oE.name] = oE.value;
  	    }
        }
      }
      setCookie(cookieName, this.serialize(options), 10);
      alert("Your preference has been saved.");
    }	
  }
};

function updateInner(Id, str){
  document.getElementById(Id).innerHTML = str;
}


function popWindow(myId){
	if (!document.getElementById || !myId) return false;
	else{
		var div = document.getElementById(myId);
		if (!div){
			div = document.createElement("div");
			div.id = myId;
			div.style.position = "absolute";
			div.style.top = "50%";
			div.style.left = "50%";
			div.style.width = "400px";
			div.style.height = "250px";
			div.style.margin = "-125px 0 0 -200px";
			div.style.border = "4px double #3366cc";
			div.style.padding = "0px";
			div.style.opacity = "0.99";
			div.style.backgroundColor = "#FFFFFF";
			div.style.fontSize = "60px";
			div.style.lineHeight = "60px";
			div.style.textAlign = "right";
			document.body.appendChild(div);
		}
		else{
			//alert("Layer already exists;")
		}
		xmlhttpPost('/webqtl/AJAX_pref.py', 'tab=assembly&divId='+myId, myId);
		div.style.visibility = 'visible';
	}
}

/*New added by NL*/
/*
Used by PartialCorrTraitPage.py, CorrelationPage.py, 
*/
function xmlhttpPost(strURL, div, querystring) {
	
    var xmlHttpReq = false;
    var self = this;
    var lay  = document.getElementById('warningLayer');
    if (lay != null) {lay.style.visibility = "visible";}
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
                responseText = self.xmlHttpReq.responseText;
            updatepage(div, responseText);
            if (lay != null) lay.style.visibility = "hidden";
        }
    }
    self.xmlHttpReq.send(querystring);
}

function updatepage(Id, str){
        document.getElementById(Id).innerHTML = str;
}
/*
Used by CorrelationPage.py,
elements: name,customizer, trait, filename, strainIds and vals are required by getquerystring function
*/
function getquerystring(thisform) {
    var db = thisform.customizer.value;
    var dbname = thisform.databaseFull.value;
    var form = thisform.name;
    var trait = thisform.identification.value;
    var file = thisform.filename.value;
    var ids = thisform.strainIds.value;
    var vals = thisform.vals.value;
    qstr = 'cmd=addCorr&db=' + escape(db) + '&dbname=' + escape(dbname) + '&form=' + escape(form) + '&trait=' + escape(trait) + '&file=' + escape(file)+ '&ids=' + escape(ids) + '&vals=' + escape(vals);  
        // NOTE: no '?' before querystring
    return qstr;
}

/*
* Used by snpBrowserPage.py and AJAX_snpbrowser.py, 
*/
function xmlhttpPostSNP(strURL) {
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
        	responseTextArray = self.xmlHttpReq.responseText.split("__split__");
            updatepage('menu_group', responseTextArray[0]);
            updatepage('menu_s1', responseTextArray[1]);
            updatepage('menu_s2', responseTextArray[2]);
            updatepage('menu_s3', responseTextArray[3]);
        }
    }    
    self.xmlHttpReq.send(getquerystringSNP());  
}
/*
* used by snpBrowserPage.py, html elements:newSNPPadding, group, s1 and s2 are required
*/
function getquerystringSNP() {
    var form = document.newSNPPadding;
    var group = form.group.value;
    var s1 = form.s1.value;
    var s2 = form.s2.value;
    qstr = 'group=' + escape(group) + '&s1=' + escape(s1) + '&s2=' + escape(s2);  
    	// NOTE: no '?' before querystring
    return qstr;
}


/*
Used by CorrelationPage.py, element's Id named 'warningLayer' is required
*/
function pageOffset() {
    lay  = document.getElementById('warningLayer');
    lay.style.top = document.body.scrollTop + 300; //document.body.clientWidth/2;
    lay.style.left = (windowWidth() -250)/2;
    setTimeout('pageOffset()',100);
}

/*
* Used by CorrelationPage.py, 
*/
function windowWidth(){
   if (document.getElementById){

       if (window.innerWidth)
         return window.innerWidth;
       if (document.documentElement&&document.documentElement.clientWidth)
         return document.documentElement.clientWidth;
       if (document.body.clientWidth)
         return document.body.clientWidth;
   }
}

/*
* Used by PartialCorrInputPage.py, 
*/
function setAllAsTarget(thisForm, inputRadioNames){
    var radioArray = new Array();
    radioArray = inputRadioNames.split(',');

        for (var i = 0; i < radioArray.length; i++){
	    radioElement = thisForm[radioArray[i]];
		
        for (var j = 0; j < radioElement.length; j++){
            radioElement[j].checked = false;
            value = radioElement[j].value;
            if (value == "target"){
                    radioElement[j].checked = true;
                }
        }
	}
}

/*
* Used by PartialCorrInputPage.py, 
*/
function setAllAsIgnore(thisForm, inputRadioNames){
    var radioArray = new Array();
    radioArray = inputRadioNames.split(',');

        for (var i = 0; i < radioArray.length; i++){
	    radioElement = thisForm[radioArray[i]];
		
	    for (var j = 0; j < radioElement.length; j++){
		    radioElement[j].checked = false;
		    value = radioElement[j].value;
	        if (value == "ignored"){
                    radioElement[j].checked = true;
                }
	    }
	}
}

/*
* moved from beta2.js 
*/
function checkUncheck(value, permCheck, bootCheck) {
		 if(value=="physic") {
			  permCheck.checked=true
			  bootCheck.checked=false
	 } else {
		  permCheck.checked=true
			  bootCheck.checked=true
		 }
}

/*
updated by NL: 06-07-2010
add new item at the top
*/
function addToList(text, value, list) {
	for (var j = list.length-1; j >=0; j--){
		list.options[j+1]= new Option(list.options[j].text,list.options[j].value);
	}
	list.options[0] = new Option(text, value)
}

function removeFromList(index, list) {
	list.options[index] = null
	list.options[index].selected = true
	if (list.length == 1) {
		list.options[0].selected = true
	}
}

function swapOptions(index1, index2, list) {
	 text1 = list.options[index1].text
	 value1 = list.options[index1].value
	 text2 = list.options[index2].text
	 value2 = list.options[index2].value
	 list.options[index1] = new Option(text2, value2)
	 list.options[index2] = new Option(text1, value1)
	 list.options[index2].selected = true
}

function selectAllElements(list) {
	 for(i=0; i<list.length; i++) {
		  list.options[i].selected = true
	 }
}

function deleteAllElements(list) {
	 list.length=0
}

function formInNewWindow(thisform) {
	 var d = new Date()
	 winName = "Intvl"+d.getDate()+""+d.getMonth()+""+d.getHours()+""+d.getMinutes()+""+d.getSeconds();
	 win = window.open("", winName, "toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes");
	 thisform.target = winName;
	 thisform.submit();
}

/*
* moved from whats_new.html 
*/
function colapse(id)
{
    if( document.getElementById(id).style.display =='none')
    {
        document.getElementById(id).style.display ='';
    }
    else if( document.getElementById(id).style.display =='')
    {
        document.getElementById(id).style.display ='none';
    }
}