AEM Cloud Service - Assets Folder Properties Dynamic Media Image Profiles Sorted Case Ignored

Goal

AEM Cloud Version : 2021.4.5226.20210427T070726Z-210325 (April 27, 2021)

Sample code in this post is for Case Ignored Sorting of Dynamic Media Image Profiles in folder properties

Package Install | Github


Product


Extension


Solution

Create a cq:ClientLibrayFolder /apps/eaem-cs-sort-image-profiles/clientlibs/sort-image-profiles with categories=cq.gui.damadmin.v2.foldershare.coral and a JS file /apps/eaem-cs-sort-image-profiles/clientlibs/sort-image-profiles/sort-profiles.js with the following logic, to read the select ./jcr:content/imageProfile and order the values....

(function ($, $document) {
    "use strict";
    var IMAGE_PROFILE_SEL = "[name='./jcr:content/imageProfile']";

    $document.on("foundation-contentloaded", sortImageProfiles);

    function sortImageProfiles(){
        var $imageProfileSelect = $(IMAGE_PROFILE_SEL);

        if(_.isEmpty($imageProfileSelect)){
            return;
        }

        var selectItems = $imageProfileSelect[0].items,
            values = selectItems.getAll(),
            noneValue = values[0];

        values.sort(function (a, b) {
            var nameA = a.textContent.toUpperCase();
            var nameB = b.textContent.toUpperCase();

            return ((nameA < nameB) ? -1 : ((nameA > nameB)  ? 1 : 0));
        });

        selectItems.clear();

        selectItems.add(noneValue);

        _.each(values, function(value){
            if(value.textContent === "None"){
                return;
            }

            selectItems.add(value);
        });
    }

}(jQuery, jQuery(document)));




No comments:

Post a Comment