0 votes

Hello,
Customer is asking to have a treeview in the search result list, this feature was in Efficy 2012...
Scenario :
Open an Opportunity,
-> link a Product
-> Search screen shows-up, input a product name
-> from the result list, be able to drill down the product hierarchy and pick the desired article

Does anyone knows if this can be customised in Efficy 10 SP2 ?

Tkx,
Frédéric

asked in Efficy/ Client side by (180 points)

2 Answers

0 votes

Salut,

comme j'étais à l'origine de la question, je donne rapidement la solution :

Résultat attendu

Dans \customs\xxx\macros\GridColumnsCustom.txt il faut réadapter les macros de la v2012:

    /* Recherche arborescente comme en 2012 !    NAMESEARCH  */
    th.TREEVIEWPLUS {[<th class="text-start"> </th>]}

    td.TREEVIEWPLUS {[<td class="icon-cell"><span id="Tree_TE<#N>" class="TREEVIEWPLUS" treeKey="<#F=K_1>" style="display: block;"
        onclick="EurTreeExpand('Div_T<#N>', '$ENTITY$', '<#F=K_1>', 'Tree_TE<#N>', 'Tree_TC<#N>', '<xA=NAMESEARCH>');"><i class="i-down"></i>
        </span><span id="Tree_TC<#N>"  style="display: none;"
        onclick="EurTreeCollapse('Div_T<#N>', '$ENTITY$', '<#F=K_1>', 'Tree_TE<#N>',  'Tree_TC<#N>');"><i class="i-up"></i></span></td>
    ]}

    td.TREEVIEWPLUS_F {[<td class="icon-cell"><span id="FTree_TE<#N>" class="TREEVIEWPLUS" treeKey="<#F=K_1>" style="display: block;"
        onclick="EurTreeExpand('Div_FT<#N>', '<#E=K_TABLE>', '<#F=K_1>', 'FTree_TE<#N>', 'FTree_TC<#N>', '<xA=NAME>');"><i class="i-down"></i>
        </span><span id="FTree_TC<#N>"  style="display: none;"
        onclick="EurTreeCollapse('Div_FT<#N>', '<#E=K_TABLE>', '<#F=K_1>', 'FTree_TE<#N>', 'FTree_TC<#N>');"><i class="i-up"></i></span></td>
    ]}

    td.NEWLINE2TREEVIEW {[<td colspan="$COLUMNCOUNT$" style="padding: 0 0 0 0;"></td>
        </tr><tr><td style="padding: 0 0 0 0;></td><td style="padding: 0 0 0 0;></td>
        <td colspan="$COLUMNCOUNT$" style="padding: 0 0 0 0;" ><div id="Div_T<#N>" class="TreePanel" style="display: none;" ><%GetLabel("Loading")%>...</div></td>]}

    td.NEWLINE2TREEVIEW_F {[<td colspan="$COLUMNCOUNT$" style="padding: 0 0 0 0;"></td>
        </tr><tr><td style="padding: 0 0 0 0;></td><td style="padding: 0 0 0 0;></td>
        <td colspan="$COLUMNCOUNT$" style="padding: 0 0 0 0;"><div id="Div_FT<#N>" class="TreePanel" style="display: none;"><%GetLabel("Loading")%>...</div></td>]}

Attention: il y a 2 versions, pour les
Favoris (sufixe "_F") et les récents. On les emploie dans \customs\xxx\pages\grid\SearchRecent.htm (je ne les ai branchés que sur les "prod", mais elles devraient fonctionner sur les autres entités) :

