Nikerabbit has submitted this change and it was merged.

Change subject: Do not show 'use equivalent' action if not equivalent template 
present
......................................................................


Do not show 'use equivalent' action if not equivalent template present

Change-Id: Icff378dac3b6b5b86efba33317aa96b462a68a1b
---
M modules/publish/ext.cx.publish.js
M modules/tools/ext.cx.tools.template.card.js
M modules/tools/ext.cx.tools.template.js
3 files changed, 109 insertions(+), 43 deletions(-)

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



diff --git a/modules/publish/ext.cx.publish.js 
b/modules/publish/ext.cx.publish.js
index 866d553..fb52d7e 100644
--- a/modules/publish/ext.cx.publish.js
+++ b/modules/publish/ext.cx.publish.js
@@ -318,8 +318,6 @@
        CXPublish.prototype.prepareTranslationForPublish = function ( $content 
) {
                // Remove all placeholders
                $content.find( '.placeholder' ).remove();
-               // Remove all unadaptable templates
-               $content.find( '.cx-unadaptable-template' ).remove();
 
                $content.find( mw.cx.getSectionSelector() ).each( function () {
                        var attributesToRemove, classesToRemove, $section = $( 
this );
diff --git a/modules/tools/ext.cx.tools.template.card.js 
b/modules/tools/ext.cx.tools.template.card.js
index fb5c9d8..22c2e1e 100644
--- a/modules/tools/ext.cx.tools.template.card.js
+++ b/modules/tools/ext.cx.tools.template.card.js
@@ -82,7 +82,7 @@
                } );
        };
 
-       TemplateControlCard.prototype.buildActionsMenu = function ( actions ) {
+       TemplateControlCard.prototype.buildActionsMenu = function ( actions, 
selectedId ) {
                var i,
                        self = this;
 
@@ -90,13 +90,18 @@
                        .addClass( 'card__template-options-menu' )
                        .hide();
 
+               if ( !selectedId ) {
+                       selectedId = actions[ 0 ];
+               }
                for ( i = 0; i < actions.length; i++ ) {
-                       this.card.$actionsMenu.append( this.getActionMenuItem( 
actions[ i ] ) );
+                       this.card.$actionsMenu.append(
+                               this.getActionMenuItem( actions[ i ], actions[ 
i ] === selectedId )
+                       );
                }
 
                // Set the main label
                this.card.$actionSelectorTrigger
-                       .text( this.getActionMenuItemLabel( 
this.templateTool.action ) )
+                       .text( this.getActionMenuItemLabel( selectedId ) )
                        .after( this.card.$actionsMenu );
 
                this.card.$actionsMenu.find( '.card__template-action-item' )
@@ -112,10 +117,9 @@
         * @param {string} actionId Action id
         */
        TemplateControlCard.prototype.onActionSelect = function ( actionId ) {
-               this.templateTool.action = actionId;
-               this.setSelectedAction( this.templateTool.action );
+               this.setSelectedAction( actionId );
 
-               switch ( this.templateTool.action ) {
+               switch ( actionId ) {
                        case 'adapt':
                                this.adapt();
                                break;
@@ -152,23 +156,24 @@
         * Get a menu item for the actions list.
         *
         * @param {string} actionId Action id.
+        * @param {boolean} selected Selected or not
         * @return {jQuery}
         */
-       TemplateControlCard.prototype.getActionMenuItem = function ( actionId ) 
{
+       TemplateControlCard.prototype.getActionMenuItem = function ( actionId, 
selected ) {
                var $label,
-                       selected = '';
+                       selectedClass = '';
 
                $label = $( '<span>' )
                        .text( this.getActionMenuItemLabel( actionId ) );
 
                // Mark the selected item
-               if ( actionId === this.templateTool.action ) {
-                       selected = 'selected';
+               if ( selected ) {
+                       selectedClass = 'selected';
                }
 
                return $( '<li>' )
                        .addClass( [
-                               'card__template-action-item', selected, actionId
+                               'card__template-action-item', selectedClass, 
actionId
                        ].join( ' ' ) )
                        .attr( 'data-template-action', actionId )
                        .append( $label );
@@ -197,6 +202,7 @@
                $sourceTemplate = mw.cx.Template.static.getTemplateDef( 
$targetTemplate );
 
                this.templateTool = $sourceTemplate.data( 'cxtemplate' );
+
                if ( !this.templateTool ||
                        mw.cx.TemplateTool.static.isReferencesBlock( 
$sourceTemplate )
                ) {
@@ -205,22 +211,29 @@
                }
                // Find what was the action used in previous save
                storedState = $targetTemplate.data( 'template-state' );
-               // Do the stored action for a restored template or default 
action
-               if ( storedState ) {
-                       this.setSelectedAction( storedState );
-               } else {
-                       this.onActionSelect( this.templateTool.action );
+               // Do the default action
+               if ( !storedState ) {
+                       this.onActionSelect( 'adapt' );
                }
+
                this.sourceTemplate = this.templateTool.sourceTemplate;
                this.targetTemplate = this.templateTool.targetTemplate;
                this.card.$sourceTemplateTitle.text( this.sourceTemplate.title 
);
 
-               if ( this.templateTool.action === 'adapt' && storedState ) {
-                       this.card.$targetTemplateTitle.text( 
this.targetTemplate.title ||
-                               mw.msg( 'cx-template-not-available', 
$.uls.data.getAutonym( mw.cx.targetLanguage ) ) );
+               // Show the appropriate menu with correct values selected
+               if ( storedState === 'unadaptable' || 
!this.templateTool.targetTemplate.title ) {
+                       this.markUndaptable();
+               } else if ( storedState === 'keep-original' ) {
+                       this.markKeepOriginal();
+               } else if ( storedState === 'adapt' ) {
+                       this.markAdaptable();
+               } else if ( storedState === 'skip' ) {
+                       this.markSkipped();
+               } else {
+                       // No stored state. Fresh adaptation.
+                       this.buildActionsMenu( this.actions );
                }
 
-               this.buildActionsMenu( this.actions );
                this.card.$container.show();
                this.onShow();
        };
@@ -232,30 +245,13 @@
                var self = this;
 
                this.templateTool.adapt().then( function () {
-                       // Adaptation passed.
-                       self.card.$targetTemplateTitle.text( 
self.templateTool.targetTemplate.title );
                        self.templateTool.updateTargetTemplate();
+                       self.markAdaptable();
                } ).fail( function () {
                        // Adaptation failed.
+                       self.templateTool.markUndaptable();
                        self.markUndaptable();
-                       self.buildActionsMenu( self.actions );
                } );
-       };
-
-       /**
-        * Skip the template and use empty section
-        */
-       TemplateControlCard.prototype.skip = function () {
-               this.templateTool.markUndaptable();
-       };
-
-       /**
-        * Mark the template as Unadaptable template
-        */
-       TemplateControlCard.prototype.markUndaptable = function () {
-               this.card.$targetTemplateTitle.text(
-                       mw.msg( 'cx-template-not-available', 
$.uls.data.getAutonym( mw.cx.targetLanguage ) ) );
-               this.templateTool.markUndaptable();
        };
 
        /**
@@ -263,6 +259,55 @@
         */
        TemplateControlCard.prototype.useSource = function () {
                this.templateTool.replaceTargetTemplate( 
this.sourceTemplate.$template, 'keep-original' );
+               this.buildActionsMenu( this.actions, 'keep-original' );
+       };
+
+       /**
+        * Skip the template and use empty section
+        */
+       TemplateControlCard.prototype.skip = function () {
+               this.templateTool.skip();
+               this.markSkipped();
+       };
+
+       /**
+        * Mark the template as adapted
+        */
+       TemplateControlCard.prototype.markAdaptable = function () {
+               // Adaptation passed.
+               this.card.$targetTemplateTitle.text( 
this.templateTool.targetTemplate.title );
+               this.buildActionsMenu( this.actions, 'adapt' );
+       };
+
+       /**
+        * Mark the template as adapted
+        */
+       TemplateControlCard.prototype.markSkipped = function () {
+               this.buildActionsMenu( this.actions, 'skip' );
+       };
+
+       /**
+        * Mark the template as adapted
+        */
+       TemplateControlCard.prototype.markKeepOriginal = function () {
+               this.card.$targetTemplateTitle.text( 
this.templateTool.targetTemplate.title );
+               this.buildActionsMenu( this.actions, 'keep-original' );
+       };
+
+       /**
+        * Mark the template as Unadaptable template
+        */
+       TemplateControlCard.prototype.markUndaptable = function () {
+               var actions = this.actions;
+
+               // Hide the menu item for 'Use equivalent'
+               if ( !this.templateTool.targetTemplate.title ) {
+                       actions = this.actions.slice( 1 );
+                       this.card.$targetTemplateTitle.text(
+                               mw.msg( 'cx-template-not-available', 
$.uls.data.getAutonym( mw.cx.targetLanguage ) )
+                       );
+               }
+               this.buildActionsMenu( actions );
        };
 
        /**
diff --git a/modules/tools/ext.cx.tools.template.js 
b/modules/tools/ext.cx.tools.template.js
index be9993b..769aed2 100644
--- a/modules/tools/ext.cx.tools.template.js
+++ b/modules/tools/ext.cx.tools.template.js
@@ -683,7 +683,6 @@
                this.templateMapping = null;
                this.options = $.extend( {}, mw.cx.TemplateTool.defaults, 
options );
                this.siteMapper = this.options.siteMapper;
-               this.action = 'adapt';
                this.status = null;
                this.prepareEditor();
        }
@@ -945,6 +944,7 @@
                if ( this.targetTemplate.options.inline ) {
                        // just leave the template unchanged. Add a class.
                        this.targetTemplate.$template.addClass( 
'cx-unadaptable-template' );
+                       this.targetTemplate.$template.attr( 
'data-template-state', 'keep-original' );
                } else {
                        $new = $( '<div>' )
                                .addClass( 'placeholder 
cx-unadaptable-template' )
@@ -952,9 +952,32 @@
                                        'data-mw': 
this.sourceTemplate.$template.attr( 'data-mw' ),
                                        'typeof': 
this.sourceTemplate.$template.attr( 'typeof' )
                                } );
-                       this.replaceTargetTemplate( $new, 'adapt' );
+                       this.replaceTargetTemplate( $new, 'unadaptable' );
                }
 
+               this.onUpdate();
+       };
+
+       /**
+        * Mark the template skipped. This is like a placeholder, ignored from
+        * content to publish.
+        */
+       TemplateTool.prototype.skip = function () {
+               var $new;
+
+               if ( this.targetTemplate.options.inline ) {
+                       // just remove the inline template
+                       this.targetTemplate.$template.remove();
+               } else {
+                       $new = $( '<div>' )
+                               .addClass( 'placeholder' )
+                               .attr( {
+                                       'data-mw': 
this.sourceTemplate.$template.attr( 'data-mw' ),
+                                       'typeof': 
this.sourceTemplate.$template.attr( 'typeof' )
+                               } );
+                       this.replaceTargetTemplate( $new, 'skip' );
+                       this.onUpdate();
+               }
        };
 
        TemplateTool.prototype.onUpdate = function () {

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

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

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

Reply via email to