Goal
Set the user's search keyword and results in Asset Finder when loading TouchUI authoring editor - http://localhost:4502/editor.html
Demo | Package Install
Keyword in User Profile
Set the property searchKeyword in user's profile manually or by extending user editor - check this post
TouchUI Editor with Keyword and Results
Solution
1) Login to CRXDE Lite (http://localhost:4502/crx/de) and create folder /apps/touchui-asset-finder-set-search-text
2) Create node /apps/touchui-asset-finder-set-search-text/clientlib of type cq:ClientLibraryFolder and add a String property categories with value cq.authoring.editor.hook.assetfinder
3) Create file (nt:file) /apps/touchui-asset-finder-set-search-text/clientlib/js.txt and add
set-search-text.js
4) Create file (nt:file) /apps/touchui-asset-finder-set-search-text/clientlib/set-search-text.js and add the following code
(function ($, $document) { "use strict"; //id "assetfinder-filter" and "assetsearch" are defined in ///libs/wcm/core/content/editor/jcr:content/sidepanels/edit/items/assetsTab/items/filterPanel/items/views/items/search/items/searchpanel var ASSET_FINDER_FILTER = "#assetfinder-filter", KEYWORD_SELECTOR = "#assetsearch", ASSET_FINDER_CONTAINER = ".assetfinder-content-container", PROFILE_SEARCH_KEYWORD = "searchKeyword"; $document.on('cq-layer-activated', getDefaultKeyword); function getDefaultKeyword(ev){ if ( ev.layer !== 'Edit' ) { return; } //Granite.author.ContentFrame.contentWindow.CQ.shared.User.getUserPropsUrl() $.ajax("/libs/cq/security/userinfo.json").done(function(data){ $.ajax(data.home + ".1.json").done(searchWithKeyword); }); } function searchWithKeyword(data){ if(!data || !data.profile || !data.profile[PROFILE_SEARCH_KEYWORD]){ return; } var $assetFinderFilter = $(ASSET_FINDER_FILTER), $assetFinderContainer = $(ASSET_FINDER_CONTAINER), $assetFinderKeyword = $assetFinderFilter.find(KEYWORD_SELECTOR); $assetFinderKeyword.val(data.profile[PROFILE_SEARCH_KEYWORD]); $assetFinderContainer.trigger({ type: "loadAssets", append: false }) } })(jQuery, jQuery(document));
No comments:
Post a Comment