<!-- VERSION CUSTOM  XXX  -->
<%LoadMacros('MacroLibrary;MacroSearch')%>
<script src="<%GetCustomBase()%>scripts/eureka2014.js"></script>
<div class="row has-icons">
    <div class="small-12 medium-6 columns">
        <h4 class="i-recent"><%GetLabel('Recent List')%></h4>
        <%GetRecentGrid(
        columndefs="%%Evaluate(|<%Macro('SearchResultColumnDefs')%>|)", entity="%%GetEntity()", key="K_1", noheader=true,
        extrafields=|%%OnEntity(comp="OPENED,PHONE1,WEB1", cont="PHONE1,EMAIL1,OPENED", docu="ATTACHMENTS,OPENED")|,
        columns="%%OnEntity(
        comp='N,TEXT{NAMESEARCH},DRAGDROP'
        prod='N,TREEVIEWPLUS,TEXT{NAMESEARCH},K_1{NEWLINE2TREEVIEW},DRAGDROP'
        proj='N,TEXT{NAMESEARCH},DRAGDROP'
        else='N,TEXT{NAMESEARCH},DRAGDROP')")%>
    </div>
    <div class="small-12 medium-6 columns">
        <h4 class="i-favorite"><%GetLabel('Favorites')%></h4>
        <%GetFavoriteGrid(
        columndefs="%%Evaluate(|<%Macro('SearchResultColumnDefs')%>|)", entity="Favo", entityfilter="%%GetEntity()", detail="%%GetEntity()", noheader="true",
        columns="%%OnEntity(
        comp='N,NAME{NAMESEARCH},DRAGDROP'
        prod='N,TREEVIEWPLUS_F,NAME{NAMESEARCH},K_1{NEWLINE2TREEVIEW_F},DRAGDROP'
        proj='N,NAME{NAMESEARCH},DRAGDROP'
        else='N,NAME{NAMESEARCH},DRAGDROP')",
        hide='EMAIL1,EMAIL2,EMAIL3'
        norecords=|<table class="data-grid"><tr><td><%GetLabel('(no favorites)')%></td></tr></table>|)%>
    </div>
