refresh matview stockprop happens in ajax controller
[sgn.git] / js / CXGN / Sunshine / NetworkBrowser.js
blob8ddfa3928181486ad86b110a883fcd09aeb29c3d
2 /** 
3 * @class Browser
4 * Functions used by System Browser
5 * @author Lukas Mueller <lam87@cornell.edu>
7 */
10 JSAN.use('MochiKit.DOM');
11 JSAN.use('MochiKit.Visual');
12 JSAN.use('MochiKit.Async');
15 if (!CXGN) CXGN = function() {};
16 if (!CXGN.Sunshine) CXGN.Sunshine = function() {};
18 CXGN.Sunshine.NetworkBrowser = function() { 
19     //alert('In constructor');
20     this.fetchRelationships();
21     this.setLevel(1);
22     //this.setHiddenRelationshipTypes('');
23     //alert('Done with constructor');
24     
29 CXGN.Sunshine.NetworkBrowser.prototype = { 
31     initialize: function() { 
32         this.render();
33         this.renderLegend();
34         this.renderLevels();
35     },
37     setExcludedNodes: function(nodeList) { 
38         this.excludedNodes = nodeList;
39     },
41     getExcludedNodes: function() { 
42         return this.excludedNodes;
43     },
45     //setHiddenRelationshipTypes: function(rTypeListString) { 
46     //  this.rTypeList = rTypeListString.split(' ');
47     //},
49     getHiddenRelationshipTypes: function() { 
50         //return this.rTypeList.join(' ');
51         var hidden = new Array();
52         for (var n=0; n<this.relationships.length; n++) {
53             
54             var checkbox_id = 'relationship_checkbox_'+this.relationships[n].id;
55             var checkbox = document.getElementById(checkbox_id);
56             //MochiKit.Logging.log('Checkbox ID: ' +checkbox_id + ' RELATIONSHIP: '+this.relationships[n].id);
57             if (checkbox != undefined && !checkbox.checked) { 
58             hidden.push(this.relationships[n].id);
59             }
60         }
61         return hidden.join(' ');
62     },
63     
64     //addHiddenRelationshipType: function(relationshipId) { 
65     //  MochiKit.Logging.log('Adding '+relationshipId+' to the list of hidden relationships');
66     //  this.rTypeList.push(relationshipId);
67     //},
69     //    removeHiddenRelationshipType: function(relationshipId) { 
71     //  MochiKit.Logging.log("relationshipId = "+ relationshipId);
72     //  var a = new Array();
73     //  var old = this.getHiddenRelationshipTypes().split(' ');
74     //  for (var i=0; i<old.length; i++) { 
75     //      if (old[i]!=relationshipId) { 
76     //          MochiKit.Logging.log('keeping '+ old[i]);
77     //          a.push(old[i]);
78     //      }
79     //      else { 
80     //          MochiKit.Logging.log('removing ' + old[i]);
81     //      }
82     //  }
83     //  var new_rs = a.join(' ');
84     //  MochiKit.Logging.log('New hidden relationships: '+new_rs);
85     //  /this.setHiddenRelationshipTypes(new_rs);
86     //  document.getElementById('relationship_checkbox_'+relationshipId).checked=false;
87     //},
89     //isRelationshipHidden: function(relationshipId) { 
90     //  if (this.rTypeList.indexOf(relationshipId) > -1) { 
91     //      MochiKit.Logging.log('The relationship '+relationshipId + ' is currently hidden');
92     //      return true;
93     //      
94     //  }
95     //  else {
96 //          MochiKit.Logging.log('The relationship '+relationshipId + ' is  currently shown');
97     //    return false;
98         //}
99     //}, 
101     toggleHideRelationshipType: function(relationshipId) { 
102         //      if (this.rTypeList.indexOf(relationshipId) != -1) { 
103         //    this.removeHiddenRelationshipType(relationshipId);
104         //}
105         //else { 
106         //   this.addHiddenRelationshipType(relationshipId);
107         //}
108         //      this.getImage(this.getName(), this.getType(), this.getLevel(), this.getHiddenRelationshipTypes());
109         this.render();
110     },
112     setLevel: function(level) { 
113         this.level = level;
114     },
115     
116     getLevel: function() { 
117         return this.level;
118     },
120     setType: function(type) { 
121         this.type = type;
122     },
124     getType: function() { 
125         return this.type;
126     },
128     setName: function(name) { 
129         //      alert('Setting name to '+name);
130         this.name = name;
131     },
133     getName: function() { 
134         return this.name;
135     },
137     render: function() { 
138         //alert('Hidden relationship types: ' + this.getHiddenRelationshipTypes());
139         this.getImage(this.getName(), this.getType(),this.getLevel(), this.getHiddenRelationshipTypes());
140         this.renderLevels();
141     },
143     setHilite: function(hiliteColor) { 
144         this.hiliteColor = hiliteColor;
145     },
147     getHilite: function() { 
148         return this.hiliteColor;
149     },
151     renderLegend: function() {  
152         var s = '';
153         //MochiKit.Logging.log('renderLegend...');
154         for (var n=0; n<this.relationships.length; n++) { 
155             var colors = this.relationships[n].color.split(',');
156             var colorString = '#'+ this.toHex(colors[0]) + this.toHex(colors[1]) +this.toHex(colors[2]);
157             var name = 'relationship_checkbox_'+this.relationships[n].id;
158             var checked = 1; // all the relationships are checked initially
159             //MochiKit.Logging.log('CHECKBOX '+name+' -- '+checked);
160             s += '<input type="checkbox" checked="'+checked+'" id="'+name+'" onClick="javascript:nb.toggleHideRelationshipType(' + this.relationships[n].id + ')" /> <font style="background-color:'+colorString+'">&nbsp;&nbsp;</font>&nbsp;'+this.relationships[n].name +'<br />\n';
161             //MochiKit.Logging.log('Color: '+ this.relationships[n].color + ' gives ' +colorString);
162             //MochiKit.Logging.log('renderLegend: '+ this.relationships[n].name);
163         }
164         document.getElementById('relationships_legend').innerHTML = "<br /><br /><b>Display relationship types:</b><br />" + s;
165     },
167         
169     //this shouldn't be here...
170     toHex: function(n) { 
171         var hex = (n * 1).toString(16); //force numerical context
172         if (hex.length ==1) { hex = '0'+hex; }
173         return hex;
174     },
176     renderLevels: function() { 
177         var s = '<b>Show levels:</b><br />\n';
178         s += '<input type="button" onClick="javascript:nb.levelMinusOne()" value="<" />';
179         s += '<b>&nbsp;' + this.getLevel() + '&nbsp;</b>';
180         s += '<input type="button" onClick="javascript:nb.levelPlusOne()" value=">" />';
181         document.getElementById('level_selector').innerHTML = s;
182     },
183     
184     levelMinusOne: function() { 
185         if (this.getLevel() >1) { 
186             this.setLevel(this.getLevel()-1);
187         }
188         this.render();      
189     },
191     levelPlusOne: function() { 
192         if (this.getLevel() < 10) { 
193             this.setLevel(this.getLevel()+1);
194         }
195         this.render();
196     },
198     getImage: function(name, type, level, relationships, hilite) {      
199         if (!name && !type) { alert("No name or type supplied. How am I supposed to do anything????"); }
200         //      var count = 0;
201         var x = MochiKit.DOM.getElement("network_browser");
202         this.setName(name);
203         this.setLevel(level);
204         this.setType(type);
205         this.setHilite(hilite);
206         //alert('Requesting image for '+name);
207         new Ajax.Request("/tools/networkbrowser/ajax_image_request.pl", {
208             parameters: { 
209                 name: name, 
210                           type: type, 
211                           level: level,
212                         hide: relationships,
213                         hilite: hilite}, 
214                           onSuccess: this.processImageResponse
215                                            });
216         
217     },
218     
219     
220     processImageResponse: function (request) { 
221         var responseText = request.responseText;
222         var e = MochiKit.DOM.getElement("network_browser").innerHTML=responseText;
223         var r = responseText;
224     },
226     fetchRelationships: function() { 
228         new Ajax.Request("/tools/networkbrowser/ajax_relationship_request.pl", {
229             parameters:   { }, 
230             asynchronous: false,
231             onException: function() { 
232                     //alert('An error occurred! The database may currently be unavailable. Please check back later.');
233             },
235             onSuccess: function(request) { 
236                 var responseText = request.responseText;
237                 //alert(responseText);
238                 nb.relationships = eval( responseText );
239                 //alert('Found ' + nb.relationships.length + ' relationship types!');
240                 
241             },
242         }
243                          );
244         
245         
246     },
247