[MediaWiki-commits] [Gerrit] LanguageInputWidget Generalization - change (mediawiki...VisualEditor)

2013-08-15 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged.

Change subject: LanguageInputWidget Generalization
..


LanguageInputWidget Generalization

This commit prepares the LanguageInputWidget to handle both annotation
and node, so it can be used as the GUI for both the LanguageInspector
and the LanguageBlockInspector that's coming up.

Cleaned up the way annotations are read into LanguageInspector and
AnnotationInspector. The attributes are kept in the Widget (without regard
to what datamodel they will serve) and are then read from the inspector.
The LinkInspector had to be adjusted slightly to accomodate a small change
in the AnnotationInspector too.

Change-Id: I17954707c00ffc4c32fbb44a6807a61760ad573c
---
M modules/ve/ui/inspectors/ve.ui.AnnotationInspector.js
M modules/ve/ui/inspectors/ve.ui.LanguageInspector.js
M modules/ve/ui/inspectors/ve.ui.LinkInspector.js
M modules/ve/ui/widgets/ve.ui.LanguageInputWidget.js
4 files changed, 153 insertions(+), 81 deletions(-)

Approvals:
  Catrope: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/modules/ve/ui/inspectors/ve.ui.AnnotationInspector.js 
b/modules/ve/ui/inspectors/ve.ui.AnnotationInspector.js
index c5f4c9c..7f5ca7e 100644
--- a/modules/ve/ui/inspectors/ve.ui.AnnotationInspector.js
+++ b/modules/ve/ui/inspectors/ve.ui.AnnotationInspector.js
@@ -121,7 +121,7 @@
clear = false,
set = false,
target = this.targetInput.getValue(),
-   annotation = this.targetInput.getAnnotation(),
+   annotation = this.getAnnotation(),
remove = target === '' || ( action === 'remove' && !!annotation 
),
surfaceModel = this.surface.getModel(),
fragment = surfaceModel.getFragment( this.initialSelection, 
false ),
diff --git a/modules/ve/ui/inspectors/ve.ui.LanguageInspector.js 
b/modules/ve/ui/inspectors/ve.ui.LanguageInspector.js
index 9f9fc1a..41ee0c4 100644
--- a/modules/ve/ui/inspectors/ve.ui.LanguageInspector.js
+++ b/modules/ve/ui/inspectors/ve.ui.LanguageInspector.js
@@ -19,8 +19,12 @@
// Parent constructor
ve.ui.AnnotationInspector.call( this, surface, config );
 
+   // Placeholder for the dm properties:
this.initLang = '';
this.initDir = '';
+
+   // Placeholder for the annotation:
+   this.annotation = null;
 };
 
 /* Inheritance */
@@ -54,7 +58,8 @@
 
// Properties
this.targetInput = new ve.ui.LanguageInputWidget( {
-   '$$': this.frame.$$, '$overlay': this.surface.$localOverlay
+   '$$': this.frame.$$,
+   '$overlay': this.surface.$localOverlay
} );
 
// Initialization
@@ -71,14 +76,14 @@
// Wait for animation to complete
setTimeout( ve.bind( function () {
// Setup annotation
-   this.targetInput.setAnnotation( this.initialAnnotation );
+   this.setAnnotation( this.initialAnnotation );
}, this ), 200 );
 };
 /**
- * Handle the inspector being setup.
- * Make sure the initial language and direction are set by the parent of the 
DOM
- * element of the selected fragment before the rest of the onSetup method is
- * processed by the parent ve.ui.AnnotationInspector
+ * Handle the inspector being set up.
+ * Make sure the initial language and direction are set by the parent
+ * of the DOM element of the selected fragment before the rest of the
+ * onSetup method is processed by the parent ve.ui.AnnotationInspector
  */
 ve.ui.LanguageInspector.prototype.onSetup = function () {
var fragDOM,
@@ -98,6 +103,90 @@
// Parent method
ve.ui.AnnotationInspector.prototype.onSetup.call( this );
 };
+
+
+/**
+ * Handle the inspector being closed: refresh the annotation
+ * from the widget values
+ *
+ * @param {string} action Action that caused the window to be closed
+ */
+ve.ui.LanguageInspector.prototype.onClose = function ( action ) {
+   // Read the annotation values from the widget:
+   var attrs = this.targetInput.getAttributes();
+
+   // Set the annotation with the new attributes:
+   this.annotation = new ve.dm.LanguageAnnotation( {
+   'type': 'language',
+   'attributes': attrs
+   } );
+
+   // Call parent method
+   ve.ui.AnnotationInspector.prototype.onClose.call( this, action );
+
+};
+
+/**
+ * Gets the annotation value.
+ *
+ * @method
+ * @returns {ve.dm.LanguageAnnotation} Language annotation
+ */
+ve.ui.LanguageInspector.prototype.getAnnotation = function () {
+   return this.annotation;
+};
+
+
+/**
+ * Validates and sets the annotation value
+ * Then updates the attributes and the widget table display
+ *
+ * @method
+ * @param {ve.dm.LanguageAnnotation} annotation Language annotation
+ * @chainable
+ */
+ve.ui.LanguageInspector.prototype.setAnnotation = function ( annotation ) {
+   var langCode = ''

[MediaWiki-commits] [Gerrit] LanguageInputWidget Generalization - change (mediawiki...VisualEditor)

2013-08-10 Thread Mooeypoo (Code Review)
Mooeypoo has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/78545


Change subject: LanguageInputWidget Generalization
..

LanguageInputWidget Generalization

This commit prepares the LanguageInputWidget to handle both annotation
and node, so it can be used as the GUI for both the LanguageInspector
and the LanguageBlockInspector that's coming up.

The LanguageInspector was adjusted mildly to accomodate the change
in the widget.

Change-Id: I17954707c00ffc4c32fbb44a6807a61760ad573c
---
M modules/ve/ui/inspectors/ve.ui.LanguageInspector.js
M modules/ve/ui/widgets/ve.ui.LanguageInputWidget.js
2 files changed, 96 insertions(+), 44 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor 
refs/changes/45/78545/1

diff --git a/modules/ve/ui/inspectors/ve.ui.LanguageInspector.js 
b/modules/ve/ui/inspectors/ve.ui.LanguageInspector.js
index 9f9fc1a..67a90a9 100644
--- a/modules/ve/ui/inspectors/ve.ui.LanguageInspector.js
+++ b/modules/ve/ui/inspectors/ve.ui.LanguageInspector.js
@@ -19,6 +19,7 @@
// Parent constructor
ve.ui.AnnotationInspector.call( this, surface, config );
 
+   // Placeholder for the dm properties:
this.initLang = '';
this.initDir = '';
 };
@@ -54,8 +55,12 @@
 
// Properties
this.targetInput = new ve.ui.LanguageInputWidget( {
-   '$$': this.frame.$$, '$overlay': this.surface.$localOverlay
+   '$$': this.frame.$$,
+   '$overlay': this.surface.$localOverlay
} );
+
+   // Define the LanguageInputWidget as an annotation:
+   this.targetInput.dataType = "annotation";
 
// Initialization
this.$form.append( this.targetInput.$ );
@@ -75,10 +80,10 @@
}, this ), 200 );
 };
 /**
- * Handle the inspector being setup.
- * Make sure the initial language and direction are set by the parent of the 
DOM
- * element of the selected fragment before the rest of the onSetup method is
- * processed by the parent ve.ui.AnnotationInspector
+ * Handle the inspector being set up.
+ * Make sure the initial language and direction are set by the parent
+ * of the DOM element of the selected fragment before the rest of the
+ * onSetup method is processed by the parent ve.ui.AnnotationInspector
  */
 ve.ui.LanguageInspector.prototype.onSetup = function () {
var fragDOM,
diff --git a/modules/ve/ui/widgets/ve.ui.LanguageInputWidget.js 
b/modules/ve/ui/widgets/ve.ui.LanguageInputWidget.js
index c76e0bc..30bc1ce 100644
--- a/modules/ve/ui/widgets/ve.ui.LanguageInputWidget.js
+++ b/modules/ve/ui/widgets/ve.ui.LanguageInputWidget.js
@@ -20,13 +20,16 @@
// Parent constructor
ve.ui.Widget.call( this, config );
 
-   // Properties
+   // Visual Properties
this.$langCodeDisp = this.getDisplayElement( config ); // language code
this.$langNameDisp = this.getDisplayElement( config ); // 
human-readable language name
this.$dirDisp = this.getDisplayElement( config );
 
-   // Placeholders for annotation value
+   // Placeholders for datamodels:
this.annotation = null;
+   this.node = null;
+
+   // Placeholders for attribute values
this.lang = '';
this.dir = '';
 
@@ -65,7 +68,17 @@
 
ulsParams = {
onSelect: function( language ) {
-   langInpObj.setValue( language );
+   var newAnnotation = new ve.dm.LanguageAnnotation( {
+   'type': 'language',
+   'attributes': {
+   'lang': language,
+   'dir': $.uls.data.getDir( 
this.lang )
+   }
+   } );
+   // Set the new value, annotation or node:
+   if ( langInpObj.dataType === 'annotation' ) {
+   langInpObj.setAnnotation( newAnnotation );
+   }
},
compact: true,
// Temporary Quicklist for the Prototype:
@@ -89,7 +102,13 @@
 
 ve.inheritClass( ve.ui.LanguageInputWidget, ve.ui.Widget );
 
+/* Static properties */
+
+// This will define whether we are in "annotation" or "node" mode:
+ve.ui.LanguageInputWidget.static.dataType = '';
+
 /* Methods */
+
 /**
  * Get display element. This replaces the 'getInputElement'
  * of the InputWidget
@@ -103,76 +122,104 @@
 };
 
 /**
- * Set the value of the language display
+ * Return the current language attributes
  *
- * Overrides setValue to keep annotations in sync.
- *
- * @method
- * @param {string} value New value
  */
-ve.ui.LanguageInputWidget.prototype.setValue = function ( value ) {
-   // Keep annotation in sync with value
-   if ( value === '' ) {
-   this.annotation = nu