Replaced HIIT/EADH logos
[scpubgit/stemmaweb.git] / root / src / index.tt
index e2e8192..1a6b1ff 100644 (file)
 [% WRAPPER header.tt
        pagetitle = "Stemmaweb - Text tradition tools"
        applicationjs = c.uri_for( 'js/componentload.js' )
+       applicationstyle = c.uri_for( 'css/dashboard.css' )
 %]
     <script type="text/javascript">
-var basepath = window.location.pathname
-if( basepath.lastIndexOf('/') == basepath.length - 1 ) { 
-       basepath = basepath.slice( 0, basepath.length - 1) 
-};
-var selectedTextID;
-var selectedTextInfo;
-var selectedStemmaID = -1;
-var stemmata = [];
-
-function refreshDirectory () {
-       var lmesg = $('#loading_message').clone();
-       $('#directory').empty().append( lmesg.contents() );
-    $('#directory').load( "[% c.uri_for( 'directory' ) %]", 
-       function(response, status, xhr) {
-                       if (status == "error") {
-                               var msg = "An error occurred: ";
-                               $("#directory").html(msg + xhr.status + " " + xhr.statusText);
-                       }
-               }
-       );
-}
-
-function start_upload_dialog() {
-    if( typeof uploader != 'undefined' ){ uploader.destroy() };
-    $('#upload-collation-dialog').dialog('option', 'attach_uploader')();
-    $('#upload_status').empty();
-    $('#upload_button').button('disable');
-    $('#upload-collation-dialog').dialog('open');
-}
-
-$(document).ready( function() {
-    // call out to load the directory div
-    $('#textinfo_container').hide();
-    $('#textinfo_waitbox').hide();
-       refreshDirectory();
-       
-       // Set up the textinfo edit dialog
-       $('#textinfo-edit-dialog').dialog({
-               autoOpen: false,
-               height: 200,
-               width: 300,
-               modal: true,
-               buttons: {
-                       Save: function (evt) {
-                               $("#edit_textinfo_status").empty();
-                               $(evt.target).button("disable");
-                               var requrl = "[% c.uri_for( '/textinfo' ) %]/" + selectedTextID;
-                               var reqparam = $('#edit_textinfo').serialize();
-                               $.post( requrl, reqparam, function (data) {
-                                       // Reload the selected text fields
-                                       selectedTextInfo = data;
-                                       load_textinfo();
-                                       // Reenable the button and close the form
-                                       $(evt.target).button("enable");
-                                       $('#textinfo-edit-dialog').dialog('close');
-                               }, 'json' );
-                       },
-                       Cancel: function() {
-                               $('#textinfo-edit-dialog').dialog('close');
-                       }
-               },
-               open: 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 ) {
-                               var fname = '#edit_' + k;
-                               // Special case: language Default is basically language null
-                               if( k == 'language' && selectedTextInfo[k] == 'Default' ) {
-                                       $(fname).val( "" );
-                               } else {
-                                       $(fname).val( selectedTextInfo[k] );
-                               }
-                       });
-                       if( selectedTextInfo['public'] == true ) {
-                               $('#edit_public').attr('checked','true');
-                       } else {
-                               $('#edit_public').removeAttr('checked');
-                       }
-               },
-       }).ajaxError( function(event, jqXHR, ajaxSettings, thrownError) {
-               $(event.target).parent().find('.ui-button').button("enable");
-       if( ajaxSettings.url.indexOf( 'textinfo' ) > -1 
-               && ajaxSettings.type == 'POST' ) {
-                       display_error( jqXHR, $("#edit_textinfo_status") );
-       }
-       });
-
-       
-       // Set up the stemma editor dialog
-       $('#stemma-edit-dialog').dialog({
-               autoOpen: false,
-               height: 700,
-               width: 600,
-               modal: true,
-               buttons: {
-                       Save: function (evt) {
-                               $("#edit_stemma_status").empty();
-                               $(evt.target).button("disable");
-                               var stemmaseq = $('#stemmaseq').val();
-                               var requrl = "[% c.uri_for( '/stemma' ) %]/" + selectedTextID + "/" + stemmaseq;
-                               var reqparam = { 'dot': $('#dot_field').val() };
-                               // TODO We need to stash the literal SVG string in stemmata
-                               // somehow. Implement accept header on server side to decide
-                               // whether to send application/json or application/xml?
-                               $.post( requrl, reqparam, function (data) {
-                                       // We received a stemma SVG string in return. 
-                                       // Update the current stemma sequence number
-                                       selectedStemmaID = data.stemmaid;
-                                       // Stash the answer in our SVG array
-                                       stemmata[selectedStemmaID] = data.stemmasvg;
-                                       // Display the new stemma
-                                       load_stemma( selectedStemmaID );
-                                       // Reenable the button and close the form
-                                       $(evt.target).button("enable");
-                                       $('#stemma-edit-dialog').dialog('close');
-                               }, 'json' );
-                       },
-                       Cancel: function() {
-                               $('#stemma-edit-dialog').dialog('close');
-                       }
-               },
-               open: function(evt) {
-                       $("#edit_stemma_status").empty();
-                       var stemmaseq = $('#stemmaseq').val();
-                       if( stemmaseq == 'n' ) {
-                               // If we are creating a new stemma, populate the textarea with a
-                               // bare digraph.
-                               $(evt.target).dialog('option', 'title', 'Add a new stemma')
-                               $('#dot_field').val( "digraph stemma {\n\n}" );
-                       } else {
-                               // If we are editing a stemma, grab its stemmadot and populate the
-                               // textarea with that.
-                               $(evt.target).dialog('option', 'title', 'Edit selected stemma')
-                               $('#dot_field').val( 'Loading, please wait...' );
-                               var doturl = "[% c.uri_for( '/stemmadot' ) %]/" + selectedTextID + "/" + stemmaseq;
-                               $.getJSON( doturl, function (data) {
-                                       // Re-insert the line breaks
-                                       var dotstring = data.dot.replace(/\|n/gm, "\n");                                        
-                                       $('#dot_field').val( dotstring );
-                               });
-                       }
-               },
-       }).ajaxError( function(event, jqXHR, ajaxSettings, thrownError) {
-               $(event.target).parent().find('.ui-button').button("enable");
-       if( ajaxSettings.url.indexOf( 'stemma' ) > -1 
-               && ajaxSettings.type == 'POST' ) {
-                       display_error( jqXHR, $("#edit_stemma_status") );
-       }
-       });
-               
-       $('#upload-collation-dialog').dialog({
-               autoOpen: false,
-               height: 325,
-               width: 480,
-               modal: true,
-               buttons: {
-                 pick: {
-                   text: "Pick File",
-                   id: "pick_uploadfile_button",
-                   click: function() {}       
-                 },
-                 upload: {
-                   text: 'Upload',
-                   id: 'upload_button',
-                   click: function() {
-                           $('#upload_status').empty();
-                uploader.start();
-                return false;
-            }
-                 },
-                 Cancel: function() {
-                   $('#upload-collation-dialog').dialog('close');
-                 }
-               },
-               attach_uploader: function() {
-                   create_uploader( "[% c.uri_for ( '/newtradition' ) %]" );
-                   $('#filelist').empty().html( 'Use the \'Pick\' button to choose a source fileā€¦' );
-               }
-       });
-       
-       $('#stemma_graph').mousedown( function(evt) {
-        evt.stopPropagation();
-        $('#stemma_graph').data( 'mousedown_xy', [evt.clientX, evt.clientY] );
-        $('body').mousemove( function(evt) {
-            mouse_scale = 1; // for now, was:  mouse_scale = svg_root_element.getScreenCTM().a;
-            dx = (evt.clientX - $('#stemma_graph').data( 'mousedown_xy' )[0]) / mouse_scale;
-            dy = (evt.clientY - $('#stemma_graph').data( 'mousedown_xy' )[1]) / mouse_scale;
-            $('#stemma_graph').data( 'mousedown_xy', [evt.clientX, evt.clientY] );
-            var svg_root = $('#stemma_graph svg').svg().svg('get').root();
-            var g = $('g.graph', svg_root).get(0);
-            current_translate = g.getAttribute( 'transform' ).split(/translate\(/)[1].split(')',1)[0].split(' ');
-            new_transform = g.getAttribute( 'transform' ).replace( /translate\([^\)]*\)/, 'translate(' + (parseFloat(current_translate[0]) + dx) + ' ' + (parseFloat(current_translate[1]) + dy) + ')' );
-            g.setAttribute( 'transform', new_transform );
-            evt.returnValue = false;
-            evt.preventDefault();
-            return false;
-        });
-        $('body').mouseup( function(evt) {
-            $('body').unbind('mousemove');
-            $('body').unbind('mouseup');
-        });
-       });
-        
-       $('#stemma_graph').mousewheel(function (event, delta) {
-        event.returnValue = false;
-        event.preventDefault();
-        if (!delta || delta == null || delta == 0) delta = event.originalEvent.wheelDelta;
-        if (!delta || delta == null || delta == 0) delta = -1 * event.originalEvent.detail;
-        if( delta < -9 ) { delta = -9 }; 
-        var z = 1 + delta/10;
-        z = delta > 0 ? 1 : -1;
-        var svg_root = $('#stemma_graph svg').svg().svg('get').root();
-        var g = $('g.graph', svg_root).get(0);
-        if (g && ((z<1 && (g.getScreenCTM().a * start_element_height) > 4.0) || (z>=1 && (g.getScreenCTM().a * start_element_height) < 1000))) {
-            var scaleLevel = z/10;
-            current_scale = parseFloat( g.getAttribute( 'transform' ).split(/scale\(/)[1].split(')',1)[0].split(' ')[0] );
-            new_transform = g.getAttribute( 'transform' ).replace( /scale\([^\)]*\)/, 'scale(' + (current_scale + scaleLevel) + ')' );
-            g.setAttribute( 'transform', new_transform );
-        }
-    });
-    
-});
+// Set global variables that must be passed by the server
+var basepath = "[% c.uri_for( '/' ) %]";
+var textOnLoad = "[% withtradition %]";
     </script>
 
 [% END %]
