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 2019/10/22 14:05:14 UTC
[sling-org-apache-sling-app-cms] 02/02: Abstracting the "taxonomy"
field out to a more generic label field which can be used for different use
cases
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 4725823f4d275a5193309fb50629a3d5a848e481
Author: Dan Klco <dk...@apache.org>
AuthorDate: Tue Oct 22 10:04:05 2019 -0400
Abstracting the "taxonomy" field out to a more generic label field which
can be used for different use cases
---
ui/src/main/frontend/js/cms.taxonomy.js | 20 +++----
.../components/editor/fields/labelfield.json | 4 ++
.../components/editor/fields/labelfield/field.jsp | 47 ++++++++++++++++
.../editor/fields/labelfield/options.jsp | 20 +++++++
.../components/editor/fields/labelfield/values.jsp | 20 +++++++
.../components/editor/fields/taxonomy.json | 2 +-
.../components/editor/fields/taxonomy/field.jsp | 62 ----------------------
.../components/editor/fields/taxonomy/options.jsp | 26 +++++++++
.../components/editor/fields/taxonomy/values.jsp | 28 ++++++++++
9 files changed, 156 insertions(+), 73 deletions(-)
diff --git a/ui/src/main/frontend/js/cms.taxonomy.js b/ui/src/main/frontend/js/cms.taxonomy.js
index 5687368..c4f4445 100644
--- a/ui/src/main/frontend/js/cms.taxonomy.js
+++ b/ui/src/main/frontend/js/cms.taxonomy.js
@@ -19,19 +19,19 @@
/* eslint-env browser, es6 */
(function (rava) {
'use strict';
- rava.bind('.taxonomy', {
+ rava.bind('.labelfield', {
events: {
- '.taxonomy__add, .taxonomy__add *': {
+ '.labelfield__add, .labelfield__add *': {
click: function (event) {
event.preventDefault();
event.stopPropagation();
var context = this,
span = document.createElement('span'),
- val = context.querySelector('.taxonomy__field input').value,
+ val = context.querySelector('.labelfield__field input').value,
found = false,
title = context.querySelector('option[value="' + val + '"]').innerText;
- span.innerHTML = context.querySelector('.taxonomy__template').innerHTML;
- context.querySelectorAll('.taxonomy__item input').forEach(function (el) {
+ span.innerHTML = context.querySelector('.labelfield__template').innerHTML;
+ context.querySelectorAll('.labelfield__item input').forEach(function (el) {
if (el.value === val) {
found = true;
}
@@ -42,21 +42,21 @@
span.querySelector('input').value = val;
if (title !== '') {
- span.querySelector('.taxonomy__title').innerText = title;
- this.closest('.taxonomy').querySelector('.taxonomy__container').appendChild(span);
- context.querySelector('.taxonomy__field input').value = '';
+ span.querySelector('.labelfield__title').innerText = title;
+ this.closest('.labelfield').querySelector('.labelfield__container').appendChild(span);
+ context.querySelector('.labelfield__field input').value = '';
}
}
}
}
});
- rava.bind('.taxonomy__item, .taxonomy__item *', {
+ rava.bind('.labelfield__item, .labelfield__item *', {
events: {
click: function () {
event.preventDefault();
event.stopPropagation();
- this.closest('.taxonomy__item').remove();
+ this.closest('.labelfield__item').remove();
}
}
});
diff --git a/ui/src/main/resources/jcr_root/libs/sling-cms/components/editor/fields/labelfield.json b/ui/src/main/resources/jcr_root/libs/sling-cms/components/editor/fields/labelfield.json
new file mode 100644
index 0000000..747e8fd
--- /dev/null
+++ b/ui/src/main/resources/jcr_root/libs/sling-cms/components/editor/fields/labelfield.json
@@ -0,0 +1,4 @@
+{
+ "jcr:primaryType": "nt:unstructured",
+ "sling:resourceSuperType" : "sling-cms/components/editor/fields/base"
+}
\ No newline at end of file
diff --git a/ui/src/main/resources/jcr_root/libs/sling-cms/components/editor/fields/labelfield/field.jsp b/ui/src/main/resources/jcr_root/libs/sling-cms/components/editor/fields/labelfield/field.jsp
new file mode 100644
index 0000000..d21b132
--- /dev/null
+++ b/ui/src/main/resources/jcr_root/libs/sling-cms/components/editor/fields/labelfield/field.jsp
@@ -0,0 +1,47 @@
+<%-- /*
+ * 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"%>
+ <div class="labelfield">
+ <fieldset disabled="disabled" class="labelfield__template is-hidden">
+ <a class="button labelfield__item">
+ <input type="hidden" name="${properties.name}" value="" />
+ <span class="labelfield__title">
+ </span>
+ <span class="jam jam-close"></span>
+ </a>
+ </fieldset>
+ <div class="labelfield__field field has-addons">
+ <div class="control is-expanded">
+ <input class="input" type="text" ${required} ${disabled} id="${properties.name}" list="labelfield-${fn:replace(resource.name,':','-')}" autocomplete="off" />
+ </div>
+ <div class="control">
+ <button class="labelfield__add button">
+ <span class="jam jam-plus">
+ <span class="is-vhidden">
+ Add
+ </span>
+ </span>
+ </button>
+ </div>
+ </div>
+ <div class="labelfield__container">
+ <sling:call script="values.jsp" />
+ </div>
+ <sling:call script="options" />
+</div>
\ No newline at end of file
diff --git a/ui/src/main/resources/jcr_root/libs/sling-cms/components/editor/fields/labelfield/options.jsp b/ui/src/main/resources/jcr_root/libs/sling-cms/components/editor/fields/labelfield/options.jsp
new file mode 100644
index 0000000..60ace42
--- /dev/null
+++ b/ui/src/main/resources/jcr_root/libs/sling-cms/components/editor/fields/labelfield/options.jsp
@@ -0,0 +1,20 @@
+<%-- /*
+ * 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"%>
+ <%-- Load the options --%>
\ No newline at end of file
diff --git a/ui/src/main/resources/jcr_root/libs/sling-cms/components/editor/fields/labelfield/values.jsp b/ui/src/main/resources/jcr_root/libs/sling-cms/components/editor/fields/labelfield/values.jsp
new file mode 100644
index 0000000..2ae2730
--- /dev/null
+++ b/ui/src/main/resources/jcr_root/libs/sling-cms/components/editor/fields/labelfield/values.jsp
@@ -0,0 +1,20 @@
+<%-- /*
+ * 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"%>
+ <%-- Load the values for the current field --%>
\ No newline at end of file
diff --git a/ui/src/main/resources/jcr_root/libs/sling-cms/components/editor/fields/taxonomy.json b/ui/src/main/resources/jcr_root/libs/sling-cms/components/editor/fields/taxonomy.json
index f42ffde..782a403 100644
--- a/ui/src/main/resources/jcr_root/libs/sling-cms/components/editor/fields/taxonomy.json
+++ b/ui/src/main/resources/jcr_root/libs/sling-cms/components/editor/fields/taxonomy.json
@@ -1,6 +1,6 @@
{
"jcr:primaryType": "sling:Component",
- "sling:resourceSuperType" : "sling-cms/components/editor/fields/base",
+ "sling:resourceSuperType" : "sling-cms/components/editor/fields/labelfield",
"componentType": "SlingCMS-FieldConfig",
"jcr:title": "Sling CMS - Taxonomy Field"
}
\ No newline at end of file
diff --git a/ui/src/main/resources/jcr_root/libs/sling-cms/components/editor/fields/taxonomy/field.jsp b/ui/src/main/resources/jcr_root/libs/sling-cms/components/editor/fields/taxonomy/field.jsp
deleted file mode 100644
index c82bb68..0000000
--- a/ui/src/main/resources/jcr_root/libs/sling-cms/components/editor/fields/taxonomy/field.jsp
+++ /dev/null
@@ -1,62 +0,0 @@
-<%-- /*
- * 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"%>
- <div class="taxonomy">
- <fieldset disabled="disabled" class="taxonomy__template is-hidden">
- <a class="button taxonomy__item">
- <input type="hidden" name="${properties.name}" value="" />
- <span class="taxonomy__title">
- </span>
- <span class="jam jam-close"></span>
- </a>
- </fieldset>
- <div class="taxonomy__field field has-addons">
- <div class="control is-expanded">
- <input class="input" type="text" ${required} ${disabled} id="${properties.name}" list="taxonomy-${fn:replace(resource.name,':','-')}" autocomplete="off" />
- </div>
- <div class="control">
- <button class="taxonomy__add button">
- <span class="jam jam-plus">
- <span class="is-vhidden">
- Add
- </span>
- </span>
- </button>
- </div>
- </div>
- <div class="taxonomy__container">
- <c:forEach var="item" items="${value}">
- <a class="button taxonomy__item">
- <input type="hidden" name="${properties.name}" value="${item}" />
- <span class="taxonomy__title">
- ${sling:encode(sling:getResource(resourceResolver,item).valueMap['jcr:title'],'HTML')}
- </span>
- <span class="jam jam-close"></span>
- </a>
- </c:forEach>
- </div>
-
- <sling:getCAConfigResource resource="${slingRequest.requestPathInfo.suffixResource}" bucket="site" name="settings" var="sitesettings" />
- <datalist id="taxonomy-${fn:replace(resource.name,':','-')}">
- <c:set var="query" value="SELECT * FROM [sling:Taxonomy] WHERE ISDESCENDANTNODE([${not empty properties.basePath ? properties.basePath : sitesettings.valueMap.taxonomyroot}])" />
- <c:forEach var="taxonomy" items="${sling:findResources(resourceResolver,query,'JCR-SQL2')}">
- <option value="${taxonomy.path}">${taxonomy.valueMap['jcr:title']}</option>
- </c:forEach>
- </datalist>
-</div>
\ No newline at end of file
diff --git a/ui/src/main/resources/jcr_root/libs/sling-cms/components/editor/fields/taxonomy/options.jsp b/ui/src/main/resources/jcr_root/libs/sling-cms/components/editor/fields/taxonomy/options.jsp
new file mode 100644
index 0000000..0a99d81
--- /dev/null
+++ b/ui/src/main/resources/jcr_root/libs/sling-cms/components/editor/fields/taxonomy/options.jsp
@@ -0,0 +1,26 @@
+<%-- /*
+ * 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"%>
+<sling:getCAConfigResource resource="${slingRequest.requestPathInfo.suffixResource}" bucket="site" name="settings" var="sitesettings" />
+<datalist id="taxonomy-${fn:replace(resource.name,':','-')}">
+ <c:set var="query" value="SELECT * FROM [sling:Taxonomy] WHERE ISDESCENDANTNODE([${not empty properties.basePath ? properties.basePath : sitesettings.valueMap.taxonomyroot}])" />
+ <c:forEach var="taxonomy" items="${sling:findResources(resourceResolver,query,'JCR-SQL2')}">
+ <option value="${taxonomy.path}">${taxonomy.valueMap['jcr:title']}</option>
+ </c:forEach>
+</datalist>
\ No newline at end of file
diff --git a/ui/src/main/resources/jcr_root/libs/sling-cms/components/editor/fields/taxonomy/values.jsp b/ui/src/main/resources/jcr_root/libs/sling-cms/components/editor/fields/taxonomy/values.jsp
new file mode 100644
index 0000000..a1e0b40
--- /dev/null
+++ b/ui/src/main/resources/jcr_root/libs/sling-cms/components/editor/fields/taxonomy/values.jsp
@@ -0,0 +1,28 @@
+<%-- /*
+ * 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"%>
+<c:forEach var="item" items="${value}">
+ <a class="button taxonomy__item">
+ <input type="hidden" name="${properties.name}" value="${item}" />
+ <span class="taxonomy__title">
+ ${sling:encode(sling:getResource(resourceResolver,item).valueMap['jcr:title'],'HTML')}
+ </span>
+ <span class="jam jam-close"></span>
+ </a>
+</c:forEach>
\ No newline at end of file