@@ -5,12 +5,6 @@ var bridge = function (presenterPath) {
55bridge . prototype = new window . rhubarb . viewBridgeClasses . SimpleHtmlFileUploadViewBridge ( ) ;
66bridge . prototype . constructor = bridge ;
77
8- bridge . prototype . onStateLoaded = function ( ) {
9- if ( ! this . model . MaxFileSize ) {
10- this . model . MaxFileSize = 5 * 1024 * 1024 ;
11- }
12- } ;
13-
148bridge . prototype . supportsHtml5Uploads = function ( ) {
159 var xhr = new XMLHttpRequest ( ) ;
1610
@@ -49,7 +43,12 @@ bridge.prototype.filesSelected = function (files) {
4943 var self = this ;
5044
5145 for ( var i = 0 , file ; file = files [ i ] ; i ++ ) {
52- var uploadFunction = function ( file ) {
46+ if ( this . model . MaxFileSize && file . size > this . model . MaxFileSize ) {
47+ this . onUploadFailed ( file . name + ' is over the maximum file size of ' + this . formatBytes ( this . model . MaxFileSize , 0 ) ) ;
48+ continue ;
49+ }
50+
51+ var uploadFile = function ( file ) {
5352 self . sendFileAsServerEvent ( "FileUploadedXhr" , file , function ( e ) {
5453 var progress =
5554 {
@@ -132,6 +131,22 @@ bridge.prototype.onUploadComplete = function (progressIndicator) {
132131 } , 3000 ) ;
133132} ;
134133
134+ bridge . prototype . onUploadFailed = function ( message ) {
135+ var upiDom = document . createElement ( "div" ) ;
136+ upiDom . className = "upload-failed" ;
137+
138+ var upiLabel = document . createElement ( "label" ) ;
139+ upiLabel . innerHTML = message ;
140+
141+ upiDom . appendChild ( upiLabel ) ;
142+
143+ this . attachUploadProgressIndicator ( upiDom ) ;
144+
145+ setTimeout ( function ( ) {
146+ upiDom . parentNode . removeChild ( upiDom ) ;
147+ } , 3000 ) ;
148+ } ;
149+
135150bridge . prototype . addClass = function ( nodes , className ) {
136151 if ( ! nodes . length ) {
137152 nodes = [ nodes ] ;
@@ -157,4 +172,14 @@ bridge.prototype.removeClass = function (nodes, className) {
157172 }
158173} ;
159174
160- window . rhubarb . viewBridgeClasses . MultipleHtmlFileUploadViewBridge = bridge ;
175+ bridge . prototype . formatBytes = function ( bytes , decimals ) {
176+ if ( bytes == 0 ) {
177+ return '0B' ;
178+ }
179+ var k = 1000 ;
180+ var sizes = [ 'B' , 'KB' , 'MB' , 'GB' , 'TB' , 'PB' , 'EB' , 'ZB' , 'YB' ] ;
181+ var i = Math . floor ( Math . log ( bytes ) / Math . log ( k ) ) ;
182+ return parseFloat ( ( bytes / Math . pow ( k , i ) ) . toFixed ( decimals ) ) + sizes [ i ] ;
183+ } ;
184+
185+ window . rhubarb . viewBridgeClasses . MultipleHtmlFileUploadViewBridge = bridge ;
0 commit comments