Working "cancel" button during upload.
This commit is contained in:
parent
1bb6b4fcb0
commit
362a125b1b
|
@ -174,6 +174,8 @@ class Files( object ):
|
|||
</div></td>
|
||||
<td></td>
|
||||
<td><span id="status"></span></td>
|
||||
<td></td>
|
||||
<td><input type="submit" id="cancel_button" class="button" value="cancel" onclick="withDocument( window.parent.document, function () { getElement( 'upload_frame' ).pulldown.shutdown(); } );" /></td>
|
||||
</tr></table>
|
||||
<script type="text/javascript">
|
||||
function tick( fraction ) {
|
||||
|
@ -181,7 +183,7 @@ class Files( object ):
|
|||
"progress_bar",
|
||||
{ "w": %s * fraction }, "em"
|
||||
);
|
||||
if ( fraction == 1.0 )
|
||||
if ( fraction >= 1.0 )
|
||||
replaceChildNodes( "status", "100%%" );
|
||||
else
|
||||
replaceChildNodes( "status", Math.floor( fraction * 100.0 ) + "%%" );
|
||||
|
@ -189,7 +191,6 @@ class Files( object ):
|
|||
</script>
|
||||
""" % ( cgi.escape( base_filename ), progress_bar, progress_width_em )
|
||||
|
||||
import time
|
||||
while True:
|
||||
chunk = upload.file.read( CHUNK_SIZE )
|
||||
if not chunk: break
|
||||
|
@ -197,9 +198,10 @@ class Files( object ):
|
|||
fraction_done = float( progress_bytes ) / float( file_size )
|
||||
|
||||
if fraction_done > fraction_reported + tick_increment:
|
||||
yield '<script type="text/javascript">tick(%s)</script>;' % fraction_reported
|
||||
yield '<script type="text/javascript">tick(%s);</script>' % fraction_reported
|
||||
fraction_reported += tick_increment
|
||||
time.sleep(0.025) # TODO: removeme
|
||||
import time
|
||||
time.sleep(0.05) # TODO: removeme
|
||||
|
||||
# TODO: write to the database
|
||||
|
||||
|
@ -209,11 +211,10 @@ class Files( object ):
|
|||
|
||||
# the file finished uploading, so fill out the progress meter to 100%
|
||||
if fraction_reported < 1.0:
|
||||
yield '<script type="text/javascript">tick(1.0)</script>;'
|
||||
yield '<script type="text/javascript">tick(1.0);</script>'
|
||||
|
||||
yield \
|
||||
u"""
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
|
|
|
@ -18,6 +18,10 @@ div {
|
|||
font-weight: bold;
|
||||
}
|
||||
|
||||
.text_field {
|
||||
border: #999999 1px solid;
|
||||
}
|
||||
|
||||
.button {
|
||||
border-style: outset;
|
||||
border-width: 0px;
|
||||
|
|
|
@ -2240,6 +2240,7 @@ function Upload_pulldown( wiki, notebook_id, invoker, editor ) {
|
|||
"id": "upload_frame",
|
||||
"name": "upload_frame"
|
||||
} );
|
||||
this.iframe.pulldown = this;
|
||||
|
||||
var self = this;
|
||||
connect( this.iframe, "onload", function ( event ) { self.init_frame(); } );
|
||||
|
@ -2280,6 +2281,9 @@ Upload_pulldown.prototype.shutdown = function () {
|
|||
Pulldown.prototype.shutdown.call( this );
|
||||
this.wiki.up_image_button( "attachFile" );
|
||||
|
||||
var self = this;
|
||||
withDocument( this.editor.document, function () { removeElement( self.link ); } );
|
||||
|
||||
disconnectAll( this.file_input );
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ class Upload_page( Html ):
|
|||
Body(
|
||||
Form(
|
||||
Span( u"attach file: ", class_ = u"field_label" ),
|
||||
Input( type = u"file", id = u"file", name = u"file", size = u"30" ),
|
||||
Input( type = u"file", id = u"file", name = u"file", class_ = "text_field", size = u"30" ),
|
||||
Input( type = u"submit", id = u"upload_button", class_ = u"button", value = u"upload" ),
|
||||
Input( type = u"hidden", id = u"notebook_id", name = u"notebook_id", value = notebook_id ),
|
||||
Input( type = u"hidden", id = u"note_id", name = u"note_id", value = note_id ),
|
||||
|
|
Reference in New Issue