Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EAK-280] Add new Content Blueprints page template #298

Open
wants to merge 16 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
[EAK-280] Skeleton Template: Create toolbar action for skeleton import
  • Loading branch information
SkoryUladzislau committed Feb 8, 2022
commit ee206e4b75031b844ca1813a07869de11acf5023
Original file line number Diff line number Diff line change
@@ -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,trojan-horse.toolbar-action]"
/>
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="[trojan-horse.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 = 'import-action';

const JCR_CONTENT = '/jcr:content/';
const NEWPAR_TYPES = ['foundation/components/parsys/newpar', 'wcm/foundation/components/parsys/newpar'];
const IMPORT_DIALOG_PATH = '/mnt/override/apps/etoolbox-authoring-kit/trojan-horse/components/content/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.EToolboxTrojanHorse.joinJCRPath(IMPORT_DIALOG_PATH, page);
const dialogConfig = {
src: Granite.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.import-action').on('cq-layer-activated.import-action', function (ev) {
if (ev.layer === 'Edit') {
author.EditorFrame.editableToolbar.registerAction(IMPORT_ACTION, {
icon: 'coral-Icon--DataDownload',
text: Granite.I18n.get('Import Trojan Horse'),
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,60 @@
/*
* 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.
*/

Granite.EToolboxTrojanHorse = Granite.EToolboxTrojanHorse || (function () {

return {
/** Join JCR path parts */
joinJCRPath: function (path1, path2, ...rest) {
if (rest.length > 0) return HPEUtils.joinJCRPath(HPEUtils.joinJCRPath(path1, path2), ...rest);
return (path1 + '/' + path2).replace(/\/(\/)+/g, '/');
},
/** Join and normalize JCR path. Removes ending '/' */
resolveJCRPath: function (path, ...rest) {
if (rest.length > 0) return HPEUtils.resolveJCRPath(HPEUtils.joinJCRPath(path, ...rest));
return path.replace(/\/$/, '').replace(/\/_jcr_content\//g, '/jcr:content/');
},
/** Resolve path to the JCR content */
resolveJCRContentPath: function (path) {
return path ? HPEUtils.joinJCRPath(path, '/_jcr_content/') : '';
},

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

const component = Granite.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 = HPEUtils.resolveJCRPath(parentPath);
const allowedComponents = Granite.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;
}
};
})();
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
importHelper.js
import-action.js