implement HTML5 file upload; fix is-public display bug
[scpubgit/stemmaweb.git] / root / src / index.tt
index b3cdb32..5914165 100644 (file)
        applicationjs = c.uri_for( 'js/componentload.js' )
 %]
     <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) {
-                               $(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;
-                               $(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) {
-                               $(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
-                                       if( stemmaseq == 'n' ) {
-                                               selectedStemmaID = stemmata.length;
-                                       } else {
-                                               selectedStemmaID = stemmaseq;
-                                       }
-                                       // Strip the carriage returns from the answer
-                                       var newsvg = data.replace(/(\r\n|\n|\r)/gm," ");
-                                       // Stash the answer in our SVG array
-                                       stemmata[selectedStemmaID] = newsvg;
-                                       // Display the new stemma
-                                       load_stemma( selectedStemmaID );
-                                       // Reenable the button and close the form
-                                       $(evt.target).button("disable");
-                                       $('#stemma-edit-dialog').dialog('close');
-                               }, 'xml' );
-                       },
-                       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ā€¦' );
-               }
-       });
-});
+// Set global variables that must be passed by the server
+var basepath = "[% c.uri_for( '/' ) %]";
+var textOnLoad = "[% withtradition %]";
     </script>
 
 [% END %]
 
     <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>
+      <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> | [% END %]<a class="navlink" href="[% c.uri_for( '/about' ) %]">About</a> </span>
     </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 %]
@@ -207,6 +30,12 @@ $(document).ready( function() {
     <div id="textinfo_container">
       <div id="textinfo_load_status"></div>
       <h2>Text <span class="texttitle"></span></h2>
+      <form id="open_textinfo_edit" action="" method="GET" name="edit_textinfo">
+        <div class="button" id="edit_textinfo_button"
+               onClick="$('#textinfo-edit-dialog').dialog('open')">
+         <span>Modify information about this tradition</span>
+        </div>
+      </form>
       <ul>
          <li>is owned by <span id="owner_id"></span></li>
          <li>is <span id="not_public"></span>public</li>
@@ -214,17 +43,11 @@ $(document).ready( function() {
              <li>has <span id="witness_num"></span> witnesses: <span id="witness_list"></span></li>
       </ul>
       
-      <!-- TODO buttons on either side of the graph div to flip through the stemmata -->
       <div id="textinfo_container_buttons">
-          <form id="open_textinfo_edit" action="" method="GET" name="edit_textinfo">
-            <div class="button" id="edit_textinfo_button"
-               onClick="$('#textinfo-edit-dialog').dialog('open')">
-                 <span>Modify information about this tradition</span>
-            </div>
-          </form>
           <form id="stemma_pager" action="" method="GET" name="stemma_pager">
-            <div class="button" id="stemma_pager_button" onClick="$('#stemma_pager').submit()">
-                 <span>Left &amp; right go here</span>
+            <div id="stemma_pager_buttons">
+              <div class="pager_left_button" id="stemma_pager_left_button"></div>
+              <div class="pager_right_button" id="stemma_pager_right_button"></div>
             </div>
           </form>
           <form id="open_stemma_add" action="" method="GET" name="add_new_stemma">
@@ -271,7 +94,7 @@ $(document).ready( function() {
                <input id="edit_public" type="checkbox" name="public"/><br/>
 [% IF c.user_exists -%]
 [% IF c.user.get_object.is_admin -%]
-               <label for="edit_owner">Publicly viewable: </label>
+               <label for="edit_owner">Tradition owner: </label>
                <input id="edit_owner" type="text" size="30" name="owner"/><br/>
 [% END -%]
 [% END -%]
@@ -314,6 +137,8 @@ $(document).ready( function() {
     <!-- File upload dialog box -->
     <div id="upload-collation-dialog" title="Upload a collation">
       <div id="upload_container">
+        <label for="new_file">Collation file: </label>
+               <input id="new_file" name="file" type="file" onchange="file_selected(this)"><br/>
         <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/>
@@ -321,7 +146,6 @@ $(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>
         <div id="upload_status"></div>
        <div>