Skip to content
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ui.apps/src/main/content/META-INF/vault/filter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@

<filter root="/apps/etoolbox-authoring-kit/clientlib-injector"/>
<filter root="/apps/etoolbox-authoring-kit/components"/>
<filter root="/apps/etoolbox-authoring-kit/content-blueprints"/>
<filter root="/apps/etoolbox-authoring-kit/coral-overlay"/>
<filter root="/apps/etoolbox-authoring-kit/depends-on"/>
<filter root="/apps/etoolbox-authoring-kit/depends-on-injector"/>
<filter root="/apps/etoolbox-authoring-kit/install"/>
<filter root="/apps/etoolbox-authoring-kit/limit-parsys"/>
<filter root="/apps/etoolbox-authoring-kit/lists"/>

<!-- The following filters clear old directories in JCR content. They can be removed after v.2 release -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
xmlns:jcr="http://www.jcp.org/jcr/1.0"
jcr:primaryType="cq:ClientLibraryFolder"
categories="[cq.authoring.dialog]"
dependencies="[cq.authoring.dependson,cq.authoring.dependson.fixes,lists.item-dialog]"
dependencies="[cq.authoring.dependson,cq.authoring.dependson.fixes,lists.item-dialog,content-blueprints.toolbar-action,content-blueprints.limit-parsys]"
/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed 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.
-->
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:granite="http://www.adobe.com/jcr/granite/1.0"
xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
jcr:primaryType="cq:Page">
<createpagedialog
jcr:primaryType="nt:unstructured"
jcr:title="Create EToolbox Content Blueprint"
sling:resourceType="granite/ui/components/coral/foundation/dialog">
<items jcr:primaryType="nt:unstructured">
<form jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form"
action="/libs/wcm/core/content/sites/createpagewizard/jcr:content"
foundationForm="{Boolean}true"
method="post"
style="vertical">
<successresponse
jcr:primaryType="nt:unstructured"
jcr:title="Success"
sling:resourceType="granite/ui/components/coral/foundation/form/responses/openprompt"
open="/bin/wcmcommand?cmd=open&amp;_charset_=utf-8&amp;path={Path}"
text="Your page has been created."/>
<items jcr:primaryType="nt:unstructured">
<content jcr:primaryType="nt:unstructured"
jcr:title="Package setup"
sling:resourceType="granite/ui/components/coral/foundation/fixedcolumns">
<items jcr:primaryType="nt:unstructured">
<column jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/container">
<items jcr:primaryType="nt:unstructured">
<charset
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/hidden"
name="_charset_"
value="utf-8"/>
<parentPath
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/hidden"
name="parentPath"
value="${requestPathInfo.suffix}"/>
<template
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/hidden"
name="./cq:template"
value="/conf/etoolbox-authoring-kit/settings/wcm/templates/simple-content-blueprint"/>
<resourceType
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/hidden"
name="./sling:resourceType"
value="/apps/etoolbox-authoring-kit/content-blueprints/components/structure/page-content-blueprint"/>
<pageProps
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/include"
resourceType="granite/ui/components/coral/foundation/container"
path="/apps/etoolbox-authoring-kit/content-blueprints/components/structure/page-content-blueprint/cq:dialog/content/items/tabs/items/mainConfig"/>
<create
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/button"
granite:class="lists-create-button"
text="Create"
type="submit"
variant="primary"/>
</items>
</column>
</items>
</content>
</items>
</form>
</items>
</createpagedialog>
</jcr:root>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
jcr:primaryType="cq:ClientLibraryFolder"
allowProxy="{Boolean}true"
categories="[content-blueprints.toolbar-action]"
jsProcessor="[min:gcc;languageIn=ECMASCRIPT_2015,compilationLevel=advanced,languageOut=ECMASCRIPT5]"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* Import Toolbar Action to import "template" page content into current position
**/
(function ($document, author, ns) {
const IMPORT_ACTION = 'content-blueprint-import-action';

const JCR_CONTENT = '/jcr:content/';
const NEWPAR_TYPES = ['foundation/components/parsys/newpar', 'wcm/foundation/components/parsys/newpar', 'wcm/foundation/components/responsivegrid/new'];
const IMPORT_DIALOG_PATH = '/mnt/override/apps/etoolbox-authoring-kit/content-blueprints/components/content/toolbar/dialog/_cq_dialog.html';

function condition(editable) {
return author.pageInfoHelper.canModify() && editable.hasAction('INSERT');
}

function openImportDialog(editable) {
const target = editable.getParent();
const path = target.path;
const order = NEWPAR_TYPES.includes(editable.type) ? 'last' : `after ${editable.name}`;
const parentType = editable.getParent().type;

const page = path.substr(0, path.indexOf(JCR_CONTENT) + JCR_CONTENT.length);
const dialogPath = ns.EToolboxContentBlueprints.joinJCRPath(IMPORT_DIALOG_PATH, page);
const dialogConfig = {
src: ns.HTTP.externalize(dialogPath.replace(/\*\//, '')),
loadingMode: 'auto',
layout: 'auto'
};
const dlg = new author.ui.Dialog({
getConfig: () => dialogConfig,
getRequestData: () => ({ order, parentType, path }),
onSuccess: () => setTimeout(() => {
author.editableHelper.actions.REFRESH.execute(target);
}, 250)
});

author.DialogFrame.openDialog(dlg);
}

$document.off('cq-layer-activated.content-blueprint-import-action').on('cq-layer-activated.content-blueprint-import-action', function (ev) {
if (ev.layer === 'Edit') {
author.EditorFrame.editableToolbar.registerAction(IMPORT_ACTION, {
icon: 'coral-Icon--dataUpload',
text: Granite.I18n.get('Import from EToolbox Content Blueprint'),
handler: openImportDialog,
condition: condition,
isNonMulti: false
});
// Restore custom action after MSM
setTimeout(() => {
const action = author.EditorFrame.editableToolbar.config.actions[IMPORT_ACTION];
if (action && action.decoratedCondition) {
action.condition = action.decoratedCondition;
delete action.decoratedCondition;
console.log('Action "', action.name, '" undecorated');
}
});
}
});
})($(document), Granite.author, Granite);
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
* Licensed 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.
*/
(function (author, ns) {
'use strict';

/**
* Join JCR path parts
* */
ns.joinJCRPath = function (path1, path2, ...rest) {
if (rest.length > 0) return ns.joinJCRPath(ns.joinJCRPath(path1, path2), ...rest);
return (path1 + '/' + path2).replace(/\/(\/)+/g, '/');
};

/**
* Join and normalize JCR path. Removes ending '/'
* */
ns.resolveJCRPath = function (path, ...rest) {
if (rest.length > 0) return ns.resolveJCRPath(ns.joinJCRPath(path, ...rest));
return path.replace(/\/$/, '').replace(/\/_jcr_content\//g, '/jcr:content/');
};

/**
* Resolve path to the JCR content
* */
ns.resolveJCRContentPath = function (path) {
return path ? ns.joinJCRPath(path, '/_jcr_content/') : '';
};

/**
* Check if the passed resource type can be placed inside of passed path
* */
ns.canInsert = function (resourceType, parentPath) {
if (!resourceType) return 'No component to insert';
if (!parentPath) return 'Insertion target is incorrect';

const component = author.components.find({ resourceType })[0];
if (!component) return 'Component resourceType is not is the list';

const componentPath = component.getPath();
const componentRelativePath = componentPath.replace(/^\/[a-z]+\//, '');
const componentGroup = 'group:' + component.getGroup();

const resolvedPath = ns.resolveJCRPath(parentPath);
const allowedComponents = author.components.allowedComponentsFor[resolvedPath];

if (!allowedComponents || !allowedComponents.length) {
return `No allowed components found for '${resolvedPath}'`;
}

if (allowedComponents.indexOf(componentPath) === -1 &&
allowedComponents.indexOf(componentRelativePath) === -1 &&
allowedComponents.indexOf(componentGroup) === -1) {
return `Component '${component.getTitle()}' is not allowed for current target`;
}
return true;
};

const isValidComponentNode = (item) => {
return item && item['sling:resourceType'];
};

const findRootName = (content) => {
if (Object.hasOwnProperty.call(content, 'content-blueprints-parsys')) return 'content-blueprints-parsys';
return null;
};

/**
* Add ending '/' to the form action.
* @returns result path
* */
ns.setupInsertionFormTarget = function ($el, path) {
path = ns.joinJCRPath(path, '/');
$el.closest('form[action]').attr('action', path);
return path;
};

/**
* Fetch action successful response handler to resolve first content component
* */
ns.mapImportResourcePath = function (response, parentName, parentPath) {
try {
const rootName = findRootName(response);
if (!rootName) return '';
const root = response[rootName];
const nodeNames = Object.keys(root);
for (const name of nodeNames) {
const node = root[name];
if (!isValidComponentNode(node)) continue;
const path = ns.resolveJCRPath(parentPath, '/', rootName, '/', name);
const type = node['sling:resourceType'];
return JSON.stringify({ type, path, name });
}
} catch {
// no action
}
return '';
};
/** Fetch action unsuccessful response handler stub */
ns.mapImportResourcePathError = () => '';
}(Granite.author, Granite.EToolboxContentBlueprints = (Granite.EToolboxContentBlueprints || {})));
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import-helper.js
import-action.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0"
xmlns:jcr="http://www.jcp.org/jcr/1.0"
jcr:primaryType="cq:Component"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root
fileName="_cq_dialog.xml"
jcr:title="Import template"
jcr:primaryType="nt:unstructured"
sling:resourceType="cq/gui/components/authoring/dialog"
xmlns:jcr="http://www.jcp.org/jcr/1.0"
xmlns:sling="http://sling.apache.org/jcr/sling/1.0"
xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
xmlns:granite="http://www.adobe.com/jcr/granite/1.0"
height="{Decimal}150">
<content jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/container">
<layout jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/fixedcolumns"/>
<items jcr:primaryType="nt:unstructured">
<column jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/container">
<items jcr:primaryType="nt:unstructured">
<!-- Hidden field to replace form action with the ending '/' and store action path -->
<action jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/hidden">
<granite:data jcr:primaryType="nt:unstructured"
dependsOnRef="targetPath"
dependsOn="Granite.EToolboxContentBlueprints.setupInsertionFormTarget(this, '${param.path}')"
dependsOnAction="set"/>
</action>

<!-- Import path field -->
<importPath
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/pathfield"
rootPath="/content"
fieldLabel="Link to EToolBox Content Blueprint"
fieldDescription="Provide link to the EToolBox Content Blueprint page.">
<granite:data jcr:primaryType="nt:unstructured"
dependsOnRef="importPath"
dependsOn="Granite.EToolboxContentBlueprints.canInsert(@importNode.type, @targetPath)"
dependsOnAction="validate"/>
</importPath>

<!-- Hidden JSON field to store resolved first child component from template -->
<node jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/hidden">
<granite:data jcr:primaryType="nt:unstructured"
dependsOnRef="importNode"
dependsOnRefType="json"
dependsOn="Granite.EToolboxContentBlueprints.resolveJCRContentPath(@importPath)"
dependsOnAction="fetch"
dependsOn-fetch-map="Granite.EToolboxContentBlueprints.mapImportResourcePath"
dependsOn-fetch-err="Granite.EToolboxContentBlueprints.mapImportResourcePathError"
dependsOn-fetch-postfix=".2.json"/>
</node>

<!-- Sling instruction to define copy target -->
<copyFrom jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/hidden"
name="./@CopyFrom"
required="{Boolean}true">
<granite:data jcr:primaryType="nt:unstructured"
dependsOn="@importNode.path || ''"
dependsOnAction="set"/>
</copyFrom>

<!-- Readonly field to define copy resource type. Contains allowed component validation -->
<resType jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/hidden"
name="./sling:resourceType">
<granite:data jcr:primaryType="nt:unstructured"
dependsOn="@importNode.type || ''"
dependsOnAction="set"/>
</resType>

<!-- Hidden field to send parent resource type -->
<parentType jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/hidden"
name="parentResourceType"
value="${param.parentType}">
</parentType>

<!-- Hidden field to send insertion order -->
<order jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/hidden"
name=":order" value="${param.order}">
</order>

<!-- Hidden field to send recommended name for new node -->
<nameHint jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/hidden"
name=":nameHint">
<granite:data jcr:primaryType="nt:unstructured"
dependsOn="@importNode.name ? (@importNode.name + ' copy') : ''"
dependsOnAction="set"/>
</nameHint>
</items>
</column>
</items>
</content>
</jcr:root>
Loading