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/01/13 01:24:26 UTC
[sling-org-apache-sling-app-cms] branch master updated: Support
page templates to be json object (#4)
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 55cc13a Support page templates to be json object (#4)
55cc13a is described below
commit 55cc13a7598e5559d2c1014d351a7fb8c86f02cd
Author: mahsumdemir <ma...@gmail.com>
AuthorDate: Sun Jan 13 04:24:22 2019 +0300
Support page templates to be json object (#4)
* Create a separate folder for docker and make Dockerfile runnable
* Implement support for json page templates
---
ui/src/main/frontend/src/js/cms.js | 27 -------
ui/src/main/frontend/src/js/cms.page.js | 83 ++++++++++++++++++++++
.../components/cms/pageproperties/include.jsp | 5 +-
3 files changed, 84 insertions(+), 31 deletions(-)
diff --git a/ui/src/main/frontend/src/js/cms.js b/ui/src/main/frontend/src/js/cms.js
index 4f11404..543ebb5 100644
--- a/ui/src/main/frontend/src/js/cms.js
+++ b/ui/src/main/frontend/src/js/cms.js
@@ -149,33 +149,6 @@ window.onbeforeunload = function() {
}
}
-rava.bind('.page-properties-container', {
- callbacks : {
- created : function(){
- var $ctr = $(this);
- var $wrapper = $ctr.closest('.form-wrapper');
- $($ctr.data('source')).change(function(){
- var $source = $(this);
- $source.attr('disabled', 'disabled');
- $ctr.html('');
- var config = $(this).val();
- $ctr.load($ctr.data('path')+config, function(){
- $source.removeAttr('disabled');
- var source = $('#content-template').html();
- var template = Handlebars.compile(source);
- var updateContent = function(){
- if(!$wrapper.is(':disabled')){
- var data = Sling.CMS.utils.form2Obj($ctr.parents('form'));
- $('input[name=":content"]').val(template(data));
- }
- }
- $ctr.find('input,textarea,select').change(updateContent);
- $ctr.parents('form').submit(updateContent);
- });
- });
- }
- }
-});
rava.bind('.sling-cms-include-config', {
callbacks : {
diff --git a/ui/src/main/frontend/src/js/cms.page.js b/ui/src/main/frontend/src/js/cms.page.js
new file mode 100644
index 0000000..1bb8c89
--- /dev/null
+++ b/ui/src/main/frontend/src/js/cms.page.js
@@ -0,0 +1,83 @@
+/*
+ * 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.
+ */
+/* eslint-env browser, es6 */
+(function (rava, Sling) {
+
+ function removeProperty(obj, propertyToDelete) {
+ for(prop in obj) {
+ if (prop === propertyToDelete)
+ delete obj[prop];
+ else if (typeof obj[prop] === 'object')
+ removeProperty(obj[prop], propertyToDelete);
+ }
+ }
+
+
+ var getPageTemplate = function(pageConfig){
+ var source = "";
+ $.ajax({
+ url: pageConfig + ".infinity.json",
+ success: function(result){
+ if (typeof result.template === "string") {
+ //String template
+ source = result.template;
+ } else if (typeof result.template === "object"){
+ //Json template
+ removeProperty(result.template, "jcr:created");
+ removeProperty(result.template, "jcr:createdBy");
+ source = JSON.stringify(result.template);
+ }
+ },
+ async: false
+ });
+
+ return source;
+ };
+
+ rava.bind('.page-properties-container', {
+ callbacks : {
+ created : function(){
+ var $ctr = $(this);
+ var $wrapper = $ctr.closest('.form-wrapper');
+ $($ctr.data('source')).change(function(){
+ var $source = $(this);
+ $source.attr('disabled', 'disabled');
+ $ctr.html('');
+ var config = $(this).val();
+ $ctr.load($ctr.data('path')+config, function(){
+ $source.removeAttr('disabled');
+
+ var source = getPageTemplate(config);
+
+ var template = Handlebars.compile(source);
+ var updateContent = function(){
+ if(!$wrapper.is(':disabled')){
+ var data = Sling.CMS.utils.form2Obj($ctr.parents('form'));
+ $('input[name=":content"]').val(template(data));
+ }
+ };
+ $ctr.find('input,textarea,select').change(updateContent);
+ $ctr.parents('form').submit(updateContent);
+ });
+ });
+ }
+ }
+ });
+
+}(window.rava = window.rava || {}, window.Sling = window.Sling || {}));
\ No newline at end of file
diff --git a/ui/src/main/resources/jcr_root/libs/sling-cms/components/cms/pageproperties/include.jsp b/ui/src/main/resources/jcr_root/libs/sling-cms/components/cms/pageproperties/include.jsp
index a3fcf79..210d283 100644
--- a/ui/src/main/resources/jcr_root/libs/sling-cms/components/cms/pageproperties/include.jsp
+++ b/ui/src/main/resources/jcr_root/libs/sling-cms/components/cms/pageproperties/include.jsp
@@ -19,7 +19,4 @@
<%@include file="/libs/sling-cms/global.jsp"%>
<c:forEach var="field" items="${sling:listChildren(sling:getRelativeResource(slingRequest.requestPathInfo.suffixResource,'fields'))}">
<sling:include resource="${field}" />
-</c:forEach>
-<script id="content-template" type="text/x-handlebars-template">
- ${slingRequest.requestPathInfo.suffixResource.valueMap.template}
-</script>
\ No newline at end of file
+</c:forEach>
\ No newline at end of file