Daniel Werner has submitted this change and it was merged.

Change subject: [coordinate.js] Implemented coordinate expert widgets
......................................................................


[coordinate.js] Implemented coordinate expert widgets

Change-Id: Id62bc61c51b1b78dbba0799d5ceea0438958bd64
---
M ValueView/ValueView.resources.mw.php
M ValueView/ValueView.resources.php
M ValueView/ValueView.tests.qunit.php
A 
ValueView/resources/jquery.valueview/valueview.experts/experts.CoordinateInput.js
A 
ValueView/resources/jquery.valueview/valueview.experts/experts.CoordinateValue.js
M ValueView/resources/mw.ext.valueView.js
A 
ValueView/tests/qunit/jquery.valueview/valueview.experts/experts.CoordinateInput.tests.js
7 files changed, 309 insertions(+), 1 deletion(-)

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



diff --git a/ValueView/ValueView.resources.mw.php 
b/ValueView/ValueView.resources.mw.php
index 11a4406..3f7bbf3 100644
--- a/ValueView/ValueView.resources.mw.php
+++ b/ValueView/ValueView.resources.mw.php
@@ -44,6 +44,7 @@
                        'dependencies' => array(
                                'jquery.valueview',
                                'jquery.valueview.experts.stringvalue',
+                               'jquery.valueview.experts.coordinatevalue',
                                'jquery.valueview.experts.timevalue',
                                'jquery.valueview.experts.commonsmediatype'
                        ),
diff --git a/ValueView/ValueView.resources.php 
b/ValueView/ValueView.resources.php
index d40ed0e..e55a3b5 100644
--- a/ValueView/ValueView.resources.php
+++ b/ValueView/ValueView.resources.php
@@ -9,6 +9,7 @@
  * - jQuery.eachchange
  * - jQuery.inputAutoExpand
  * - jQuery.ui.suggester
+ * - jQuery.coordinate.coordinateinput
  * - jQuery.time.timeinput
  * - jQuery.ui.toggler
  *
@@ -197,6 +198,34 @@
                        ),
                ),
 
+               'jquery.valueview.experts.coordinateinput' => $moduleTemplate + 
array(
+                       'scripts' => array(
+                               
'jquery.valueview/valueview.experts/experts.CoordinateInput.js',
+                       ),
+                       'dependencies' => array(
+                               'jquery.valueview.experts',
+                               'jquery.fn.focusAt',
+                               'jquery.coordinate.coordinateinput',
+                               'jquery.ui.inputextender',
+                               'jquery.valueview.preview',
+                       ),
+                       'messages' => array(
+                               'valueview-preview-label',
+                               'valueview-preview-novalue',
+                       ),
+               ),
+
+               'jquery.valueview.experts.coordinatevalue' => $moduleTemplate + 
array(
+                       'scripts' => array(
+                               
'jquery.valueview/valueview.experts/experts.CoordinateValue.js',
+                       ),
+                       'dependencies' => array(
+                               'jquery.valueview.experts.staticdom',
+                               'jquery.valueview.BifidExpert',
+                               'jquery.valueview.experts.coordinateinput',
+                       ),
+               ),
+
                'jquery.valueview.experts.timeinput' => $moduleTemplate + array(
                        'scripts' => array(
                                
'jquery.valueview/valueview.experts/experts.TimeInput.js',
diff --git a/ValueView/ValueView.tests.qunit.php 
b/ValueView/ValueView.tests.qunit.php
index 0da1fec..b34d455 100644
--- a/ValueView/ValueView.tests.qunit.php
+++ b/ValueView/ValueView.tests.qunit.php
@@ -157,6 +157,15 @@
                        ),
                ),
 
