0 votes

Hello,

We would like to customise Efficy in order to have a DetailMenu, with a condition in it.

The macro is the following one :

DetailMenu..Docu {[<%GetPopupMenu(id="detail-menu", class="has-icons small", ulargs='data-channel="detailmenu"', count="6",
text1="Edit #DETAIL", image1="i-edit",
message1="edit;{dropdownKey};#DETAIL",
text2="Delete #DETAIL", image2="i-delete",
message2="deleteItem;#DETAIL;{dropdownKey}",
text3="Edit Relation", image3="i-link", onlinehelp3="e110_linkitems",
message3=`%%IfCategories(then="editRelation;#ENTITY;#KEY;#DETAIL;{dropdownKey}")`,
text4="Duplicate #DETAIL", image4="i-Dupl", onlinehelp4="e110_duplicateitems",
message4="duplicate;#DETAIL;{dropdownKey}",
text5="Mark as Handled", image5="i-done",
message5="markDocumentHandled;{dropdownKey};0",
text6="Convert to Opportunity", image6="i-Oppo", rights6="Oppo", onlinehelp6="e110_convertitems2salesopp",
message6="convertToEntity;Oppo;#DETAIL;{dropdownKey};Comp\\;Cont\\;Proj\\;Prod;true;NAME"
)%>]}

What I would like to do is detect the reference or a field value of the document to propose other options.
But the dev on this cannot make it work.

He tried this, but it does not seems to work "efficiently" (it always show the option, whatever the reference)

DetailMenu..Docu {[
<%GetPopupMenu(
id="detail-menu", class="has-icons small", ulargs='data-channel="detailmenu"', count="7",
text1="Edit #DETAIL", image1="i-edit",
message1="edit;{dropdownKey};#DETAIL",
text2="Delete #DETAIL", image2="i-delete",
message2="deleteItem;#DETAIL;{dropdownKey}",
text3="Edit Relation", image3="i-link", onlinehelp3="e110_linkitems",
message3=`%%IfCategories(then="editRelation;#ENTITY;#KEY;#DETAIL;{dropdownKey}")`,
text4="Duplicate #DETAIL", image4="i-Dupl", onlinehelp4="e110_duplicateitems",
message4="duplicate;#DETAIL;{dropdownKey}",
text5="Mark as Handled", image5="i-done",
message5="markDocumentHandled;{dropdownKey};0",
text6="Convert to Opportunity", image6="i-Oppo", rights6="Oppo", onlinehelp6="e110_convertitems2salesopp",
message6="convertToEntity;Oppo;#DETAIL;{dropdownKey};Comp\\;Cont\\;Proj\\;Prod;true;NAME",
`%%OnField("MakeNCG", query="select CASE WHEN /*doc.REFERENCE LIKE 'DRAFT-%' OR */doc.REFERENCE LIKE 'NC-%' OR doc.id_kleos IS NOT NULL OR doc.F_INVOICE_STATUS < 4 THEN 0 ELSE 1 END AS MakeNCG from DOCUMENTS doc where doc.K_DOCUMENT = {dropdownKey}", value=1, then="text7=`Make NC Globalazzz`, image7=`i-edit`, message7=`NCGlobal;{dropdownKey}`", else="text7=`Make NC non`, image7=`i-edit`, message7=`NCGlobal;{dropdownKey}`")`
)%>]}

I suppose there is a way to :

  • Make this "clean"
  • Avoid a SQL query

Regards,

Loïc

asked in Efficy/ Client side by (460 points)

2 Answers

0 votes
Best answer

Hi Loic,

If you look at the HTML code of the icon for the menu you will see that the menu display is using a specific HTML element id called detail-menu.

<span class="dropdown no-pip i-menu small" data-dropdown="detail-menu" data-args="16"></span>

So the solution I propose is to call a server script that will decide which id to use and to create 2 different menu for that.

First I will override the standard GridColumn definition in order to to call a ServerJs which will return the Id of the menu to use in the dropdown, we only need the key of the document to do our choice.
Here you will see that I passed the needed fields value that will be used to do our choice. If you cannot access them, you will have to add them into the SYSQUERIES of all KDETAIL = 31 (document)
By doing this, we save a lot of execution time by avoiding to execute a SQL query in the ServerJs.

