add download button for viewable traditions; fixes #8
[scpubgit/stemmaweb.git] / root / js / componentload.js
index 522c879..da3ad7f 100644 (file)
@@ -47,10 +47,12 @@ function loadTradition( textid, textname, 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');
     }
 
     // Then get and load the actual content.
@@ -73,6 +75,9 @@ function loadTradition( textid, textname, editable ) {
                load_stemma( selectedStemmaID );
        // Set up the relationship mapper button
                $('#run_relater').attr( 'action', _get_url([ "relation", textid ]) );
+               // Set up the download button
+               $('#dl_tradition').attr( 'href', _get_url([ "download", textid ]) );
+               $('#dl_tradition').attr( 'download', selectedTextInfo.name + '.xml' );
        });
 }
 
@@ -88,7 +93,12 @@ function load_textinfo() {
        // Who the owner is
        $('#owner_id').empty().append('no one');
        if( selectedTextInfo.owner ) {
-               $('#owner_id').empty().append( selectedTextInfo.owner );
+               var owneremail = selectedTextInfo.owner;
+               var chop = owneremail.indexOf( '@' );
+               if( chop > -1 ) {
+                       owneremail = owneremail.substr( 0, chop + 1 ) + '...';
+               }
+               $('#owner_id').empty().append( owneremail );
        }
        // Whether or not it is public
        $('#not_public').empty();
@@ -188,8 +198,10 @@ function display_error( jqXHR, el ) {
 function file_selected( e ) {
        if( e.files.length == 1 ) {
                $('#upload_button').button('enable');
+               $('#new_file_name_container').html( '<span id="new_file_name">' + e.files[0].name + '</span>' );
        } else {
                $('#upload_button').button('disable');
+               $('#new_file_name_container').html( '(Use \'pick file\' to select a tradition file to upload.)' );
        }
 }
 
@@ -438,6 +450,13 @@ $(document).ready( function() {
                 upload_new();
             }
                  },
+                 pick_file: {
+                   text: 'Pick File',
+                   id: 'pick_file_button',
+                   click: function() {
+                $('#new_file').click();
+            }
+                 },
                  Cancel: function() {
                    $('#upload-collation-dialog').dialog('close');
                  }