Henning Snater has uploaded a new change for review.

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


Change subject: [coordinate.js] Implemented list rotator to set precision
......................................................................

[coordinate.js] Implemented list rotator to set precision

A list rotator widget instance may be used to adjust the automatically
detected coordinate precision.

Change-Id: I00af947ac30a26cdac76fbe7f6eb23d6e3164f05
---
M ValueView/ValueView.i18n.php
M ValueView/ValueView.resources.php
A 
ValueView/resources/jquery.valueview/valueview.experts/experts.CoordinateInput.css
M 
ValueView/resources/jquery.valueview/valueview.experts/experts.CoordinateInput.js
4 files changed, 136 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DataValues 
refs/changes/89/66089/1

diff --git a/ValueView/ValueView.i18n.php b/ValueView/ValueView.i18n.php
index e1962c9..b4a93b3 100644
--- a/ValueView/ValueView.i18n.php
+++ b/ValueView/ValueView.i18n.php
@@ -45,6 +45,9 @@
        // EmptyValue expert:
        'valueview-expert-emptyvalue-empty' => 'empty',
 
+       // CoordinateInput expert:
+       'valueview-expert-coordinateinput-precision' => 'Precision:',
+
        // TimeInput expert:
        'valueview-expert-timeinput-precision' => 'Precision:',
        'valueview-expert-timeinput-calendar' => 'Calendar:',
@@ -76,6 +79,7 @@
 * $1 - the name of the data type which lacks support',
        'valueview-expert-emptyvalue-empty' => 'Message expressing that there 
is currently no value set in a jQuery valueview.
 {{Identical|Empty}}',
+       'valueview-expert-coordinateinput-precision' => 'Label for the user 
interface element used to set a specific precision (e.g. 1, 0.1, 0.001) when 
entering a coordinate value.',
        'valueview-expert-timeinput-precision' => 'Label for the user interface 
element used to set a specific precision (e.g. hour, day, month, year) when 
entering a time value.',
        'valueview-expert-timeinput-calendar' => 'Label for the user interface 
element used to select a specific calendar (e.g. Gregorian, Julian) entering a 
time value.
 
diff --git a/ValueView/ValueView.resources.php 
b/ValueView/ValueView.resources.php
index e55a3b5..c1e4f85 100644
--- a/ValueView/ValueView.resources.php
+++ b/ValueView/ValueView.resources.php
@@ -210,6 +210,7 @@
                                'jquery.valueview.preview',
                        ),
                        'messages' => array(
+                               'valueview-expert-coordinateinput-precision',
                                'valueview-preview-label',
                                'valueview-preview-novalue',
                        ),
@@ -219,6 +220,9 @@
                        'scripts' => array(
                                
'jquery.valueview/valueview.experts/experts.CoordinateValue.js',
                        ),
