AEM 65 - Show Approved Assets in Asset Finder

Goal


Show approved assets in asset finder "jcr:content/metadata/dam:status=approved"

Demo | Package Install | Github


Review Task - Approve Assets



Approved Asset Metadata



Asset Finder - Approved Assets



Solution


1) To add the Images - Approved filter in Asset Finder, login to CRXDE Lite, create folder (nt:folder) /apps/eaem-asset-finder-show-approved-assets

2) Create clientlib (type cq:ClientLibraryFolder) /apps/eaem-asset-finder-show-approved-assets/clientlib and set a property categories of String[] type to [cq.authoring.editor.hook.assetfinder]dependencies of type String[] with value lodash

3) Create file ( type nt:file ) /apps/eaem-asset-finder-show-approved-assets/clientlib/js.txt, add the following

                         assetfinder-approved.js

4) Create file ( type nt:file ) /apps/eaem-asset-finder-show-approved-assets/clientlib/assetfinder-approved.js, add the following code

(function ($, $document, author) {
    var self = {},
        EAEM_APPROVED = 'Images - Approved';

    var searchPath = self.searchRoot = "/content/dam",
        imageServlet = '/bin/wcm/contentfinder/asset/view.html',
        itemResourceType = 'cq/gui/components/authoring/assetfinder/asset';

    self.loadAssets = function (query, lowerLimit, upperLimit) {
        query = query.concat("\"jcr:content/metadata/dam:status\": \"approved\" ");
        query = query.concat("order:\"-jcr:content/jcr:lastModified\" ");

        var param = {
            '_dc': new Date().getTime(),
            'query': query.concat("order:\"-jcr:content/jcr:lastModified\" "),
            'mimeType': 'image,application/x-ImageSet,application/x-SpinSet,application/x-MixedMediaSet,application/x-CarouselSet',
            'itemResourceType': itemResourceType,
            'limit': lowerLimit + ".." + upperLimit,
            '_charset_': 'utf-8'
        };

        return $.ajax({
            type: 'GET',
            dataType: 'html',
            url: Granite.HTTP.externalize(imageServlet) + searchPath,
            data: param
        });
    };

    self.setSearchPath = function (spath) {
        searchPath = spath;
    };

    author.ui.assetFinder.register(EAEM_APPROVED, self);
}(jQuery, jQuery(document), Granite.author));

No comments:

Post a Comment