Index: branches/js2-work/phase3/js/mwEmbed/modules/UploadWizard/mw.UploadWizard.js |
— | — | @@ -1,13 +1,13 @@ |
2 | 2 | mw.addMessages( { |
3 | 3 | 'mwe-upwiz-tab-file': 'Step 1', |
4 | | - 'mwe-upwiz-tab-metadata': 'Step 2', |
| 4 | + 'mwe-upwiz-tab-details': 'Step 2', |
5 | 5 | 'mwe-upwiz-tab-thanks': 'Step 3', |
6 | 6 | 'mwe-upwiz-intro': 'Introductory text (short)', |
7 | 7 | 'mwe-upwiz-select-files': 'Select files:', |
8 | 8 | 'mwe-upwiz-add-file-n': 'Add another file', |
9 | 9 | 'mwe-upwiz-add-file-0': 'Add a file', |
10 | 10 | 'mwe-upwiz-browse': 'Browse...', |
11 | | - 'mwe-upwiz-completed': 'OK', |
| 11 | + 'mwe-upwiz-transported': 'OK', |
12 | 12 | 'mwe-upwiz-click-here': 'Click here to select a file', |
13 | 13 | 'mwe-upwiz-uploading': 'uploading...', |
14 | 14 | 'mwe-upwiz-remove-upload': 'Remove this file from the list of files to upload', |
— | — | @@ -16,7 +16,7 @@ |
17 | 17 | 'mwe-upwiz-upload-count': '$1 of $2 files uploaded', |
18 | 18 | 'mwe-upwiz-progressbar-uploading': 'uploading', |
19 | 19 | 'mwe-upwiz-remaining': '$1 remaining', |
20 | | - 'mwe-upwiz-intro-metadata': 'Thank you for uploading your works! Now we need some basic information in order to complete your upload.', |
| 20 | + 'mwe-upwiz-intro-details': 'Thank you for uploading your works! Now we need some basic information in order to complete your upload.', |
21 | 21 | 'mwe-upwiz-provenance-ownwork': 'They are entirely your own work.', |
22 | 22 | 'mwe-upwiz-provenance-ownwork-assert': 'I, $1, the copyright holder of this work, hereby grant anyone the right to use these works for any purpose, as long as they credit me and share derivative work under the same terms.', |
23 | 23 | 'mwe-upwiz-provenance-ownwork-assert-note': 'This means you release your work under a double Creative Commons Attribution ShareAlike and GFDL license.', |
— | — | @@ -64,7 +64,89 @@ |
65 | 65 | } ); |
66 | 66 | |
67 | 67 | |
| 68 | +/** |
| 69 | + * Represents the upload -- in its local and remote state. (Possibly those could be separate objects too...) |
| 70 | + * This is our 'model' object if we are thinking MVC. Needs to be better factored, lots of feature envy with the UploadWizard |
| 71 | + */ |
| 72 | +mw.UploadWizardUpload = function() { |
| 73 | + var _this = this; |
| 74 | + _this._thumbnails = {}; |
| 75 | + _this.imageinfo = {}; |
| 76 | +}; |
68 | 77 | |
| 78 | +mw.UploadWizardUpload.prototype = { |
| 79 | + /** |
| 80 | + * Accept the result from a successful API upload transport, and fill our own info |
| 81 | + * |
| 82 | + * @param result The JSON object from a successful API upload result. |
| 83 | + */ |
| 84 | + extractImageInfo: function( result ) { |
| 85 | + var _this = this; |
| 86 | + |
| 87 | + _this.filename = result.upload.filename; |
| 88 | + _this.title = "File:" + _this.filename; |
| 89 | + |
| 90 | + for (var key in result.upload.imageinfo) { |
| 91 | + _this.imageinfo[key] = result.upload.imageinfo[key]; |
| 92 | + } |
| 93 | + }, |
| 94 | + |
| 95 | + /** |
| 96 | + * Supply information to create a thumbnail for this Upload. Runs async, with a callback. |
| 97 | + * It is assumed you don't call this until it's been transported. |
| 98 | + * |
| 99 | + * XXX should check if we really need this second API call or if we can get MediaWiki to make us a thumbnail URL upon upload |
| 100 | + * |
| 101 | + * @param width - desired width of thumbnail (height will scale to match) |
| 102 | + * @param callback - callback to execute once thumbnail has been obtained -- must accept object with properties of width, height, and url. |
| 103 | + */ |
| 104 | + getThumbnail: function( width, callback ) { |
| 105 | + var _this = this; |
| 106 | + if ( _this._thumbnails[ "width" + width ] !== undefined ) { |
| 107 | + callback( _this.thumbnails[ "width" + width ] ); |
| 108 | + return; |
| 109 | + } |
| 110 | + |
| 111 | + var apiUrl = mw.getLocalApiUrl(); |
| 112 | + |
| 113 | + var params = { |
| 114 | + 'titles': _this.title, |
| 115 | + 'iiurlwidth': width, |
| 116 | + 'prop': 'imageinfo', |
| 117 | + 'iiprop': 'url' |
| 118 | + }; |
| 119 | + |
| 120 | + mw.getJSON( apiUrl, params, function( data ) { |
| 121 | + if ( !data || !data.query || !data.query.pages ) { |
| 122 | + mw.log(" No data? ") |
| 123 | + // XXX do something about the thumbnail spinner, maybe call the callback with a broken image. |
| 124 | + return; |
| 125 | + } |
| 126 | + |
| 127 | + if ( data.query.pages[-1] ) { |
| 128 | + // XXX do something about the thumbnail spinner, maybe call the callback with a broken image. |
| 129 | + return; |
| 130 | + } |
| 131 | + for ( var page_id in data.query.pages ) { |
| 132 | + var page = data.query.pages[ page_id ]; |
| 133 | + if ( ! page.imageinfo ) { |
| 134 | + // not found? error |
| 135 | + } else { |
| 136 | + var imageInfo = page.imageinfo[0]; |
| 137 | + var thumbnail = { |
| 138 | + width: imageInfo.thumbwidth, |
| 139 | + height: imageInfo.thumbheight, |
| 140 | + url: imageInfo.url |
| 141 | + } |
| 142 | + _this._thumbnails[ "width" + width ] = thumbnail; |
| 143 | + callback( thumbnail ); |
| 144 | + } |
| 145 | + } |
| 146 | + } ); |
| 147 | + |
| 148 | + } |
| 149 | +}; |
| 150 | + |
69 | 151 | /** |
70 | 152 | * Create an interface fragment corresponding to a file input, suitable for Upload Wizard. |
71 | 153 | * @param filenameAcceptedCb Execute if good filename entered into this interface; useful for knowing if we're ready to upload |
— | — | @@ -105,7 +187,7 @@ |
106 | 188 | .append( _this.errorDiv ); |
107 | 189 | |
108 | 190 | // _this.progressBar = ( no progress bar for individual uploads yet ) |
109 | | - // add a metadata thing to metadata |
| 191 | + // add a details thing to details |
110 | 192 | }; |
111 | 193 | |
112 | 194 | mw.UploadWizardUploadInterface.prototype = { |
— | — | @@ -141,14 +223,14 @@ |
142 | 224 | }, |
143 | 225 | |
144 | 226 | /** |
145 | | - * Execute when this upload is completed; cleans up interface. |
| 227 | + * Execute when this upload is transported; cleans up interface. |
146 | 228 | * @param result AJAx result object |
147 | 229 | */ |
148 | | - completed: function( result ) { |
| 230 | + transported: function( result ) { |
149 | 231 | var _this = this; |
150 | 232 | $j( _this.progressMessage ).removeClass( 'mwe-upwiz-status-progress' ) |
151 | | - .addClass( 'mwe-upwiz-status-completed' ) |
152 | | - .html( gM( 'mwe-upwiz-completed' ) ); |
| 233 | + .addClass( 'mwe-upwiz-status-transported' ) |
| 234 | + .html( gM( 'mwe-upwiz-transported' ) ); |
153 | 235 | }, |
154 | 236 | |
155 | 237 | /** |
— | — | @@ -276,7 +358,7 @@ |
277 | 359 | }; |
278 | 360 | |
279 | 361 | /** |
280 | | - * Object that represents an indvidual language description, in the metadata portion of Upload Wizard |
| 362 | + * Object that represents an indvidual language description, in the details portion of Upload Wizard |
281 | 363 | * @param languageCode |
282 | 364 | */ |
283 | 365 | mw.UploadWizardDescription = function( languageCode ) { |
— | — | @@ -313,26 +395,31 @@ |
314 | 396 | }; |
315 | 397 | |
316 | 398 | /** |
317 | | - * Object that represents the Metadata (step 2) portion of the UploadWizard |
| 399 | + * Object that represents the Details (step 2) portion of the UploadWizard |
| 400 | + * n.b. each upload gets its own details. |
| 401 | + * |
| 402 | + * @param UploadWizardUpload |
318 | 403 | * @param containerDiv The div to put the interface into |
319 | 404 | */ |
320 | | -mw.UploadWizardMetadata = function( containerDiv ) { |
| 405 | +mw.UploadWizardDetails = function( upload, containerDiv ) { |
321 | 406 | |
322 | 407 | var _this = this; |
| 408 | + _this.upload = upload; |
| 409 | + |
323 | 410 | _this.descriptions = []; |
324 | 411 | |
325 | | - _this.div = $j( '<div class="mwe-upwiz-metadata-file"></div>' ); |
| 412 | + _this.div = $j( '<div class="mwe-upwiz-details-file"></div>' ); |
326 | 413 | |
327 | 414 | _this.macroDiv = $j( '<div class="mwe-upwiz-macro"></div>' ) |
328 | 415 | .append( $j( '<input type="submit" value="test edit"/>' ).click( function( ) { _this.submit( ) } )); |
329 | 416 | |
330 | 417 | _this.thumbnailDiv = $j( '<div class="mwe-upwiz-thumbnail"></div>' ); |
331 | 418 | |
332 | | - _this.errorDiv = $j( '<div class="mwe-upwiz-metadata-error"></div>' ); |
| 419 | + _this.errorDiv = $j( '<div class="mwe-upwiz-details-error"></div>' ); |
333 | 420 | |
334 | | - _this.dataDiv = $j( '<div class="mwe-upwiz-metadata-data"></div>' ); |
| 421 | + _this.dataDiv = $j( '<div class="mwe-upwiz-details-data"></div>' ); |
335 | 422 | |
336 | | - _this.descriptionsDiv = $j( '<div class="mwe-upwiz-metadata-descriptions"></div>' ); |
| 423 | + _this.descriptionsDiv = $j( '<div class="mwe-upwiz-details-descriptions"></div>' ); |
337 | 424 | |
338 | 425 | _this.descriptionAdder = $j( '<a id="mwe-upwiz-desc-add"/>' ) |
339 | 426 | .attr( 'href', '#' ) |
— | — | @@ -340,10 +427,10 @@ |
341 | 428 | .click( function( ) { _this.addDescription( ) } ); |
342 | 429 | |
343 | 430 | _this.descriptionsContainerDiv = |
344 | | - $j( '<div class="mwe-upwiz-metadata-descriptions-container"></div>' ) |
345 | | - .append( $j( '<div class="mwe-upwiz-metadata-descriptions-title">' + gM( 'mwe-upwiz-desc' ) + '</div>' ) ) |
| 431 | + $j( '<div class="mwe-upwiz-details-descriptions-container"></div>' ) |
| 432 | + .append( $j( '<div class="mwe-upwiz-details-descriptions-title">' + gM( 'mwe-upwiz-desc' ) + '</div>' ) ) |
346 | 433 | .append( _this.descriptionsDiv ) |
347 | | - .append( $j( '<div class="mwe-upwiz-metadata-descriptions-add"></div>' ) |
| 434 | + .append( $j( '<div class="mwe-upwiz-details-descriptions-add"></div>' ) |
348 | 435 | .append( _this.descriptionAdder ) ); |
349 | 436 | |
350 | 437 | |
— | — | @@ -383,7 +470,7 @@ |
384 | 471 | |
385 | 472 | }; |
386 | 473 | |
387 | | -mw.UploadWizardMetadata.prototype = { |
| 474 | +mw.UploadWizardDetails.prototype = { |
388 | 475 | |
389 | 476 | /** |
390 | 477 | * Do anything related to a change in the number of descriptions |
— | — | @@ -427,7 +514,7 @@ |
428 | 515 | }, |
429 | 516 | |
430 | 517 | /** |
431 | | - * Display an error with metadata |
| 518 | + * Display an error with details |
432 | 519 | * XXX this is a lot like upload ui's error -- should merge |
433 | 520 | */ |
434 | 521 | error: function() { |
— | — | @@ -475,19 +562,18 @@ |
476 | 563 | * Given the API result pull some info into the form ( for instance, extracted from EXIF, desired filename ) |
477 | 564 | * @param result Upload API result object |
478 | 565 | */ |
479 | | - populateFromResult: function( result ) { |
| 566 | + populate: function() { |
480 | 567 | var _this = this; |
481 | | - var upload = result.upload; |
482 | | - mw.log( "populating from result" ); |
483 | | - _this.setThumbnail( upload.filename, mw.getConfig( 'thumbnailWidth' )); |
484 | | - //_this.setSource( upload. result ); |
| 568 | + mw.log( "populating details from upload" ); |
| 569 | + _this.setThumbnail( mw.getConfig( 'thumbnailWidth' ) ); |
| 570 | + //_this.setDate(); |
| 571 | + |
| 572 | + //_this.setSource(); |
485 | 573 | |
486 | | - //_this.setFilename( upload.filename ); |
| 574 | + //_this.setFilename(); |
487 | 575 | |
488 | | - //_this.setDescription(); // is there anything worthwhile here? image comment? |
489 | | - //_this.setDate( upload.metadata ); |
490 | | - //_this.setLocation( upload.metadata ); // we could be VERY clever with location sensing... |
491 | | - //_this.setAuthor( _this.config.user, upload.exif.Copyright ); |
| 576 | + //_this.setLocation(); // we could be VERY clever with location sensing... |
| 577 | + //_this.setAuthor(); |
492 | 578 | }, |
493 | 579 | |
494 | 580 | /** |
— | — | @@ -495,71 +581,31 @@ |
496 | 582 | * @param filename |
497 | 583 | * @param width |
498 | 584 | */ |
499 | | - setThumbnail: function( filename, width ) { |
| 585 | + setThumbnail: function( width ) { |
500 | 586 | var _this = this; |
501 | 587 | |
502 | | - var callback = function( imageInfo ) { |
503 | | - var thumbnail = $j( '<img class="mwe-upwiz-thumbnail"/>' ).get( 0 ); |
504 | | - thumbnail.width = imageInfo.thumbwidth; |
505 | | - thumbnail.height = imageInfo.thumbheight; |
506 | | - thumbnail.src = imageInfo.thumburl; |
| 588 | + var callback = function( thumbnail ) { |
507 | 589 | // side effect: will replace thumbnail's loadingSpinner |
508 | | - _this.thumbnailDiv.html( thumbnail ); |
| 590 | + _this.thumbnailDiv.html( |
| 591 | + $j('<a>') |
| 592 | + .attr( 'href', _this.upload.imageinfo.descriptionurl ) |
| 593 | + .append( |
| 594 | + $j( '<img/>' ) |
| 595 | + .addClass( "mwe-upwiz-thumbnail" ) |
| 596 | + .attr( 'width', thumbnail.width ) |
| 597 | + .attr( 'height', thumbnail.height ) |
| 598 | + .attr( 'src', thumbnail.url ) ) ); |
509 | 599 | }; |
510 | 600 | |
511 | 601 | _this.thumbnailDiv.loadingSpinner(); |
512 | | - _this.getThumbnail( "File:" + filename, width, callback ); |
| 602 | + _this.upload.getThumbnail( width, callback ); |
513 | 603 | |
514 | 604 | }, |
515 | 605 | |
516 | 606 | /** |
517 | | - * use iinfo to get thumbnail info |
518 | | - * this API method can be used to get a lot of thumbnails at once, but that may not be so useful for us ATM |
519 | | - * this is mostly ripped off from mw.UploadHandler's doDestCheck, but: stripped of UI, does only one, does not check for name collisions. |
520 | | - * @param title - name of the file on mediawiki (e.g. File:Foo.jpg) |
521 | | - * @param width - desired width of thumbnail (height will scale to match) |
522 | | - * @param setThumbnailCb - callback to execute once info has been obtained (for instance, put it into the interface) |
523 | | - * @param apiUrl - where to get your API results |
| 607 | + * Convert entire details for this file into wikiText, which will then be posted to the file |
| 608 | + * @return wikitext representing all details |
524 | 609 | */ |
525 | | - getThumbnail: function( title, width, setThumbnailCb, apiUrl ) { |
526 | | - |
527 | | - if ( apiUrl === undefined ) { |
528 | | - apiUrl = mw.getLocalApiUrl(); |
529 | | - } |
530 | | - |
531 | | - var params = { |
532 | | - 'titles': title, |
533 | | - 'iiurlwidth': width, |
534 | | - 'prop': 'imageinfo', |
535 | | - 'iiprop': 'url|mime|size' |
536 | | - }; |
537 | | - |
538 | | - mw.getJSON( apiUrl, params, function( data ) { |
539 | | - if ( !data || !data.query || !data.query.pages ) { |
540 | | - mw.log(" No data? ") |
541 | | - return; |
542 | | - } |
543 | | - |
544 | | - if ( data.query.pages[-1] ) { |
545 | | - // not found ? error |
546 | | - } |
547 | | - for ( var page_id in data.query.pages ) { |
548 | | - var page = data.query.pages[ page_id ]; |
549 | | - if ( ! page.imageinfo ) { |
550 | | - // not found? error |
551 | | - } else { |
552 | | - var imageInfo = page.imageinfo[0]; |
553 | | - setThumbnailCb( imageInfo ); |
554 | | - } |
555 | | - } |
556 | | - } ); |
557 | | - }, |
558 | | - |
559 | | - |
560 | | - /** |
561 | | - * Convert entire metadata for this file into wikiText, which will then be posted to the file |
562 | | - * @return wikitext representing all metadata |
563 | | - */ |
564 | 610 | getWikiText: function() { |
565 | 611 | var _this = this; |
566 | 612 | wikiText = ''; |
— | — | @@ -623,9 +669,9 @@ |
624 | 670 | // check descriptions |
625 | 671 | |
626 | 672 | // are we changing the name ( moving the file? ) if so, do that first, and the rest of this submission has to become |
627 | | - // a callback when that is completed? |
| 673 | + // a callback when that is transported? |
628 | 674 | |
629 | | - // XXX check state of metadata for okayness ( license selected, at least one desc, sane filename ) |
| 675 | + // XXX check state of details for okayness ( license selected, at least one desc, sane filename ) |
630 | 676 | var wikiText = _this.getWikiText(); |
631 | 677 | mw.log( wikiText ); |
632 | 678 | // do some api call to edit the info |
— | — | @@ -656,12 +702,14 @@ |
657 | 703 | mw.UploadWizard = function() { |
658 | 704 | |
659 | 705 | this.uploadHandlerClass = mw.getConfig('uploadHandlerClass') || this.getUploadHandlerClass(); |
660 | | - this.isCompleted = false; |
| 706 | + this.isTransported = false; |
661 | 707 | |
662 | 708 | this.uploads = []; |
663 | 709 | // leading underline for privacy. DO NOT TAMPER. |
664 | 710 | this._uploadsQueued = []; |
665 | 711 | this._uploadsInProgress = []; |
| 712 | + this._uploadsTransported = []; |
| 713 | + this._uploadsEditingDetails = []; |
666 | 714 | this._uploadsCompleted = []; |
667 | 715 | |
668 | 716 | this.uploadsBeginTime = null; |
— | — | @@ -671,7 +719,7 @@ |
672 | 720 | mw.UploadWizard.prototype = { |
673 | 721 | maxUploads: 10, // XXX get this from config |
674 | 722 | maxSimultaneousUploads: 2, // XXX get this from config |
675 | | - tabs: [ 'file', 'metadata', 'thanks' ], |
| 723 | + tabs: [ 'file', 'details', 'thanks' ], |
676 | 724 | |
677 | 725 | /* |
678 | 726 | // list possible upload handlers in order of preference |
— | — | @@ -719,7 +767,7 @@ |
720 | 768 | '<div id="mwe-upwiz-tabs">' |
721 | 769 | + '<ul>' |
722 | 770 | + '<li id="mwe-upwiz-tab-file">' + gM('mwe-upwiz-tab-file') + '</li>' |
723 | | - + '<li id="mwe-upwiz-tab-metadata">' + gM('mwe-upwiz-tab-metadata') + '</li>' |
| 771 | + + '<li id="mwe-upwiz-tab-details">' + gM('mwe-upwiz-tab-details') + '</li>' |
724 | 772 | + '<li id="mwe-upwiz-tab-thanks">' + gM('mwe-upwiz-tab-thanks') + '</li>' |
725 | 773 | + '</ul>' |
726 | 774 | + '</div>' |
— | — | @@ -742,9 +790,9 @@ |
743 | 791 | + '<div style="clear: left;"></div>' |
744 | 792 | + '</div>' |
745 | 793 | + '</div>' |
746 | | - + '<div id="mwe-upwiz-tabdiv-metadata">' |
747 | | - + '<div id="mwe-upwiz-metadata-macro"></div>' |
748 | | - + '<div id="mwe-upwiz-metadata-files"></div>' |
| 794 | + + '<div id="mwe-upwiz-tabdiv-details">' |
| 795 | + + '<div id="mwe-upwiz-details-macro"></div>' |
| 796 | + + '<div id="mwe-upwiz-details-files"></div>' |
749 | 797 | + '</div>' |
750 | 798 | + '<div id="mwe-upwiz-tabdiv-thanks">' |
751 | 799 | + '<div id="mwe-upwiz-thanks"></div>' |
— | — | @@ -795,7 +843,7 @@ |
796 | 844 | /** |
797 | 845 | * add an Upload |
798 | 846 | * we create the upload interface, a handler to transport it to the server, |
799 | | - * and UI for the upload itself and the "metadata" at the second step of the wizard. |
| 847 | + * and UI for the upload itself and the "details" at the second step of the wizard. |
800 | 848 | * Finally stuff it into an array of uploads. |
801 | 849 | * @return boolean success |
802 | 850 | */ |
— | — | @@ -806,15 +854,10 @@ |
807 | 855 | return false; |
808 | 856 | } |
809 | 857 | |
810 | | - // could (should?) be an object, but so far it doesn't have its own methods really. |
811 | | - // plus, here in UploadWizard, we have additional concepts like metadata... |
812 | | - var upload = {}; |
| 858 | + var upload = new mw.UploadWizardUpload(); |
813 | 859 | |
814 | | - // API |
815 | | - // XXX hardcoded for now. Maybe passed through config or guessed at here. |
816 | | - // upload.api = new mw.UploadApiProcessor( function( result ) { _this.uploadCompleted ); |
| 860 | + // XXX much of the following should be moved to UploadWizardUpload constructor. |
817 | 861 | |
818 | | - |
819 | 862 | // UI |
820 | 863 | // originalFilename is the basename of the file on our file system. This is what we really wanted ( probably ). |
821 | 864 | // the system will upload with a temporary filename and we'll get that back from the API return when we upload |
— | — | @@ -836,18 +879,17 @@ |
837 | 880 | upload.handler.addProgressCb( function( fraction ) { _this.uploadProgress( upload, fraction ) } ); |
838 | 881 | |
839 | 882 | // this is only the UI one, so is the result even going to be there? |
840 | | - upload.handler.addCompletedCb( function( result ) { _this.uploadCompleted( upload, result ) } ); |
| 883 | + upload.handler.addTransportedCb( function( result ) { _this.uploadTransported( upload, result ) } ); |
841 | 884 | |
842 | 885 | // not sure about this...UI only? |
843 | 886 | // this will tell us that at least one of our uploads has had an error -- may change messaging, |
844 | 887 | // like, please fix below |
845 | 888 | upload.handler.addErrorCb( function( error ) { _this.uploadError( upload, error ) } ); |
846 | 889 | |
847 | | - // metadata |
848 | | - upload.metadata = new mw.UploadWizardMetadata( $j( '#mwe-upwiz-metadata-files' )); |
| 890 | + // details |
| 891 | + upload.details = new mw.UploadWizardDetails( upload, $j( '#mwe-upwiz-details-files' )); |
849 | 892 | |
850 | 893 | |
851 | | - |
852 | 894 | _this.uploads.push( upload ); |
853 | 895 | |
854 | 896 | $j( "#mwe-upwiz-files" ).append( upload.ui.div ); |
— | — | @@ -872,7 +914,7 @@ |
873 | 915 | removeUpload: function( upload ) { |
874 | 916 | var _this = this; |
875 | 917 | $j( upload.ui.div ).remove(); |
876 | | - $j( upload.metadata.div ).remove(); |
| 918 | + $j( upload.details.div ).remove(); |
877 | 919 | mw.UploadWizardUtil.removeItem( _this.uploads, upload ); |
878 | 920 | _this.updateFileCounts(); |
879 | 921 | }, |
— | — | @@ -944,7 +986,7 @@ |
945 | 987 | * Uploads must be 'queued' to be considered for uploading |
946 | 988 | * making this another thread of execution, because we want to avoid any race condition |
947 | 989 | * this way, this is the only "thread" that can start uploads |
948 | | - * it may miss a newly completed upload but it will get it eventually |
| 990 | + * it may miss a newly transported upload but it will get it eventually |
949 | 991 | * |
950 | 992 | */ |
951 | 993 | _startUploadsQueued: function() { |
— | — | @@ -971,7 +1013,7 @@ |
972 | 1014 | */ |
973 | 1015 | showProgress: function() { |
974 | 1016 | var _this = this; |
975 | | - if ( _this.isCompleted ) { |
| 1017 | + if ( _this.isTransported ) { |
976 | 1018 | return; |
977 | 1019 | } |
978 | 1020 | |
— | — | @@ -991,7 +1033,7 @@ |
992 | 1034 | |
993 | 1035 | /** |
994 | 1036 | * Show the progress bar for the entire Upload Wizard. |
995 | | - * @param fraction fraction completed (float between 0 and 1) |
| 1037 | + * @param fraction fraction transported (float between 0 and 1) |
996 | 1038 | */ |
997 | 1039 | showProgressBar: function( fraction ) { |
998 | 1040 | $j( '#mwe-upwiz-progress-bar' ).progressbar( 'value', parseInt( fraction * 100 ) ); |
— | — | @@ -1011,15 +1053,15 @@ |
1012 | 1054 | * Calculate remaining time for all uploads to complete. |
1013 | 1055 | * |
1014 | 1056 | * @param beginTime time in whatever unit getTime returns, presume epoch milliseconds |
1015 | | - * @param fractionCompleted fraction completed |
| 1057 | + * @param fractionTransported fraction transported |
1016 | 1058 | * @return time in whatever units getTime() returns; presumed milliseconds |
1017 | 1059 | */ |
1018 | | - getRemainingTime: function ( beginTime, fractionCompleted ) { |
| 1060 | + getRemainingTime: function ( beginTime, fractionTransported ) { |
1019 | 1061 | if ( beginTime ) { |
1020 | 1062 | var elapsedTime = ( new Date() ).getTime() - beginTime; |
1021 | | - if ( fractionCompleted > 0.0 && elapsedTime > 0 ) { // or some other minimums for good data |
1022 | | - var rate = fractionCompleted / elapsedTime; |
1023 | | - return parseInt( ( 1.0 - fractionCompleted ) / rate ); |
| 1063 | + if ( fractionTransported > 0.0 && elapsedTime > 0 ) { // or some other minimums for good data |
| 1064 | + var rate = fractionTransported / elapsedTime; |
| 1065 | + return parseInt( ( 1.0 - fractionTransported ) / rate ); |
1024 | 1066 | } |
1025 | 1067 | } |
1026 | 1068 | return null; |
— | — | @@ -1040,25 +1082,26 @@ |
1041 | 1083 | }, |
1042 | 1084 | |
1043 | 1085 | /** |
1044 | | - * To be executed when an individual upload finishes. Processes the result and updates step 2's metadata |
| 1086 | + * To be executed when an individual upload finishes. Processes the result and updates step 2's details |
1045 | 1087 | * @param upload an Upload object |
1046 | 1088 | * @param result the API result in parsed JSON form |
1047 | 1089 | */ |
1048 | | - uploadCompleted: function( upload, result ) { |
| 1090 | + uploadTransported: function( upload, result ) { |
1049 | 1091 | var _this = this; |
1050 | | - _this._uploadsCompleted.push( upload ); |
| 1092 | + _this._uploadsTransported.push( upload ); |
1051 | 1093 | mw.UploadWizardUtil.removeItem( _this._uploadsInProgress, upload ); |
1052 | 1094 | |
1053 | 1095 | if ( result.upload && result.upload.imageinfo && result.upload.imageinfo.descriptionurl ) { |
1054 | 1096 | // success |
1055 | | - setTimeout( function() { |
1056 | | - upload.metadata.populateFromResult( result ); }, 0 ); |
| 1097 | + _this._uploadsEditingDetails.push( upload ); |
| 1098 | + upload.extractImageInfo( result ); |
| 1099 | + upload.details.populate(); |
1057 | 1100 | |
1058 | 1101 | } else if ( result.upload && result.upload.sessionkey ) { |
1059 | 1102 | // there was a warning - type error which prevented it from adding the result to the db |
1060 | 1103 | if ( result.upload.warnings.duplicate ) { |
1061 | 1104 | var duplicates = result.upload.warnings.duplicate; |
1062 | | - _this.metadata.errorDuplicate( result.upload.sessionkey, duplicates ); |
| 1105 | + _this.details.errorDuplicate( result.upload.sessionkey, duplicates ); |
1063 | 1106 | } |
1064 | 1107 | |
1065 | 1108 | // XXX namespace collision |
— | — | @@ -1072,8 +1115,8 @@ |
1073 | 1116 | |
1074 | 1117 | |
1075 | 1118 | /** |
1076 | | - * Occurs whenever we need to update the interface based on how many files are there or have completed |
1077 | | - * Also detects if all uploads have completed and kicks off the process that eventually gets us to Step 2. |
| 1119 | + * Occurs whenever we need to update the interface based on how many files are there or have transported |
| 1120 | + * Also detects if all uploads have transported and kicks off the process that eventually gets us to Step 2. |
1078 | 1121 | */ |
1079 | 1122 | updateFileCounts: function() { |
1080 | 1123 | mw.log( "update counts" ); |
— | — | @@ -1099,11 +1142,11 @@ |
1100 | 1143 | } |
1101 | 1144 | |
1102 | 1145 | |
1103 | | - $j( '#mwe-upwiz-count' ).html( gM( 'mwe-upwiz-upload-count', [ _this._uploadsCompleted.length, _this.uploads.length ] ) ); |
| 1146 | + $j( '#mwe-upwiz-count' ).html( gM( 'mwe-upwiz-upload-count', [ _this._uploadsTransported.length, _this.uploads.length ] ) ); |
1104 | 1147 | |
1105 | | - if ( _this.uploads.length > 0 && _this._uploadsCompleted.length == _this.uploads.length ) { |
| 1148 | + if ( _this.uploads.length > 0 && _this._uploadsTransported.length == _this.uploads.length ) { |
1106 | 1149 | // is this enough to stop the progress monitor? |
1107 | | - _this.isCompleted = true; |
| 1150 | + _this.isTransported = true; |
1108 | 1151 | // set progress to 100% |
1109 | 1152 | _this.showProgressBar( 1 ); |
1110 | 1153 | _this.showRemainingTime( 0 ); |
— | — | @@ -1112,7 +1155,7 @@ |
1113 | 1156 | // likewise, the remaining time should disappear, fadeout maybe. |
1114 | 1157 | |
1115 | 1158 | // do some sort of "all done" thing for the UI - advance to next tab maybe. |
1116 | | - _this.moveToTab( 'metadata' ); |
| 1159 | + _this.moveToTab( 'details' ); |
1117 | 1160 | } |
1118 | 1161 | |
1119 | 1162 | }, |
— | — | @@ -1139,14 +1182,14 @@ |
1140 | 1183 | /** |
1141 | 1184 | * |
1142 | 1185 | */ |
1143 | | - createMetadata: function() { |
| 1186 | + createDetails: function() { |
1144 | 1187 | |
1145 | 1188 | }, |
1146 | 1189 | |
1147 | 1190 | /** |
1148 | 1191 | * |
1149 | 1192 | */ |
1150 | | - submitMetadata: function() { |
| 1193 | + submitDetails: function() { |
1151 | 1194 | |
1152 | 1195 | }, |
1153 | 1196 | |
Index: branches/js2-work/phase3/js/mwEmbed/modules/UploadWizard/css/uploadWizard.css |
— | — | @@ -154,7 +154,7 @@ |
155 | 155 | background: #ffffe0; |
156 | 156 | } |
157 | 157 | |
158 | | -.mwe-upwiz-metadata-error { |
| 158 | +.mwe-upwiz-details-error { |
159 | 159 | display: none; |
160 | 160 | background: #ffffe0; |
161 | 161 | } |
Index: branches/js2-work/phase3/js/mwEmbed/modules/UploadWizard/mw.ApiUploadHandler.js |
— | — | @@ -17,7 +17,7 @@ |
18 | 18 | |
19 | 19 | var form = _this.ui.form; |
20 | 20 | |
21 | | - _this.completedCallbacks = []; |
| 21 | + _this.transportedCallbacks = []; |
22 | 22 | _this.progressCallbacks = []; |
23 | 23 | _this.errorCallbacks = []; |
24 | 24 | |
— | — | @@ -28,7 +28,7 @@ |
29 | 29 | _this.transport = new mw.IframeTransport( |
30 | 30 | _this.ui.form, |
31 | 31 | function( fraction ){ _this.progress( fraction ) }, |
32 | | - function( result ) { _this.completed( result ) } |
| 32 | + function( result ) { _this.transported( result ) } |
33 | 33 | ); |
34 | 34 | |
35 | 35 | }; |
— | — | @@ -47,9 +47,9 @@ |
48 | 48 | * Allow other parties to register interest in when we finish uploading |
49 | 49 | * @param callback |
50 | 50 | */ |
51 | | - addCompletedCb: function( f ) { |
| 51 | + addTransportedCb: function( f ) { |
52 | 52 | var _this = this; |
53 | | - _this.completedCallbacks.push( f ); |
| 53 | + _this.transportedCallbacks.push( f ); |
54 | 54 | }, |
55 | 55 | |
56 | 56 | /** |
— | — | @@ -144,15 +144,15 @@ |
145 | 145 | }, |
146 | 146 | |
147 | 147 | /** |
148 | | - * Central dispatch function for everyone else interested if we've completed |
| 148 | + * Central dispatch function for everyone else interested if we've transported |
149 | 149 | * @param result javascript object representing MediaWiki API result. |
150 | 150 | */ |
151 | | - completed: function( result ) { |
152 | | - mw.log( "api: upload completed!" ); |
| 151 | + transported: function( result ) { |
| 152 | + mw.log( "api: upload transported!" ); |
153 | 153 | var _this = this; |
154 | | - _this.ui.completed(); |
155 | | - for ( var i = 0; i < _this.completedCallbacks.length; i++ ) { |
156 | | - _this.completedCallbacks[i]( result ); |
| 154 | + _this.ui.transported(); |
| 155 | + for ( var i = 0; i < _this.transportedCallbacks.length; i++ ) { |
| 156 | + _this.transportedCallbacks[i]( result ); |
157 | 157 | } |
158 | 158 | }, |
159 | 159 | |
Index: branches/js2-work/phase3/js/mwEmbed/modules/UploadWizard/mw.IframeTransport.js |
— | — | @@ -4,14 +4,14 @@ |
5 | 5 | * @param form an HTML form |
6 | 6 | * @param progressCb callback to execute when we've started. (does not do float here because iframes can't |
7 | 7 | * monitor fractional progress). |
8 | | - * @param completedCb callback to execute when we've finished the upload |
| 8 | + * @param transportedCb callback to execute when we've finished the upload |
9 | 9 | */ |
10 | | -mw.IframeTransport = function( form, progressCb, completedCb ) { |
| 10 | +mw.IframeTransport = function( form, progressCb, transportedCb ) { |
11 | 11 | var _this = this; |
12 | 12 | |
13 | 13 | _this.form = form; |
14 | 14 | _this.progressCb = progressCb; |
15 | | - _this.completedCb = completedCb; |
| 15 | + _this.transportedCb = transportedCb; |
16 | 16 | |
17 | 17 | _this.iframeId = 'f_' + ( $j( 'iframe' ).length + 1 ); |
18 | 18 | |
— | — | @@ -101,7 +101,7 @@ |
102 | 102 | response = doc; |
103 | 103 | } |
104 | 104 | // Process the API result |
105 | | - _this.completedCb( response ); |
| 105 | + _this.transportedCb( response ); |
106 | 106 | } |
107 | 107 | }; |
108 | 108 | |