-
+   <div id="main_page" class="clearfix">
+   <div class="mainnav">
+       <span>[% IF c.user_exists %]Hello! [% c.user.get_object.email %]! &nbsp; <a class="navlink" href="[% c.uri_for( '/logout' ) %]">Sign out</a> | [% ELSE %]<a class="navlink" onclick="window.open('[% c.uri_for( '/login' ) %]', 'loginwindow', 'height=385,width=445')">Sign in/Register</a> | [% END %]<a class="navlink" href="[% c.uri_for( '/about' ) %]">About Stemmaweb</a> </span>
+   </div>
     <div id="topbanner">
-      <h1>Stemmaweb - a collection of tools for analysis of collated texts</h1>
-      <span class="mainnav">[% IF c.user_exists %]Hello! [% c.user.get_object.email %] <a class="navlink" href="[% c.uri_for( '/logout' ) %]">Sign out</a> | [% ELSE %]<a class="navlink" onclick="window.open('[% c.uri_for( '/login' ) %]', 'loginwindow', 'height=385,width=445')">Login</a> | <a class="navlink" onclick="window.open('[% c.uri_for( '/register' ) %]', 'regwindow', 'height=385,width=445')">Register</a> | [% END %]<a class="navlink" href="[% c.uri_for( 'about.html' ) %]">About</a> </span>
+      <h1 class="title">Stemmaweb - a collection of tools for analysis of collated texts</h1>
+      <p id="compatibility_check"><span class="error">This browser does not support 
+      the functions necessary for Stemmaweb to work properly. We recommend use of 
+      <a href="http://mozilla.org/firefox">Mozilla Firefox</a> or 
+      <a href="http://www.google.com/chrome">Google Chrome</a>.</span></p>
     </div>
     <div id="directory_container">
       <h2>Text directory</h2>
       <div id="directory"></div>
 [% IF c.user_exists -%]
