This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch v4
in repository https://gitbox.apache.org/repos/asf/causeway.git
The following commit(s) were added to refs/heads/v4 by this push:
new e9eebb7a1c8 CAUSEWAY-3906: Select2 JS Consolidation (base64 decoder)
e9eebb7a1c8 is described below
commit e9eebb7a1c82840084dbba596aa91a96a0f6dd5f
Author: Andi Huber <[email protected]>
AuthorDate: Sat Oct 4 17:13:16 2025 +0200
CAUSEWAY-3906: Select2 JS Consolidation (base64 decoder)
---
.../wicket/ui/components/widgets/select2/Select2.java | 9 +--------
.../common/viewer/js/causeway-wicket-viewer.nocompress.js | 15 ++++++++++++++-
2 files changed, 15 insertions(+), 9 deletions(-)
diff --git
a/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/widgets/select2/Select2.java
b/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/widgets/select2/Select2.java
index cab62684fd7..0eae32f863a 100644
---
a/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/widgets/select2/Select2.java
+++
b/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/widgets/select2/Select2.java
@@ -58,17 +58,10 @@ static Select2 create(
settings.setWidth("100%");
settings.setPlaceholder(attributeModel.getFriendlyName());
// the id string is url-safe base64 encoded JSON coming from
ChoiceProvider using ObjectDisplayDto as JSON
- // for UTF8 formatted JSON decoding see
https://stackoverflow.com/questions/30106476/using-javascripts-atob-to-decode-base64-doesnt-properly-decode-utf-8-strings
- // TODO perhaps declare this JS else where, then just reference to it
var template = """
function(opt) {
if(!opt) return "undefined";
- if(!opt.id) return "undefined";
- var base64 = opt.id.replace(/-/g, '+').replace(/_/g, '/')
- var json =
decodeURIComponent(atob(base64).split('').map(function(c) {
- return '%' + ('00' +
c.charCodeAt(0).toString(16)).slice(-2);
- }).join(''));
- var dto = JSON.parse(json);
+ var dto = decodeBase64ToJson(opt.id);
if(!dto) return "undefined";
if(!dto.title) return "undefined";
if(dto.iconHtml) {
diff --git
a/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/pages/common/viewer/js/causeway-wicket-viewer.nocompress.js
b/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/pages/common/viewer/js/causeway-wicket-viewer.nocompress.js
index e5aa0e23f0d..b61dd7a3ee3 100644
---
a/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/pages/common/viewer/js/causeway-wicket-viewer.nocompress.js
+++
b/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/pages/common/viewer/js/causeway-wicket-viewer.nocompress.js
@@ -16,6 +16,20 @@
* specific language governing permissions and limitations
* under the License.
*/
+
+/**
+ * Decodes UTF8 formatted JSON that was then base64 URL-safe encoded.
+ * see
https://stackoverflow.com/questions/30106476/using-javascripts-atob-to-decode-base64-doesnt-properly-decode-utf-8-strings
+ */
+function decodeBase64ToJson(input) {
+ if(!input) return null;
+ var base64 = input.replace(/-/g, '+').replace(/_/g, '/')
+ var json = decodeURIComponent(atob(base64).split('').map(function(c) {
+ return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
+ }).join(''));
+ return JSON.parse(json);
+}
+
$(function() {
'use strict';
@@ -281,7 +295,6 @@ $(function() {
});
-
/**
* enables 'maxlength' to work as an attribute on 'textarea'
*