+               'jquery.valueview.experts.coordinateinput.tests' => array(
+                       'scripts' => array(
+                               
"$bp/jquery.valueview/valueview.experts/experts.CoordinateInput.tests.js",
+                       ),
+                       'dependencies' => array(
+                               'jquery.valueview.experts.coordinateinput',
+                       ),
+               ),
+
                'jquery.valueview.experts.timeinput.tests' => array(
                        'scripts' => array(
                                
"$bp/jquery.valueview/valueview.experts/experts.TimeInput.tests.js",
diff --git 
a/ValueView/resources/jquery.valueview/valueview.experts/experts.CoordinateInput.js
 
b/ValueView/resources/jquery.valueview/valueview.experts/experts.CoordinateInput.js
new file mode 100644
index 0000000..4fa6ff2
--- /dev/null
+++ 
b/ValueView/resources/jquery.valueview/valueview.experts/experts.CoordinateInput.js
@@ -0,0 +1,180 @@
+/**
+ * @file
+ * @ingroup ValueView
+ * @licence GNU GPL v2+
+ *
+ * @author H. Snater < [email protected] >
+ */
+( function( dv, vp, $, vv, Coordinate ) {
+       'use strict';
+
+       var PARENT = vv.Expert;
+
+       /**
+        * Valueview expert handling input of coordinate values.
+        *
+        * @since 0.1
+        *
+        * @constructor
+        * @extends jQuery.valueview.Expert
+        */
+       vv.experts.CoordinateInput = vv.expert( 'coordinateinput', PARENT, {
+               /**
+                * The the input element's node.
+                * @type {jQuery}
+                */
+               $input: null,
+
+               /**
+                * Caches a new value (or null for no value) set by 
_setRawValue() until draw() displaying
+                * the new value has been called. The use of this, basically, 
is a structural improvement
+                * which allows moving setting the displayed value to the 
draw() method which is supposed to
+                * handle all visual manners.
+                * @type {coordinate.Coordinate|null|false}
+                */
+               _newValue: null,
+
+               /**
+                * The preview widget.
+                * @type {jQuery.valueview.preview}
+                */
+               preview: null,
+
+               /**
+                * @see jQuery.valueview.Expert._init
+                */
+               _init: function() {
+                       var self = this;
+
+                       this.$input = $( '<input/>', {
+                               type: 'text',
+                               'class': this.uiBaseClass + '-input 
valueview-input'
+                       } )
+                       .appendTo( this.$viewPort );
+
+                       var $preview = $( '<div/>' ).preview( { $input: 
this.$input } );
+                       this.preview = $preview.data( 'preview' );
+
+                       this.$input.eachchange( function( event, oldValue ) {
+                               var value = self.$input.data( 'coordinateinput' 
).value();
+                               if( oldValue === '' && value === null || 
self.$input.val() === '' ) {
+                                       self._updatePreview();
+                               }
+                       } )
+                       .coordinateinput()
+                       .inputextender( {
+                               content: [ $preview ]
+                       } )
+                       .on( 'coordinateinputupdate.' + this.uiBaseClass, 
function( event, value ) {
+                               self._newValue = false; // value, not yet 
handled by draw(), is outdated now
+                               self._viewNotifier.notify( 'change' );
+                               self._updatePreview();
+                       } );
+
+               },
+
+               /**
+                * @see jQuery.valueview.Expert.destroy
+                */
+               destroy: function() {
+                       var previewElement = this.preview.element;
+                       this.preview.destroy();
+                       previewElement.remove();
+
+                       this.$input.data( 'inputextender' ).destroy();
+                       this.$input.data( 'coordinateinput' ).destroy();
+                       this.$input.remove();
+
+                       PARENT.prototype.destroy.call( this );
+               },
+
+               /**
+                * Updates the preview.
+                */
+               _updatePreview: function() {
+                       var rawValue = this._getRawValue();
+                       this.preview.update( ( rawValue ) ? 
rawValue.degreeText() : null );
+               },
+
+               /**
+                * @see jQuery.valueview.Expert.parser
+                */
+               parser: function() {
+                       return new vp.CoordinateParser();
+               },
+
+               /**
+                * @see jQuery.valueview.Expert._getRawValue
+                *
+                * @return {coordinate.Coordinate|null}
+                */
+               _getRawValue: function() {
+                       return ( this._newValue !== false )
+                               ? this._newValue
+                               : this.$input.data( 'coordinateinput' ).value();
+               },
+
+               /**
+                * @see jQuery.valueview.Expert._setRawValue
+                *
+                * @param {coordinate.Coordinate|null} coordinate
+                */
+               _setRawValue: function( coordinate ) {
+                       if( !( coordinate instanceof Coordinate ) || 
!coordinate.isValid() ) {
+                               coordinate = null;
+                       }
+                       this._newValue = coordinate;
+               },
+
+               /**
+                * @see jQuery.valueview.Expert.rawValueCompare
+                */
+               rawValueCompare: function( coordinate1, coordinate2 ) {
+                       if( coordinate2 === undefined ) {
+                               coordinate2 = this._getRawValue();
+                       }
+
+                       if( coordinate1 === null && coordinate2 === null ) {
+                               return true;
+                       }
+
+                       if( !( coordinate1 instanceof Coordinate ) || !( 
coordinate2 instanceof Coordinate ) ) {
+                               return false;
+                       }
+
+                       return coordinate1.equals( coordinate2 );
+               },
+
+               /**
+                * @see jQuery.valueview.Expert.draw
+                */
+               draw: function() {
+                       if( this._viewState.isDisabled() ) {
+                               this.$input.data( 'coordinateinput' ).disable();
+                       } else {
+                               this.$input.data( 'coordinateinput' ).enable();
+                       }
+
+                       if( this._newValue !== false ) {
+                               this.$input.data( 'coordinateinput' ).value( 
this._newValue );
+                               this._newValue = false;
+                               this._updatePreview();
+                       }
+               },
+
+               /**
+                * @see jQuery.valueview.Expert.focus
+                */
+               focus: function() {
+                       this.$input.focusAt( 'end' );
+               },
+
+               /**
+                * @see jQuery.valueview.Expert.blur
+                */
+               blur: function() {
+                       this.$input.blur();
+               }
+       } );
+
+}( dataValues, valueParsers, jQuery, jQuery.valueview, coordinate.Coordinate ) 
);
diff --git 
a/ValueView/resources/jquery.valueview/valueview.experts/experts.CoordinateValue.js
 
b/ValueView/resources/jquery.valueview/valueview.experts/experts.CoordinateValue.js
new file mode 100644
index 0000000..dc29150
--- /dev/null
+++ 
b/ValueView/resources/jquery.valueview/valueview.experts/experts.CoordinateValue.js
@@ -0,0 +1,54 @@
+/**
+ * @file
+ * @ingroup ValueView
+ * @licence GNU GPL v2+
+ *
+ * @author H. Snater < [email protected] >
+ */
+( function( dv, vp, $, vv ) {
+       'use strict';
+
+       var PARENT = vv.BifidExpert,
+               editableExpert = vv.experts.CoordinateInput;
+
+       /**
+        * Valueview expert for handling coordinate values.
+        *
+        * @since 0.1
+        *
+        * @constructor
+        * @extends jQuery.valueview.experts.BifidExpert
+        */
+       vv.experts.CoordinateValue = vv.expert( 'coordinatevalue', PARENT, {
+               /**
+                * @see jQuery.valueview.BifidExpert._editableExpert
+                */
+               _editableExpert: editableExpert,
+
+               /**
+                * @see jQuery.valueview.BifidExpert._editableExpertOptions
+                */
+               _editableExpertOptions: {},
+
+               /**
+                * @see jQuery.valueview.BifidExpert._staticExpert
+                */
+               _staticExpert: vv.experts.StaticDom,
+
+               /**
+                * @see jQuery.valueview.BifidExpert._staticExpertOptions
+                */
+               _staticExpertOptions: {
+                       /**
+                        * @param {coordinate.Coordinate|null} currentRawValue
+                        * @param {jQuery.valueview.ViewState} viewState
+                        */
+                       domBuilder: function( currentRawValue, viewState ) {
+                               var $node = $( '<span/>' );
+                               return ( currentRawValue ) ? $node.text( 
currentRawValue.degreeText() ) : $node;
+                       },
+                       baseExpert: editableExpert
+               }
+       } );
+
+}( dataValues, valueParsers, jQuery, jQuery.valueview ) );
diff --git a/ValueView/resources/mw.ext.valueView.js 
b/ValueView/resources/mw.ext.valueView.js
index 1988a42..ea18c12 100644
--- a/ValueView/resources/mw.ext.valueView.js
+++ b/ValueView/resources/mw.ext.valueView.js
@@ -8,7 +8,7 @@
  * @author Daniel Werner < [email protected] >
  */
 ( function( mw, dv, dt, $, vv ) {
-       "use strict";
+       'use strict';
 
        mw.ext = mw.ext || {};
 
@@ -21,6 +21,11 @@
        );
 
        expertProvider.registerExpert(
+               dv.CoordinateValue,
+               vv.experts.CoordinateValue
+       );
+
+       expertProvider.registerExpert(
                dv.TimeValue,
                vv.experts.TimeValue
        );
diff --git 
a/ValueView/tests/qunit/jquery.valueview/valueview.experts/experts.CoordinateInput.tests.js
 
b/ValueView/tests/qunit/jquery.valueview/valueview.experts/experts.CoordinateInput.tests.js
new file mode 100644
index 0000000..10854f6
--- /dev/null
+++ 
b/ValueView/tests/qunit/jquery.valueview/valueview.experts/experts.CoordinateInput.tests.js
@@ -0,0 +1,30 @@
+/**
+ * @since 0.1
+ * @ingroup ValueView
+ * @licence GNU GPL v2+
+ *
+ * @author H. Snater < [email protected] >
+ */
+( function( $, QUnit, valueview, Coordinate, CoordinateParser ) {
+       'use strict';
+
+       var testExpert = valueview.tests.testExpert;
+
+       QUnit.module( 'jquery.valueview.experts.CoordinateInput' );
+
+       testExpert( {
+               expertConstructor: valueview.experts.CoordinateInput,
+               rawValues: {
+                       valid: [
+                               new Coordinate( '30, 30' ),
+                               new Coordinate( '-1.5 -1.25' )
+                       ],
+                       unknown: 
testExpert.basicTestDefinition.rawValues.unknown.concat( [
+                               42,
+                               '1 1'
+                       ] )
+               },
+               relatedValueParser: CoordinateParser
+       } );
+
+}( jQuery, QUnit, jQuery.valueview, coordinate.Coordinate, 
valueParsers.CoordinateParser ) );

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Id62bc61c51b1b78dbba0799d5ceea0438958bd64
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/DataValues
Gerrit-Branch: master
Gerrit-Owner: Henning Snater <[email protected]>
Gerrit-Reviewer: Daniel Werner <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to