5 * mw.ForeignStructuredUpload.BookletLayout encapsulates the process
6 * of uploading a file to MediaWiki using the mw.ForeignStructuredUpload model.
8 * var uploadDialog = new mw.Upload.Dialog( {
9 * bookletClass: mw.ForeignStructuredUpload.BookletLayout,
11 * targetHost: 'localhost:8080'
14 * var windowManager = new OO.ui.WindowManager();
15 * $( 'body' ).append( windowManager.$element );
16 * windowManager.addWindows( [ uploadDialog ] );
18 * @class mw.ForeignStructuredUpload.BookletLayout
19 * @uses mw.ForeignStructuredUpload
20 * @extends mw.Upload.BookletLayout
21 * @cfg {string} [targetHost] Used to set up the target wiki.
22 * If nothing is passed, the {@link mw.ForeignUpload#property-targetHost default} is used.
24 mw
.ForeignStructuredUpload
.BookletLayout = function ( config
) {
25 config
= config
|| {};
27 mw
.ForeignStructuredUpload
.BookletLayout
.parent
.call( this, config
);
29 this.targetHost
= config
.targetHost
;
34 OO
.inheritClass( mw
.ForeignStructuredUpload
.BookletLayout
, mw
.Upload
.BookletLayout
);
39 * Returns a {@link mw.ForeignStructuredUpload mw.ForeignStructuredUpload}
40 * with the {@link #cfg-targetHost targetHost} specified in config.
45 mw
.ForeignStructuredUpload
.BookletLayout
.prototype.createUpload = function () {
46 return new mw
.ForeignStructuredUpload( this.targetHost
);
54 mw
.ForeignStructuredUpload
.BookletLayout
.prototype.renderUploadForm = function () {
56 targets
= mw
.config
.get( 'wgForeignUploadTargets' ),
57 // Default to using local, but try to use a configured target.
58 // TODO allow finer configuration of this somehow?
59 target
= ( targets
&& targets
.length
) ? targets
[ 0 ] : 'local',
60 $ownWorkMessage
= $( '<p>' ).html(
61 mw
.message( 'foreign-structured-upload-form-label-own-work-message-' + target
).parse()
63 $notOwnWorkMessage
= $( '<div>' ).append(
65 mw
.message( 'foreign-structured-upload-form-label-not-own-work-message-' + target
).parse()
68 mw
.message( 'foreign-structured-upload-form-label-not-own-work-local-' + target
).parse()
73 this.selectFileWidget
= new OO
.ui
.SelectFileWidget();
74 this.messageLabel
= new OO
.ui
.LabelWidget( {
75 label
: $notOwnWorkMessage
77 this.ownWorkCheckbox
= new OO
.ui
.CheckboxInputWidget().on( 'change', function ( on
) {
79 layout
.messageLabel
.setLabel( $ownWorkMessage
);
81 layout
.messageLabel
.setLabel( $notOwnWorkMessage
);
85 fieldset
= new OO
.ui
.FieldsetLayout();
87 new OO
.ui
.FieldLayout( this.selectFileWidget
, {
89 label
: mw
.msg( 'upload-form-label-select-file' )
91 new OO
.ui
.FieldLayout( this.ownWorkCheckbox
, {
93 label
: mw
.msg( 'foreign-structured-upload-form-label-own-work' )
97 this.uploadForm
= new OO
.ui
.FormLayout( { items
: [ fieldset
] } );
100 this.selectFileWidget
.on( 'change', this.onUploadFormChange
.bind( this ) );
101 this.ownWorkCheckbox
.on( 'change', this.onUploadFormChange
.bind( this ) );
103 return this.uploadForm
;
109 mw
.ForeignStructuredUpload
.BookletLayout
.prototype.onUploadFormChange = function () {
110 var file
= this.selectFileWidget
.getValue(),
111 ownWork
= this.ownWorkCheckbox
.isSelected(),
112 valid
= !!file
&& ownWork
;
113 this.emit( 'uploadValid', valid
);
119 mw
.ForeignStructuredUpload
.BookletLayout
.prototype.renderInfoForm = function () {
122 this.filenameWidget
= new OO
.ui
.TextInputWidget( {
126 this.descriptionWidget
= new OO
.ui
.TextInputWidget( {
132 this.dateWidget
= new mw
.widgets
.DateInputWidget( {
133 $overlay
: this.$overlay
,
135 mustBeBefore
: moment().add( 1, 'day' ).locale( 'en' ).format( 'YYYY-MM-DD' ) // Tomorrow
137 this.categoriesWidget
= new mw
.widgets
.CategorySelector( {
138 $overlay
: this.$overlay
141 fieldset
= new OO
.ui
.FieldsetLayout( {
142 label
: mw
.msg( 'upload-form-label-infoform-title' )
145 new OO
.ui
.FieldLayout( this.filenameWidget
, {
146 label
: mw
.msg( 'upload-form-label-infoform-name' ),
149 new OO
.ui
.FieldLayout( this.categoriesWidget
, {
150 label
: mw
.msg( 'foreign-structured-upload-form-label-infoform-categories' ),
153 new OO
.ui
.FieldLayout( this.descriptionWidget
, {
154 label
: mw
.msg( 'upload-form-label-infoform-description' ),
157 new OO
.ui
.FieldLayout( this.dateWidget
, {
158 label
: mw
.msg( 'foreign-structured-upload-form-label-infoform-date' ),
162 this.infoForm
= new OO
.ui
.FormLayout( { items
: [ fieldset
] } );
165 this.filenameWidget
.on( 'change', this.onInfoFormChange
.bind( this ) );
166 this.descriptionWidget
.on( 'change', this.onInfoFormChange
.bind( this ) );
167 this.dateWidget
.on( 'change', this.onInfoFormChange
.bind( this ) );
169 return this.infoForm
;
175 mw
.ForeignStructuredUpload
.BookletLayout
.prototype.onInfoFormChange = function () {
178 this.filenameWidget
.getValidity(),
179 this.descriptionWidget
.getValidity(),
180 this.dateWidget
.getValidity()
181 ).done( function () {
182 layout
.emit( 'infoValid', true );
183 } ).fail( function () {
184 layout
.emit( 'infoValid', false );
193 mw
.ForeignStructuredUpload
.BookletLayout
.prototype.getText = function () {
194 this.upload
.addDescription( 'en', this.descriptionWidget
.getValue() );
195 this.upload
.setDate( this.dateWidget
.getValue() );
196 this.upload
.addCategories( this.categoriesWidget
.getItemsData() );
197 return this.upload
.getText();
199 }( jQuery
, mediaWiki
) );