( function ( mw, uw, $, OO ) { function LicensePreviewDialog( config ) { LicensePreviewDialog.parent.call( this, config ); } OO.inheritClass( LicensePreviewDialog, OO.ui.Dialog ); LicensePreviewDialog.static.name = 'licensePreviewDialog'; LicensePreviewDialog.prototype.initialize = function () { var dialog = this; LicensePreviewDialog.parent.prototype.initialize.call( this ); this.content = new OO.ui.PanelLayout( { padded: true, expanded: false } ); this.$body.append( this.content.$element ); this.$spinner = $.createSpinner( { size: 'large', type: 'block' } ) .css( { width: 200, padding: 20, 'float': 'none', margin: '0 auto' } ); $( 'body' ).on( 'click', function ( e ) { if ( !$.contains( dialog.$body.get( 0 ), e.target ) ) { dialog.close(); } } ); }; LicensePreviewDialog.prototype.addCloseButton = function () { var dialog = this, closeButton = new OO.ui.ButtonWidget( { label: OO.ui.msg( 'ooui-dialog-process-dismiss' ) } ); closeButton.on( 'click', function () { dialog.close(); } ); this.content.$element.append( closeButton.$element ); }; LicensePreviewDialog.prototype.getBodyHeight = function () { return this.content.$element.outerHeight( true ); }; LicensePreviewDialog.prototype.setLoading = function ( isLoading ) { if ( isLoading ) { this.content.$element.empty().append( this.$spinner ); this.addCloseButton(); } else { this.content.$element.empty(); } this.updateSize(); }; LicensePreviewDialog.prototype.setPreview = function ( html ) { this.content.$element.empty().append( html ); this.addCloseButton(); this.updateSize(); }; /** * Create a group of radio buttons for licenses. N.B. the licenses are named after the templates they invoke. * Note that this is very anti-MVC. The values are held only in the actual form elements themselves. * * @extends OO.ui.Widget * @param {Array|undefined} values License key name(s) to activate by default * @param {Object} config Configuration. Must have following properties: * @param {string} config.type Whether inclusive or exclusive license allowed ("and"|"or") * @param {string[]} config.licenses Template string names (matching keys in mw.UploadWizard.config.licenses) * @param {string[]} [config.licenseGroups] Groups of licenses, with more explanation * @param {string} [config.special] Indicates, don't put licenses here, instead use a special widget * @param {Number} count Number of the things we are licensing (it matters to some texts) * @param {mw.Api} api API object, used for wikitext previews */ mw.UploadWizardLicenseInput = function ( values, config, count, api ) { mw.UploadWizardLicenseInput.parent.call( this ); this.count = count; this.api = api; if ( config.type === undefined || ( config.licenses === undefined && config.licenseGroups === undefined ) ) { throw new Error( 'improper initialization' ); } this.$selector = this.$element; this.type = config.type === 'or' ? 'radio' : 'checkbox'; this.defaults = []; if ( config.defaults ) { this.defaults = config.defaults; } else if ( config.licenses && config.licenses[ 0 ] ) { this.defaults = [ config.licenses[ 0 ] ]; } mw.UploadWizardLicenseInput.prototype.count++; this.name = 'license' + mw.UploadWizardLicenseInput.prototype.count; // the jquery wrapped inputs (checkboxes or radio buttons) for this licenseInput. this.inputs = []; // create inputs and licenses from config if ( config.licenseGroups === undefined ) { this.createInputs( this.$selector, config ); } else { this.createGroupedInputs( this.$selector, config.licenseGroups ); } // set values of the whole license input if ( values ) { this.setValues( values ); } this.windowManager = new OO.ui.WindowManager(); $( 'body' ).append( this.windowManager.$element ); this.previewDialog = new LicensePreviewDialog(); this.windowManager.addWindows( [ this.previewDialog ] ); // [wikitext => list of templates used in wikitext] map, used in // getUsedTemplates to reduce amount of API calls this.templateCache = {}; }; OO.inheritClass( mw.UploadWizardLicenseInput, OO.ui.Widget ); $.extend( mw.UploadWizardLicenseInput.prototype, { count: 0, /** * Creates the license input interface in toggleable groups. * * @param {jQuery} $el Selector * @param {Object} configGroups License input configuration groups */ createGroupedInputs: function ( $el, configGroups ) { var input = this; $.each( configGroups, function ( i, group ) { var $body, $head, $licensesDiv, $group = $( '
' ).append( message ) ) ); } this.api.parse( wikiText, { pst: true } ).done( show ).fail( error ); }, /** * @return {Object} */ getSerialized: function () { var i, values = {}, $inputs = this.getSelectedInputs(); for ( i = 0; i < $inputs.length; i++ ) { values[ $inputs[ i ].data( 'licenseName' ) ] = this.getInputTextAreaVal( $inputs[ i ] ) || true; } return values; }, /** * @param {Object} serialized */ setSerialized: function ( serialized ) { this.setValues( serialized ); } } ); }( mediaWiki, mediaWiki.uploadWizard, jQuery, OO ) );