You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by dk...@apache.org on 2020/11/23 14:28:56 UTC

[sling-org-apache-sling-app-cms] 04/05: Updating the style wrapper to allow for combining multiple styles

This is an automated email from the ASF dual-hosted git repository.

dklco pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-app-cms.git

commit 9517bfbd1d125e4958f0332073120b555dfdcd49
Author: Dan Klco <dk...@apache.org>
AuthorDate: Mon Nov 23 09:27:04 2020 -0500

    Updating the style wrapper to allow for combining multiple styles
---
 .../components/general/stylewrapper/edit.json      |  9 +++-
 .../components/general/stylewrapper/options.jsp    |  4 +-
 .../general/stylewrapper/stylewrapper.jsp          |  8 +++-
 .../components/editor/fields/combobox.json         |  6 +++
 .../components/editor/fields/combobox/options.jsp  | 54 ++++++++++++++++++++++
 .../components/editor/fields/combobox/values.jsp   | 14 ++++--
 6 files changed, 85 insertions(+), 10 deletions(-)

diff --git a/reference/src/main/resources/jcr_root/apps/reference/components/general/stylewrapper/edit.json b/reference/src/main/resources/jcr_root/apps/reference/components/general/stylewrapper/edit.json
index e577436..8217309 100644
--- a/reference/src/main/resources/jcr_root/apps/reference/components/general/stylewrapper/edit.json
+++ b/reference/src/main/resources/jcr_root/apps/reference/components/general/stylewrapper/edit.json
@@ -7,11 +7,16 @@
         "sling:resourceType": "sling-cms/components/general/container",
         "style": {
             "jcr:primaryType": "nt:unstructured",
-            "sling:resourceType": "sling-cms/components/editor/fields/select",
+            "sling:resourceType": "sling-cms/components/editor/fields/combobox",
             "label": "Style Option",
             "name": "style",
-            "required": true,
             "optionsScript": "/apps/reference/components/general/stylewrapper/options.jsp"
+        },
+        "styleTypeHint": {
+            "jcr:primaryType": "nt:unstructured",
+            "sling:resourceType": "sling-cms/components/editor/fields/hidden",
+            "name": "style@TypeHint",
+            "value": "String[]"
         }
     }
 }
\ No newline at end of file
diff --git a/reference/src/main/resources/jcr_root/apps/reference/components/general/stylewrapper/options.jsp b/reference/src/main/resources/jcr_root/apps/reference/components/general/stylewrapper/options.jsp
index 1a87293..642c788 100644
--- a/reference/src/main/resources/jcr_root/apps/reference/components/general/stylewrapper/options.jsp
+++ b/reference/src/main/resources/jcr_root/apps/reference/components/general/stylewrapper/options.jsp
@@ -18,7 +18,5 @@
  */ --%>
  <%@include file="/libs/sling-cms/global.jsp"%>
 <c:forEach var="style" items="${sling:adaptTo(slingRequest.requestPathInfo.suffixResource,'org.apache.sling.cms.ComponentConfiguration').properties.styles}">
-    <option ${slingRequest.requestPathInfo.suffixResource.valueMap.style == fn:split(style,'=')[1] ? 'selected' : ''} value="${sling:encode(fn:split(style,'=')[1],'HTML_ATTR')}">
-        ${sling:encode(fn:split(style,'=')[0],'HTML')}
-    </option>
+    <option ${slingRequest.requestPathInfo.suffixResource.valueMap.style == fn:split(style,'=')[1] ? 'selected' : ''} value="${sling:encode(fn:split(style,'=')[1],'HTML_ATTR')}">${sling:encode(fn:split(style,'=')[0],'HTML')}</option>
 </c:forEach>
\ No newline at end of file
diff --git a/reference/src/main/resources/jcr_root/apps/reference/components/general/stylewrapper/stylewrapper.jsp b/reference/src/main/resources/jcr_root/apps/reference/components/general/stylewrapper/stylewrapper.jsp
index 8aecba7..28f87b7 100644
--- a/reference/src/main/resources/jcr_root/apps/reference/components/general/stylewrapper/stylewrapper.jsp
+++ b/reference/src/main/resources/jcr_root/apps/reference/components/general/stylewrapper/stylewrapper.jsp
@@ -17,6 +17,12 @@
  * under the License.
  */ --%>
  <%@include file="/libs/sling-cms/global.jsp"%>
-<div class="${properties.style}">
+<c:catch var="ex">
+    <c:set var="style" value="${fn:join(properties.style, ' ')}" />
+</c:catch>
+<c:if test="${ex != null}">
+    <c:set var="style" value="${properties.style}" />
+</c:if>
+<div class="${style}">
     <sling:include path="container" resourceType="sling-cms/components/general/container" />
 </div>
