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 = ''