td.MENU.Docu {[<td class="menu icon-cell hide-for-print">
<span class="dropdown no-pip i-menu small" 
data-dropdown="<%RunScript("getDocuMenuId", 
kDocument=<#G=$KEY$>, 
Reference="<#F=REFERENCE;context=TAG>",
IdKloes="<#F=id_kleos;context=TAG>")%>", 
InvoiceStatus="<#F=F_INVOICE_STATUS;context=TAG>")%>" 
data-args="<#G=$KEY$>"></span>
</td>]}

Then I will create the different menu and Load the ServerJS in MacroConsultCustom.txt
Here I have created 2 menus one with id "detail-menu-std" and another with id "detail-menu-ngc"

DetailGrid..Docu {[
<%LoadServerJs("documentNGCMenu")%><!-- CUSTOM -->
<%GetDetailGrid(columndefs="GridColumns", entity="$DETAIL$", columns="%%Macro('DetailGridColumns')", sum="%%Macro('DetailGridSum')")%>
<%Macro("DetailMenu")%>
]}

DetailMenu..Docu {[
<%GetPopupMenu(id="detail-menu-std", class="has-icons small", ulargs='data-channel="detailmenu"', count="7",
text1="Edit #DETAIL", image1="i-edit",
message1="edit;{dropdownKey};#DETAIL",
text2="Delete #DETAIL", image2="i-delete",
message2="deleteItem;#DETAIL;{dropdownKey}",
text3="Edit Relation", image3="i-link", onlinehelp3="e110_linkitems",
message3=`%%IfCategories(then="editRelation;#ENTITY;#KEY;#DETAIL;{dropdownKey}")`,
text4="Duplicate #DETAIL", image4="i-Dupl", onlinehelp4="e110_duplicateitems",
message4="duplicate;#DETAIL;{dropdownKey}",
text5="Mark as Handled", image5="i-done",
message5="markDocumentHandled;{dropdownKey};0",
text6="Convert to Opportunity", image6="i-Oppo", rights6="Oppo", onlinehelp6="e110_convertitems2salesopp",
message6="convertToEntity;Oppo;#DETAIL;{dropdownKey};Comp\\;Cont\\;Proj\\;Prod;true;NAME"

,text7="Make NC non", image7="i-edit", message7="NCGlobal;{dropdownKey}"
)%>

<%GetPopupMenu(id="detail-menu-ngc", class="has-icons small", ulargs='data-channel="detailmenu"', count="7",
text1="Edit #DETAIL", image1="i-edit",
message1="edit;{dropdownKey};#DETAIL",
text2="Delete #DETAIL", image2="i-delete",
message2="deleteItem;#DETAIL;{dropdownKey}",
text3="Edit Relation", image3="i-link", onlinehelp3="e110_linkitems",
message3=`%%IfCategories(then="editRelation;#ENTITY;#KEY;#DETAIL;{dropdownKey}")`,
text4="Duplicate #DETAIL", image4="i-Dupl", onlinehelp4="e110_duplicateitems",
message4="duplicate;#DETAIL;{dropdownKey}",
text5="Mark as Handled", image5="i-done",
message5="markDocumentHandled;{dropdownKey};0",
text6="Convert to Opportunity", image6="i-Oppo", rights6="Oppo", onlinehelp6="e110_convertitems2salesopp",
message6="convertToEntity;Oppo;#DETAIL;{dropdownKey};Comp\\;Cont\\;Proj\\;Prod;true;NAME"

,text7="Make NC Globalazzz", image7="i-edit", message7="NCGlobal;{dropdownKey}"
)%>
]}

Finally I will create the ServerJs that I called previously : documentNGCMenu.js
This serverJS will return only a string containing the id of the menu to use for this document

function getDocuMenuId() {
var menuId = 'detail-menu-std';
var kDocument = Arguments.values("kDocument");
var reference = Arguments.values("Reference");
var idKleos = Arguments.values("IdKloes");
var invoiceStatus = Arguments.values("InvoiceStatus");

if (kDocument <= 0 || reference == '') return menuId;

if (reference.indexOf('NC-') >= 0 || idKleos != '' || invoiceStatus < 4) {
menuId = "detail-menu-ngc";
}
return menuId;
}
answered by (1.8k points)
selected by
it is approximately what we did. But your implementation is cleaner than ours :)
Thanks a lot !
0 votes

This architecture will never work, because it is impossible to combine a server side query with a client side parameter {dropdownKey}.

The context menu is generated once per page and the visibility is toggled when clicking on the menu item. At click, {dropdownKey} is populated with the key of the currently selected record.

What you need is a context menu where the content is loaded with an ajax request to the server, getting the record information of the current record. We have used it for our largest customer, but the code is not isolated.

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