diff --git a/ui/src/main/resources/jcr_root/libs/sling-cms/components/editor/fields/combobox.json b/ui/src/main/resources/jcr_root/libs/sling-cms/components/editor/fields/combobox.json
new file mode 100644
index 0000000..36d5192
--- /dev/null
+++ b/ui/src/main/resources/jcr_root/libs/sling-cms/components/editor/fields/combobox.json
@@ -0,0 +1,6 @@
+{
+	"jcr:primaryType": "sling:Component",
+	"sling:resourceSuperType" : "sling-cms/components/editor/fields/labelfield",
+    "componentType": "SlingCMS-FieldConfig",
+    "jcr:title": "Sling CMS - Combobox"
+}
\ No newline at end of file
diff --git a/ui/src/main/resources/jcr_root/libs/sling-cms/components/editor/fields/combobox/options.jsp b/ui/src/main/resources/jcr_root/libs/sling-cms/components/editor/fields/combobox/options.jsp
new file mode 100644
index 0000000..e60ef02
--- /dev/null
+++ b/ui/src/main/resources/jcr_root/libs/sling-cms/components/editor/fields/combobox/options.jsp
@@ -0,0 +1,54 @@
+<%-- /*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */ --%>
+<%@include file="/libs/sling-cms/global.jsp"%>
+<datalist id="labelfield-${fn:replace(resource.name,':','-')}">
+    <c:choose>
+        <c:when test="${not empty properties.options}">
+            <c:forEach var="option" items="${properties.options}">
+                <c:set var="label" value="${fn:split(option,'=')[0]}" />
+                <c:set var="value" value="${fn:split(option,'=')[1]}" />
+                <c:choose>
+                    <c:when test="${val eq value}">
+                        <c:set var="selected" value="selected=\"selected\"" />
+                    </c:when>
+                    <c:otherwise>
+                        <c:set var="selected" value="" />
+                    </c:otherwise>
+                </c:choose>
+                <option ${selected} value="${sling:encode(value,'HTML_ATTR')}"><sling:encode value="${label}" mode="HTML" /></option>
+            </c:forEach>
+        </c:when>
+        <c:when test="${sling:getRelativeResource(resource,'options') != null}">
+            <c:forEach var="option" items="${sling:listChildren(sling:getRelativeResource(resource,'options'))}">
+                <c:choose>
+                    <c:when test="${option.valueMap.value eq editProperties[properties.name]}">
+                        <c:set var="selected" value="selected=\"selected\"" />
+                    </c:when>
+                    <c:otherwise>
+                        <c:set var="selected" value="" />
+                    </c:otherwise>
+                </c:choose>
+                <option ${selected} value="${sling:encode(option.valueMap.value,'HTML_ATTR')}"><sling:encode value="${option.valueMap.label}" mode="HTML" /></option>
+            </c:forEach>
+        </c:when>
+        <c:when test="${not empty properties.optionsScript}">
+            <sling:call script="${properties.optionsScript}" />
+        </c:when>
+    </c:choose>
+</datalist>
\ No newline at end of file
diff --git a/reference/src/main/resources/jcr_root/apps/reference/components/general/stylewrapper/stylewrapper.jsp b/ui/src/main/resources/jcr_root/libs/sling-cms/components/editor/fields/combobox/values.jsp
similarity index 68%
copy from reference/src/main/resources/jcr_root/apps/reference/components/general/stylewrapper/stylewrapper.jsp
copy to ui/src/main/resources/jcr_root/libs/sling-cms/components/editor/fields/combobox/values.jsp
index 8aecba7..f365e87 100644
--- a/reference/src/main/resources/jcr_root/apps/reference/components/general/stylewrapper/stylewrapper.jsp
+++ b/ui/src/main/resources/jcr_root/libs/sling-cms/components/editor/fields/combobox/values.jsp
@@ -16,7 +16,13 @@
  * specific language governing permissions and limitations
  * under the License.
  */ --%>
- <%@include file="/libs/sling-cms/global.jsp"%>
-<div class="${properties.style}">
-    <sling:include path="container" resourceType="sling-cms/components/general/container" />
-</div>
+<%@include file="/libs/sling-cms/global.jsp"%>
+<c:forEach var="item" items="${value}">
+    <a class="tag labelfield__item" title="${item}">
+        <input type="hidden" name="${properties.name}" value="${item}" />
+        <span class="labelfield__title">
+            ${sling:encode(item,'HTML')}
+        </span>
+        <button class="delete is-small"></button>
+    </a>
+</c:forEach>