1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
( function ( mw, uw, $, OO ) {
/**
* A deed chooser field in UploadWizard's "Details" step form.
*
* @extends uw.DetailsWidget
*/
uw.DeedChooserDetailsWidget = function UWDeedChooserDetailsWidget() {
uw.DeedChooserDetailsWidget.parent.call( this );
this.deedChooser = false;
this.$element.addClass( 'mwe-upwiz-deedChooserDetailsWidget' );
};
OO.inheritClass( uw.DeedChooserDetailsWidget, uw.DetailsWidget );
/**
* Toggles whether we use the 'macro' deed or our own
*
* @param {mw.UploadWizardUpload} upload
*/
uw.DeedChooserDetailsWidget.prototype.useCustomDeedChooser = function ( upload ) {
var deedDiv;
// Defining own deedChooser for uploads coming from external service
if ( upload.file.fromURL ) {
// XXX can be made a separate class as mw.UploadFromUrlDeedChooser
this.deedChooser = upload.deedChooser = {
deed: {},
valid: function () {
return true;
},
getSerialized: function () {
return this.deed ? this.deed.getSerialized() : {};
},
setSerialized: function ( serialized ) {
if ( this.deed.setSerialized ) {
this.deed.setSerialized( serialized );
}
}
};
if ( upload.file.license ) {
// XXX need to add code in the remaining functions
this.$element.append( upload.file.licenseMessage );
this.deedChooser.deed = new uw.deed.Custom( mw.UploadWizard.config, upload );
} else {
this.deedChooser.deed = new uw.deed.External(
mw.UploadWizard.config,
upload,
{ type: 'or', licenses: [ 'custom' ], special: 'custom' }
);
this.$element.append( this.deedChooser.deed.licenseInputField.$element );
this.$element.append( upload.file.licenseMessage );
}
} else {
deedDiv = $( '<div class="mwe-upwiz-custom-deed" />' );
this.$element.append( deedDiv );
this.deedChooser = upload.deedChooser = new mw.UploadWizardDeedChooser(
mw.UploadWizard.config,
deedDiv,
mw.UploadWizard.getLicensingDeeds( [ upload ], mw.UploadWizard.config ),
[ upload ] );
this.deedChooser.onLayoutReady();
}
};
/**
* @inheritdoc
*/
uw.DeedChooserDetailsWidget.prototype.getErrors = function () {
var errors = [];
if ( this.deedChooser ) {
if ( !this.deedChooser.deed ) {
errors.push( mw.message( 'mwe-upwiz-deeds-need-deed' ) );
}
}
return $.Deferred().resolve( errors ).promise();
};
/**
* @return {Object}
*/
uw.DeedChooserDetailsWidget.prototype.getSerialized = function () {
if ( this.deedChooser ) {
return this.deedChooser.getSerialized();
}
return {};
};
/**
* @param {Object} serialized
*/
uw.DeedChooserDetailsWidget.prototype.setSerialized = function ( serialized ) {
if ( this.deedChooser ) {
this.deedChooser.setSerialized( serialized );
}
};
}( mediaWiki, mediaWiki.uploadWizard, jQuery, OO ) );
|