Santhosh has uploaded a new change for review. https://gerrit.wikimedia.org/r/322637
Change subject: Do not show 'use equivalent' action if not equivalent template present ...................................................................... Do not show 'use equivalent' action if not equivalent template present In progress. 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, 43 insertions(+), 28 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation refs/changes/37/322637/1 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..e0ba733 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; @@ -91,12 +91,14 @@ .hide(); 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 || i === 0 ) + ); } // Set the main label this.card.$actionSelectorTrigger - .text( this.getActionMenuItemLabel( this.templateTool.action ) ) + .text( this.getActionMenuItemLabel( selectedId || actions[ 0 ] ) ) .after( this.card.$actionsMenu ); this.card.$actionsMenu.find( '.card__template-action-item' ) @@ -112,10 +114,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 +153,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 +199,7 @@ $sourceTemplate = mw.cx.Template.static.getTemplateDef( $targetTemplate ); this.templateTool = $sourceTemplate.data( 'cxtemplate' ); + if ( !this.templateTool || mw.cx.TemplateTool.static.isReferencesBlock( $sourceTemplate ) ) { @@ -205,22 +208,23 @@ } // 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 ) ) ); + this.buildActionsMenu( this.actions ); + + if ( storedState === 'keep-original' ) { + this.markUndaptable(); + } else if ( storedState === 'adapt' ) { + this.markAdaptable(); } - this.buildActionsMenu( this.actions ); this.card.$container.show(); this.onShow(); }; @@ -232,13 +236,10 @@ 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.markUndaptable(); - self.buildActionsMenu( self.actions ); } ); }; @@ -250,12 +251,28 @@ }; /** + * Mark the template as adapted + */ + TemplateControlCard.prototype.markAdaptable = function () { + // Adaptation passed. + this.card.$targetTemplateTitle.text( this.templateTool.targetTemplate.title ); + this.templateTool.updateTargetTemplate(); + }; + + /** * Mark the template as Unadaptable template */ TemplateControlCard.prototype.markUndaptable = function () { + var actions; + + this.templateTool.markUndaptable(); this.card.$targetTemplateTitle.text( mw.msg( 'cx-template-not-available', $.uls.data.getAutonym( mw.cx.targetLanguage ) ) ); - this.templateTool.markUndaptable(); + + // Hide the menu item for 'Use equivalent' + actions = this.actions.slice( 1 ); + this.buildActionsMenu( actions ); + this.setSelectedAction( 'keep-original' ); }; /** diff --git a/modules/tools/ext.cx.tools.template.js b/modules/tools/ext.cx.tools.template.js index be9993b..ff25664 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' ) -- To view, visit https://gerrit.wikimedia.org/r/322637 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Icff378dac3b6b5b86efba33317aa96b462a68a1b 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