+                       'styles' => array(
+                               
'jquery.valueview/valueview.experts/experts.CoordinateInput.css',
+                       ),
                        'dependencies' => array(
                                'jquery.valueview.experts.staticdom',
                                'jquery.valueview.BifidExpert',
diff --git 
a/ValueView/resources/jquery.valueview/valueview.experts/experts.CoordinateInput.css
 
b/ValueView/resources/jquery.valueview/valueview.experts/experts.CoordinateInput.css
new file mode 100644
index 0000000..cc34775
--- /dev/null
+++ 
b/ValueView/resources/jquery.valueview/valueview.experts/experts.CoordinateInput.css
@@ -0,0 +1,23 @@
+/**
+ * Styles for valueview's CoordinateInput expert.
+ *
+ * @since 0.1
+ * @file
+ * @ingroup ValueView
+ *
+ * @license GNU GPL v2+
+ * @author H. Snater < [email protected] >
+ */
+
+.valueview-expert-coordinateinput-input {
+       width: 100%;
+}
+
+.ui-inputextender-extension .valueview-expert-coordinateinput-advancedtoggler {
+       border: none;
+       background: none;
+       margin-top: 0.5em;
+       padding-top: 0.5em;
+       border-top: 1px dashed #CCC;
+       width: 100%;
+}
diff --git 
a/ValueView/resources/jquery.valueview/valueview.experts/experts.CoordinateInput.js
 
b/ValueView/resources/jquery.valueview/valueview.experts/experts.CoordinateInput.js
index 4fa6ff2..9664bf8 100644
--- 
a/ValueView/resources/jquery.valueview/valueview.experts/experts.CoordinateInput.js
+++ 
b/ValueView/resources/jquery.valueview/valueview.experts/experts.CoordinateInput.js
@@ -5,8 +5,12 @@
  *
  * @author H. Snater < [email protected] >
  */
-( function( dv, vp, $, vv, Coordinate ) {
+// TODO: Remove mediaWiki dependency
+( function( dv, vp, $, vv, coordinate, mw ) {
        'use strict';
+
+       var Coordinate = coordinate.Coordinate,
+               coordinateSettings = coordinate.settings;
 
        var PARENT = vv.Expert;
 
@@ -41,10 +45,63 @@
                preview: null,
 
                /**
+                * Container node for precision input and label.
+                * @type {jQuery}
+                */
+               $precisionContainer: null,
+
+               /**
+                * Node of the widget used to specify the precision.
+                * @type {jQuery}
+                */
+               $precision: null,
+
+               /**
                 * @see jQuery.valueview.Expert._init
                 */
                _init: function() {
                        var self = this;
+
+                       this.$precisionContainer = $( '<div/>' )
+                       .addClass( this.uiBaseClass + '-precisioncontainer' )
+                       .append( $( '<div/>' ).text( mw.msg( 
'valueview-expert-coordinateinput-precision' ) ) );
+
+                       var precisionValues = [];
+                       $.each( coordinateSettings.precisions, function( i, 
precisionDefinition ) {
+                               var label = ( precisionDefinition.text )
+                                       ? precisionDefinition.text
+                                       : precisionDefinition.level;
+
+                               precisionValues.push( { value: 
precisionDefinition.level, label: label } );
+                       } );
+
+                       this.$precision = $( '<div/>' )
+                               .addClass( this.uiBaseClass + '-precision' )
+                               .listrotator( {
+                                       values: precisionValues.reverse(),
+                                       deferInit: true
+                               } )
+                               .on(
+                               'listrotatorauto.' + this.uiBaseClass + ' 
listrotatorselected.' + this.uiBaseClass,
+                               function( event ) {
+                                       var overwrite = {};
+
+                                       if( event.type === 'listrotatorauto' ) {
+                                               overwrite.precision = undefined;
+                                       }
+
+                                       var value = self._updateValue( 
overwrite );
+
+                                       if( event.type === 'listrotatorauto' ) {
+                                               $( this ).data( 'listrotator' 
).rotate( value.getPrecision() );
+                                       }
+                               }
+                       )
+                       .appendTo( this.$precisionContainer );
+
+                       var $toggler = $( '<a/>' )
+                       .addClass( this.uiBaseClass + '-advancedtoggler' )
+                       .text( mw.msg( 'valueview-expert-advancedadjustments' ) 
);
 
                        this.$input = $( '<input/>', {
                                type: 'text',
@@ -63,9 +120,17 @@
                        } )
                        .coordinateinput()
                        .inputextender( {
-                               content: [ $preview ]
+                               content: [ $preview, $toggler, 
this.$precisionContainer ],
+                               initCallback: function() {
+                                       self.$precision.data( 'listrotator' 
).initWidths();
+                                       self.$precisionContainer.css( 
'display', 'none' );
+                                       $toggler.toggler( { $subject: 
self.$precisionContainer } );
+                               }
                        } )
                        .on( 'coordinateinputupdate.' + this.uiBaseClass, 
function( event, value ) {
+                               if( value && value.isValid() ) {
+                                       self.$precision.data( 'listrotator' 
).rotate( value.getPrecision() );
+                               }
                                self._newValue = false; // value, not yet 
handled by draw(), is outdated now
                                self._viewNotifier.notify( 'change' );
                                self._updatePreview();
@@ -77,6 +142,10 @@
                 * @see jQuery.valueview.Expert.destroy
                 */
                destroy: function() {
+                       this.$precision.data( 'listrotator' ).destroy();
+                       this.$precision.remove();
+                       this.$precisionContainer.remove();
+
                        var previewElement = this.preview.element;
                        this.preview.destroy();
                        previewElement.remove();
@@ -86,6 +155,36 @@
                        this.$input.remove();
 
                        PARENT.prototype.destroy.call( this );
+               },
+
+               /**
+                * Builds a coordinate.Coordinate object from the widget's 
current input taking the
+                * precision into account if set manually.
+                *
+                * @param {Object} [overwrites] Values that should be used 
instead of the ones picked from
+                *        the input elements.
+                * @return {coordinate.Coordinate}
+                */
+               _updateValue: function( overwrites ) {
+                       overwrites = overwrites || {};
+
+                       var options = {},
+                               precision = ( overwrites.hasOwnProperty( 
'precision' ) )
+                                       ? overwrites.precision
+                                       : this.$precision.data( 'listrotator' 
).value(),
+                               value;
+
+                       if( precision !== undefined ) {
+                               options.precision = precision;
+                       }
+
+                       value = new Coordinate( this.$input.val(), options );
+
+                       this._setRawValue( value );
+                       this._updatePreview();
+                       this._viewNotifier.notify( 'change' );
+
+                       return value;
                },
 
                /**
@@ -157,6 +256,9 @@
 
                        if( this._newValue !== false ) {
                                this.$input.data( 'coordinateinput' ).value( 
this._newValue );
+                               if( this._newValue !== null ) {
+                                       this.$precision.data( 'listrotator' 
).value( this._newValue.getPrecision() );
+                               }
                                this._newValue = false;
                                this._updatePreview();
                        }
@@ -177,4 +279,4 @@
                }
        } );
 
-}( dataValues, valueParsers, jQuery, jQuery.valueview, coordinate.Coordinate ) 
);
+}( dataValues, valueParsers, jQuery, jQuery.valueview, coordinate, mediaWiki ) 
);

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I00af947ac30a26cdac76fbe7f6eb23d6e3164f05
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/DataValues
Gerrit-Branch: master
Gerrit-Owner: Henning Snater <[email protected]>

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

Reply via email to