jenkins-bot has submitted this change and it was merged. Change subject: Move updateFileCounts to the upload controller ......................................................................
Move updateFileCounts to the upload controller ...mostly. This method had a lot of step-specific stuff in it, but it's looking much neater now. It'll improve as I move more things out into the Upload step. Change-Id: I5a1be4ae4b4bf42f12fd599b626e5b132ae7ea30 --- M UploadWizardHooks.php M resources/controller/uw.controller.Step.js M resources/controller/uw.controller.Upload.js M resources/mw.UploadWizard.js A resources/ui/uw.ui.Upload.js 5 files changed, 224 insertions(+), 94 deletions(-) Approvals: Gilles: Looks good to me, approved jenkins-bot: Verified diff --git a/UploadWizardHooks.php b/UploadWizardHooks.php index 09a1514..0e15ea0 100644 --- a/UploadWizardHooks.php +++ b/UploadWizardHooks.php @@ -174,14 +174,10 @@ 'mwe-upwiz-tutorial-error-file-missing', 'mwe-upwiz-tutorial-error-cannot-transform', 'mwe-upwiz-help-desk', - 'mwe-upwiz-add-file-n', 'mwe-upwiz-multi-file-select', - 'mwe-upwiz-add-file-0-free', 'mwe-upwiz-flickr-input-placeholder', 'mwe-upwiz-add-flickr-or', 'mwe-upwiz-add-flickr', - 'mwe-upwiz-add-file-flickr', - 'mwe-upwiz-add-file-flickr-n', 'mwe-upwiz-select-flickr', 'mwe-upwiz-flickr-disclaimer1', 'mwe-upwiz-flickr-disclaimer2', @@ -573,8 +569,7 @@ 'dependencies' => array( 'oojs', 'uw.controller.Step', - 'uw.controller.base', - 'uw.ui.Step', + 'uw.ui.Upload', ), ), @@ -616,7 +611,7 @@ 'dependencies' => array( 'oojs', - 'uw.ui.base', + 'uw.ui.Step', ), ), @@ -686,6 +681,24 @@ 'prefs-upwiz-interface', ), ), + + 'uw.ui.Upload' => array( + 'scripts' => array( + 'resources/ui/uw.ui.Upload.js', + ), + + 'dependencies' => array( + 'oojs', + 'uw.ui.Step', + ), + + 'messages' => array( + 'mwe-upwiz-add-file-n', + 'mwe-upwiz-add-file-0-free', + 'mwe-upwiz-add-file-flickr-n', + 'mwe-upwiz-add-file-flickr', + ), + ), ); /** diff --git a/resources/controller/uw.controller.Step.js b/resources/controller/uw.controller.Step.js index b74663d..5cad482 100644 --- a/resources/controller/uw.controller.Step.js +++ b/resources/controller/uw.controller.Step.js @@ -47,7 +47,8 @@ * Move to this step. * @param {mw.UploadWizardUpload[]} uploads List of uploads being carried forward. */ - SP.moveTo = function () { + SP.moveTo = function ( uploads ) { + this.uploads = uploads; this.ui.moveTo(); }; @@ -59,5 +60,10 @@ this.ui.moveFrom(); }; + /** + * Update file counts for the step. + */ + SP.updateFileCounts = function () {}; + uw.controller.Step = Step; }( mediaWiki.uploadWizard, OO ) ); diff --git a/resources/controller/uw.controller.Upload.js b/resources/controller/uw.controller.Upload.js index 3c28068..647e43b 100644 --- a/resources/controller/uw.controller.Upload.js +++ b/resources/controller/uw.controller.Upload.js @@ -16,14 +16,31 @@ */ ( function ( uw, $, oo ) { + var UP; + function Upload() { uw.controller.Step.call( this, - new uw.ui.Step( $( '#mwe-upwiz-stepdiv-file' ), $( '#mwe-upwiz-step-file' ) ) + new uw.ui.Upload() ); } oo.inheritClass( Upload, uw.controller.Step ); + UP = Upload.prototype; + + /** + * Updates the upload step data when a file is added or removed. + */ + UP.updateFileCounts = function ( haveUploads, max, uploadToAdd ) { + var fewerThanMax = this.uploads.length < max; + + this.ui.updateFileCounts( haveUploads, fewerThanMax, uploadToAdd ); + }; + + UP.empty = function () { + this.ui.empty(); + }; + uw.controller.Upload = Upload; }( mediaWiki.uploadWizard, jQuery, OO ) ); diff --git a/resources/mw.UploadWizard.js b/resources/mw.UploadWizard.js index 1c23111..35ef830 100644 --- a/resources/mw.UploadWizard.js +++ b/resources/mw.UploadWizard.js @@ -361,6 +361,8 @@ upload.state = selectedStepName; } ); + this.currentStepObject = targetStep; + if ( callback ) { callback(); } @@ -773,86 +775,16 @@ // First reset the wizard buttons. this.ui.hideFileEndButtons(); - if ( this.uploads.length - this.countEmpties() ) { - // we have uploads ready to go, so allow us to proceed - $( '#mwe-upwiz-upload-ctrl-container' ).show(); - $( '#mwe-upwiz-upload-ctr-divide' ).hide(); - $( '#mwe-upwiz-stepdiv-file .mwe-upwiz-buttons' ).show(); + this.currentStepObject.updateFileCounts( ( this.uploads.length - this.countEmpties() ) > 0, this.maxUploads, this.uploadToAdd ); - if ( mw.UploadWizard.config.enableMultipleFiles === true ) { - // changes the initial centered invitation button to something like "add another file" - this.$addFile = this.$addFile || $( '#mwe-upwiz-add-file' ); - this.$addFile.button( 'option', 'label', mw.message( 'mwe-upwiz-add-file-n' ).escaped() ); - $( '#mwe-upwiz-add-file, #mwe-upwiz-upload-ctrl-flickr' ).addClass( 'mwe-upwiz-add-files-n' ); - this.$addFileContainer = this.$addFileContainer || $( '#mwe-upwiz-add-file-container' ); - this.$addFileContainer.removeClass( 'mwe-upwiz-add-files-0' ); - this.$addFileContainer.show(); - // changes the flickr add button to "add more files from flickr" - $( '#mwe-upwiz-upload-ctrl-flickr' ).button( 'option', 'label', mw.message( 'mwe-upwiz-add-file-flickr-n' ).escaped() ); - // show the add file interface - $( '#mwe-upwiz-add-file-container' ).show(); - // if Flickr uploading is available to this user, show the "add more files from flickr" button - if ( mw.UploadWizard.config.UploadFromUrl && mw.UploadWizard.config.flickrApiKey !== '' ) { - $( '#mwe-upwiz-upload-ctrl-flickr-container' ).show(); - } - // empty the flickr lists - $( '#mwe-upwiz-flickr-select-list' ).empty(); - $( '#mwe-upwiz-flickr-select-list-container' ).unbind(); - $( '#mwe-upwiz-select-flickr' ).unbind(); - } else { - this.$addFile = this.$addFile || $( '#mwe-upwiz-add-file' ); - this.$addFile.hide(); - this.$fileInput = this.$fileInput || $( '.mwe-upwiz-file-input' ); - this.$fileInput.hide(); - $( '#mwe-upwiz-upload-ctrl-flickr-container, #mwe-upwiz-flickr-select-list-container' ).hide(); - } - - // add the styling to the filelist, so it has rounded corners and is visible and all. - $( '#mwe-upwiz-filelist' ).addClass( 'mwe-upwiz-filled-filelist' ); - - // fix the rounded corners on file elements. - // we want them to be rounded only when their edge touched the top or bottom of the filelist. - $( '#mwe-upwiz-filelist .filled .mwe-upwiz-visible-file' ).removeClass( 'ui-corner-top' ).removeClass( 'ui-corner-bottom' ); - $( '#mwe-upwiz-filelist .filled .mwe-upwiz-visible-file:first' ).addClass( 'ui-corner-top' ); - $( '#mwe-upwiz-filelist .filled .mwe-upwiz-visible-file:last' ).addClass( 'ui-corner-bottom' ); - $( '#mwe-upwiz-filelist .filled:odd' ).addClass( 'odd' ); - $( '#mwe-upwiz-filelist .filled:even' ).removeClass( 'odd' ); - } else { - // no uploads, so don't allow us to proceed - $( '#mwe-upwiz-upload-ctrl-container' ).hide(); - - // remove the border from the filelist. We can't hide it or make it invisible since it contains the displaced - // file input element that becomes the "click here to add" - $( '#mwe-upwiz-filelist' ).removeClass( 'mwe-upwiz-filled-filelist' ); - - // we can't continue - $( '#mwe-upwiz-stepdiv-file .mwe-upwiz-buttons' ).hide(); - + if ( this.uploads.length - this.countEmpties() <= 0 ) { // destroy the flickr interface if it exists this.flickrInterfaceDestroy(); - - // changes the button back from "add another file" to the initial centered invitation button - $( '#mwe-upwiz-add-file' ).button( 'option', 'label', mw.message( 'mwe-upwiz-add-file-0-free' ).escaped() ); - $( '#mwe-upwiz-upload-ctr-divide' ).show(); - // changes the button back from "add more files from flickr" to the initial text - $( '#mwe-upwiz-upload-ctrl-flickr' ).button( 'option', 'label', mw.message( 'mwe-upwiz-add-file-flickr' ).escaped() ); - $( '#mwe-upwiz-add-file, #mwe-upwiz-upload-ctrl-flickr' ).removeClass( 'mwe-upwiz-add-files-n' ); - $( '#mwe-upwiz-add-file-container' ).addClass( 'mwe-upwiz-add-files-0' ); - $( '#mwe-upwiz-add-file-container, #mwe-upwiz-upload-ctrl-flickr-container' ).show(); - - // recovering from an earlier attempt to upload - $( '#mwe-upwiz-upload-ctrls' ).show(); - $( '#mwe-upwiz-progress' ).hide(); - $( '#mwe-upwiz-add-file' ).show(); // fix various other pages that may have state $.each( this.steps, function ( i, step ) { step.empty(); } ); - - $( '#mwe-upwiz-flickr-select-list' ).empty(); - $( '#mwe-upwiz-flickr-select-list-container' ).unbind(); - $( '#mwe-upwiz-select-flickr' ).unbind(); if ( this.deedChooser !== undefined ) { this.deedChooser.remove(); @@ -865,19 +797,6 @@ this.resetFileStepUploads(); this.moveToStep( 'file' ); - } - - // allow an "add another upload" button only if we aren't at max - if ( this.uploads.length < this.maxUploads ) { - $( '#mwe-upwiz-add-file' ).button( 'option', 'disabled', false ); - $( '#mwe-upwiz-upload-ctrl-flickr' ).button( 'option', 'disabled', false ); - $( this.uploadToAdd.ui.div ).show(); - this.uploadToAdd.ui.moveFileInputToCover( '#mwe-upwiz-add-file', 'resize' ); - } else { - $( '#mwe-upwiz-add-file' ).button( 'option', 'disabled', true ); - $( '#mwe-upwiz-upload-ctrl-flickr' ).button( 'option', 'disabled', true ); - $( this.uploadToAdd.ui.div ).hide(); - this.uploadToAdd.ui.hideFileInput(); } }, diff --git a/resources/ui/uw.ui.Upload.js b/resources/ui/uw.ui.Upload.js new file mode 100644 index 0000000..fa29610 --- /dev/null +++ b/resources/ui/uw.ui.Upload.js @@ -0,0 +1,175 @@ +/* + * This file is part of the MediaWiki extension UploadWizard. + * + * UploadWizard is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * UploadWizard is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with UploadWizard. If not, see <http://www.gnu.org/licenses/>. + */ + +( function ( mw, $, ui, oo ) { + var UP; + + /** + * Represents the UI for the wizard's Upload step. + * @class uw.ui.Upload + * @extends uw.ui.Step + * @constructor + */ + function Upload() { + ui.Step.call( + this, + $( '#mwe-upwiz-stepdiv-file' ), + $( '#mwe-upwiz-step-file' ) + ); + + this.$uploadCtrl = $( '#mwe-upwiz-upload-ctrls' ); + this.$uploadCtrlContainer = $( '#mwe-upwiz-upload-ctrl-container' ); + this.$uploadCenterDivide = $( '#mwe-upwiz-upload-ctr-divide' ); + this.$uploadStepButtons = $( '#mwe-upwiz-stepdiv-file .mwe-upwiz-buttons' ); + + this.$addFile = $( '#mwe-upwiz-add-file' ); + this.$addFileContainer = $( '#mwe-upwiz-add-file-container' ); + + this.$flickrAddFile = $( '#mwe-upwiz-upload-ctrl-flickr' ); + this.$flickrAddFileContainer = $( '#mwe-upwiz-upload-ctrl-flickr-container' ); + + this.$flickrSelect = $( '#mwe-upwiz-select-flickr' ); + this.$flickrSelectList = $( '#mwe-upwiz-flickr-select-list' ); + this.$flickrSelectListContainer = $( '#mwe-upwiz-flickr-select-list-container' ); + + this.$fileList = $( '#mwe-upwiz-filelist' ); + + this.$progress = $( '#mwe-upwiz-progress' ); + } + + oo.inheritClass( Upload, ui.Step ); + + UP = Upload.prototype; + + /** + * Updates the interface based on the number of uploads. + * @param {boolean} haveUploads Whether there are any uploads at all. + * @param {boolean} fewerThanMax Whether we can add more uploads. + * @param {mw.UploadWizardUpload} uploadToAdd The last upload object added to the interface, if any. + */ + UP.updateFileCounts = function ( haveUploads, fewerThanMax, uploadToAdd ) { + this.$fileList.toggleClass( 'mwe-upwiz-filled-filelist', haveUploads ); + this.$addFile.add( this.$flickrAddFile ).toggleClass( 'mwe-upwiz-add-files-n', haveUploads ); + this.$addFileContainer.toggleClass( 'mwe-upwiz-add-files-0', !haveUploads ); + + if ( haveUploads ) { + // we have uploads ready to go, so allow us to proceed + this.$uploadCtrlContainer.add( this.$uploadStepButtons ).show(); + this.$uploadCenterDivide.hide(); + + if ( mw.UploadWizard.config.enableMultipleFiles === true ) { + this.showAddAnotherFile(); + } else { + $( '.mwe-upwiz-file-input' ) + .add( this.$addFile ) + .add( this.$flickrAddFileContainer ) + .add( this.$flickrSelectListContainer ) + .hide(); + } + + // fix the rounded corners on file elements. + // we want them to be rounded only when their edge touched the top or bottom of the filelist. + this.$fileListings = this.$fileList.find( '.filled' ); + + this.$visibleFileListings = this.$fileListings.find( '.mwe-upwiz-visible-file' ); + this.$visibleFileListings.removeClass( 'ui-corner-top ui-corner-bottom' ); + this.$visibleFileListings.first().addClass( 'ui-corner-top' ); + this.$visibleFileListings.last().addClass( 'ui-corner-bottom' ); + + this.$fileListings.filter( ':odd' ).addClass( 'odd' ); + this.$fileListings.filter( ':even' ).removeClass( 'odd' ); + } + + this.$addFile + .add( this.$flickrAddFile ) + .button( 'option', 'disabled', !fewerThanMax ); + + if ( uploadToAdd ) { + // allow an "add another upload" button only if we aren't at max + if ( fewerThanMax ) { + $( uploadToAdd.ui.div ).show(); + uploadToAdd.ui.moveFileInputToCover( '#mwe-upwiz-add-file', 'resize' ); + } else { + $( uploadToAdd.ui.div ).hide(); + uploadToAdd.ui.hideFileInput(); + } + } + }; + + /** + * Changes the initial centered invitation button to something like "add another file" + */ + UP.showAddAnotherFile = function () { + this.$addFile.button( 'option', 'label', mw.message( 'mwe-upwiz-add-file-n' ).escaped() ); + this.$addFileContainer.show(); + + // if Flickr uploading is available to this user, show the "add more files from flickr" button + if ( mw.UploadWizard.config.UploadFromUrl && mw.UploadWizard.config.flickrApiKey !== '' ) { + // changes the flickr add button to "add more files from flickr" + this.$flickrAddFile.button( 'option', 'label', mw.message( 'mwe-upwiz-add-file-flickr-n' ).escaped() ); + + this.$flickrAddFileContainer.show(); + } + + this.emptyFlickrLists(); + }; + + /** + * Empties the upload list. + */ + UP.empty = function () { + this.$uploadCtrlContainer + .add( this.$uploadStepButtons ) + .add( this.$progress ) + .hide(); + + this.$addFileContainer + .add( this.$flickrAddFileContainer ) + .add( this.$uploadCenterDivide ) + .add( this.$addFile ) + .add( this.$uploadCtrls ) + .show(); + + // changes the button back from "add another file" to the initial centered invitation button + this.$addFile.button( 'option', 'label', mw.message( 'mwe-upwiz-add-file-0-free' ).escaped() ); + + // changes the button back from "add more files from flickr" to the initial text + this.$flickrAddFile.button( 'option', 'label', mw.message( 'mwe-upwiz-add-file-flickr' ).escaped() ); + + this.emptyFlickrLists(); + }; + + /** + * Empties the Flickr selection lists. + */ + UP.emptyFlickrLists = function () { + // empty the flickr lists + this.$flickrSelectList.empty(); + this.$flickrSelectListContainer.unbind(); + this.$flickrSelect.unbind(); + }; + + UP.moveTo = function () { + ui.Step.prototype.moveTo.call( this ); + + this.$addFile.add( this.$flickrAddFile ).removeClass( 'mwe-upwiz-add-files-n' ); + this.$addFileContainer.addClass( 'mwe-upwiz-add-files-0' ); + this.$fileList.removeClass( 'mwe-upwiz-filled-filelist' ); + }; + + ui.Upload = Upload; +}( mediaWiki, jQuery, mediaWiki.uploadWizard.ui, OO ) ); -- To view, visit https://gerrit.wikimedia.org/r/153632 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I5a1be4ae4b4bf42f12fd599b626e5b132ae7ea30 Gerrit-PatchSet: 21 Gerrit-Project: mediawiki/extensions/UploadWizard Gerrit-Branch: master Gerrit-Owner: MarkTraceur <mtrac...@member.fsf.org> Gerrit-Reviewer: Gilles <gdu...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits