Santhosh has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/322874

Change subject: Don't show edit indicator when template cannot be adapted
......................................................................

Don't show edit indicator when template cannot be adapted

Change-Id: Iecdb9b9a7aaee64e08a2495cc483b262e3bb02ca
---
M modules/tools/ext.cx.tools.template.card.js
M modules/tools/ext.cx.tools.template.js
2 files changed, 44 insertions(+), 12 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation 
refs/changes/74/322874/1

diff --git a/modules/tools/ext.cx.tools.template.card.js 
b/modules/tools/ext.cx.tools.template.card.js
index c2a3924..64f2693 100644
--- a/modules/tools/ext.cx.tools.template.card.js
+++ b/modules/tools/ext.cx.tools.template.card.js
@@ -312,6 +312,8 @@
                                .text(
                                        mw.msg( 'cx-template-not-available', 
$.uls.data.getAutonym( mw.cx.targetLanguage ) )
                                );
+               } else {
+                       this.card.$targetTemplateTitle.text( 
this.templateTool.targetTemplate.title );
                }
                this.buildActionsMenu( actions );
        };
diff --git a/modules/tools/ext.cx.tools.template.js 
b/modules/tools/ext.cx.tools.template.js
index 769aed2..53c49e0 100644
--- a/modules/tools/ext.cx.tools.template.js
+++ b/modules/tools/ext.cx.tools.template.js
@@ -256,17 +256,20 @@
         */
        Template.prototype.onClick = function ( event ) {
                event.stopPropagation();
-               if ( this.templateData && this.options.onEdit ) {
+
+               if ( this.options.onEdit ) {
+                       // Template is editable
                        if ( this.$template.is( '.cx-highlight' ) ) {
                                this.options.onEdit.call( this );
                        }
-               } else {
-                       mw.log( '[CX] Cannot activate editor for ' + this.title 
);
+
+                       this.$template.toggleClass( 'cx-highlight' );
                }
-               this.$template.toggleClass( 'cx-highlight' );
-               if ( !this.isSourceTemplate() ) {
+
+               if ( this.isTargetTemplate() ) {
                        mw.hook( 'mw.cx.translation.template.focus' ).fire( 
this.$template );
                }
+
                // Dont bubble this. Will cause section focus events and all.
                return false;
        };
@@ -291,6 +294,17 @@
         */
        Template.prototype.isSourceTemplate = function () {
                return this.language === mw.cx.sourceLanguage;
+       };
+
+       /**
+        * Whether the template is target template or not.
+        * TODO: Should we just pass this as option to the constructor of this 
class
+        * instead of referring a global mw.cx?
+        *
+        * @return {boolean}
+        */
+       Template.prototype.isTargetTemplate = function () {
+               return this.language === mw.cx.targetLanguage;
        };
 
        /**
@@ -684,7 +698,6 @@
                this.options = $.extend( {}, mw.cx.TemplateTool.defaults, 
options );
                this.siteMapper = this.options.siteMapper;
                this.status = null;
-               this.prepareEditor();
        }
 
        TemplateTool.static = {};
@@ -744,6 +757,8 @@
                                        // It is possible that source template 
definition has params and target
                                        // does not have any. Mapping failed 
only when target has some params.
                                        mw.log( '[CX] None of template params 
were able to map for ' + self.sourceTemplate.title );
+                                       // Fully adapted
+                                       self.status = 'adaptable';
                                        return $.Deferred().reject().promise();
                                }
                        }
@@ -752,7 +767,7 @@
                        // TODO: Should we check for all params mapping based 
on count match of
                        // source and target template params?
                        if ( Object.keys( self.templateParamMapping ).length > 
0 ) {
-                               self.status = 'partially-adapted';
+                               self.status = 'adaptable';
                        }
 
                        if ( Object.keys( self.templateParamMapping ).length 
=== Object.keys( self.sourceTemplate.params ).length ) {
@@ -824,6 +839,15 @@
                        // Qunit tests might note load this module.
                        return false;
                }
+
+               if ( !this.isEditable() ) {
+                       return false;
+               }
+
+               if ( this.editor ) {
+                       return true;
+               }
+
                this.editor = new mw.cx.TemplateEditor(
                        this.sourceTemplate,
                        this.targetTemplate, {
@@ -844,11 +868,12 @@
         * Editor request handler
         */
        TemplateTool.prototype.onEdit = function () {
-               if ( this.targetTemplate.$template.data( 'template-state' ) !== 
'adapt' ) {
-                       // Editor is given only when 'adapt' is the option
-                       return;
-               }
                this.editor.show();
+       };
+
+       TemplateTool.prototype.isEditable = function () {
+               // Editor is given only when 'adapt' is the option
+               return this.status === 'adaptable' || this.status === 'adapted';
        };
 
        /**
@@ -992,6 +1017,11 @@
                }
        };
 
+       TemplateTool.prototype.onAdapt = function () {
+               this.onUpdate();
+               this.prepareEditor();
+       };
+
        /**
         * Process a template pair.
         *
@@ -1056,7 +1086,7 @@
                                return $.Deferred().reject().promise();
                        }
                } ).always( function () {
-                       templateTool.onUpdate();
+                       templateTool.onAdapt();
                } );
        };
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iecdb9b9a7aaee64e08a2495cc483b262e3bb02ca
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ContentTranslation
Gerrit-Branch: master
Gerrit-Owner: Santhosh <santhosh.thottin...@gmail.com>

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

Reply via email to