Bartosz Dziewoński has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/327795 )
Change subject: Split off uw.ValidationMessageElement from uw.FieldLayout
......................................................................
Split off uw.ValidationMessageElement from uw.FieldLayout
We might want to display validation messages without a FieldLayout.
Change-Id: I19e523d5248b67ddf14c03f4af069bcc2c055290
---
M extension.json
M resources/uw.FieldLayout.js
A resources/uw.ValidationMessageElement.js
3 files changed, 74 insertions(+), 41 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/UploadWizard
refs/changes/95/327795/1
diff --git a/extension.json b/extension.json
index aa73e19..550ced5 100644
--- a/extension.json
+++ b/extension.json
@@ -207,6 +207,7 @@
"scripts": [
"resources/jquery/jquery.morphCrossfade.js",
"resources/jquery/jquery.lazyload.js",
+ "resources/uw.ValidationMessageElement.js",
"resources/uw.DetailsWidget.js",
"resources/uw.FieldLayout.js",
"resources/details/uw.TitleDetailsWidget.js",
diff --git a/resources/uw.FieldLayout.js b/resources/uw.FieldLayout.js
index 1e24a04..9bdcac9 100644
--- a/resources/uw.FieldLayout.js
+++ b/resources/uw.FieldLayout.js
@@ -15,6 +15,7 @@
uw.FieldLayout = function UWFieldLayout( fieldWidget, config ) {
config = $.extend( { align: 'top', required: false }, config );
uw.FieldLayout.parent.call( this, fieldWidget, config );
+ uw.ValidationMessageElement.call( this, { validatedWidget:
fieldWidget } );
this.required = null;
this.requiredMarker = new OO.ui.IndicatorWidget( {
@@ -29,13 +30,10 @@
this.$label.addClass( 'mwe-upwiz-details-fieldname' );
this.$field.addClass( 'mwe-upwiz-details-input' );
- this.fieldWidget.connect( this, {
- change: 'checkValidity'
- } );
-
this.setRequired( config.required );
};
OO.inheritClass( uw.FieldLayout, OO.ui.FieldLayout );
+ OO.mixinClass( uw.FieldLayout, uw.ValidationMessageElement );
/**
* @return {boolean} Whether this field is marked as required
@@ -54,43 +52,6 @@
} else {
this.requiredMarker.$element.remove();
}
- };
-
- /**
- * Check the field's widget for errors and warnings and display them in
the UI.
- */
- uw.FieldLayout.prototype.checkValidity = function () {
- var layout = this;
- if ( !this.fieldWidget.getWarnings ||
!this.fieldWidget.getErrors ) {
- // Don't do anything for non-Details widgets
- return;
- }
- if ( this.fieldWidget.pushPending ) {
- this.fieldWidget.pushPending();
- }
- $.when(
- this.fieldWidget.getWarnings(),
- this.fieldWidget.getErrors()
- ).done( function ( warnings, errors ) {
- // this.notices and this.errors are arrays of
mw.Messages and not strings in this subclass
- layout.setNotices( warnings );
- layout.setErrors( errors );
- } ).always( function () {
- if ( layout.fieldWidget.popPending ) {
- layout.fieldWidget.popPending();
- }
- } );
- };
-
- /**
- * @inheritdoc
- */
- uw.FieldLayout.prototype.makeMessage = function ( kind, msg ) {
- var
- content = msg.parseDom(),
- $listItem =
uw.FieldLayout.parent.prototype.makeMessage.call( this, kind, content );
- $listItem.addClass( 'mwe-upwiz-fieldLayout-' + kind + '-' +
msg.key );
- return $listItem;
};
} )( mediaWiki, mediaWiki.uploadWizard, jQuery, OO );
diff --git a/resources/uw.ValidationMessageElement.js
b/resources/uw.ValidationMessageElement.js
new file mode 100644
index 0000000..3b0a461
--- /dev/null
+++ b/resources/uw.ValidationMessageElement.js
@@ -0,0 +1,71 @@
+( function ( mw, uw, $, OO ) {
+
+ /**
+ * Element that is able to display validation messages from itself or
another widget.
+ *
+ * @abstract
+ * @class
+ *
+ * @constructor
+ * @param {Object} [config]
+ * @param {OO.ui.Widget} [config.validatedWidget] Widget to validate
+ */
+ uw.ValidationMessageElement = function UWValidationMessageElement(
config ) {
+ config = config || {};
+
+ this.validatedWidget = config.validatedWidget || this;
+ this.$messages = $( '<ul>' );
+
+ this.errors = [];
+ this.notices = [];
+
+ this.validatedWidget.connect( this, {
+ change: 'checkValidity'
+ } );
+
+ this.$messages.addClass( 'oo-ui-fieldLayout-messages' );
+ this.$element.addClass( 'mwe-upwiz-validationMessageElement' );
+ };
+
+ // Hack: Steal methods from OO.ui.FieldLayout.
+ // TODO: Upstream ValidationMessageElement to OOjs UI, make FieldLayout
use it.
+ uw.ValidationMessageElement.prototype.makeMessage =
OO.ui.FieldLayout.prototype.makeMessage;
+ uw.ValidationMessageElement.prototype.setErrors =
OO.ui.FieldLayout.prototype.setErrors;
+ uw.ValidationMessageElement.prototype.setNotices =
OO.ui.FieldLayout.prototype.setNotices;
+ uw.ValidationMessageElement.prototype.updateMessages =
OO.ui.FieldLayout.prototype.updateMessages;
+
+ /**
+ * Check the field's widget for errors and warnings and display them in
the UI.
+ */
+ uw.ValidationMessageElement.prototype.checkValidity = function () {
+ var element = this;
+ if ( !this.validatedWidget.getWarnings ||
!this.validatedWidget.getErrors ) {
+ // Don't do anything for non-Details widgets
+ return;
+ }
+ if ( this.validatedWidget.pushPending ) {
+ this.validatedWidget.pushPending();
+ }
+ $.when(
+ this.validatedWidget.getWarnings(),
+ this.validatedWidget.getErrors()
+ ).done( function ( warnings, errors ) {
+ // this.notices and this.errors are arrays of
mw.Messages and not strings in this subclass
+ element.setNotices( warnings );
+ element.setErrors( errors );
+ } ).always( function () {
+ if ( element.validatedWidget.popPending ) {
+ element.validatedWidget.popPending();
+ }
+ } );
+ };
+
+ uw.ValidationMessageElement.prototype.makeMessage = function ( kind,
msg ) {
+ var
+ content = msg.parseDom(),
+ $listItem =
OO.ui.FieldLayout.prototype.makeMessage.call( this, kind, content );
+ $listItem.addClass( 'mwe-upwiz-fieldLayout-' + kind + '-' +
msg.key );
+ return $listItem;
+ };
+
+} )( mediaWiki, mediaWiki.uploadWizard, jQuery, OO );
--
To view, visit https://gerrit.wikimedia.org/r/327795
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I19e523d5248b67ddf14c03f4af069bcc2c055290
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/UploadWizard
Gerrit-Branch: master
Gerrit-Owner: Bartosz Dziewoński <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits