[MediaWiki-commits] [Gerrit] mediawiki...ContentTranslation[master]: Show only relevant languages in New translation

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

Change subject: Show only relevant languages in New translation
..


Show only relevant languages in New translation

- Show only source languages the article exists in,
and make bold target languages where the article does not exist.
- Fix validation on embedded New translation dialog.

Bug: T111094
Change-Id: Ia7c11f00a2125bec0d17471b426b44655209c595
---
M modules/source/ext.cx.source.selector.js
1 file changed, 188 insertions(+), 46 deletions(-)

Approvals:
  jenkins-bot: Verified
  Nikerabbit: Checked; Looks good to me, approved



diff --git a/modules/source/ext.cx.source.selector.js 
b/modules/source/ext.cx.source.selector.js
index 0145240..fe55bc1 100644
--- a/modules/source/ext.cx.source.selector.js
+++ b/modules/source/ext.cx.source.selector.js
@@ -25,18 +25,26 @@
 
// Boolean property indicating if CXSourceSelector is used as
// modal dialog or embedded
-   this.embedded = !!options.container && options.container 
instanceof jQuery;
+   this.isEmbedded = !!options.container && options.container 
instanceof jQuery;
 
-   this.sourceLanguages = [];
-   this.targetLanguages = [];
-   this.sourceLanguage = null;
-   this.targetLanguage = null;
// this.$container is used for both types of CXSourceSelector - 
embedded and modal dialog
// Embedded version - $container field gets DOM container 
passed through options parameter
// Dialog version - $container fields gets created in 
renderAsDialog method of this class
-   this.$container = this.embedded ? options.container : null;
+   this.$container = this.isEmbedded ? options.container : null;
+
+   // this.sourceLanguages and this.targetLanguages are arrays of 
language codes retrieved from cx-server
+   // Represents all possible source/target language codes
+   this.sourceLanguages = [];
+   this.targetLanguages = [];
+   // this.sourceLanguage and this.targetLanguage are selected 
source/target languages respectively
+   this.sourceLanguage = null;
+   this.targetLanguage = null;
+   // this.sourceTitles is a map of language codes to article 
titles in those languages
+   this.sourceTitles = {};
+
this.$selectedItem = null;
this.$selectedItemImage = null;
+   this.$selectedItemLink = null;
this.$selectedItemInfo = null;
this.$languageFilter = null;
this.$sourceLanguage = null;
@@ -75,15 +83,11 @@
 * @return {string} wide, medium or narrow
 */
function getUlsMenuWidth( languagesCount ) {
-   if ( languagesCount <= 12 ) {
+   if ( languagesCount <= 16 ) {
return 'narrow';
}
 
-   if ( languagesCount <= 100 ) {
-   return 'medium';
-   }
-
-   return 'wide';
+   return 'medium';
}
 
/**
@@ -130,8 +134,8 @@
this.sourcePageSelector.setValue( 
this.options.sourceTitle );
}
 
-   // !this.embedded is extra check, second one may be sufficient
-   if ( !this.embedded && this.options.targetTitle ) {
+   // !this.isEmbedded is extra check, second one may be sufficient
+   if ( !this.isEmbedded && this.options.targetTitle ) {
this.$targetTitleInput.val( this.options.targetTitle );
}
 
@@ -208,7 +212,8 @@
 * @param {string} language A language code
 */
CXSourceSelector.prototype.setSourceLanguage = function ( language ) {
-   var langProps, currentSource;
+   var langProps, currentSource,
+   languagesArticleExistsIn = Object.keys( 
this.sourceTitles );
 
// Do not allow selection of invalid source languages under any 
circumstances
if ( !this.isValidSource( language ) ) {
@@ -240,7 +245,8 @@
.text( $.uls.data.getAutonym( this.sourceLanguage ) );
mw.storage.set( 'cxSourceLanguage', this.sourceLanguage );
this.sourcePageSelector.setLanguage( this.sourceLanguage );
-   this.fillTargetLanguages( this.targetLanguages );
+
+   this.fillTargetLanguages( languagesArticleExistsIn );
};
 
/**
@@ -268,7 +274,7 @@
lang: this.targetLanguage,
dir: $.uls.data.getDir( this.targetLanguage )
};
-   if ( !this.embedded ) {
+   if ( !this.isEmbedded ) {
 

[MediaWiki-commits] [Gerrit] mediawiki...ContentTranslation[master]: Show only relevant languages in New translation

2017-08-28 Thread Petar.petkovic (Code Review)
Petar.petkovic has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/374425 )

Change subject: Show only relevant languages in New translation
..

Show only relevant languages in New translation

- Show only source languages the article exists in,
and make bold target languages where the article does not exist.
- Fix validation on embedded New translation dialog.

Bug: T111094
Change-Id: Ia7c11f00a2125bec0d17471b426b44655209c595
---
M modules/source/ext.cx.source.selector.js
1 file changed, 194 insertions(+), 40 deletions(-)


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

diff --git a/modules/source/ext.cx.source.selector.js 
b/modules/source/ext.cx.source.selector.js
index f500149..7404e4c 100644
--- a/modules/source/ext.cx.source.selector.js
+++ b/modules/source/ext.cx.source.selector.js
@@ -25,18 +25,26 @@
 
// Boolean property indicating if CXSourceSelector is used as
// modal dialog or embedded
-   this.embedded = !!options.container && options.container 
instanceof jQuery;
+   this.isEmbedded = !!options.container && options.container 
instanceof jQuery;
 
-   this.sourceLanguages = [];
-   this.targetLanguages = [];
-   this.sourceLanguage = null;
-   this.targetLanguage = null;
// this.$container is used for both types of CXSourceSelector - 
embedded and modal dialog
// Embedded version - $container field gets DOM container 
passed through options parameter
// Dialog version - $container fields gets created in 
renderAsDialog method of this class
-   this.$container = this.embedded ? options.container : null;
+   this.$container = this.isEmbedded ? options.container : null;
+
+   // this.sourceLanguages and this.targetLanguages are arrays of 
language codes retrieved from cx-server
+   // Represents all possible source/target language codes
+   this.sourceLanguages = [];
+   this.targetLanguages = [];
+   // this.sourceLanguage and this.targetLanguage are selected 
source/target languages respectively
+   this.sourceLanguage = null;
+   this.targetLanguage = null;
+   // this.sourceTitles is a map of language codes to article 
titles in those languages
+   this.sourceTitles = {};
+
this.$selectedItem = null;
this.$selectedItemImage = null;
+   this.$selectedItemLink = null;
this.$selectedItemInfo = null;
this.$languageFilter = null;
this.$sourceLanguage = null;
@@ -130,8 +138,8 @@
this.sourcePageSelector.setValue( 
this.options.sourceTitle );
}
 
-   // !this.embedded is extra check, second one may be sufficient
-   if ( !this.embedded && this.options.targetTitle ) {
+   // !this.isEmbedded is extra check, second one may be sufficient
+   if ( !this.isEmbedded && this.options.targetTitle ) {
this.$targetTitleInput.val( this.options.targetTitle );
}
 
@@ -208,7 +216,8 @@
 * @param {string} language A language code
 */
CXSourceSelector.prototype.setSourceLanguage = function ( language ) {
-   var langProps, currentSource;
+   var langProps, currentSource,
+   languagesArticleExistsIn = Object.keys( 
this.sourceTitles );
 
// Do not allow selection of invalid source languages under any 
circumstances
if ( !this.isValidSource( language ) ) {
@@ -240,7 +249,8 @@
.text( $.uls.data.getAutonym( this.sourceLanguage ) );
mw.storage.set( 'cxSourceLanguage', this.sourceLanguage );
this.sourcePageSelector.setLanguage( this.sourceLanguage );
-   this.fillTargetLanguages( this.targetLanguages );
+
+   this.fillTargetLanguages( languagesArticleExistsIn );
};
 
/**
@@ -268,7 +278,7 @@
lang: this.targetLanguage,
dir: $.uls.data.getDir( this.targetLanguage )
};
-   if ( !this.embedded ) {
+   if ( !this.isEmbedded ) {
this.$targetTitleInput.prop( langProps );
}
this.$targetLanguage.prop( langProps )
@@ -277,13 +287,54 @@
mw.storage.set( 'cxTargetLanguage', this.targetLanguage );
};
 
+   /*
+   * Fill the source language dropdown with source languages
+   * for which selected article exists
+   * @param {array} sourceLanguages - array of language codes used to 
populate ULS
+   */
+