save and display relationship annotations
Tara L Andrews [Wed, 22 Feb 2012 15:20:02 +0000 (16:20 +0100)]
lib/Text/Tradition/Collation/Relationship.pm
stemmaweb/lib/stemmaweb/Controller/Relation.pm
stemmaweb/root/js/relationship.js

index e08fb3c..06748dc 100644 (file)
@@ -96,6 +96,7 @@ has 'scope' => (
 has 'annotation' => (
        is => 'ro',
        isa => 'Str',
+       predicate => 'has_annotation',
        );
 
 has 'non_correctable' => (
index 54830ac..832a447 100644 (file)
@@ -97,9 +97,10 @@ sub relationships :Chained('text') :PathPart :Args(0) {
                my @all_relations;
                foreach my $p ( @pairs ) {
                        my $relobj = $collation->relations->get_relationship( @$p );
-                       push( @all_relations, 
-                               { source => $p->[0], target => $p->[1], 
-                                 type => $relobj->type, scope => $relobj->scope } );
+                       my $relhash = { source => $p->[0], target => $p->[1], 
+                                 type => $relobj->type, scope => $relobj->scope };
+                       $relhash->{'note'} = $relobj->annotation if $relobj->has_annotation;
+                       push( @all_relations, $relhash );
                }
                $c->stash->{'result'} = \@all_relations;
        } elsif( $c->request->method eq 'POST' ) {
@@ -110,8 +111,8 @@ sub relationships :Chained('text') :PathPart :Args(0) {
                my $scope = $c->request->param('scope');
        
                my $opts = { 'type' => $relation,
-                                        'scope' => $scope,
-                                        'annotation' => $note };
+                                        'scope' => $scope };
+               $opts->{'annotation'} = $note if $note;
                
                try {
                        my @vectors = $collation->add_relationship( $node, $target, $opts );
index b135c71..2cbd7ee 100644 (file)
@@ -57,6 +57,7 @@ function add_relations() {
                     var relation = relation_manager.create( rel_info.source, rel_info.target, type_index );
                     relation.data( 'type', rel_info.type );
                     relation.data( 'scope', rel_info.scope );
+                    relation.data( 'note', rel_info.note );
                     var node_obj = get_node_obj(rel_info.source);
                     node_obj.set_draggable( false );
                     node_obj.ellipse.data( 'node_obj', null );
@@ -341,7 +342,11 @@ function relation_factory() {
         }
     }
     this.showinfo = function(relation) {
-        $('#delete-form-text').html( 'type: ' + relation.data( 'type' ) + '<br/>scope: ' + relation.data( 'scope' ) );
+       var htmlstr = 'type: ' + relation.data( 'type' ) + '<br/>scope: ' + relation.data( 'scope' );
+       if( relation.data( 'note' ) ) {
+               htmlstr = htmlstr + '<br/>note: ' + relation.data( 'note' );
+       }
+        $('#delete-form-text').html( htmlstr );
         var points = relation.children('path').attr('d').slice(1).replace('C',' ').split(' ');
         var xs = parseFloat( points[0].split(',')[0] );
         var xe = parseFloat( points[1].split(',')[0] );
@@ -454,6 +459,7 @@ $(document).ready(function () {
                 var relation = relation_manager.create( source_target[0], source_target[1], $('#rel_type').attr('selectedIndex') );
                 relation.data( 'type', $('#rel_type :selected').text()  );
                 relation.data( 'scope', $('#scope :selected').text()  );
+                relation.data( 'note', $('#note').val()  );
                 relation_manager.toggle_active( relation.children('title').text() );
             });
             $( "#dialog-form" ).dialog( "close" );
@@ -501,7 +507,7 @@ $(document).ready(function () {
 
   $( "#delete-form" ).dialog({
     autoOpen: false,
-    height: 120,
+    height: 135,
     width: 160,
     modal: false,
     buttons: {