From b80ad248f91e28bf0efcab82ad141ea43efdcfb3 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Mon, 18 Feb 2008 23:44:17 +0000 Subject: [PATCH] Fixed to make progress bar and download link work properly in IE 6 and 7. --- controller/Files.py | 6 ++++-- model/File.py | 2 -- static/js/Wiki.js | 27 ++++++++++++++------------- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/controller/Files.py b/controller/Files.py index a4418bc..2544bba 100644 --- a/controller/Files.py +++ b/controller/Files.py @@ -147,6 +147,8 @@ class FieldStorage( cherrypy._cpcgifs.FieldStorage ): except ValueError: raise Upload_error( "The file_id is invalid." ) + self.filename = self.filename.split( "/" )[ -1 ].split( "\\" )[ -1 ].strip() + if not self.filename: raise Upload_error( "Please provide a filename." ) @@ -164,7 +166,7 @@ class FieldStorage( cherrypy._cpcgifs.FieldStorage ): if existing_file: existing_file.close() - upload_file = Upload_file( file_id, self.filename.strip(), content_length ) + upload_file = Upload_file( file_id, self.filename, content_length ) current_uploads_lock.acquire() try: @@ -232,9 +234,9 @@ class Files( object ): db_file = self.__database.load( File, file_id ) + cherrypy.response.headerMap[ u"Content-Type" ] = db_file.content_type cherrypy.response.headerMap[ u"Content-Disposition" ] = u"attachment; filename=%s" % db_file.filename cherrypy.response.headerMap[ u"Content-Length" ] = db_file.size_bytes - cherrypy.response.headerMap[ u"Content-Type" ] = db_file.content_type def stream(): CHUNK_SIZE = 8192 diff --git a/model/File.py b/model/File.py index 5b5b961..29a3c2a 100644 --- a/model/File.py +++ b/model/File.py @@ -1,6 +1,4 @@ from Persistent import Persistent, quote -from psycopg2 import Binary -from StringIO import StringIO class File( Persistent ): diff --git a/static/js/Wiki.js b/static/js/Wiki.js index 6cc95a2..fa378c5 100644 --- a/static/js/Wiki.js +++ b/static/js/Wiki.js @@ -2260,6 +2260,17 @@ function Upload_pulldown( wiki, notebook_id, invoker, editor ) { connect( this.iframe, "onload", function ( event ) { self.init_frame(); } ); appendChildNodes( this.div, this.iframe ); + + this.progress_iframe = createDOM( "iframe", { + "frameBorder": "0", + "scrolling": "no", + "id": "progress_frame", + "name": "progress_frame", + "class": "upload_frame" + } ); + addElementClass( this.progress_iframe, "undisplayed" ); + + appendChildNodes( this.div, this.progress_iframe ); } Upload_pulldown.prototype = new function () { this.prototype = Pulldown.prototype; }; @@ -2282,7 +2293,6 @@ Upload_pulldown.prototype.upload_started = function ( file_id, filename ) { this.file_id = file_id; // make the upload iframe invisible but still present so that the upload continues - addElementClass( this.iframe, "invisible" ); setElementDimensions( this.iframe, { "h": "0" } ); // get the basename of the file @@ -2295,24 +2305,15 @@ Upload_pulldown.prototype.upload_started = function ( file_id, filename ) { if ( link_title( this.link ) == "" ) replaceChildNodes( this.link, this.editor.document.createTextNode( filename ) ); - // FIXME: this call might occur before upload() is even called - var progress_iframe = createDOM( "iframe", { - "src": "/files/progress?file_id=" + file_id + "&filename=" + escape( filename ), - "frameBorder": "0", - "scrolling": "no", - "id": "progress_frame", - "name": "progress_frame", - "class": "upload_frame" - } ); - - appendChildNodes( this.div, progress_iframe ); + removeElementClass( this.progress_iframe, "undisplayed" ); + frames[ "progress_frame" ].location.href = "/files/progress?file_id=" + file_id + "&filename=" + escape( filename ); } Upload_pulldown.prototype.upload_complete = function () { // now that the upload is done, the file link should point to the uploaded file + // FIXME: this may kill the text cursor in IE 7 this.link.href = "/files/download?file_id=" + this.file_id -// FIXME: the upload pulldown is sometimes being closed here before the upload is complete, thereby truncating the upload new File_link_pulldown( this.wiki, this.notebook_id, this.invoker, this.editor, this.link ); this.shutdown(); }