jenkins-bot has submitted this change and it was merged.

Change subject: Source selector: Relax the validations on source title
......................................................................


Source selector: Relax the validations on source title

Since we have a pageselector, and it works on prefix search,
validating title on every input event does not make sense.
Most of the time we might be doing a validation on the prefix.
Showing error message everytime the pageselector is open is not good.

Following changes are made:
* Enable the translate button as soon as the user type something as
  a gesture of invitation.
* Make sure the validations are done when you press the translate button
  even if we missed to validate in any previous events.
* Do not do validations when user type something on source title input.
  User will most likely select something from pageselector, which is a
  valid title for sure.
* If the user did not select anything from page selector, but typed some
  random title, the translate button press will catch it. Or the validation
  for target title will include the validation for this wrong source title.

In effect, less frequent validations and therefore less number of API hits for
source title. Showing lot of errors or warnings are not good while we trust the
user to select a meaningful source title. Ultimately the translate button will
capture anything missed to validate.

Bug: T99874
Change-Id: I3725e6493de63c1b06e429ce9832601aa680cbff
---
M modules/source/ext.cx.source.selector.js
M modules/widgets/pageselector/ext.cx.pageselector.js
2 files changed, 22 insertions(+), 9 deletions(-)

Approvals:
  Nikerabbit: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/modules/source/ext.cx.source.selector.js 
b/modules/source/ext.cx.source.selector.js
index 0596c2e..b00854f 100644
--- a/modules/source/ext.cx.source.selector.js
+++ b/modules/source/ext.cx.source.selector.js
@@ -270,14 +270,19 @@
         * Listen for events.
         */
        CXSourceSelector.prototype.listen = function () {
+               var self = this;
                // Open or close the dialog when clicking the link.
                // The dialog will be unitialized until the first click.
                this.$trigger.click( $.proxy( this.show, this ) );
 
-               // Source title input or target title input, input or search 
(check)
-               this.$dialog.on(
-                       'input blur',
-                       '.cx-sourceselector-dialog__title',
+               this.$sourceTitleInput.on( 'input', function () {
+                       self.$translateFromButton.prop( 'disabled', false );
+                       // Hide any previous errors.
+                       self.$messageBar.hide();
+               } );
+
+               // Target title input (check)
+               this.$targetTitleInput.on( 'input blur',
                        $.debounce( 600, false, $.proxy( this.check, this ) )
                );
 
@@ -719,8 +724,9 @@
         * Does nothing if source page does not exist.
         */
        CXSourceSelector.prototype.startPageInCX = function () {
-               var targetTitle, originalSourceTitle, sourceLanguage, 
targetLanguage, siteMapper;
+               var targetTitle, originalSourceTitle, sourceLanguage, 
targetLanguage, siteMapper, selector;
 
+               selector = this;
                siteMapper = this.siteMapper;
                sourceLanguage = this.getSourceLanguage();
                targetLanguage = this.getTargetLanguage();
@@ -732,6 +738,8 @@
                        originalSourceTitle
                ).done( function ( sourceTitle ) {
                        if ( sourceTitle === false ) {
+                               selector.showSourceTitleError( sourceLanguage );
+                               selector.$sourceTitleInput.focus();
                                return;
                        }
 
diff --git a/modules/widgets/pageselector/ext.cx.pageselector.js 
b/modules/widgets/pageselector/ext.cx.pageselector.js
index 3989a54..898d83c 100644
--- a/modules/widgets/pageselector/ext.cx.pageselector.js
+++ b/modules/widgets/pageselector/ext.cx.pageselector.js
@@ -72,7 +72,7 @@
                var self = this;
 
                this.getPages( this.$input.val().trim() ).then( function ( 
items ) {
-                       var page, pageId, pages, $resultItem;
+                       var page, pageId, pages, $resultItem, $description;
 
                        pages = items.query.pages;
                        self.$menu.empty().attr( {
@@ -82,12 +82,15 @@
 
                        for ( pageId in pages ) {
                                page = pages[ pageId ];
+                               $description = $( '<div>' )
+                                       .addClass( 'mw-page-description' )
+                                       .text( page.terms ? 
page.terms.description : '' );
                                $resultItem = $( '<li>' )
+                                       .data( 'page-title', page.title )
                                        .append(
                                                $( '<div>' ).addClass( 
'mw-page-title' ).text( page.title ),
-                                               $( '<div>' ).addClass( 
'mw-page-description' ).text( page.terms.description )
-                                       )
-                                       .data( 'page-title', page.title );
+                                               $description
+                                       );
                                if ( page.thumbnail ) {
                                        $resultItem.css( {
                                                'background-image': 'url(' + 
page.thumbnail.source + ')',
@@ -179,6 +182,8 @@
                        $items = $menu.find( '> li' );
                        if ( $items.length ) {
                                self.show();
+                       } else {
+                               return;
                        }
                        currentItem = $menu.find( '> 
li.mw-pageselector-selected' ).index();
 

-- 
To view, visit https://gerrit.wikimedia.org/r/212748
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I3725e6493de63c1b06e429ce9832601aa680cbff
Gerrit-PatchSet: 8
Gerrit-Project: mediawiki/extensions/ContentTranslation
Gerrit-Branch: master
Gerrit-Owner: Santhosh <santhosh.thottin...@gmail.com>
Gerrit-Reviewer: Amire80 <amir.ahar...@mail.huji.ac.il>
Gerrit-Reviewer: Nikerabbit <niklas.laxst...@gmail.com>
Gerrit-Reviewer: Pginer <pgi...@wikimedia.org>
Gerrit-Reviewer: Santhosh <santhosh.thottin...@gmail.com>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to