Index: trunk/extensions/MetavidWiki/skins/mv_embed/libAddMedia/mvUploader.js |
— | — | @@ -15,8 +15,14 @@ |
16 | 16 | "wgfogg_waring_ogg_upload": "You have selected an ogg file for conversion to ogg (this is probably unnessesary). Maybe disable the video converter?", |
17 | 17 | "wgfogg_waring_bad_extension" : "You have selected a file with an unsuported extension. <a href=\"http://commons.wikimedia.org/wiki/Commons:Firefogg#Supported_File_Types\">More help</a>", |
18 | 18 | "upload-stats-fileprogres": "$1 of $2", |
19 | | - "mv_upload_done" : "Your upload <i>should be<\/i> accessible <a href=\"$1\">here<\/a>", |
20 | | - "mv_upload_completed" : "Upload Completed" |
| 19 | + "mv_upload_done" : "Your upload <i>should be<\/i> accessible <a href=\"$1\">here<\/a>", |
| 20 | + |
| 21 | + "successfulupload" : 'Successful upload', |
| 22 | + "uploaderror" : "Upload error", |
| 23 | + "uploadwarning": "Upload warning", |
| 24 | + "unknown-error": "Unknown Error", |
| 25 | + "return-to-form": "Return to form" |
| 26 | + |
21 | 27 | }); |
22 | 28 | |
23 | 29 | var default_upload_options = { |
— | — | @@ -106,11 +112,12 @@ |
107 | 113 | var intFirefoggObj = ( this.on_upload_page )? |
108 | 114 | {'upload_done_action':'redirect'}: |
109 | 115 | {'upload_done_action':function( rTitle ){ |
110 | | - js_log('add_done_action callback for uploader'); |
| 116 | + js_log( 'add_done_action callback for uploader' ); |
111 | 117 | //call the parent insert resource preview |
112 | 118 | _this.upload_done_action( rTitle ); |
113 | 119 | } |
114 | 120 | }; |
| 121 | + |
115 | 122 | if( _this.api_url ) |
116 | 123 | intFirefoggObj['api_url'] = _this.api_url; |
117 | 124 | |
— | — | @@ -192,15 +199,12 @@ |
193 | 200 | //error in org submit return false; |
194 | 201 | return false; |
195 | 202 | } |
196 | | - } |
197 | | - |
| 203 | + } |
198 | 204 | //check for post action override: |
199 | 205 | if( _this.form_post_override ){ |
200 | 206 | //alert('woudld submit here'); |
201 | 207 | return true; |
202 | | - } |
203 | | - |
204 | | - |
| 208 | + } |
205 | 209 | //get the input form data in flat json: |
206 | 210 | var tmpAryData = $j( _this.editForm ).serializeArray(); |
207 | 211 | for(var i=0; i < tmpAryData.length; i++){ |
— | — | @@ -214,8 +218,7 @@ |
215 | 219 | //for some unknown reason we have to drop down the #p-search z-index: |
216 | 220 | $j('#p-search').css('z-index', 1); |
217 | 221 | |
218 | | - //select upload mode: |
219 | | - |
| 222 | + //select upload mode: |
220 | 223 | _this.detectUploadMode(); |
221 | 224 | |
222 | 225 | //don't submit the form we will do the post in ajax |
— | — | @@ -334,7 +337,8 @@ |
335 | 338 | }else{ |
336 | 339 | var apiResult = JSON.parse ( data.upload['apiUploadResult'] ) ; |
337 | 340 | _this.processApiResult( apiResult ); |
338 | | - } |
| 341 | + } |
| 342 | + return ; |
339 | 343 | } |
340 | 344 | |
341 | 345 | //@@ else update status: |
— | — | @@ -358,12 +362,39 @@ |
359 | 363 | } |
360 | 364 | uploadStatus(); |
361 | 365 | }, |
362 | | - processApiResult: function( apiResult ){ |
363 | | - if(apiResult['descriptionurl']) |
364 | | - _this.updateUploadDone( apiResult['descriptionurl'] ); |
| 366 | + processApiResult: function( apiRes ){ |
| 367 | + var _this = this; |
| 368 | + //check for error |
| 369 | + if( apiRes.upload.result == "Failure" ){ |
| 370 | + //error space is too large so we don't front load it |
| 371 | + //do a remote call to get the error msg: |
| 372 | + if(apiRes.upload.error != "unknown-error"){ |
| 373 | + gMsgLoadRemote(apiRes.upload.error, function(msg){ |
| 374 | + _this.updateUploadError( gM( apiRes.upload.error )); |
| 375 | + }); |
| 376 | + }else{ |
| 377 | + _this.updateUploadError( gM('unknown-error')); |
| 378 | + } |
| 379 | + }else if( apiRes.upload.imageinfo && apiRes.upload.imageinfo.descriptionurl ){ |
| 380 | + _this.updateUploadDone( apiRes.upload.imageinfo.descriptionurl ); |
| 381 | + }else{ |
| 382 | + //nothing fits assume unkown error: |
| 383 | + _this.updateUploadError( gM('unknown-error')); |
| 384 | + } |
| 385 | + |
365 | 386 | }, |
| 387 | + updateUploadError:function( msg ){ |
| 388 | + $j( '#dlbox-centered' ).html( '<h3>' + gM('uploaderror') + '</h3>' + |
| 389 | + msg + '<p>' + |
| 390 | + '<a id="mv-return-to-form" href="#" >' + gM('return-to-form') + '</a>'); |
| 391 | + $j('#mv-return-to-form').click(function(){ |
| 392 | + //hide / close up shop |
| 393 | + $j('#dlbox-overlay,#dlbox-centered').hide(); |
| 394 | + return false; |
| 395 | + }); |
| 396 | + }, |
366 | 397 | updateUploadDone:function(url){ |
367 | | - $j( '#dlbox-centered' ).html( '<h3>' + gM('mv_upload_completed') + '</h3>' + |
| 398 | + $j( '#dlbox-centered' ).html( '<h3>' + gM('successfulupload') + '</h3>' + |
368 | 399 | gM( 'mv_upload_done', url) ); |
369 | 400 | }, |
370 | 401 | getProgressTitle:function(){ |
— | — | @@ -378,24 +409,23 @@ |
379 | 410 | }, |
380 | 411 | dispProgressOverlay:function(){ |
381 | 412 | var _this = this; |
382 | | - //add in loader dl box if not present: |
383 | | - if( $j('#dlbox-centered').length ==0 ){ |
384 | | - //hard code style (since not always easy to import style sheets) |
385 | | - $j('body').append('<div id="dlbox-centered" class="dlbox-centered" style="'+ |
386 | | - 'position:fixed;background:#DDD;border:3px solid #AAA;font-size:115%;width:40%;'+ |
387 | | - 'height:300px;padding: 10px;z-index:100;top:100px;bottom:40%;left:20%;" >'+ |
388 | | - '<h5>' + _this.getProgressTitle() + '</h5>' + |
389 | | - '<div id="up-pbar-container" style="border:solid thin gray;width:90%;height:15px;" >' + |
390 | | - '<div id="up-progressbar" style="background:#AAC;width:0%;height:15px;"></div>' + |
391 | | - '</div>' + |
392 | | - '<span id="up-pstatus">0% - </span> ' + |
393 | | - '<span id="up-status-state">' + gM('uploaded-status') + '</span> ' + |
394 | | - '<span id="upload-stats-fileprogres"></span>'+ |
395 | | - '</div>' + |
396 | | - '<div id="dlbox-overlay" class="dlbox-overlay" style="background:#000;cursor:wait;height:100%;'+ |
397 | | - 'left:0;top:0;position:fixed;width:100%;z-index:99;filter:alpha(opacity=60);'+ |
398 | | - '-moz-opacity: 0.6; opacity: 0.6;" ></div>'); |
399 | | - } |
| 413 | + //remove old instance: |
| 414 | + $j('#dlbox-centered,#dlbox-overlay').remove(); |
| 415 | + //hard code style (since not always easy to import style sheets) |
| 416 | + $j('body').append('<div id="dlbox-centered" class="dlbox-centered" style="'+ |
| 417 | + 'position:fixed;background:#DDD;border:3px solid #AAA;font-size:115%;width:40%;'+ |
| 418 | + 'height:300px;padding: 10px;z-index:100;top:100px;bottom:40%;left:20%;" >'+ |
| 419 | + '<h5>' + _this.getProgressTitle() + '</h5>' + |
| 420 | + '<div id="up-pbar-container" style="border:solid thin gray;width:90%;height:15px;" >' + |
| 421 | + '<div id="up-progressbar" style="background:#AAC;width:0%;height:15px;"></div>' + |
| 422 | + '</div>' + |
| 423 | + '<span id="up-pstatus">0% - </span> ' + |
| 424 | + '<span id="up-status-state">' + gM('uploaded-status') + '</span> ' + |
| 425 | + '<span id="upload-stats-fileprogres"></span>'+ |
| 426 | + '</div>' + |
| 427 | + '<div id="dlbox-overlay" class="dlbox-overlay" style="background:#000;cursor:wait;height:100%;'+ |
| 428 | + 'left:0;top:0;position:fixed;width:100%;z-index:99;filter:alpha(opacity=60);'+ |
| 429 | + '-moz-opacity: 0.6; opacity: 0.6;" ></div>'); |
400 | 430 | } |
401 | 431 | |
402 | 432 | } |
\ No newline at end of file |
Index: trunk/extensions/MetavidWiki/skins/mv_embed/mv_embed.js |
— | — | @@ -138,6 +138,37 @@ |
139 | 139 | return '[' + key + ']'; |
140 | 140 | } |
141 | 141 | } |
| 142 | +/* |
| 143 | + * msgSet is either a string corresponding to a single msg to load |
| 144 | + * or msgSet is an array with set of msg to load |
| 145 | + */ |
| 146 | +function gMsgLoadRemote(msgSet, callback){ |
| 147 | + var ammessages = ''; |
| 148 | + if(typeof msgSet == 'object' ){ |
| 149 | + for(var i in msgSet){ |
| 150 | + ammessages += msgSet[i]; |
| 151 | + } |
| 152 | + }else if(typeof msgSet == 'string'){ |
| 153 | + ammessages += msgSet; |
| 154 | + } |
| 155 | + if(ammessages=='') |
| 156 | + return js_log('gMsgLoadRemote::no msg set requested'); |
| 157 | + |
| 158 | + do_api_req({ |
| 159 | + 'data':{'meta':'allmessages', 'ammessages':ammessages} |
| 160 | + },function(data){ |
| 161 | + if(data.query.allmessages){ |
| 162 | + var msgs = data.query.allmessages; |
| 163 | + for(var i in msgs){ |
| 164 | + var ld = {}; |
| 165 | + ld[ msgs[i]['name'] ] = msgs[i]['*']; |
| 166 | + loadGM( ld ); |
| 167 | + } |
| 168 | + } |
| 169 | + //load the result into local msg var |
| 170 | + callback(); |
| 171 | + }); |
| 172 | +} |
142 | 173 | |
143 | 174 | /** |
144 | 175 | * Format a size in bytes for output, using an appropriate |
— | — | @@ -784,6 +815,10 @@ |
785 | 816 | //force format to json (if not already set) |
786 | 817 | options.data['format'] = 'json'; |
787 | 818 | |
| 819 | + //if action not set assume query |
| 820 | + if(!options.data['action']) |
| 821 | + options.data['action']='query'; |
| 822 | + |
788 | 823 | js_log('do api req: ' + options.url +'?' + jQuery.param(options.data) ); |
789 | 824 | //build request string: |
790 | 825 | if( parseUri( document.URL ).host == parseUri( options.url ).host ){ |