Merge pull request #59 from tla/textdirection
tla [Wed, 17 Jun 2015 12:02:50 +0000 (14:02 +0200)]
Textdirection

lib/stemmaweb/Controller/Relation.pm
lib/stemmaweb/Controller/Root.pm
root/js/componentload.js
root/js/relationship.js
root/src/index.tt
root/src/relate.tt

index 24d1de3..0a0579c 100644 (file)
@@ -70,7 +70,10 @@ sub main :Chained('text') :PathPart('') :Args(0) {
        my( $self, $c ) = @_;
        my $tradition = delete $c->stash->{'tradition'};
        my $collation = $tradition->collation;
-       
+
+       # Stash text direction to use in JS.
+       $c->stash->{'direction'} = $collation->direction;
+
        # Stash the relationship definitions
        $c->stash->{'relationship_scopes'} = 
                to_json( find_type_constraint( 'RelationshipScope' )->values );
index 7159680..9a0d3f4 100644 (file)
@@ -123,12 +123,15 @@ sub newtradition :Local :Args(0) {
        my $name = $c->request->param('name') || 'Uploaded tradition';
        my $lang = $c->request->param( 'language' ) || 'Default';
        my $public = $c->request->param( 'public' ) ? 1 : undef;
+       my $direction = $c->request->param('direction') || 'LR';
+
        my( $ext ) = $upload->filename =~ /\.(\w+)$/;
        my %newopts = (
                'name' => $name,
                'language' => $lang,
                'public' => $public,
-               'file' => $upload->tempname
+               'file' => $upload->tempname,
+               'direction' => $direction,
                );
 
        my $tradition;
@@ -275,6 +278,20 @@ sub textinfo :Local :Args(1) {
                        $changed = 1 if $ispublic;
                }
                
+               # Handle text direction
+               my $tdval = delete $params->{direction} || 'LR';
+               
+               unless( $tradition->collation->direction
+                               && $tradition->collation->direction eq $tdval ) {
+                       try {
+                               $tradition->collation->change_direction( $tdval );
+                               $changed = 1;
+                       } catch {
+                               return _json_error( $c, 500, "Error setting direction to $tdval: $@" );
+                       }
+               }
+               
+               
                # Handle ownership change
                if( exists $params->{'owner'} ) {
                        # Only admins can update user / owner
@@ -314,6 +331,7 @@ sub textinfo :Local :Args(1) {
        my $textinfo = {
                textid => $textid,
                name => $tradition->name,
+               direction => $tradition->collation->direction || 'LR',
                public => $tradition->public || 0,
                owner => $tradition->user ? $tradition->user->email : undef,
                witnesses => [ map { $_->sigil } $tradition->witnesses ],
index 76fe2df..60757c6 100644 (file)
@@ -503,7 +503,7 @@ $(document).ready( function() {
                        $("#edit_textinfo_status").empty();
                        // Populate the form fields with the current values
                        // edit_(name, language, public, owner)
-                       $.each([ 'name', 'language', 'owner' ], function( idx, k ) {
+                       $.each([ 'name', 'language', 'owner', 'direction' ], function( idx, k ) {
                                var fname = '#edit_' + k;
                                // Special case: language Default is basically language null
                                if( k == 'language' && selectedTextInfo[k] == 'Default' ) {
index 495d28c..9a4a169 100644 (file)
@@ -4,6 +4,7 @@ var svg_root_element = null;
 var start_element_height = 0;
 var reltypes = {};
 var readingdata = {};
+var text_direction = 'LR';
 
 jQuery.removeFromArray = function(value, arr) {
     return jQuery.grep(arr, function(elem, index) {
@@ -224,7 +225,10 @@ function svgEnlargementLoaded() {
     
     //initialize marquee
     marquee = new Marquee();
-    
+
+       if (text_direction == 'RL') {
+               scrollToEnd();
+       }
 }
 
 function add_relations( callback_fn ) {
@@ -981,6 +985,21 @@ function readings_equivalent( source, target ) {
        return false;
 }
 
+function scrollToEnd() {
+       var stateTf = svg_root_element.getCTM().inverse();
+
+       var vbdim = svg_root.viewBox.baseVal;
+       var width = Math.floor(svg_root_element.getBoundingClientRect().width) - vbdim.width;
+
+       var p = svg_root.createSVGPoint();
+       p.x = width;
+       p.y = 0;
+       p = p.matrixTransform(stateTf);
+
+       var matrix = stateTf.inverse().translate(-p.x, -100);
+       var s = "matrix(" + matrix.a + "," + matrix.b + "," + matrix.c + "," + matrix.d + "," + matrix.e + "," + matrix.f + ")";
+       svg_root_element.setAttribute("transform", s);
+}
 
 $(document).ready(function () {
     
@@ -1468,7 +1487,9 @@ function expandFillPageClients() {
        });
 }
 
-function loadSVG(svgData) {
+function loadSVG(svgData, direction) {
+       text_direction = direction;
+
        var svgElement = $('#svgenlargement');
 
        $(svgElement).svg('destroy');
index 4066c6e..2437e54 100644 (file)
@@ -120,6 +120,12 @@ var textOnLoad = "[% withtradition %]";
                <input id="edit_language" type="text" size="12" name="language"/>
                <label for="edit_public">Publicly viewable: </label>
                <input id="edit_public" type="checkbox" name="public"/><br/>
+               <label for="edit_direction">Text direction: </label>
+               <select id="edit_direction" name="direction">
+                       <option value="LR" selected>Left-to-right</option>
+                       <option value="RL">Right-to-left</option>
+                       <option value="BI">Bidirectional</option>
+               </select><br/>
 [% IF c.user_exists -%]
 [% IF c.user.get_object.is_admin -%]
                <label for="edit_owner">Tradition owner: </label>
@@ -225,6 +231,15 @@ var textOnLoad = "[% withtradition %]";
             <input id="new_name" type="text" name="name" size="40"/><br/>
             <label for="new_lang">Primary language of the text: </label>
             <input id="new_lang" type="text" name="language" size="20"/><br/>
+
+            <label for="direction">Text direction:</label>
+
+            <select name="direction" id="direction">
+                <option value="LR" selected>Left to Right</option>
+                <option value="RL">Right to Left</option>
+                <option value="BI">Bi-directional</option>
+            </select><Br/>
+
             <label for="new_public">Allow public display: </label>
             <input id="new_public" name="public" type="checkbox"/><br/>
         </form>
index e46c5de..4d9d4e4 100644 (file)
@@ -24,7 +24,7 @@ var ternary_values = [% ternary_values %];
 [% END -%]
 
 $(document).ready(function () {
-  loadSVG('[% svg_string %]');
+  loadSVG('[% svg_string %]', '[% direction %]');
 });
 </script>
 [% END %]