From: tla Date: Mon, 28 Oct 2013 22:33:13 +0000 (+0100) Subject: Only show stexaminer button for directed graphs X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=63378fe0ded6c73b770dc34025f5508467a16ade;p=scpubgit%2Fstemmaweb.git Only show stexaminer button for directed graphs --- diff --git a/lib/stemmaweb/Controller/Root.pm b/lib/stemmaweb/Controller/Root.pm index c50a660..d798cbd 100644 --- a/lib/stemmaweb/Controller/Root.pm +++ b/lib/stemmaweb/Controller/Root.pm @@ -322,7 +322,10 @@ sub textinfo :Local :Args(1) { if( $tradition->can('language') ) { $textinfo->{'language'} = $tradition->language; } - my @stemmasvg = map { { name => $_->identifier, svg => $_->as_svg() } } + my @stemmasvg = map { { + name => $_->identifier, + directed => _json_bool( !$_->is_undirected ), + svg => $_->as_svg() } } $tradition->stemmata; map { $_ =~ s/\n/ /mg } @stemmasvg; $textinfo->{stemmata} = \@stemmasvg; @@ -448,6 +451,7 @@ sub stemma :Local :Args(2) { $c->stash->{'result'} = { 'stemmaid' => $stemmaid, 'name' => $stemma->identifier, + 'directed' => _json_bool( !$stemma->is_undirected ), 'svg' => $stemma_xml }; $c->forward('View::JSON'); } @@ -532,6 +536,10 @@ sub _json_error { return 0; } +sub _json_bool { + return $_[0] ? JSON::true : JSON::false; +} + =head2 default Standard 404 error page diff --git a/root/js/componentload.js b/root/js/componentload.js index 3bb43a9..aba03fd 100644 --- a/root/js/componentload.js +++ b/root/js/componentload.js @@ -45,12 +45,10 @@ function loadTradition( textid, textname, editable ) { // Hide the functionality that is irrelevant if( editable ) { $('#open_stemma_add').show(); - $('#open_stemma_edit').show(); $('#open_textinfo_edit').show(); $('#relatebutton_label').text('View collation and edit relationships'); } else { $('#open_stemma_add').hide(); - $('#open_stemma_edit').hide(); $('#open_textinfo_edit').hide(); $('#relatebutton_label').text('View collation and relationships'); } @@ -62,17 +60,14 @@ function loadTradition( textid, textname, editable ) { // Add the scalar data selectedTextInfo = textdata; load_textinfo(); - // Add the stemma(ta) and set up the stexaminer button + // Add the stemma(ta) stemmata = textdata.stemmata; if( stemmata.length ) { selectedStemmaID = 0; - $('#run_stexaminer').show(); } else { selectedStemmaID = -1; - $('#open_stemma_edit').hide(); - $('#run_stexaminer').hide(); } - load_stemma( selectedStemmaID ); + load_stemma( selectedStemmaID, editable ); // Set up the relationship mapper button $('#run_relater').attr( 'action', _get_url([ "relation", textid ]) ); // Set up the download button @@ -113,34 +108,43 @@ function load_textinfo() { } // Enable / disable the appropriate buttons for paging through the stemma. -function show_stemmapager () { +function show_stemmapager ( editable ) { $('.pager_left_button').unbind('click').addClass( 'greyed_out' ); $('.pager_right_button').unbind('click').addClass( 'greyed_out' ); if( selectedStemmaID > 0 ) { $('.pager_left_button').click( function () { - load_stemma( selectedStemmaID - 1 ); + load_stemma( selectedStemmaID - 1, editable ); }).removeClass( 'greyed_out' ); } if( selectedStemmaID + 1 < stemmata.length ) { $('.pager_right_button').click( function () { - load_stemma( selectedStemmaID + 1 ); + load_stemma( selectedStemmaID + 1, editable ); }).removeClass( 'greyed_out' ); } } // Load a given stemma SVG into the stemmagraph box. -function load_stemma( idx ) { +function load_stemma( idx, editable ) { // Load the stemma at idx selectedStemmaID = idx; - show_stemmapager(); + show_stemmapager( editable ); + $('#open_stemma_edit').hide(); + $('#run_stexaminer').hide(); + $('#stemma_identifier').empty(); if( idx > -1 ) { - // Load the SVG and identifier of the stemma + // Load the stemma and its properties var stemmadata = stemmata[idx]; - loadSVG( stemmadata['svg'] ); - $('#stemma_identifier').empty().text( stemmadata['name'] ); - // Stexaminer submit action - var stexpath = _get_url([ "stexaminer", selectedTextID, idx ]); - $('#run_stexaminer').attr( 'action', stexpath ); + if( editable ) { + $('#open_stemma_edit').show(); + } + if( stemmadata.directed ) { + // Stexaminer submit action + var stexpath = _get_url([ "stexaminer", selectedTextID, idx ]); + $('#run_stexaminer').attr( 'action', stexpath ); + $('#run_stexaminer').show(); + } + loadSVG( stemmadata.svg ); + $('#stemma_identifier').text( stemmadata.name ); setTimeout( 'start_element_height = $("#stemma_graph .node")[0].getBBox().height;', 500 ); } } @@ -400,9 +404,7 @@ $(document).ready( function() { // Stash the answer in the appropriate spot in our stemma array stemmata[selectedStemmaID] = data; // Display the new stemma - load_stemma( selectedStemmaID ); - // Show the edit button, in case this was the first new stemma - $('#open_stemma_edit').show(); + load_stemma( selectedStemmaID, true ); // Reenable the button and close the form $(evt.target).button("enable"); $('#stemma-edit-dialog').dialog('close');