4 * Functions used by System Browser
5 * @author Lukas Mueller <lam87@cornell.edu>
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();
22 //this.setHiddenRelationshipTypes('');
23 //alert('Done with constructor');
29 CXGN.Sunshine.NetworkBrowser.prototype = {
31 initialize: function() {
37 setExcludedNodes: function(nodeList) {
38 this.excludedNodes = nodeList;
41 getExcludedNodes: function() {
42 return this.excludedNodes;
45 //setHiddenRelationshipTypes: function(rTypeListString) {
46 // this.rTypeList = rTypeListString.split(' ');
49 getHiddenRelationshipTypes: function() {
50 //return this.rTypeList.join(' ');
51 var hidden = new Array();
52 for (var n=0; n<this.relationships.length; n++) {
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);
61 return hidden.join(' ');
64 //addHiddenRelationshipType: function(relationshipId) {
65 // MochiKit.Logging.log('Adding '+relationshipId+' to the list of hidden relationships');
66 // this.rTypeList.push(relationshipId);
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]);
80 // MochiKit.Logging.log('removing ' + old[i]);
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;
89 //isRelationshipHidden: function(relationshipId) {
90 // if (this.rTypeList.indexOf(relationshipId) > -1) {
91 // MochiKit.Logging.log('The relationship '+relationshipId + ' is currently hidden');
96 // MochiKit.Logging.log('The relationship '+relationshipId + ' is currently shown');
101 toggleHideRelationshipType: function(relationshipId) {
102 // if (this.rTypeList.indexOf(relationshipId) != -1) {
103 // this.removeHiddenRelationshipType(relationshipId);
106 // this.addHiddenRelationshipType(relationshipId);
108 // this.getImage(this.getName(), this.getType(), this.getLevel(), this.getHiddenRelationshipTypes());
112 setLevel: function(level) {
116 getLevel: function() {
120 setType: function(type) {
124 getType: function() {
128 setName: function(name) {
129 // alert('Setting name to '+name);
133 getName: function() {
138 //alert('Hidden relationship types: ' + this.getHiddenRelationshipTypes());
139 this.getImage(this.getName(), this.getType(),this.getLevel(), this.getHiddenRelationshipTypes());
143 setHilite: function(hiliteColor) {
144 this.hiliteColor = hiliteColor;
147 getHilite: function() {
148 return this.hiliteColor;
151 renderLegend: function() {
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+'"> </font> '+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);
164 document.getElementById('relationships_legend').innerHTML = "<br /><br /><b>Display relationship types:</b><br />" + s;
169 //this shouldn't be here...
171 var hex = (n * 1).toString(16); //force numerical context
172 if (hex.length ==1) { hex = '0'+hex; }
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> ' + this.getLevel() + ' </b>';
180 s += '<input type="button" onClick="javascript:nb.levelPlusOne()" value=">" />';
181 document.getElementById('level_selector').innerHTML = s;
184 levelMinusOne: function() {
185 if (this.getLevel() >1) {
186 this.setLevel(this.getLevel()-1);
191 levelPlusOne: function() {
192 if (this.getLevel() < 10) {
193 this.setLevel(this.getLevel()+1);
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????"); }
201 var x = MochiKit.DOM.getElement("network_browser");
203 this.setLevel(level);
205 this.setHilite(hilite);
206 //alert('Requesting image for '+name);
207 new Ajax.Request("/tools/networkbrowser/ajax_image_request.pl", {
214 onSuccess: this.processImageResponse
220 processImageResponse: function (request) {
221 var responseText = request.responseText;
222 var e = MochiKit.DOM.getElement("network_browser").innerHTML=responseText;
223 var r = responseText;
226 fetchRelationships: function() {
228 new Ajax.Request("/tools/networkbrowser/ajax_relationship_request.pl", {
231 onException: function() {
232 //alert('An error occurred! The database may currently be unavailable. Please check back later.');
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!');