Santhosh has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/347357 )

Change subject: WIP: CX2: Tool to add new link to the current section
......................................................................

WIP: CX2: Tool to add new link to the current section

Change-Id: If748e00d58bad83ec8135ac9b38e4a570d955cd7
---
M extension.json
A modules/tools/mw.cx.tools.NewLinkTool.js
M modules/tools/mw.cx.tools.TargetLinkTool.js
M modules/tools/styles/mw.cx.tools.LinkTool.less
A modules/tools/styles/mw.cx.tools.NewLinkTool.less
M modules/ui/translationunits/mw.cx.ui.LinkTranslationUnit.js
M modules/ui/translationunits/mw.cx.ui.SectionTranslationUnit.js
7 files changed, 149 insertions(+), 13 deletions(-)


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

diff --git a/extension.json b/extension.json
index 6b7a637..9542e0f 100644
--- a/extension.json
+++ b/extension.json
@@ -1806,6 +1806,7 @@
                                "mw.cx.tools.InstructionsTool",
                                "mw.cx.tools.SourceLinkTool",
                                "mw.cx.tools.TargetLinkTool",
+                               "mw.cx.tools.NewLinkTool",
                                "mw.cx.tools.MachineTranslationTool",
                                "mw.cx.tools.ReferenceTool",
                                "mw.cx.tools.SearchTool",
@@ -1895,6 +1896,17 @@
                                "mw.cx.tools.TranslationTool"
                        ]
                },
+               "mw.cx.tools.NewLinkTool":{
+                       "scripts": [
+                               "tools/mw.cx.tools.NewLinkTool.js"
+                       ],
+                       "styles": [
+                               "tools/styles/mw.cx.tools.NewLinkTool.less"
+                       ],
+                       "dependencies": [
+                               "mw.cx.tools.TranslationTool"
+                       ]
+               },
                "mw.cx.tools.ExternalLinkTool": {
                        "scripts": [
                                "tools/mw.cx.tools.ExternalLinkTool.js"
diff --git a/modules/tools/mw.cx.tools.NewLinkTool.js 
b/modules/tools/mw.cx.tools.NewLinkTool.js
new file mode 100644
index 0000000..e435350
--- /dev/null
+++ b/modules/tools/mw.cx.tools.NewLinkTool.js
@@ -0,0 +1,58 @@
+/**
+ * Link Tool
+ *
+ * @class
+ * @extends mw.cx.tools.TranslationTool
+ * @constructor
+ * @param {mw.cx.dm.TranslationUnit} model
+ * @param {Object} config
+ */
+
+mw.cx.tools.NewLinkTool = function CXNewLinkTool( model, config ) {
+       config.order = 52;
+       config.title = 'Link';
+       config.language = config.targetLanguage;
+       // Parent constructor
+       mw.cx.tools.NewLinkTool.super.call( this, model, config );
+
+       this.sourceTitle = null;
+       this.targetTitle = null;
+       this.pageInfo = null;
+       this.makeRedLinkButton = null;
+       this.removeLinkButton = null;
+};
+
+/* Inheritance */
+OO.inheritClass( mw.cx.tools.NewLinkTool, mw.cx.tools.TranslationTool );
+
+mw.cx.tools.NewLinkTool.static.name = 'newlink';
+
+mw.cx.tools.NewLinkTool.prototype.getContent = function () {
+       var panel;
+
+       panel = new OO.ui.PanelLayout( {
+               expanded: false,
+               framed: false,
+               padded: false,
+               text: mw.msg( 'cx-tools-link-to-another-page' )
+       } );
+
+       return panel.$element;
+};
+
+mw.cx.tools.NewLinkTool.prototype.getBackgroundImage = function () {
+       if ( this.pageInfo && this.pageInfo.imageUrl ) {
+               return this.pageInfo.imageUrl;
+       }
+       if ( !this.model.isTargetExist() ) {
+               return;
+       }
+};
+
+mw.cx.tools.NewLinkTool.prototype.removeLink = function () {
+       this.emit( 'remove' );
+       this.destroy();
+};
+
+/* Register */
+mw.cx.tools.translationToolFactory.register( mw.cx.tools.NewLinkTool );
diff --git a/modules/tools/mw.cx.tools.TargetLinkTool.js 
b/modules/tools/mw.cx.tools.TargetLinkTool.js
index 7e882a3..3090ebb 100644
--- a/modules/tools/mw.cx.tools.TargetLinkTool.js
+++ b/modules/tools/mw.cx.tools.TargetLinkTool.js
@@ -18,8 +18,10 @@
        this.sourceTitle = null;
        this.targetTitle = null;
        this.pageInfo = null;
+       this.selection = null;
        this.makeRedLinkButton = null;
        this.removeLinkButton = null;
+       this.addLinkButton = null;
 };
 
 /* Inheritance */
@@ -28,10 +30,36 @@
 mw.cx.tools.TargetLinkTool.static.name = 'targetlink';
 
 /**
+ * Text selection handler
+ * @param {Selection} selectionObj Selection object
+ */
+mw.cx.tools.TargetLinkTool.prototype.onSelect = function ( selectionObj ) {
+       var selection;
+
+       // TODO: Sanitize content
+       selection = selectionObj.toString();
+       if ( selection && selection.length < 1000 ) {
+               this.selection = selection;
+       }
+       this.pageInfo = null;
+       this.refresh();
+};
+
+/**
  * @inheritDoc
  */
 mw.cx.tools.TargetLinkTool.prototype.getActions = function () {
-       if ( this.model.isTargetExist() ) {
+       this.actions = [];
+
+       if ( this.selection ) {
+               this.addLinkButton = new OO.ui.ButtonWidget( {
+                       label: mw.msg( 'cx-tools-link-add' ),
+                       icon: 'add',
+                       framed: false,
+                       classes: [ 'cx-tools-link-add-button' ]
+               } );
+               this.actions.push( this.addLinkButton );
+       } else if ( this.model.isTargetExist() ) {
                this.removeLinkButton = new OO.ui.ButtonWidget( {
                        label: mw.msg( 'cx-tools-link-remove' ),
                        icon: 'close',
@@ -41,9 +69,7 @@
                this.removeLinkButton.connect( this, {
                        click: 'removeLink'
                } );
-               this.actions = [
-                       this.removeLinkButton
-               ];
+               this.actions.push( this.removeLinkButton );
        } else {
                this.makeRedLinkButton = new OO.ui.ButtonWidget( {
                        label: mw.msg( 'cx-tools-missing-link-mark-link' ),
@@ -51,9 +77,7 @@
                        framed: false,
                        classes: [ 'cx-tools-link-mark-red' ]
                } );
-               this.actions = [
-                       this.makeRedLinkButton
-               ];
+               this.actions.push( this.makeRedLinkButton );
        }
 
        return this.actions;
@@ -62,9 +86,22 @@
 mw.cx.tools.TargetLinkTool.prototype.getContent = function () {
        var panel, $linkTitle, $linkDesc, $linkInfo, $missingLink;
 
-       this.targetTitle = this.model.getTargetTitle();
-
-       if ( this.model.isTargetExist() )       {
+       if ( this.selection ) {
+               // TODO: refactor. code duplication
+               $linkTitle = $( '<a>' )
+                       .addClass( 'cx-tools-link-text' )
+                       .text( this.selection )
+                       .prop( {
+                               target: '_blank',
+                               title: this.selection,
+                               href: this.model.config.siteMapper.getPageUrl( 
this.model.config.targetLanguage, this.selection )
+                       } );
+               $linkInfo = $( '<div>' )
+                       .addClass( 'cx-tools-link-info' )
+                       .append( $linkTitle );
+               // TODO: we need to fetch the link info here too.
+       } else if ( this.model.isTargetExist() )        {
+               this.targetTitle = this.model.getTargetTitle();
                $linkTitle = $( '<a>' )
                        .addClass( 'cx-tools-link-text' )
                        .text( this.targetTitle )
diff --git a/modules/tools/styles/mw.cx.tools.LinkTool.less 
b/modules/tools/styles/mw.cx.tools.LinkTool.less
index 4670d67..aee33ab 100644
--- a/modules/tools/styles/mw.cx.tools.LinkTool.less
+++ b/modules/tools/styles/mw.cx.tools.LinkTool.less
@@ -8,7 +8,6 @@
        background-size: 30% 100%;
        background-position: top left;
        transition: top 0.3s;
-       position: relative;
        min-height: 100px;
 
        .cx-widget-translationtool-header {
@@ -48,6 +47,7 @@
 
 // Stack the source and target link cards
 .cx-card-sourcelink + .cx-card-targetlink {
+       position: relative;
        top: -90px;
 }
 
diff --git a/modules/tools/styles/mw.cx.tools.NewLinkTool.less 
b/modules/tools/styles/mw.cx.tools.NewLinkTool.less
new file mode 100644
index 0000000..b2d7175
--- /dev/null
+++ b/modules/tools/styles/mw.cx.tools.NewLinkTool.less
@@ -0,0 +1,26 @@
+@import '../../widgets/common/ext.cx.common.less';
+
+.cx-card-newlink {
+       .cx-widget-translationtool-header {
+               display: none;
+       }
+
+       padding-left: 30px;
+       background-repeat: no-repeat;
+       .background-image-svg('../images/add_link_gray.svg', 
'../images/add_link_gray.png');
+       background-size: 20px 100%;
+       background-position: top left 10px;
+       transition: all 0.3s;
+       min-height: 20px;
+       cursor: pointer;
+}
+
+// Stack the source and target link cards
+.cx-card-sourcelink ~ .cx-card-newlink {
+       position: relative;
+       top: -90px;
+}
+
+.cx-card-sourcelink:hover ~ .cx-card-newlink {
+       top: 0;
+}
diff --git a/modules/ui/translationunits/mw.cx.ui.LinkTranslationUnit.js 
b/modules/ui/translationunits/mw.cx.ui.LinkTranslationUnit.js
index 82e14a4..1f589c8 100644
--- a/modules/ui/translationunits/mw.cx.ui.LinkTranslationUnit.js
+++ b/modules/ui/translationunits/mw.cx.ui.LinkTranslationUnit.js
@@ -24,7 +24,8 @@
 mw.cx.ui.LinkTranslationUnit.static.highlightClass = 'cx-highlight--lightblue';
 mw.cx.ui.LinkTranslationUnit.static.tools = {
        sourcelink: [ 'click', 'focus' ],
-       targetlink: [ 'click', 'focus' ]
+       targetlink: [ 'click', 'focus' ],
+       newlink: [ 'click', 'focus' ]
 };
 
 /**
diff --git a/modules/ui/translationunits/mw.cx.ui.SectionTranslationUnit.js 
b/modules/ui/translationunits/mw.cx.ui.SectionTranslationUnit.js
index d69cd22..45092e9 100644
--- a/modules/ui/translationunits/mw.cx.ui.SectionTranslationUnit.js
+++ b/modules/ui/translationunits/mw.cx.ui.SectionTranslationUnit.js
@@ -28,7 +28,9 @@
        search: [ 'click' ],
        formatter: [ 'select', 'click', 'focus' ],
        machinetranslation: [ 'click' ],
-       dictionary: [ 'select' ]
+       dictionary: [ 'select' ],
+       targetlink: [ 'select' ],
+       newlink: [ 'select' ]
 };
 
 /**

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: If748e00d58bad83ec8135ac9b38e4a570d955cd7
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

Reply via email to