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

Change subject: MTControlCard: Use data attributes to keep track of current 
state
......................................................................


MTControlCard: Use data attributes to keep track of current state

To indicate the state of whether the section is pure MT or something
changed or using the source text.

If section has data-cx-mt = true, section is pure MT
If section has data-cx-mt = false, section has manual edits
If section has data-cx-source = true, section uses source text as translation

Previously, the restore translation was not shown if user edited something.
With this patch, we show restore translation button whenever translator edit
something. This helps the translator to easily undo all edits and start from
MT.

Removed the MTControlCard.enableRestory object and
updateSection, showRestore, hideRestore methods

Change-Id: I76d49ed0c6803e61de5da7757e2cde910f8a5ae2
---
M modules/tools/ext.cx.tools.mt.js
1 file changed, 11 insertions(+), 60 deletions(-)

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



diff --git a/modules/tools/ext.cx.tools.mt.js b/modules/tools/ext.cx.tools.mt.js
index 626143f..299c26a 100644
--- a/modules/tools/ext.cx.tools.mt.js
+++ b/modules/tools/ext.cx.tools.mt.js
@@ -140,12 +140,6 @@
                this.$card = null;
                this.$translations = null;
                this.$providersMenu = null;
-
-               // This is static because the card can be reinitialized.
-               // Indexed by section id.
-               if ( !MTControlCard.enableRestore ) {
-                       MTControlCard.enableRestore = {};
-               }
        }
 
        MTControlCard.prototype.getCard = function () {
@@ -205,33 +199,13 @@
        };
 
        /**
-        * Update the section with text from source, applying tools like
-        * adaptation and machine translation.
-        * @param {boolean} machineTranslate Whether to apply machine 
translation to the section.
-        */
-       MTControlCard.prototype.updateSection = function ( machineTranslate ) {
-               var sourceId = this.$section.data( 'source' ),
-                       cxMtCard = this;
-
-               // Paste the source without machine translation
-               mw.hook( 'mw.cx.translation.add' ).fire( sourceId, 
machineTranslate );
-
-               // Updating the section replaced the DOM element,
-               // so it needs to be reinitialized
-               mw.hook( 'mw.cx.translation.updated' ).add( function () {
-                       cxMtCard.$section = $( '#cx' + sourceId );
-               } );
-       };
-
-       /**
         * Update the section with text from source,
         * not applying machine translation.
         */
        MTControlCard.prototype.useSource = function () {
-               this.updateSection( false );
-               this.showRestore();
-
-               this.$section.focus();
+               var sourceId = this.$section.data( 'source' );
+               // Use the source without machine translation
+               mw.hook( 'mw.cx.translation.add' ).fire( sourceId, false );
        };
 
        /**
@@ -240,44 +214,19 @@
         * and hide the restore button.
         */
        MTControlCard.prototype.restoreTranslation = function () {
-               this.updateSection( true );
-               this.hideRestore();
-
-               this.$section.focus();
+               var sourceId = this.$section.data( 'source' );
+               // Use the source without machine translation
+               mw.hook( 'mw.cx.translation.add' ).fire( sourceId, true );
+               this.stop();
        };
 
        /**
         * Clear the translation text.
         */
        MTControlCard.prototype.clearTranslation = function () {
-               this.$section
-                       .html( '' );
+               this.$section.empty();
                mw.hook( 'mw.cx.translation.change' ).fire( this.$section );
-               this.showRestore();
-
                this.$section.focus();
-       };
-
-       /**
-        * Show the restore button.
-        */
-       MTControlCard.prototype.showRestore = function () {
-               // TODO Investigate why isn't it initialized sometimes.
-               // It should always be initialized by the time this runs.
-               if ( !this.$section ) {
-                       return;
-               }
-
-               MTControlCard.enableRestore[ this.$section.prop( 'id' ) ] = 
true;
-               this.$restore.removeClass( 'hidden' );
-       };
-
-       /**
-        * Hide the restore button.
-        */
-       MTControlCard.prototype.hideRestore = function () {
-               MTControlCard.enableRestore[ this.$section.prop( 'id' ) ] = 
false;
-               this.$restore.addClass( 'hidden' );
        };
 
        MTControlCard.prototype.selectProvider = function ( providerId ) {
@@ -388,8 +337,10 @@
                this.$section = $section;
                this.selectProvider( MTControlCard.provider );
 
-               if ( !MTControlCard.enableRestore[ this.$section.prop( 'id' ) ] 
) {
+               if ( this.$section.data( 'cx-mt' ) ) {
                        this.$restore.addClass( 'hidden' );
+               } else {
+                       this.$restore.removeClass( 'hidden' );
                }
 
                this.$card.show();

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I76d49ed0c6803e61de5da7757e2cde910f8a5ae2
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/extensions/ContentTranslation
Gerrit-Branch: master
Gerrit-Owner: Santhosh <santhosh.thottin...@gmail.com>
Gerrit-Reviewer: KartikMistry <kartik.mis...@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