/*
* 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 .
*/
( function ( mw, uw, $, OO ) {
/**
* Set up the form and deed object for the deed option that says these uploads are the work of a third party.
*
* @class uw.deed.ThirdParty
* @constructor
* @param {Object} config The UW config
* @param {mw.UploadWizardUpload[]} uploads Array of uploads that this deed refers to
* @param {mw.Api} api API object - useful for doing previews
*/
uw.deed.ThirdParty = function UWDeedThirdParty( config, uploads, api ) {
var deed = this;
uw.deed.Abstract.call( this, 'thirdparty', config );
this.uploadCount = uploads.length;
this.threeDCount = uploads.filter( this.needsPatentAgreement.bind( this ) ).length;
this.sourceInput = new OO.ui.MultilineTextInputWidget( {
autosize: true,
classes: [ 'mwe-source' ],
name: 'source'
} );
this.sourceInput.$input.attr( 'id', 'mwe-source-' + this.getInstanceCount() );
// See uw.DetailsWidget
this.sourceInput.getErrors = function () {
var
errors = [],
minLength = deed.config.minSourceLength,
maxLength = deed.config.maxSourceLength,
text = this.getValue().trim();
if ( text === '' ) {
errors.push( mw.message( 'mwe-upwiz-error-blank' ) );
} else if ( text.length < minLength ) {
errors.push( mw.message( 'mwe-upwiz-error-too-short', minLength ) );
} else if ( text.length > maxLength ) {
errors.push( mw.message( 'mwe-upwiz-error-too-long', maxLength ) );
}
return $.Deferred().resolve( errors ).promise();
};
// See uw.DetailsWidget
this.sourceInput.getWarnings = function () {
return $.Deferred().resolve( [] ).promise();
};
this.sourceInputField = new uw.FieldLayout( this.sourceInput, {
label: mw.message( 'mwe-upwiz-source' ).text(),
help: mw.message( 'mwe-upwiz-tooltip-source' ).text(),
required: true
} );
this.authorInput = new OO.ui.MultilineTextInputWidget( {
autosize: true,
classes: [ 'mwe-author' ],
name: 'author'
} );
this.authorInput.$input.attr( 'id', 'mwe-author-' + this.getInstanceCount() );
// See uw.DetailsWidget
this.authorInput.getErrors = function () {
var
errors = [],
minLength = deed.config.minAuthorLength,
maxLength = deed.config.maxAuthorLength,
text = this.getValue().trim();
if ( text === '' ) {
errors.push( mw.message( 'mwe-upwiz-error-blank' ) );
} else if ( text.length < minLength ) {
errors.push( mw.message( 'mwe-upwiz-error-too-short', minLength ) );
} else if ( text.length > maxLength ) {
errors.push( mw.message( 'mwe-upwiz-error-too-long', maxLength ) );
}
return $.Deferred().resolve( errors ).promise();
};
// See uw.DetailsWidget
this.authorInput.getWarnings = function () {
return $.Deferred().resolve( [] ).promise();
};
this.authorInputField = new uw.FieldLayout( this.authorInput, {
label: mw.message( 'mwe-upwiz-author' ).text(),
help: mw.message( 'mwe-upwiz-tooltip-author' ).text(),
required: true
} );
this.licenseInput = new mw.UploadWizardLicenseInput(
undefined,
this.config.licensing.thirdParty,
this.uploadCount,
api
);
this.licenseInput.$element.addClass( 'mwe-upwiz-deed-license-groups' );
this.licenseInput.setDefaultValues();
this.licenseInputField = new uw.FieldLayout( this.licenseInput, {
label: mw.message( 'mwe-upwiz-source-thirdparty-cases', this.uploadCount ).text()
} );
if ( this.threeDCount > 0 ) {
this.patentAgreementField = this.getPatentAgreementField( uploads );
}
};
OO.inheritClass( uw.deed.ThirdParty, uw.deed.Abstract );
/**
* @return {uw.FieldLayout[]} Fields that need validation
*/
uw.deed.ThirdParty.prototype.getFields = function () {
var fields = [ this.authorInputField, this.sourceInputField, this.licenseInputField ];
if ( this.threeDCount > 0 ) {
fields.push( this.patentAgreementField );
}
return fields;
};
uw.deed.ThirdParty.prototype.setFormFields = function ( $selector ) {
var $defaultLicense, defaultLicense, defaultLicenseNum, defaultType, collapsible,
$formFields = $( '
' );
this.$form = $( '