## For morphological analysis
+has 'grammar_invalid' => (
+ is => 'rw',
+ isa => 'Bool',
+ default => undef,
+ );
+
+has 'is_nonsense' => (
+ is => 'rw',
+ isa => 'Bool',
+ default => 'undef',
+ );
+
has 'normal_form' => (
is => 'rw',
isa => 'Str',
}
}
$c->forward('View::JSON');
-}
-
+}
+
+=head2 readings
+
+ GET relation/$textid/readings
+
+Returns the list of readings defined for this text along with their metadata.
+
+=cut
+
+sub _reading_struct {
+ my( $reading ) = @_;
+ # Return a JSONable struct of the useful keys. Keys meant to be writable
+ # have a true value; read-only keys have a false value.
+ my %read_write_keys = (
+ 'id' => 0,
+ 'text' => 0,
+ 'is_meta' => 0,
+ 'grammar_invalid' => 1,
+ 'is_nonsense' => 1,
+ 'normal_form' => 1,
+ 'lexemes' => 1, # special case?
+ );
+ my $struct = {};
+ map { $struct->{$_} = $reading->$_ } keys( %read_write_keys );
+ # Special case
+ $struct->{'lexemes'} = [ $reading->lexemes ];
+ return $struct;
+}
+
+sub readings :Chained('text') :PathPart :Args(0) {
+ my( $self, $c ) = @_;
+ my $tradition = delete $c->stash->{'tradition'};
+ my $collation = $tradition->collation;
+ my $m = $c->model('Directory');
+ if( $c->request->method eq 'GET' ) {
+ my $rdginfo = {};
+ foreach my $rdg ( $collation->readings ) {
+ $rdginfo->{$rdg->id} = _reading_struct( $rdg );
+ }
+ $c->stash->{'result'} = $rdginfo;
+ }
+ $c->forward('View::JSON');
+}
+
+=head2 reading
+
+ GET relation/$textid/reading/$id
+
+Returns the list of readings defined for this text along with their metadata.
+
+ POST relation/$textid/reading/$id { request }
+
+Alters the reading according to the values in request. Returns 403 Forbidden if
+the alteration isn't allowed.
+
+=cut
+
+sub reading :Chained('text') :PathPart :Args(1) {
+ my( $self, $c, $reading_id ) = @_;
+ my $tradition = delete $c->stash->{'tradition'};
+ my $collation = $tradition->collation;
+ my $m = $c->model('Directory');
+ if( $c->request->method eq 'GET' ) {
+ my $rdg = $collation->reading( $reading_id );
+ $c->stash->{'result'} = $rdg ? _reading_struct( $rdg )
+ : { 'error' => "No reading with ID $reading_id" };
+ } elsif ( $c->request->method eq 'POST' ) {
+ # TODO Update the reading if we can.
+ }
+ $c->forward('View::JSON');
+
+}
=head2 end
use strict;
use base 'Catalyst::View::JSON';
+use JSON::XS ();
+
+sub encode_json {
+ my( $self, $c, $data ) = @_;
+ my $json = JSON::XS->new->utf8->convert_blessed(1);
+ $json->encode( $data );
+}
+
+1;
+
=head1 NAME
stemmaweb::View::JSON - Catalyst JSON View
This library is free software, you can redistribute it and/or modify
it under the same terms as Perl itself.
-
-=cut
-
-1;
var svg_root_element = null;
var start_element_height = 0;
var reltypes = {};
+var readingdata = {};
function getTextPath() {
var currpath = window.location.pathname;
return path_parts[0];
}
-function getRelationshipURL() {
+function getTextURL( which ) {
var path_parts = getTextPath();
- return path_parts[0] + '/' + path_parts[1] + '/relationships';
+ return path_parts[0] + '/' + path_parts[1] + '/' + which;
+}
+
+function getReadingURL( reading_id ) {
+ var path_parts = getTextPath();
+ return path_parts[0] + '/' + path_parts[1] + '/reading/' + reading_id;
}
// Make an XML ID into a valid selector
function add_relations( callback_fn ) {
var basepath = getRelativePath();
- var textrelpath = getRelationshipURL();
+ var textrelpath = getTextURL( 'relationships' );
$.getJSON( basepath + '/definitions', function(data) {
var rel_types = data.types.sort();
$.getJSON( textrelpath,
'cursor' : '-moz-grab'
});
+ var rdgpath = getTextURL( 'readings' );
+ $.getJSON( rdgpath, function( data ) {
+ readingdata = data;
+ });
$( "#dialog-form" ).dialog({
autoOpen: false,
"Ok": function() {
$('#status').empty();
form_values = $('#collapse_node_form').serialize();
- ncpath = getRelationshipURL();
+ ncpath = getTextURL( 'relationships' );
$(':button :contains("Ok")').attr("disabled", true);
var jqjson = $.post( ncpath, form_values, function(data) {
$.each( data, function(item, source_target) {
$( this ).dialog( "close" );
},
Delete: function() {
- form_values = $('#delete_relation_form').serialize()
- ncpath = getRelationshipURL()
+ form_values = $('#delete_relation_form').serialize();
+ ncpath = getTextURL( 'relationships' );
var jqjson = $.ajax({ url: ncpath, data: form_values, success: function(data) {
$.each( data, function(item, source_target) {
relation_manager.remove( get_relation_id( source_target[0], source_target[1] ) );