-         <div class="button" id="new_trad_button" onClick="start_upload_dialog();">
+         <div class="button" id="new_trad_button" onClick="$('#upload-collation-dialog').dialog('open')">
            <span>Add a new text tradition</span>
          </div>
 [% END %]
@@ -247,7 +34,7 @@ $(document).ready( function() {
        <h3>Loading tradition information, please wait...</h3>
        <img src="[% c.uri_for( 'images', 'ajax-loader.gif' ) %]" alt="Loading tradition info..." />
     </div>
-    <div id="textinfo_container">
+    <div id="textinfo_container" class="clearfix">
       <div id="textinfo_load_status"></div>
       <h2>Text <span class="texttitle"></span></h2>
       <form id="open_textinfo_edit" action="" method="GET" name="edit_textinfo">
@@ -282,6 +69,18 @@ $(document).ready( function() {
                  <span>Edit this stemma</span>
             </div>
           </form>
+          <form id="open_stemweb_ui" action="" method="GET" name="run_stemweb">
+            <div class="button" id="run_stemweb_button"
+               onClick="$('#stemweb-ui-dialog').dialog('open');">
+              <span>Run a Stemweb algorithm</span>
+            </div>
+          </form>
+          <form id="query_stemweb_ui" action="" method="GET" name="query_stemweb">
+            <div class="button" id="query_stemweb_button"
+               onClick="query_stemweb_progress();">
+              <span>Check progress of Stemweb algorithm</span>
+            </div>
+          </form>
           <form id="run_stexaminer" action="" method="GET" name="run_stexaminer">
             <div class="button" id="stexaminer_button" onClick="$('#run_stexaminer').submit()">
                  <span>Examine variants against this stemma</span>
@@ -289,11 +88,19 @@ $(document).ready( function() {
           </form>
           <form id="run_relater" action="" method="GET" name="run_relater">
             <div class="button" id="relater_button" onClick="$('#run_relater').submit()">
-              <span>Run relationship mapper</span>
+              <span id='relatebutton_label'>View collation and relationships</span>
+            </div>
+          </form>
+          <form id="dl_tradition" action="" method="GET" name="run_downloader">
+            <div class="button" id="download_button"
+               onClick="$('#download-dialog').dialog('open');">
+              <span id='dlbutton_label'>Download tradition</span>
             </div>
           </form>
       </div>
+      <div id="stemma_load_status"></div>
       <div id="stemma_graph"></div>
+      <div id="stemma_graph_title"><span id="stemma_identifier"></span></div>
     </div>
 
     <!-- Interim 'loading' message for directory box -->
@@ -301,7 +108,8 @@ $(document).ready( function() {
        <h3>Loading texts, please wait...</h3>
        <img src="[% c.uri_for( 'images', 'ajax-loader.gif' ) %]" alt="Loading tradition list..."/>
     </div>
-    
+  </div> <!-- main_page -->
+  
     <!-- Textinfo editor dialog -->
     <div id="textinfo-edit-dialog" title="Edit information about this tradition">
       <div id="textinfo_edit_container">
@@ -332,9 +140,10 @@ $(document).ready( function() {
                <input id="stemmaseq" type="hidden" name="stemmaseq" val="n"/>
                        <div id="edit_instructions">
                                <p>All definitions begin with the line
-                                       <pre>digraph stemma {</pre>
+                                       <pre>digraph "Stemma Name" {</pre>
                                and end with the line 
-                                       <pre>}</pre>Please do not change these lines.</p>
+                                       <pre>}</pre>
+                               Please do not change these lines except to edit the stemma name.</p>
                                <p>First list each witness in your stemma, whether extant or lost /
                                reconstructed / hypothetical, and assign them a class of either "extant"
                                or "hypothetical". For example:</p><pre>  
@@ -354,9 +163,63 @@ $(document).ready( function() {
       </div>
     </div>
 
+       <!-- Stemweb UI dialog box -->
+    <div id="stemweb-ui-dialog" title="Generate a Stemweb tree">
+      <div id="stemweb_ui_container">
+               <div id="sponsor_container">
+                       <img id="hiit_logo" src="[% c.uri_for( '/images/hiit_logo.jpg' ) %]"></img>
+                       <img id="eadh_logo" src="[% c.uri_for( '/images/eadh-150.png' ) %]"></img>
+                       <p>Stemweb is a webservice provided by the Helsinki Institute for Information Technology HIIT. The integration into Stemmaweb was generously supported by a small project grant from the European Association for Digital Humanities.
+                       </p>
+               </div>
+               <hr/>
+               <form id="call_stemweb">
+               <input id="stemweb_tradition" type="hidden" name="tradition"/>
+               <h5>Choose an algorithm</h5>
+               <label for="algorithm">Run algorithm: </label>
+               <select id="stemweb_algorithm" name="algorithm"></select>
+               <span id="stemweb_algorithm_help">What is this?</span><br/>
+                       <div id="stemweb_algorithm_desc_text"></div>
+                       <br/>
+                       <h5>Set the options</h5>
+               <!-- Algorithm-specific options, if any, will be added within this div -->
+               <div id="stemweb_runtime_options"></div>
+               <br/>
+               <!-- Options applicable to all algorithms belong within this div -->
+               <div id="stemweb_local_options">
+                       <label for="merge_reltypes">Disregard variation of type:</label>
+                       <select multiple name="merge_reltypes" id="stemweb_merge_reltypes"></select>
+               </div>
+       </form>
+       <div id="stemweb_run_status"></div>
+      </div>
+    </div>
+    
+    <!-- Data download dialog box -->
+    <div id="download-dialog" title="Download tradition data">
+      <div id="download_container">
+       <form id="download_form">
+               <input id="download_tradition" type="hidden" name="tradition"/><br/>
+               <label for="download_format">Choose a format for download: </label>
+               <select id="download_format" name="format">
+                       <option value="GraphML">Native XML format</option>
+                       <option value="CSV">Comma-separated values (collation only)</option>
+                       <option value="TSV">Tab-separated values (collation only)</option>
+                       <option value="SVG">SVG graph display (collation and relationships)</option>                            
+                       <!-- option value="tei_ps" -->
+                       <!-- option value="tei_dea" -->
+               </select>
+       </form>
+       <div id="download_status"></div>
+      </div>
+    </div>    
+    
     <!-- File upload dialog box -->
     <div id="upload-collation-dialog" title="Upload a collation">
       <div id="upload_container">
+               <input id="new_file" name="file" type="file" onchange="file_selected(this)">
+               <label for="new_file" id="new_file_label">Collation file: </label>
+        <div id="new_file_name_container" onclick="$('#new_file').click();">&nbsp;(Use 'pick file' to select a tradition file to upload.)</div>
         <form id="new_tradition">
             <label for="new_name">Name of this text / tradition: </label>
             <input id="new_name" type="text" name="name" size="40"/><br/>
@@ -364,8 +227,7 @@ $(document).ready( function() {
             <input id="new_lang" type="text" name="language" size="20"/><br/>
             <label for="new_public">Allow public display: </label>
             <input id="new_public" name="public" type="checkbox"/><br/>
-            <div id="filelist"></div>
-        <form>
+        </form>
         <div id="upload_status"></div>
        <div>
          <h4>Supported file types / extensions:</h4>
@@ -381,5 +243,10 @@ $(document).ready( function() {
          <p>All spreadsheet collations should be arranged with the witness sigla in the first row, and the words aligned by row each in its correct witness column.</p>
        </div>
       </div>
-    </div>    
+    </div>
+    
+    <div id="root_tree_dialog">
+        Use this node to root the stemma? <img id="root_tree_dialog_button_ok" src="[% c.uri_for( 'images', 'tick_circle_frame_24.png' ) %]"/>
+    </div>
+    
 [% PROCESS footer.tt %]
\ No newline at end of file