Santhosh has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/349939 )
Change subject: LinkTranslationUnit: Avoid the target document dangling without
parent
......................................................................
LinkTranslationUnit: Avoid the target document dangling without parent
The target document created by cloning source document will not be attached
to any parent node. With this state, it cannot be removed too.
This commit make sure that the target document refer to an actual node
under parent target node.
Change-Id: I8a7bd31b202b8265af1e004175f8936b9df84923
---
M modules/dm/translationunits/mw.cx.dm.LinkTranslationUnit.js
1 file changed, 25 insertions(+), 23 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation
refs/changes/39/349939/1
diff --git a/modules/dm/translationunits/mw.cx.dm.LinkTranslationUnit.js
b/modules/dm/translationunits/mw.cx.dm.LinkTranslationUnit.js
index dfc7c73..39690c7 100644
--- a/modules/dm/translationunits/mw.cx.dm.LinkTranslationUnit.js
+++ b/modules/dm/translationunits/mw.cx.dm.LinkTranslationUnit.js
@@ -40,25 +40,41 @@
* @return {jQuery.Promise}
*/
mw.cx.dm.LinkTranslationUnit.prototype.adapt = function () {
- var self = this;
+ var sourceCopy;
- this.targetDocument = this.sourceDocument.cloneNode( true );
- this.setTargetId();
+ if ( this.targetDocument ) {
+ mw.log.warn( '[CX] Adapting a link which looks already adapted:
' + this.toString() );
+ }
+
+ // Find the element in parent section for this link.
+ sourceCopy = this.parentTranslationUnit.getTargetDocument()
+ .querySelector( '[id="' + this.sourceDocument.id + '"]' );
+
+ // If this is a restored translation, the link will exist with cx id
prefix
+ this.targetDocument = this.parentTranslationUnit.getTargetDocument()
+ .querySelector( '[id="cx' + this.sourceDocument.id +
'"]' );
+
+ if ( !sourceCopy && !this.targetDocument ) {
+ mw.log.error( '[CX] Could not find the target element in parent
document. ' + this.toString() );
+ }
return this.requestManager.getTitlePair( this.sourceLanguage,
this.sourceTitle )
.then( function( pairInfo ) {
var targetTitle = pairInfo.targetTitle;
+
+ this.targetDocument = this.targetDocument || sourceCopy;
if ( targetTitle ) {
- self.targetDocument.title = targetTitle;
- self.targetDocument.href = targetTitle;
+ this.targetDocument.title = targetTitle;
+ this.targetDocument.href = targetTitle;
// TODO: This is just for testing. We should
not do this if there is MT for
// the source-target language pair.
- self.targetDocument.text = targetTitle;
- self.targetTitleMissing = false;
+ this.targetDocument.text = targetTitle;
+ this.targetTitleMissing = false;
} else {
- self.targetTitleMissing = true;
+ this.targetTitleMissing = true;
}
- } );
+ this.setTargetId();
+ }.bind( this ) );
};
/**
@@ -76,20 +92,6 @@
*/
mw.cx.dm.LinkTranslationUnit.prototype.isTargetExist = function () {
return !this.targetTitleMissing;
-};
-
-/**
- * Remove the link. Removes only from the target document.
- */
-mw.cx.dm.LinkTranslationUnit.prototype.removeLink = function () {
- var parentDocument;
- parentDocument = this.getParentTranslationUnit().getTargetDocument();
- if ( parentDocument ) {
- parentDocument.removeChild( this.targetDocument );
- } else {
- mw.log.error( '[CX] Parent document not found for the link to
remove' );
- }
- this.targetDocument = null;
};
mw.cx.dm.modelRegistry.register( mw.cx.dm.LinkTranslationUnit );
--
To view, visit https://gerrit.wikimedia.org/r/349939
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I8a7bd31b202b8265af1e004175f8936b9df84923
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ContentTranslation
Gerrit-Branch: master
Gerrit-Owner: Santhosh <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits