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>
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");
23 else { alert('invalid request') }
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");
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);
44 else if(newsize < oldsize) {
45 Hotlist._removeResponse(buttonId, content, newsize);
48 Hotlist._nullResponse(buttonId, content, action);
51 _addResponse: function(buttonId, content, newsize){
52 Effects.Hotlist.switchButton(buttonId, 'remove', content); //will restore onClick attribute
53 document.getElementById('hlsize').firstChild.nodeValue = newsize;
55 _removeResponse: function(buttonId, content, newsize){
56 Effects.Hotlist.switchButton(buttonId, 'add', content);
57 document.getElementById('hlsize').firstChild.nodeValue = newsize;
59 _nullResponse: function(buttonId, content, action) {
60 //probably just jumped the gun...do nothing