From: Tara L Andrews Date: Fri, 31 Aug 2012 21:29:18 +0000 (+0200) Subject: handle file upload server responses X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8c64c9bc539d1ea563c45009610f9c4d4535fe7b;p=scpubgit%2Fstemmatology.git handle file upload server responses --- diff --git a/stemmaweb/root/css/style.css b/stemmaweb/root/css/style.css index ab699a6..ed3b262 100644 --- a/stemmaweb/root/css/style.css +++ b/stemmaweb/root/css/style.css @@ -79,6 +79,9 @@ div.button:hover span { padding-left: 10px; padding-right: 10px; } +#loading_message { + display: none; +} #directory { height: 360px; margin-left: 10px; diff --git a/stemmaweb/root/js/componentload.js b/stemmaweb/root/js/componentload.js index 9c9c848..02cd0fc 100644 --- a/stemmaweb/root/js/componentload.js +++ b/stemmaweb/root/js/componentload.js @@ -5,6 +5,7 @@ function loadTradition( textid, textname, editable ) { if( basepath.lastIndexOf('/') == basepath.length - 1 ) { basepath = basepath.slice( 0, basepath.length - 1) }; + $('#textinfo_load_status').empty(); $('#stemma_graph').empty(); $('#textinfo_waitbox').show(); $('#textinfo_container').ajaxError( @@ -14,7 +15,7 @@ function loadTradition( textid, textname, editable ) { var msg = "An error occurred: "; var msghtml = $('').attr('class', 'error').text( msg + jqxhr.status + " " + jqxhr.statusText); - $("#textinfo_container").append( msghtml ).show(); + $("#textinfo_load_status").append( msghtml ).show(); } } ); diff --git a/stemmaweb/root/js/uploader.js b/stemmaweb/root/js/uploader.js index a4d470c..102b9f1 100644 --- a/stemmaweb/root/js/uploader.js +++ b/stemmaweb/root/js/uploader.js @@ -12,6 +12,12 @@ function limitFiles( up, files ) { $('#upload_button').button('enable'); } +// Utility function to pull the JSON out of the
-wrapped HTML that
+// plupload irritatingly returns.
+function parseResponse( resp ) {
+	return $.parseJSON($(resp).text() );
+}
+
 function create_uploader(upload_url) {
         uploader = new plupload.Uploader({
         runtimes : 'html4',
@@ -44,10 +50,24 @@ function create_uploader(upload_url) {
     uploader.bind('UploadProgress', function(up, file) {
         $upl(file.id).getElementsByTagName('b')[0].innerHTML = '' + file.percent + "%";
     });
+    
+    uploader.bind('Error', function( up, args ) {
+    	$('#upload_status').empty().append(
+    		$('').attr('class', 'error').append( 'A server error occurred' ) );
+    });
+    
 
     uploader.bind('FileUploaded', function(up, file, ret) {
-                   //token = ret.response;
-                   $('#upload-collation-dialog').dialog( 'option', 'buttons').cancel();
+		var result = parseResponse( ret.response );
+		if( result.id ) {
+			$('#upload-collation-dialog').dialog( 'option', 'buttons').cancel();
+			refreshDirectory();
+			loadTradition( result.id, result.name, 1 );
+		} else if( result.error ) {
+			file.status = plupload.FAILED;
+			$('#upload_status').empty().append( 
+				$('').attr('class', 'error').append( result.error ) );
+		}
     });
             
     uploader.init();
diff --git a/stemmaweb/root/src/index.tt b/stemmaweb/root/src/index.tt
index 8256b0a..539ab3b 100644
--- a/stemmaweb/root/src/index.tt
+++ b/stemmaweb/root/src/index.tt
@@ -8,6 +8,8 @@ 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") {
@@ -70,10 +72,7 @@ $(document).ready( function() {
     
     

Text directory

-
-

Loading texts, please wait...

- -
+
[% IF c.user_exists -%]
Add a new text tradition @@ -84,6 +83,7 @@ $(document).ready( function() { Loading tradition info...
+

Text

  • has witnesses:
  • @@ -112,6 +112,11 @@ $(document).ready( function() {
+ +
+

Loading texts, please wait...

+ +