</div>
<%Macro("SelectEmailMenu")%>
answered by (193 points)
(suite car j'ai dépassé les 8000 caractères....)

Dans les macros, on appelle 2 fonctions JS EurTreeExpand() et EurTreeCollapse()   (j'ai du les renommer car les fonctions v2012 trainent encore dans efficy.js, et ne sont pas compatibles v10...). Je les ai placé dans un sources custom ...\customs\xxx\partials\SearchArbo.js :



    //---------------------------------------------------------------------------------------------------------------------
    // Gestion des arborescences....
    //---------------------------------------------------------------------------------------------------------------------

    function EurTreeExpand(divTarget, entity, key, treeToExpand, treeToCollapse, cmdmodel) {

        var ftreeToExpand = document.getElementById(treeToExpand);
        if (ftreeToExpand != null) {
            ftreeToExpand.style.display = "none";
        }

        var ftreeToCollapse = document.getElementById(treeToCollapse);
        if (ftreeToCollapse != null) {
            ftreeToCollapse.style.display = "inline";
        }

        var fdivTarget = document.getElementById(divTarget);
        if (fdivTarget != null) {
            fdivTarget.style.display = "inline";
            if (fdivTarget.className.indexOf('jstree') >= 0) {
                return;
            }
        }

        requirejs(['jquery', 'jstree', 'model'], function ($, JsTree, Model) {

            // ex: http://pood:20162/efficy.dll/dialog?_macrofile=MacroConsult&insearch=0&entity=Prod&_macro=TreeChildren&root=126

            //javascript:CreateRelation('1010','Oppo','93','Prod',23)

            // exemple de retours:
            // ,{"id":"node_23","text":"MANUBLOC 500 mm Auget d'alimentation","icon":"i-Prod","a_attr":{"class":"","data-msg":"consult;23;13;"},"state":{} }
            // ,{"id":"node_19","children":true,"text":"MANUBLOC 500 mm Elément de pied","icon":"i-folder","a_attr":{"class":"","data-msg":"consult;19;13;"},"state":{} }

            var url = 'dialog?_macrofile=MacroConsult.txt&_macro=TreeChildren&entity=' + entity + '&root=' + key + '&insearch=0';
            var waction = 'javascript:' + Model('TREEACTION').slice(0, -1).replace(/;/g, "','").replace('(', "('") + "','" + entity + "',";
         
            var setting = {
                  'plugins': ["menuicon"]
                , 'core': {
                    // "multiple": false,
                    "animation": 0,
                    "removeDuplicates": false,
                    "data": {
                        "dataType": "json",
                        "url": function (node) {

                            if (node.id == '#') {
                                // Node root...
                                var url = 'dialog?_macrofile=MacroConsult.txt&_macro=TreeChildren&entity=' + entity + '&root=' + key + '&insearch=0';
                                return url;
                            }
                            // sub-nodes
                            var nodeId = node.id;
                            if (isEmpty(nodeId) || nodeId.indexOf('_') < 0) {
                                return null;
                            }
                            var k = nodeId.split('_')[1];
                            var url = 'dialog?_macrofile=MacroConsult.txt&_macro=TreeChildren&entity=' + entity + '&root=' + k + '&insearch=0';
                            return url;
                        }
                        , "success": function (wdata) {

                            for (var i = 0; i < wdata.length; i++) {
                                var k = wdata[i].id.split('_')[1];

                                wdata[i].a_attr.href = waction + k + ')';
                                delete wdata[i].a_attr['data-msg'];
                            }
                            return wdata;
                        }
                    }
                    , "error": function (err) {
                        //alert('erreur treeview : ' + err)
                        console.error('A jsTree treeview error occured', err);
                    }
                }//core
            }; // setting


            $('#' + divTarget).jstree(setting);

            $('#' + divTarget).on("click", ".jstree-anchor", function (e) {
                // il faut lancer soi-meme la fonction du HREF car le treeJs surcharge les "onclick natifs"
                var whref = $('#' + divTarget).jstree(true).get_node($(this)).a_attr.href;
                if (!isEmpty(whref)) {
                    //alert(whref);
                    eval(whref);
                    return;
                }
            });
            return;
        });// requirejs
    }


    // Pour masquer une arborescence...
    function EurTreeCollapse(divTarget, entity, key, treeToExpand, treeToCollapse) {

        var ftreeToExpand = document.getElementById(treeToExpand);
        if (ftreeToExpand != null) {
            ftreeToExpand.style.display = "inline";
        }

        var ftreeToCollapse = document.getElementById(treeToCollapse);
        if (ftreeToCollapse != null) {
            ftreeToCollapse.style.display = "none";
        }

        var fdivTarget = document.getElementById(divTarget);
        if (fdivTarget != null) {
            fdivTarget.style.display = "none";
            //fdivTarget.innerHTML = "Loading..."; Surtout pas, car données corrompues...
        }
    }



Pour finir, il y a 2 macros à reprendre dans ...\customs\xxx\macros\MacroSearchCustom.txt :


 
    JsonSearchModelCustom {[
        ,"TREEACTION": "<%GetArgument('action')%>"
    ]}

    SearchHeaderCustom {[
        <!-- SearchHeaderCustom  -->
         <script src ="<%GetCustomBase()%>scripts/eureka2014.js" ></script>
         <script src ="<%GetCustomBase()%>partials/SearchArbo.js" ></script>
    ]}
Hello Didier,
Merci bcp., je vais le MEO d'ici peu :-)
@+
Ca se rassure de savoir que je ne suis pas seul à avoir besoin de cette fonctionnalité... Dommage que la R&D ne l'ait pas reconduite...
0 votes

Hello,

First tanks for ths useful post, it helps me good. But i', stuck in the middle. I want to display tree like structure on search like the following screenshot (on Profiles)
enter image description here

But when i want to expand any of the children i got the following error

enter image description here

I suppose is related to that the url to call on expanding the children should be something like dialog?macrofile=MacroConsult.txt&macro=TreeChildren&entity=Prof&root=100&insearch=0
but acyually it's not as you can notice in screenshot.

Please advise and help.

Thank you for your kind cooperation.
Best Regards.

answered by (559 points)
1,165 questions
1,423 answers
1,713 comments
325 users