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 2018/08/23 04:39:48 UTC

[sling-org-apache-sling-app-cms] branch master updated: Adding support for path based suggestions and a search modal for the path field.

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


The following commit(s) were added to refs/heads/master by this push:
     new 4cc75f5  Adding support for path based suggestions and a search modal for the path field.
4cc75f5 is described below

commit 4cc75f533bdbf162d56e762b9b5c2c5bce30d25a
Author: Dan Klco <dk...@apache.org>
AuthorDate: Thu Aug 23 00:39:01 2018 -0400

    Adding support for path based suggestions and a search modal for the path field.
---
 .../internal/servlets/PathSuggestionServlet.java   |  3 ++
 ui/src/main/frontend/src/js/scripts.js             | 57 ++++++++++++++++------
 ui/src/main/frontend/src/scss/styles.scss          |  9 ++++
 .../cms/contentbreadcrumb/contentbreadcrumb.jsp    |  4 +-
 .../components/cms/searchresults/searchresults.jsp |  4 +-
 .../components/editor/fields/path/field.jsp        | 18 ++++++-
 .../editor/fields/references/references.jsp        |  2 +-
 .../components/editor/fields/richtext/field.jsp    | 18 +------
 .../components/editor/fields/taxonomy/field.jsp    |  4 +-
 .../libs/sling-cms/content/shared/search.json      |  8 +--
 .../libs/sling-cms/content/site/create.json        |  3 +-
 .../libs/sling-cms/content/site/creategroup.json   |  3 +-
 .../jcr_root/libs/sling-cms/content/site/edit.json |  3 +-
 .../libs/sling-cms/content/site/editgroup.json     |  3 +-
 14 files changed, 90 insertions(+), 49 deletions(-)

diff --git a/core/src/main/java/org/apache/sling/cms/core/internal/servlets/PathSuggestionServlet.java b/core/src/main/java/org/apache/sling/cms/core/internal/servlets/PathSuggestionServlet.java
index 3f0c15b..05ac560 100644
--- a/core/src/main/java/org/apache/sling/cms/core/internal/servlets/PathSuggestionServlet.java
+++ b/core/src/main/java/org/apache/sling/cms/core/internal/servlets/PathSuggestionServlet.java
@@ -53,6 +53,9 @@ public class PathSuggestionServlet extends SlingSafeMethodsServlet {
 		typeMaps.put("page", new String[] { "sling:Page", "nt:folder", "sling:Site" });
 		typeMaps.put("file", new String[] { "nt:file", "nt:folder", "sling:Site" });
 		typeMaps.put("folder", new String[] { "nt:folder", "sling:Site" });
+		typeMaps.put("taxonomy", new String[] { "nt:folder", "sling:Taxonomy" });
+		typeMaps.put("config", new String[] { "nt:folder", "sling:Config" });
+		typeMaps.put("content", new String[] { "nt:hierarchyNode" });
 		typeMaps.put("all", new String[] { "nt:base" });
 	}
 
diff --git a/ui/src/main/frontend/src/js/scripts.js b/ui/src/main/frontend/src/js/scripts.js
index d9db291..ca3ecfa 100644
--- a/ui/src/main/frontend/src/js/scripts.js
+++ b/ui/src/main/frontend/src/js/scripts.js
@@ -356,21 +356,30 @@ Sling.CMS = {
 	};
 
 	Sling.CMS.ext['pathfield'] = {
+		suggest: function(field, type, base) {
+			var xhr;
+			new autoComplete({
+				minChars: 1,
+			    selector: field,
+			    source: function(term, response){
+			        try {
+			        	xhr.abort();
+			        } catch(e){}
+			        var t = term;
+			        if(term === '/'){
+			        	term = base;
+			        }
+			        xhr = $.getJSON('/bin/cms/paths', { path: term, type: type }, function(data){
+			        	response(data);
+			        });
+			    }
+			});
+		},
 		decorate: function($ctx){
 			$ctx.find('input.Field-Path').each(function(){
 				var type = $(this).data('type');
-				var xhr;
-				new autoComplete({
-				    selector: this,
-				    source: function(term, response){
-				        try {
-				        	xhr.abort();
-				        } catch(e){}
-				        xhr = $.getJSON('/bin/cms/paths', { path: term, type: type }, function(data){
-				        	response(data);
-				        });
-				    }
-				});
+				var base = $(this).data('base');
+				Sling.CMS.ext.pathfield.suggest(this, type, base);
 			});
 		}
 	};
