1- function Tree ( type , frame_id , server , node_id = "t0" , action = "open " )
1+ function Tree ( type , frame_id , server , node_id = "t0" , action = "none " )
22{
33 //Creates a tree visualization with a type of <type> inside the DOM element <frame_id>
44
@@ -80,7 +80,7 @@ function Tree(type, frame_id, server, node_id = "t0", action = "open")
8080 self . menuContextNodeCreate ( ) ;
8181
8282
83- if ( action !== "open " && node_id . charAt ( 0 ) !== 'r' )
83+ if ( action !== "none " && node_id . charAt ( 0 ) !== 'r' )
8484 {
8585 throw "Tree constructor attempting to edit/add non-resource node " + node_id ;
8686 }
@@ -97,7 +97,7 @@ function Tree(type, frame_id, server, node_id = "t0", action = "open")
9797 {
9898 self . centerAndAdd ( node_id ) ;
9999 }
100- else
100+ else if ( action !== "none" )
101101 {
102102 throw "Invalid action passed to tree constructor: " + action ;
103103 }
@@ -929,9 +929,17 @@ Tree.prototype.centerOnNode = function(node)
929929 {
930930 var style = self . locals . style . get ( this ) ;
931931
932+ isResource = this . __data__ . id . charAt ( 0 ) === 'r' ;
933+
932934 switch ( style . level )
933935 {
936+
934937 case - 1 :
938+ case 0 :
939+ if ( isResource ) {
940+ self . nodeClicked ( this ) ;
941+ break ;
942+ }
935943 case 1 :
936944 case 2 :
937945 self . nodeClicked ( this ) ;
@@ -1029,8 +1037,7 @@ Tree.prototype.nodeClicked = function(node)
10291037 }
10301038 else
10311039 {
1032- alert ( "Clicked resource: " + node . __data__ . name ) ;
1033- //TODO: call the resource viewer on this node.
1040+ self . centerAndOpen ( node_ID ) ;
10341041 }
10351042
10361043} ;
@@ -1167,9 +1174,13 @@ Tree.prototype.menuContextNodeOpen = function(node, data, index)
11671174
11681175 if ( data . id . charAt ( 0 ) !== 'r' )
11691176 {
1170- menu_context_items . add . enabled = false ;
11711177 menu_context_items . edit . enabled = false ;
11721178 }
1179+
1180+ if ( data . id . charAt ( 0 ) !== 't' )
1181+ {
1182+ menu_context_items . add . enabled = false ;
1183+ }
11731184
11741185 if ( self . user_active_id === 0 )
11751186 {
@@ -1421,16 +1432,34 @@ Tree.prototype.nodeUncapture = function(node, data, index)
14211432Tree . prototype . centerAndAdd = function ( node_id )
14221433{
14231434 var self = this ;
1435+
1436+ var node = self . nodes . filter ( function ( d , i ) {
1437+ return d . id === node_id ;
1438+ } ) ;
1439+ self . centerOnNode ( node . nodes ( ) [ 0 ] ) ; //kinda not really d3-ish, but whatever
1440+ openResourceCreator ( node_id . substr ( 1 ) ) ;
14241441} ;
14251442
14261443Tree . prototype . centerAndEdit = function ( node_id )
14271444{
14281445 var self = this ;
1446+
1447+ var node = self . nodes . filter ( function ( d , i ) {
1448+ return d . id === node_id ;
1449+ } ) ;
1450+ self . centerOnNode ( node . nodes ( ) [ 0 ] ) ; //kinda not really d3-ish, but whatever
1451+ openResourceEditor ( node_id . substr ( 1 ) ) ;
14291452} ;
14301453
14311454Tree . prototype . centerAndOpen = function ( node_id )
14321455{
14331456 var self = this ;
1457+
1458+ var node = self . nodes . filter ( function ( d , i ) {
1459+ return d . id === node_id ;
1460+ } ) ;
1461+ self . centerOnNode ( node . nodes ( ) [ 0 ] ) ; //kinda not really d3-ish, but whatever
1462+ openResourceViewer ( node_id . substr ( 1 ) ) ;
14341463} ;
14351464
14361465//wrapper for centerAndAdd to be called from context menu
0 commit comments