From 0de7cac586bf2f5212cd5e35fae005ed6de2de1b Mon Sep 17 00:00:00 2001
From: ifaliana <ifaomega@gmail.com>
Date: Fri, 14 Feb 2025 14:45:33 +0300
Subject: [PATCH] Hot fix costumizer

---
 views/element/firstStepCostum.php | 131 ++++++++++++++++++++++++------
 1 file changed, 106 insertions(+), 25 deletions(-)

diff --git a/views/element/firstStepCostum.php b/views/element/firstStepCostum.php
index 140fa03eb..a338b0de5 100644
--- a/views/element/firstStepCostum.php
+++ b/views/element/firstStepCostum.php
@@ -395,26 +395,65 @@ HtmlHelper::registerCssAndScriptsFiles(["/css/blockcms/swiper/swiper-bundle.min.
 <script type="text/javascript">
 if(!notNull(contextData))
     contextData = <?= json_encode($element);?>;
-firstStepCostum = {
+
+var firstStepCostum = {
     template: { 
-        category :{
-            costum : {
-                thirdPlace            : tradCategory.thirdPlace, 
-                commons               : tradCategory.commons, 
-                greenTransition       : tradCategory.greenTransition,
-                aap                   : tradCategory.aap,
-                territorialConnectivity : tradCategory.territorialConnectivity,
-                Cocity                : tradCategory.Cocity, 
-                Community             : trad.community,
-                citizenAgora          : tradCategory.citizenAgora, 
-                researchAndInnovation : tradCategory.researchAndInnovation,
-                socialMapping         : tradCategory.socialMapping,
-                media                 : "Media",
-                ArtsAndMusic          : tradCategory.ArtsAndMusic,
-                SportAndActivity      : tradCategory.SportAndActivity,
-                coEvent               : "CoEvent",
-                businessCorporation   : tradCategory.businessCorporation
-            }
+        categoryused :{
+            costum : {}
+        },
+        getCategoryUsedByTemplate(callback) {
+                var dataCostum = {
+                    contextId   : contextId,
+                    contextType : contextType
+                }
+
+                ajaxPost(
+                    null,
+                    baseUrl+"/"+moduleId+"/cms/categoryusedbytplcms",
+                    {
+                        dataCostum
+                    },
+                    function(data){
+                        // firstStepCostum.template.categoryused = {};
+                        $.each(data, function(type, tplByType) {
+                            $.each(tplByType, function(keyC, tplByCategory) {
+                                if (tplByCategory.type == "costum") {
+                                    console.log("tplByCategory",tplByCategory)
+                                    if (typeof tplByCategory.category == "string") {
+                                     var category = (typeof tradCms[tplByCategory.category] == "undefined" ? (typeof trad[tplByCategory.category] == "undefined" ? tplByCategory.category : trad[tplByCategory.category] ) : tradCms[tplByCategory.category] )
+
+                                     tplByCategory.category = tplByCategory.category.replace("&","&amp;")
+                                     firstStepCostum.template.categoryused["costum"][tplByCategory.category] = category
+                                     if (typeof userConnected.roles.isSuperAdminCms == "undefined" && typeof tplByCategory.shared == "undefined") {
+                                        delete firstStepCostum.template.categoryused["costum"][tplByCategory.category]
+                                    }
+
+                                 }else{
+                                    $.each(tplByType, function(keyC, tplByCategory) {
+                                        if (!firstStepCostum.template.categoryused["costum"]) {
+                                            if (typeof tplByCategory.category == "string") {
+                                                var category = (typeof tradCms[tplByCategory.category] == "undefined" ? (typeof trad[tplByCategory.category] == "undefined" ? tplByCategory.category : trad[tplByCategory.category] ) : tradCms[tplByCategory.category] )
+
+                                                tplByCategory.category = tplByCategory.category.replace("&","&amp;")
+                                                firstStepCostum.template.categoryused["costum"][tplByCategory.category] = category
+                                                if (typeof userConnected.roles.isSuperAdminCms == "undefined" && typeof tplByCategory.shared == "undefined") {
+                                                    delete firstStepCostum.template.categoryused["costum"][tplByCategory.category]
+                                                }
+
+                                            }
+                                        }
+                                    });
+                                }
+                                }
+                            });
+                            if (callback && typeof callback === 'function') {
+                                callback();
+                            }
+                        });
+                    },
+                    null
+
+                    );
         },
         dataTpl:{},
         views : {
@@ -425,7 +464,7 @@ firstStepCostum = {
 
                 var paramsTemplateList = {
                     urlData: baseUrl + "/co2/search/globalautocomplete",
-                    container: ".modal-filter-template",
+                    container: ".modal-blockcms-header .modal-filter-template",
                     loadEvent : {
                         default : "scroll"
                     },
@@ -439,11 +478,10 @@ firstStepCostum = {
                         notSourceKey: true,
                         types: ["templates"],
                         filters: {
-                            type: ["costum"]
-                            //shared: true
+                            type: config.key,
+                            shared: true
                         },
                         fields : ["userCounter","shared","blocTplId","source.key"]
-
                     },
                     results: {
                         dom: "#modal-template-results",
@@ -473,10 +511,53 @@ firstStepCostum = {
                             keyValue:false,
                             multiple:true,
                             active : true,
-                            list: firstStepCostum.template.category[config.key]
+                            list: firstStepCostum.template.categoryused["costum"]
                         }
                     }
                 };
+                if (typeof userConnected.roles.superAdmin != "undefined") {
+                    delete paramsTemplateList.defaults.filters.shared;
+                    paramsTemplateList.filters["shared"] = {
+                        view: "dropdownList",
+                        type: "filters",
+                        action: "filters",
+                        name: "Trier par restriction",
+                        icon: "globe",
+                        typeList : "object",
+                        event : "exists",
+                        keyValue: false,
+                        list: {
+                            restricted : {
+                                label: "Unrestricted",
+                                field : "shared",
+                                value : true
+                            },
+                            shared : {
+                                label: "Restricted",
+                                field : "shared",
+                                value : false
+                            }
+                        }
+                    }
+                }
+                if (typeof config.category != "undefined") {
+                    paramsTemplateList.defaults.filters["category"] = config.category;
+                }
+
+
+                if ( config.key == "costum"){
+                    $(".tpl-info-container").css("background","linear-gradient(to right, #333333, #ffa500, #333333)");
+                    // var pageAndCostumCategory = costumizer.template.categoryused.costum
+                    // for (const key in costumizer.template.categoryused.page) {
+                    //  if (costumizer.template.categoryused.page.hasOwnProperty(key) && !pageAndCostumCategory.hasOwnProperty(key)) {
+                    //      pageAndCostumCategory[key] = costumizer.template.categoryused.page[key];
+                    //  }
+                    // }
+                    // costumizer.template.paramsTemplateList.filters.category.list = pageAndCostumCategory;
+                    paramsTemplateList.filters.category.list = firstStepCostum.template.categoryused["costum"];
+                    // costumizer.template.paramsTemplateList.defaults.filters.type = [config.key,"page"]
+                    paramsTemplateList.defaults.filters.type = [config.key]
+                }
                 var filterGroupTemplate = searchObj.init(paramsTemplateList);
                 filterGroupTemplate.search.init(filterGroupTemplate);
                 
@@ -719,7 +800,6 @@ firstStepCostum = {
                             "newCostum"  : true,
                             "collection" : tplCollection,
                             "parentId"   : contextData.id,
-                            "page"       : "#",
                             "parentSlug" : contextData.slug,
                             "parentType" : contextData.collection
                         };
@@ -740,4 +820,5 @@ firstStepCostum = {
 
     }
 }
+firstStepCostum.template.getCategoryUsedByTemplate()
 </script>
\ No newline at end of file
-- 
GitLab