[Libreoffice-commits] online.git: loleaflet/src

Henry Castro (via logerrit) logerrit at kemper.freedesktop.org
Mon May 11 02:48:27 UTC 2020


 loleaflet/src/control/Control.JSDialogBuilder.js |   58 ++++++++++++++++-------
 1 file changed, 41 insertions(+), 17 deletions(-)

New commits:
commit 4617903be2666f437ff87a3ca07b713e39e685d1
Author:     Henry Castro <hcastro at collabora.com>
AuthorDate: Wed May 6 15:04:22 2020 -0400
Commit:     Henry Castro <hcastro at collabora.com>
CommitDate: Mon May 11 04:48:07 2020 +0200

    jsdialog: add formatted field handler
    
    In master branch by default the legacy control like the
    metric control is not created, that force to create the
    replacement which is formatted field control.
    
    Change-Id: Ib5dcaa9516057a3aed304b748f13d44098dc525b
    Reviewed-on: https://gerrit.libreoffice.org/c/online/+/93588
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Henry Castro <hcastro at collabora.com>

diff --git a/loleaflet/src/control/Control.JSDialogBuilder.js b/loleaflet/src/control/Control.JSDialogBuilder.js
index a72fe2959..4ecbc0ad9 100644
--- a/loleaflet/src/control/Control.JSDialogBuilder.js
+++ b/loleaflet/src/control/Control.JSDialogBuilder.js
@@ -112,6 +112,25 @@ L.Control.JSDialogBuilder = L.Control.extend({
 			});
 
 			return controls;
+		},
+
+		listenNumericChanges: function (data, builder, controls, customCallback) {
+			// It listens server state changes using GetControlState
+			// to avoid unit conversion
+			builder.map.on('commandstatechanged', function(e) {
+				var value = e.state[data.id];
+				if (value) {
+					value = parseFloat(value);
+					$(controls.spinfield).attr('value', value);
+				}
+			}, this);
+
+			controls.spinfield.addEventListener('change', function() {
+				if (customCallback)
+					customCallback();
+				else
+					builder.callback('spinfield', 'value', controls.container, this.value, builder);
+			});
 		}
 	},
 
@@ -125,6 +144,7 @@ L.Control.JSDialogBuilder = L.Control.extend({
 		this._controlHandlers['checkbox'] = this._checkboxControl;
 		this._controlHandlers['spinfield'] = this._spinfieldControl;
 		this._controlHandlers['metricfield'] = this._metricfieldControl;
+		this._controlHandlers['formattedfield'] = this._formattedfieldControl;
 		this._controlHandlers['edit'] = this._editControl;
 		this._controlHandlers['multilineedit'] = this._multiLineEditControl;
 		this._controlHandlers['pushbutton'] = this._pushbuttonControl;
@@ -1183,26 +1203,30 @@ L.Control.JSDialogBuilder = L.Control.extend({
 		return false;
 	},
 
+	_formattedfieldControl: function(parentContainer, data, builder, customCallback) {
+		var value, units, controls;
+
+		// formatted control does not contain unit property
+		units = data.text.split(' ');
+		if (units.length == 2) {
+			data.unit = units[1];
+		}
+
+		controls = L.Control.JSDialogBuilder.baseSpinField(parentContainer, data, builder, customCallback);
+
+		L.Control.JSDialogBuilder.listenNumericChanges(data, builder, controls, customCallback);
+
+		value = parseFloat(data.value);
+		$(controls.spinfield).attr('value', value);
+
+		return false;
+	},
+
+
 	_metricfieldControl: function(parentContainer, data, builder, customCallback) {
 		var value;
 		var controls = L.Control.JSDialogBuilder.baseSpinField(parentContainer, data, builder, customCallback);
-
-		// It listens server state changes using GetControlState
-		// to avoid unit conversion
-		builder.map.on('commandstatechanged', function(e) {
-			value = e.state[data.id];
-			if (value) {
-				value = parseFloat(value);
-				$(controls.spinfield).attr('value', value);
-			}
-		}, this);
-
-		controls.spinfield.addEventListener('change', function() {
-			if (customCallback)
-				customCallback();
-			else
-				builder.callback('spinfield', 'value', controls.container, this.value, builder);
-		});
+		L.Control.JSDialogBuilder.listenNumericChanges(data, builder, controls, customCallback);
 
 		value = parseFloat(data.value);
 		$(controls.spinfield).attr('value', value);


More information about the Libreoffice-commits mailing list