@@ -411,14 +420,34 @@ Sling.CMS = {
 			    },
 			    callbacks: {
 		    		onDialogShown: function(e){
-		    			$('.note-link-url').attr('list','richtext-pages');
-		    			$('.note-image-url').attr('list','richtext-images');
+						Sling.CMS.ext.pathfield.suggest($('.note-link-url')[0], 'content', '/content');
+						Sling.CMS.ext.pathfield.suggest($('.note-image-url')[0], 'content', '/content');
 		    		}
 			    }
 			});
 		}
 	};
 	
+	Sling.CMS.ext['searchselect'] = {
+		decorate: function($ctx) {
+			$ctx.find('.Search-Select-Button').click(function(evt){
+				var $btn = $(evt.target);
+				var $active = Sling.CMS.ext['searchbutton'].active;
+				$active.val($btn.data('path'));
+				$btn.closest('.Modal').remove();
+			});
+		}
+	}
+	
+	Sling.CMS.ext['searchbutton'] = {
+		active: null,
+		decorate: function($ctx) {
+			$ctx.find('.Search-Button').click(function(evt){
+				Sling.CMS.ext['searchbutton'].active = $(evt.target).closest('.Field-Input').find('.Field-Path');
+			});
+		}
+	}
+	
 	Sling.CMS.ext['table'] = {
 		decorate: function($ctx) {
 			$ctx.find('table tr').click(function(el){
diff --git a/ui/src/main/frontend/src/scss/styles.scss b/ui/src/main/frontend/src/scss/styles.scss
index e23a05e..e576a4e 100644
--- a/ui/src/main/frontend/src/scss/styles.scss
+++ b/ui/src/main/frontend/src/scss/styles.scss
@@ -78,6 +78,15 @@ ul.Breadcrumb  {
     margin: 1em 0;
 }
 
+.Field-Input a.Button {
+	height: 30px;
+	padding: 8px 9px;
+}
+
+.Field-Input .jam:before {
+	font-size: 12px;
+}
+
 .Hide {
 	display:none;
 }
diff --git a/ui/src/main/resources/jcr_root/libs/sling-cms/components/cms/contentbreadcrumb/contentbreadcrumb.jsp b/ui/src/main/resources/jcr_root/libs/sling-cms/components/cms/contentbreadcrumb/contentbreadcrumb.jsp
index 6f483fe..651fc93 100644
--- a/ui/src/main/resources/jcr_root/libs/sling-cms/components/cms/contentbreadcrumb/contentbreadcrumb.jsp
+++ b/ui/src/main/resources/jcr_root/libs/sling-cms/components/cms/contentbreadcrumb/contentbreadcrumb.jsp
@@ -21,7 +21,7 @@
 <ul class="Breadcrumb">
 	<li class="Breadcrumb-Item">
 		<a href="${resource.valueMap.prefix}${root.path}">
-			<sling:encode value="${root.valueMap['jcr:title'] != null ? root.valueMap['jcr:title'] : root.valueMap['jcr:content/jcr:title']}" mode="HTML" />
+			<sling:encode value="${root.valueMap['jcr:title'] != null ? root.valueMap['jcr:title'] : root.valueMap['jcr:content/jcr:title']}" default="${root.name}" mode="HTML" />
 		</a>
 	</li>
 	<c:if test="${site.path != slingRequest.requestPathInfo.suffix && site.path != slingRequest.requestPathInfo.suffixResource.parent.path}">
@@ -35,7 +35,7 @@
 	</c:if>
 	<c:if test="${root.path != slingRequest.requestPathInfo.suffix}">
 		<li class="Breadcrumb-Item">
-			<sling:encode value="${slingRequest.requestPathInfo.suffixResource.valueMap['jcr:title'] != null ? slingRequest.requestPathInfo.suffixResource.valueMap['jcr:title'] : slingRequest.requestPathInfo.suffixResource.valueMap['jcr:content/jcr:title']}" default="${slingRequest.requestPathInfo.suffix}" mode="HTML" />
+			<sling:encode value="${slingRequest.requestPathInfo.suffixResource.valueMap['jcr:title'] != null ? slingRequest.requestPathInfo.suffixResource.valueMap['jcr:title'] : slingRequest.requestPathInfo.suffixResource.valueMap['jcr:content/jcr:title']}" default="${slingRequest.requestPathInfo.suffixResource.name}" mode="HTML" />
 		</li>
 	</c:if>
 	<li class="Pull-Right">
diff --git a/ui/src/main/resources/jcr_root/libs/sling-cms/components/cms/searchresults/searchresults.jsp b/ui/src/main/resources/jcr_root/libs/sling-cms/components/cms/searchresults/searchresults.jsp
index a99c4db..186358f 100644
--- a/ui/src/main/resources/jcr_root/libs/sling-cms/components/cms/searchresults/searchresults.jsp
+++ b/ui/src/main/resources/jcr_root/libs/sling-cms/components/cms/searchresults/searchresults.jsp
@@ -20,7 +20,7 @@
 <div id="search-results">
 	<div class="Grid">
 	<sling:adaptTo adaptable="${slingRequest}" adaptTo="org.apache.sling.cms.core.models.SearchResults" var="results" />
-		<c:forEach var="result" items="${results.results}" begin="0" end="100" varStatus="status">
+		<c:forEach var="result" items="${results.results}" begin="0" end="20" varStatus="status">
 			<div class="Cell Search-Result Small-50">
 				<div class="Search-Result__Container">
 					<c:choose>
@@ -56,7 +56,7 @@
 						<em>${result.path}</em>
 					</small><br/>
 					<br />
-					<a href="#" class="Button Select-Button" data-path="${result.path}">Select</a>
+					<a href="#" class="Button Search-Select-Button" data-path="${result.path}">Select</a>
 				</div>
 			</div>
 		</c:forEach>
diff --git a/ui/src/main/resources/jcr_root/libs/sling-cms/components/editor/fields/path/field.jsp b/ui/src/main/resources/jcr_root/libs/sling-cms/components/editor/fields/path/field.jsp
index e6e8b70..baf2036 100644
--- a/ui/src/main/resources/jcr_root/libs/sling-cms/components/editor/fields/path/field.jsp
+++ b/ui/src/main/resources/jcr_root/libs/sling-cms/components/editor/fields/path/field.jsp
@@ -17,4 +17,20 @@
  * under the License.
  */ --%>
  <%@include file="/libs/sling-cms/global.jsp"%>
-<input class="Field-Path" type="text" name="${properties.name}" value="${editProperties[properties.name]}" ${required} ${disabled} data-type="${type}" autocomplete="off" />
\ No newline at end of file
+<c:choose>
+	<c:when test="${properties.hidesearch != true}">
+		<div class="Grid">
+			<div class="Cell Mobile-80">
+				<input class="Field-Path" type="text" name="${properties.name}" value="${editProperties[properties.name]}" ${required} ${disabled} data-type="${properties.type}" data-base="${properties.basePath}" autocomplete="off" />
+			</div>
+			<div class="Cell Mobile-20">
+				<a href="/cms/shared/search.html" class="Button Fetch-Modal Search-Button" data-title="Search" data-path=".Main-Content > .Grid > .Cell > *">
+					<span class="jam jam-search"></span>
+				</a>
+			</div>
+		</div>
+	</c:when>
+	<c:otherwise>
+		<input class="Field-Path" type="text" name="${properties.name}" value="${editProperties[properties.name]}" ${required} ${disabled} data-type="${properties.type}" data-base="${properties.basePath}" autocomplete="off" />
+	</c:otherwise>
+</c:choose>
\ No newline at end of file
diff --git a/ui/src/main/resources/jcr_root/libs/sling-cms/components/editor/fields/references/references.jsp b/ui/src/main/resources/jcr_root/libs/sling-cms/components/editor/fields/references/references.jsp
index 2b9026a..290e267 100644
--- a/ui/src/main/resources/jcr_root/libs/sling-cms/components/editor/fields/references/references.jsp
+++ b/ui/src/main/resources/jcr_root/libs/sling-cms/components/editor/fields/references/references.jsp
@@ -37,7 +37,7 @@
 					Replacement Path
 				</label>
 				<div class="Field-Input">
-					<input type="text" name=":dest" />
+					<input type="text" name=":dest" class="Field-Path" />
 				</div>
 			</div>
 		</c:if>
diff --git a/ui/src/main/resources/jcr_root/libs/sling-cms/components/editor/fields/richtext/field.jsp b/ui/src/main/resources/jcr_root/libs/sling-cms/components/editor/fields/richtext/field.jsp
index 518c323..45da1c3 100644
--- a/ui/src/main/resources/jcr_root/libs/sling-cms/components/editor/fields/richtext/field.jsp
+++ b/ui/src/main/resources/jcr_root/libs/sling-cms/components/editor/fields/richtext/field.jsp
@@ -25,20 +25,4 @@
 	<c:otherwise>
 		<c:set var="path" value="/content" />
 	</c:otherwise>
-</c:choose>
-<c:set var="pageQuery" value="SELECT * FROM [sling:Page] AS s WHERE ISDESCENDANTNODE([${path}])" />
-<c:set var="imageQuery" value="SELECT * FROM [sling:File] AS s WHERE ISDESCENDANTNODE([${path}]) AND [jcr:content/jcr:mimeType] LIKE 'image/%'" />
-<datalist id="richtext-pages">
-	<c:forEach var="page" items="${sling:findResources(resourceResolver,pageQuery,'JCR-SQL2')}">
-		<option value="${page.path}.html">
-			<sling:encode value="${page.valueMap['jcr:content/jcr:title']}" mode="HTML" />
-		</option>
-	</c:forEach>
-</datalist>
-<datalist id="richtext-images">
-	<c:forEach var="image" items="${sling:findResources(resourceResolver,imageQuery,'JCR-SQL2')}">
-		<option value="${image.path}">
-			<sling:encode value="${image.valueMap['jcr:content/jcr:title']}" mode="HTML" default="${image.name }" />
-		</option>
-	</c:forEach>
-</datalist>
\ No newline at end of file
+</c:choose>
\ 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
index 6a912d3..98adb5c 100644
--- 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
@@ -19,7 +19,7 @@
  <%@include file="/libs/sling-cms/global.jsp"%>
  <div class="taxonomy">
  	<fieldset disabled="disabled" class="taxonomy__template Hide">
- 		<a class="button taxonomy__item">
+ 		<a class="Button taxonomy__item">
 			<input type="hidden" name="${properties.name}" value="" />
 			<span class="taxonomy__title"></span>
 		</a>
@@ -34,7 +34,7 @@
  	</div>
  	<div class="taxonomy__container">
  		<c:forEach var="item" items="${editProperties[properties.name]}">
- 			<a class="button taxonomy__item">
+ 			<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>
  			</a>
diff --git a/ui/src/main/resources/jcr_root/libs/sling-cms/content/shared/search.json b/ui/src/main/resources/jcr_root/libs/sling-cms/content/shared/search.json
index e5dce60..63655ff 100644
--- a/ui/src/main/resources/jcr_root/libs/sling-cms/content/shared/search.json
+++ b/ui/src/main/resources/jcr_root/libs/sling-cms/content/shared/search.json
@@ -7,11 +7,6 @@
 		"container": {
 			"jcr:primaryType": "nt:unstructured",
 			"sling:resourceType": "sling-cms/components/general/container",
-			"richtext": {
-				"jcr:primaryType": "nt:unstructured",
-				"sling:resourceType": "sling-cms/components/general/richtext",
-				"text": "<h3>Search</h3>"
-			},
 			"searchform": {
 				"jcr:primaryType": "nt:unstructured",
 				"sling:resourceType": "sling-cms/components/cms/getform",
@@ -44,7 +39,8 @@
 						"jcr:primaryType": "nt:unstructured",
 						"sling:resourceType": "sling-cms/components/editor/fields/path",
 						"label": "Path",
-						"name": "path"
+						"name": "path",
+						"hidesearch": true
 					}
 				}
 			},
diff --git a/ui/src/main/resources/jcr_root/libs/sling-cms/content/site/create.json b/ui/src/main/resources/jcr_root/libs/sling-cms/content/site/create.json
index 70d7647..5d6c0e9 100644
--- a/ui/src/main/resources/jcr_root/libs/sling-cms/content/site/create.json
+++ b/ui/src/main/resources/jcr_root/libs/sling-cms/content/site/create.json
@@ -61,7 +61,8 @@
 						"basePath": "/conf",
 						"label": "Config",
 						"name": "sling:configRef",
-						"required": false
+						"required": false,
+						"type": "config"
 					},
 					"primaryType": {
 						"jcr:primaryType": "nt:unstructured",
diff --git a/ui/src/main/resources/jcr_root/libs/sling-cms/content/site/creategroup.json b/ui/src/main/resources/jcr_root/libs/sling-cms/content/site/creategroup.json
index 05351c4..9b434ac 100644
--- a/ui/src/main/resources/jcr_root/libs/sling-cms/content/site/creategroup.json
+++ b/ui/src/main/resources/jcr_root/libs/sling-cms/content/site/creategroup.json
@@ -46,7 +46,8 @@
 						"basePath": "/conf",
 						"label": "Config",
 						"name": "sling:configRef",
-						"required": false
+						"required": false,
+						"type": "config"
 					},
 					"primaryType": {
 						"jcr:primaryType": "nt:unstructured",
diff --git a/ui/src/main/resources/jcr_root/libs/sling-cms/content/site/edit.json b/ui/src/main/resources/jcr_root/libs/sling-cms/content/site/edit.json
index 3b95969..319e9a5 100644
--- a/ui/src/main/resources/jcr_root/libs/sling-cms/content/site/edit.json
+++ b/ui/src/main/resources/jcr_root/libs/sling-cms/content/site/edit.json
@@ -54,7 +54,8 @@
 						"basePath": "/conf",
 						"label": "Config",
 						"name": "sling:configRef",
-						"required": false
+						"required": false,
+						"type": "config"
 					}
 				}
 			}
diff --git a/ui/src/main/resources/jcr_root/libs/sling-cms/content/site/editgroup.json b/ui/src/main/resources/jcr_root/libs/sling-cms/content/site/editgroup.json
index 405bcb0..a508fc6 100644
--- a/ui/src/main/resources/jcr_root/libs/sling-cms/content/site/editgroup.json
+++ b/ui/src/main/resources/jcr_root/libs/sling-cms/content/site/editgroup.json
@@ -34,7 +34,8 @@
 						"basePath": "/conf",
 						"label": "Config",
 						"name": "sling:configRef",
-						"required": false
+						"required": false,
+						"type": "config"
 					}
 				}
 			}