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

Change subject: Enable or disable the publish button based on progress of 
translation
......................................................................


Enable or disable the publish button based on progress of translation

Checking presence of text was not reliable. The event on which this check
was done also not reliable.

For example, translating first paragraph and then selecting that
and deleting using delete key made the publish button active.

In this commit, we use the percentage of completion as the criteria
for enabling and disabling the button. If progress is at least 1%,
we enable the publish button.

Change-Id: I1acc9a19e89c6cecd25a918391bdf30fbf4ba82c
---
M modules/header/ext.cx.header.js
M modules/header/ext.cx.header.render.js
2 files changed, 12 insertions(+), 12 deletions(-)

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



diff --git a/modules/header/ext.cx.header.js b/modules/header/ext.cx.header.js
index f2f79c6..666c480 100644
--- a/modules/header/ext.cx.header.js
+++ b/modules/header/ext.cx.header.js
@@ -18,6 +18,7 @@
         */
        function ContentTranslationHeader( element, options ) {
                this.$container = $( element );
+               this.$publishButton = null;
                this.options = $.extend( true, {}, $.fn.cxHeader.defaults, 
options );
                this.init();
        }
@@ -27,21 +28,19 @@
                this.listen();
        };
 
-       ContentTranslationHeader.prototype.setPublishButtonState = function () {
-               var translationText = $( '.cx-column--translation 
.cx-column__content' ).text();
-
-               // Disable the publish button if it has any non-space characters
-               this.$container.find( '.cx-header__publish' ).prop( {
-                       disabled: !translationText.match( /\S/ )
-               } );
+       /**
+        * Enable/Disable the publish button based on progress of translation
+        * @param {float} progress
+        */
+       ContentTranslationHeader.prototype.setPublishButtonState = function ( 
progress ) {
+               this.$publishButton.prop( 'disabled', parseInt( progress, 10 ) 
=== 0 );
        };
 
        ContentTranslationHeader.prototype.listen = function () {
                this.$container.find( '.publish' ).on( 'click', function () {
                        mw.hook( 'mw.cx.publish' ).fire();
                } );
-
-               mw.hook( 'mw.cx.translation.change' ).add( $.proxy( 
this.setPublishButtonState, this ) );
+               mw.hook( 'mw.cx.progress' ).add( $.proxy( 
this.setPublishButtonState, this ) );
        };
 
        $.fn.cxHeader = function ( options ) {
diff --git a/modules/header/ext.cx.header.render.js 
b/modules/header/ext.cx.header.render.js
index 63b9d52..fdab480 100644
--- a/modules/header/ext.cx.header.render.js
+++ b/modules/header/ext.cx.header.render.js
@@ -12,7 +12,7 @@
        'use strict';
 
        mw.cx.ContentTranslationHeader.prototype.render = function () {
-               var $logo, $userName, $userDetails, $headerBar, $publishButton,
+               var $logo, $userName, $userDetails, $headerBar,
                        $translationCenterLink, $translationCenter, $infoBar;
 
                $logo = $( '<div>' ).addClass( 'cx-header__logo' );
@@ -26,8 +26,9 @@
                        .addClass( 'cx-header__user-details' )
                        .append( $userName );
 
-               $publishButton = $( '<button>' )
+               this.$publishButton = $( '<button>' )
                        .addClass( 'cx-header__publish publish mw-ui-button 
mw-ui-constructive' )
+                       .prop( 'disabled', true )
                        .text( mw.msg( 'cx-publish-button' ) );
 
                $translationCenterLink = $( '<a>' )
@@ -40,7 +41,7 @@
 
                $headerBar = $( '<div>' )
                        .addClass( 'cx-header__bar' )
-                       .append( $translationCenter, $publishButton );
+                       .append( $translationCenter, this.$publishButton );
 
                $infoBar = $( '<div>' )
                        .addClass( 'cx-header__infobar' )

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I1acc9a19e89c6cecd25a918391bdf30fbf4ba82c
Gerrit-PatchSet: 5
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: jenkins-bot <>

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

Reply via email to