Goal
Start workflow on Sites Pages in Omni Search results...
Demo | Package Install | Github
Solution
1) Create a clientlib /apps/eaem-omni-search-create-workflow with categories=cq.gui.common.admin.searchpanel and below code to add the workflow button in search action bar...
(function ($, $document) { const FOUNDATION_CONTENT_LOADED = "foundation-contentloaded", GRANITE_OMNI_SEARCH_CONTENT = ".granite-omnisearch-content", SITES_EDIT_ACTIVATOR = "cq-siteadmin-admin-actions-edit-activator", START_WF_URL = "/mnt/override/libs/wcm/core/content/common/startbulkworkflows.html", CREATE_WF_BUT_URL = "/apps/eaem-omni-search-create-workflow/create-wf-but.html"; let init = false; $document.on(FOUNDATION_CONTENT_LOADED, GRANITE_OMNI_SEARCH_CONTENT, function(event){ $.ajax(CREATE_WF_BUT_URL).done(function(html){ init = addCreateButton(html); }); }); function addCreateButton(html){ html = html || ""; if(!html.trim()){ return; } const $eActivator = $("." + SITES_EDIT_ACTIVATOR); if ($eActivator.length == 0) { return false; } let $createWFBut = $("<coral-actionbar-item>" + html + "</coral-actionbar-item>") .insertBefore($eActivator.closest("coral-actionbar-item")); $createWFBut = $createWFBut.find("button"); $createWFBut.click(startWorkflow); return true; } function startWorkflow(){ const $selectedItems = $(".foundation-selections-item"); if($selectedItems.length == 0){ return; } let startWfUrl = START_WF_URL + "?" $selectedItems.each(function(){ startWfUrl = startWfUrl + "item=" + $(this).data("graniteCollectionItemId") + "&"; }) window.open(startWfUrl, '_blank'); } })(jQuery, jQuery(document));
2) Create button /apps/eaem-omni-search-create-workflow/create-wf-but with the following config...
<?xml version="1.0" encoding="UTF-8"?> <jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:granite="http://www.adobe.com/jcr/granite/1.0" xmlns:dam="http://www.day.com/dam/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="nt:unstructured" sling:resourceType="granite/ui/components/coral/foundation/collection/action" granite:rel="eaem-create-workflow" activeSelectionCount="multiple" target=".granite-omnisearch-result" relScope="none" icon="workflow" text="Workflow" title="Workflow" variant="actionBar"> <granite:rendercondition jcr:primaryType="nt:unstructured" sling:resourceType="cq/gui/components/renderconditions/canreadworkflowmodels"/> </jcr:root>
No comments:
Post a Comment