loleaflet/src/control/Control.JSDialogBuilder.js | 77 ++++++++++++++++++++--- 1 file changed, 70 insertions(+), 7 deletions(-)
New commits: commit c183dea223c2ce6ae2cf92fd7a84775f786c884a Author: Szymon Kłos <szymon.k...@collabora.com> AuthorDate: Wed Sep 25 16:28:57 2019 +0200 Commit: Szymon Kłos <szymon.k...@collabora.com> CommitDate: Wed Sep 25 16:28:57 2019 +0200 jsdialogs: better grid handling Change-Id: I497325cb31a9d88a734eebba0046fbffb0505f25 diff --git a/loleaflet/src/control/Control.JSDialogBuilder.js b/loleaflet/src/control/Control.JSDialogBuilder.js index 3bc5c84ea..164f1aaaa 100644 --- a/loleaflet/src/control/Control.JSDialogBuilder.js +++ b/loleaflet/src/control/Control.JSDialogBuilder.js @@ -29,6 +29,7 @@ L.Control.JSDialogBuilder = L.Control.extend({ this._controlHandlers['combobox'] = this._comboboxControl; this._controlHandlers['listbox'] = this._comboboxControl; this._controlHandlers['fixedtext'] = this._fixedtextControl; + this._controlHandlers['grid'] = this._gridHandler; this._controlHandlers['frame'] = this._frameHandler; this._controlHandlers['panel'] = this._panelHandler; this._controlHandlers['container'] = this._containerHandler; @@ -70,6 +71,66 @@ L.Control.JSDialogBuilder = L.Control.extend({ return false; }, + _getGridColumns: function(children) { + var columns = 0; + for (var index in children) { + if (parseInt(children[index].left) > columns) + columns = parseInt(children[index].left); + } + return columns + 1; + }, + + _getGridRows: function(children) { + var rows = 0; + for (var index in children) { + if (parseInt(children[index].top) > rows) + rows = parseInt(children[index].top); + } + return rows + 1; + }, + + _getGridChild: function(children, row, col) { + for (var index in children) { + if (parseInt(children[index].top) == row + && parseInt(children[index].left) == col) + return children[index]; + } + return null; + }, + + _gridHandler: function(parentContainer, data, builder) { + var columns = builder._getGridColumns(data.children); + var rows = builder._getGridRows(data.children); + var index = 0; + + var table = L.DomUtil.create('table', '', parentContainer); + for (var row = 0; row < rows; row++) { + var tr = L.DomUtil.create('tr', '', table); + for (var col = 0; col < columns; col++) { + var td = L.DomUtil.create('td', '', tr); + var child = builder._getGridChild(data.children, row, col); + + if (child) { + var childObject = null; + if (child.type == 'container') + childObject = L.DomUtil.create('table', '', td); + else + childObject = td; + + builder.build(childObject, [child], data.type); + index++; + } + + if (index > data.children.length) { + console.warn('index > data.children.length'); + return false; + } + } + } + + return false; + }, + _explorableEntry: function(parentContainer, title, contentNode, builder) { var sectionTitle = L.DomUtil.create('div', 'ui-header level-' + builder._currentDepth + ' mobile-wizard ui-widget', parentContainer); sectionTitle.innerHTML = title; @@ -171,6 +232,9 @@ L.Control.JSDialogBuilder = L.Control.extend({ }, _comboboxControl: function(parentContainer, data, builder) { + if (!data.entries || data.entries.length == 0) + return false; + var listbox = L.DomUtil.create('select', '', parentContainer); listbox.value = builder._cleanText(data.text); @@ -219,9 +283,10 @@ L.Control.JSDialogBuilder = L.Control.extend({ return false; }, - build: function(parent, data, currentIsContainer, currentIsVertival, columns) { + build: function(parent, data, currentType, currentIsVertival) { var currentInsertPlace = parent; var currentHorizontalRow = parent; + var currentIsContainer = currentType == 'container'; if (currentIsContainer && !currentIsVertival) currentHorizontalRow = L.DomUtil.create('tr', '', parent); @@ -232,18 +297,16 @@ L.Control.JSDialogBuilder = L.Control.extend({ var processChildren = true; if (currentIsContainer) { - var horizontalOverflow = (childIndex > 0 && columns && (childIndex % columns == 0)); - var newRow = currentIsVertival || horizontalOverflow; - if (newRow) { + if (currentIsVertival) { currentHorizontalRow = L.DomUtil.create('tr', '', parent); currentInsertPlace = L.DomUtil.create('td', '', currentHorizontalRow); } else currentInsertPlace = L.DomUtil.create('td', '', currentHorizontalRow); } - var childIsContainer = (childType == 'container' || childType == 'borderwindow') && childData.children.length > 1; + var childIsContainer = (childType == 'container' || childType == 'borderwindow') + && childData.children.length > 1; var childIsVertical = childData.vertical == 'true'; - var childColumns = childData.cols; var childObject = null; if (childIsContainer && childType != 'borderwindow') @@ -259,7 +322,7 @@ L.Control.JSDialogBuilder = L.Control.extend({ console.warn('Unsupported control type: \"' + childType + '\"'); if (processChildren && childData.children != undefined) - this.build(childObject, childData.children, childIsContainer, childIsVertical, childColumns); + this.build(childObject, childData.children, childType, childIsVertical); } } }); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits