[Libreoffice-commits] online.git: loleaflet/src
Henry Castro (via logerrit)
logerrit at kemper.freedesktop.org
Tue Apr 28 01:13:56 UTC 2020
loleaflet/src/control/Control.JSDialogBuilder.js | 163 +++++++++++------------
1 file changed, 85 insertions(+), 78 deletions(-)
New commits:
commit d0ca14d40484aad01e1c5964537131fe3ae280a0
Author: Henry Castro <hcastro at collabora.com>
AuthorDate: Wed Apr 22 19:55:13 2020 -0400
Commit: Henry Castro <hcastro at collabora.com>
CommitDate: Tue Apr 28 03:13:38 2020 +0200
jsdialog: create a static base spinfiled function
The next patch will re-use to implement metric field control
Change-Id: Iebfb2584fe4771e8a98eac1fc5b63768013b817a
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/92798
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 e27220fa1..5bc0ac9ba 100644
--- a/loleaflet/src/control/Control.JSDialogBuilder.js
+++ b/loleaflet/src/control/Control.JSDialogBuilder.js
@@ -23,6 +23,83 @@ L.Control.JSDialogBuilder = L.Control.extend({
_currentDepth: 0,
+ statics: {
+ baseSpinField: function(parentContainer, data, builder, customCallback) {
+ var controls = {};
+ if (data.label) {
+ var fixedTextData = { text: data.label };
+ builder._fixedtextControl(parentContainer, fixedTextData, builder);
+ }
+
+ var div = L.DomUtil.create('div', 'spinfieldcontainer', parentContainer);
+ div.id = data.id;
+ controls['container'] = div;
+
+ var commandName = data.id ? data.id.substring('.uno:'.length) : data.id;
+ if (commandName && commandName.length && L.LOUtil.existsIconForCommand(commandName, builder.map.getDocType())) {
+ var image = L.DomUtil.create('img', 'spinfieldimage', div);
+ var icon = builder._createIconPath(data.id);
+ image.src = icon;
+ icon.alt = '';
+ }
+
+ var spinfield = L.DomUtil.create('input', 'spinfield', div);
+ spinfield.type = 'number';
+ controls['spinfield'] = spinfield;
+
+ if (data.unit) {
+ var unit = L.DomUtil.create('span', 'spinfieldunit', div);
+ unit.innerHTML = builder._unitToVisibleString(data.unit);
+ }
+
+ var controlsContainer = L.DomUtil.create('div', 'spinfieldcontrols', div);
+ var minus = L.DomUtil.create('div', 'minus', controlsContainer);
+ minus.innerHTML = '-';
+
+ var plus = L.DomUtil.create('div', 'plus', controlsContainer);
+ plus.innerHTML = '+';
+
+ if (data.min != undefined)
+ $(spinfield).attr('min', data.min);
+
+ if (data.max != undefined)
+ $(spinfield).attr('max', data.max);
+
+ if (data.enabled == 'false') {
+ $(spinfield).attr('disabled', 'disabled');
+ $(image).addClass('disabled');
+ }
+
+ if (data.readOnly === true)
+ $(spinfield).attr('readOnly', 'true');
+
+ if (data.hidden)
+ $(spinfield).hide();
+
+ plus.addEventListener('click', function() {
+ var attrdisabled = $(spinfield).attr('disabled');
+ if (attrdisabled !== 'disabled') {
+ if (customCallback)
+ customCallback('spinfield', 'plus', div, this.value, builder);
+ else
+ builder.callback('spinfield', 'plus', div, this.value, builder);
+ }
+ });
+
+ minus.addEventListener('click', function() {
+ var attrdisabled = $(spinfield).attr('disabled');
+ if (attrdisabled !== 'disabled') {
+ if (customCallback)
+ customCallback('spinfield', 'minus', div, this.value, builder);
+ else
+ builder.callback('spinfield', 'minus', div, this.value, builder);
+ }
+ });
+
+ return controls;
+ }
+ },
+
_setup: function(options) {
this._clearColorPickers();
this.wizard = options.mobileWizard;
@@ -1003,102 +1080,32 @@ L.Control.JSDialogBuilder = L.Control.extend({
},
_spinfieldControl: function(parentContainer, data, builder, customCallback) {
- if (data.label) {
- var fixedTextData = { text: data.label };
- builder._fixedtextControl(parentContainer, fixedTextData, builder);
- }
+ var controls = L.Control.JSDialogBuilder.baseSpinField(parentContainer, data, builder, customCallback);
- var div = L.DomUtil.create('div', 'spinfieldcontainer', parentContainer);
- div.id = data.id;
-
- var commandName = data.id ? data.id.substring('.uno:'.length) : data.id;
- if (commandName && commandName.length && L.LOUtil.existsIconForCommand(commandName, builder.map.getDocType())) {
- var image = L.DomUtil.create('img', 'spinfieldimage', div);
- var icon = builder._createIconPath(data.id);
- image.src = icon;
- icon.alt = '';
- }
-
- var spinfield = L.DomUtil.create('input', 'spinfield', div);
- spinfield.type = 'number';
-
- if (data.unit) {
- var unit = L.DomUtil.create('span', 'spinfieldunit', div);
- unit.innerHTML = builder._unitToVisibleString(data.unit);
- }
-
- var controlsContainer = L.DomUtil.create('div', 'spinfieldcontrols', div);
- var minus = L.DomUtil.create('div', 'minus', controlsContainer);
- minus.innerHTML = '-';
- var plus = L.DomUtil.create('div', 'plus', controlsContainer);
- plus.innerHTML = '+';
-
- if (data.min != undefined)
- $(spinfield).attr('min', data.min);
-
- if (data.max != undefined)
- $(spinfield).attr('max', data.max);
-
- if (data.enabled == 'false') {
- $(spinfield).attr('disabled', 'disabled');
- $(image).addClass('disabled');
- }
-
- if (data.readOnly === true)
- $(spinfield).attr('readOnly', 'true');
-
- var updateFunction = function(e) {
- var value = e ? e[data.id] : undefined;
- if (!value) {
- value = builder._getUnoStateForItemId(data.id, builder);
- }
+ var updateFunction = function() {
+ var value = builder._getUnoStateForItemId(data.id, builder);
if (!value && data.text != undefined)
value = data.text;
else if (!value && data.children && data.children.length)
value = data.children[0].text;
- $(spinfield).attr('value', builder._cleanValueFromUnits(value));
+ $(controls.spinfield).attr('value', builder._cleanValueFromUnits(value));
};
- updateFunction();
-
builder.map.on('commandstatechanged', function(e) {
- if (e.state[data.id]) {
- updateFunction(e.state);
- } else if (e.commandName === builder._mapWindowIdToUnoCommand(data.id))
+ if (e.commandName === builder._mapWindowIdToUnoCommand(data.id))
updateFunction();
}, this);
- spinfield.addEventListener('change', function() {
+ controls.spinfield.addEventListener('change', function() {
if (customCallback)
customCallback();
else
- builder.callback('spinfield', 'set', div, this.value, builder);
- });
-
- plus.addEventListener('click', function() {
- var attrdisabled = $(spinfield).attr('disabled');
- if (attrdisabled !== 'disabled') {
- if (customCallback)
- customCallback('spinfield', 'plus', div, this.value, builder);
- else
- builder.callback('spinfield', 'plus', div, this.value, builder);
- }
+ builder.callback('spinfield', 'set', controls.container, this.value, builder);
});
- minus.addEventListener('click', function() {
- var attrdisabled = $(spinfield).attr('disabled');
- if (attrdisabled !== 'disabled') {
- if (customCallback)
- customCallback('spinfield', 'minus', div, this.value, builder);
- else
- builder.callback('spinfield', 'minus', div, this.value, builder);
- }
- });
-
- if (data.hidden)
- $(spinfield).hide();
+ updateFunction();
return false;
},
More information about the Libreoffice-commits
mailing list