[MediaWiki-commits] [Gerrit] mediawiki...ContentTranslation[master]: Prevent js error in template adaptation

2017-11-27 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/393556 )

Change subject: Prevent js error in template adaptation
..


Prevent js error in template adaptation

The root cause for not having a visible fragment for template in
target language is unknown, and the issue was not reproducible
for me. This patch just prevents further damages. Not really nice
though.

Bug: T176237
Change-Id: I9b23f893944e46e21f4fa531aae5894830911669
---
M modules/tools/ext.cx.tools.template.js
1 file changed, 9 insertions(+), 2 deletions(-)

Approvals:
  Amire80: Looks good to me, but someone else must approve
  jenkins-bot: Verified
  Nikerabbit: Looks good to me, approved



diff --git a/modules/tools/ext.cx.tools.template.js 
b/modules/tools/ext.cx.tools.template.js
index 403bd87..13e4d0d 100644
--- a/modules/tools/ext.cx.tools.template.js
+++ b/modules/tools/ext.cx.tools.template.js
@@ -978,9 +978,16 @@
 * @param {string} state The new state of the template.
 */
TemplateTool.prototype.replaceTargetTemplate = function ( $newTemplate, 
state ) {
-   var sourceId, $new;
+   var sourceId, $new, $visibleFragment;
 
-   sourceId = this.sourceTemplate.getFirstVisibleFragment().prop( 
'id' );
+   $visibleFragment = 
this.sourceTemplate.getFirstVisibleFragment();
+   if ( !$visibleFragment ) {
+   // This should not happen. But prevent the js error if 
it happens. See T176237
+   mw.error( '[CX] Error: No visible fragment for template 
for ' + this.sourceTemplate.title );
+   // Stopping here means no template editor for this 
particular template.
+   return;
+   }
+   sourceId = $visibleFragment.prop( 'id' );
$new = $newTemplate
.clone()
.attr( {

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I9b23f893944e46e21f4fa531aae5894830911669
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/ContentTranslation
Gerrit-Branch: master
Gerrit-Owner: Santhosh 
Gerrit-Reviewer: Amire80 
Gerrit-Reviewer: Nikerabbit 
Gerrit-Reviewer: jenkins-bot <>

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


[MediaWiki-commits] [Gerrit] mediawiki...ContentTranslation[master]: Prevent js error in template adaptation

2017-11-27 Thread Santhosh (Code Review)
Santhosh has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/393556 )

Change subject: Prevent js error in template adaptation
..

Prevent js error in template adaptation

The root cause for not having a visible fragment for template in
target langauge is unknow and issue was not able to reproducable
for me. This patch just prevents further damages. Not really nice
though.

Bug: T176237
Change-Id: I9b23f893944e46e21f4fa531aae5894830911669
---
M modules/tools/ext.cx.tools.template.js
1 file changed, 9 insertions(+), 4 deletions(-)


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

diff --git a/modules/tools/ext.cx.tools.template.js 
b/modules/tools/ext.cx.tools.template.js
index 403bd87..50d77c4 100644
--- a/modules/tools/ext.cx.tools.template.js
+++ b/modules/tools/ext.cx.tools.template.js
@@ -962,7 +962,6 @@
var self = this;
 
this.targetTemplate.$template.first().cxoverlay( {
-   fullscreen: false,
showLoading: true
} );
return this.targetTemplate.getUpdatedTemplate().then( function 
( $newTemplate ) {
@@ -978,9 +977,16 @@
 * @param {string} state The new state of the template.
 */
TemplateTool.prototype.replaceTargetTemplate = function ( $newTemplate, 
state ) {
-   var sourceId, $new;
+   var sourceId, $new, $visibleFragment;
 
-   sourceId = this.sourceTemplate.getFirstVisibleFragment().prop( 
'id' );
+   $visibleFragment = 
this.sourceTemplate.getFirstVisibleFragment();
+   if ( !$visibleFragment ) {
+   // This should not happen. But prevent js error if it 
happens. See T176237
+   mw.error( '[CX] Error: No visible fragment for template 
for ' + this.sourceTemplate.title );
+   // Stopping here means no template editor for this 
particular template.
+   return;
+   }
+   sourceId = $visibleFragment.prop( 'id' );
$new = $newTemplate
.clone()
.attr( {
@@ -1147,7 +1153,6 @@
 
// Not a processed template. Proceed with attempt to adapt.
$targetTemplate.first().cxoverlay( {
-   fullscreen: false,
showLoading: true
} );
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9b23f893944e46e21f4fa531aae5894830911669
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ContentTranslation
Gerrit-Branch: master
Gerrit-Owner: Santhosh 

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