make mixed-xrefs "Related views" collapsible on feature page
[sgn.git] / js / CXGN / Hotlist.js
blob3be47a80aa90ecedd9189141dbc3a045a55cda69
1 /**
2 * @class Hotlist
3 * A singleton object for easy handling of a user's hotlist.
4 * Methods: add(buttonId, content), remove(buttonId, content)
5 * @author Chris Carpita <csc32@cornell.edu>
6 */
8 JSAN.use("CXGN.Request");
9 JSAN.use("CXGN.Effects.Hotlist");
11 //Hotlist is defined as a single object instead of a class. We can't have more than one!
12 var Hotlist = window.Hotlist || {};
13 Hotlist = { //buttonId: id of the clicked button, for changing the button
14         add: function(buttonId, content) {
15                 if(!buttonId) { alert("buttonId not sent!"); }
16                 var waitIndicator;// = new RequestWaitIndicator("hotlistWait:" + content);              
17                 var request = new Request();
18                 if(request.isValid()) {
19                         Effects.Hotlist.switchButton(buttonId, 'remove', content, 1);  //last argument clears onClick to prevent user interaction
20                         var parameters = "owner=" + user_id + "&button_id=" + buttonId + "&cookie_string=" + cookie_string + "&action=add&content=" + content;
21                         request.send("/scraps/hotlist.pl", parameters, "POST");
22                 }
23                 else { alert('invalid request') }
24         },
25         remove: function (buttonId, content) {
26                 if(!buttonId) { alert("buttonId not sent!"); }
27                 var waitIndicator;// = new RequestWaitIndicator("hotlistWait:" + content);              
28                 var request = new Request();
29                 if(request.isValid()) {
30                         Effects.Hotlist.switchButton(buttonId, 'add', content, 1);
31                         var parameters = "owner=" + user_id + "&button_id=" + buttonId + "&cookie_string=" + cookie_string + "&action=remove&content=" + content;
32                         request.send("/scraps/hotlist.pl", parameters, "POST");
33                 }
34         },
35         _response: function(doc) {
36                 var newsize = doc.getElementsByTagName("newsize")[0].firstChild.nodeValue;
37                 var oldsize = doc.getElementsByTagName("oldsize")[0].firstChild.nodeValue;
38                 var content = doc.getElementsByTagName("content")[0].firstChild.nodeValue;
39                 var action = doc.getElementsByTagName("action")[0].firstChild.nodeValue;
40                 var buttonId = doc.getElementsByTagName("buttonId")[0].firstChild.nodeValue;
41                 if(newsize > oldsize){
42                         Hotlist._addResponse(buttonId, content, newsize);
43                 }
44                 else if(newsize < oldsize) {
45                         Hotlist._removeResponse(buttonId, content, newsize);
46                 }
47                 else {
48                         Hotlist._nullResponse(buttonId, content, action);
49                 }
50         },
51         _addResponse: function(buttonId, content, newsize){
52                 Effects.Hotlist.switchButton(buttonId, 'remove', content); //will restore onClick attribute
53                 document.getElementById('hlsize').firstChild.nodeValue = newsize;
54         },
55         _removeResponse: function(buttonId, content, newsize){
56                 Effects.Hotlist.switchButton(buttonId, 'add', content);
57                 document.getElementById('hlsize').firstChild.nodeValue = newsize;
58         },
59         _nullResponse: function(buttonId, content, action) {
60                 //probably just jumped the gun...do nothing     
61         }