How to apply condition based role in hbs file ..

Hi Folks 

I have override the phone field and put one image beside phone number..

So

i want like if user has access rights of edit on Lead then icon will display else not visible.

ex.

custom/clients/base/fields/phone/detail.hbs

{{#if value}}
    
    <a class="ellipsis_inline" style="float: left" onclick="sendsms('{{value}}','{{module}}','{{model.id}}');"><img style="cursor:pointer;float:left;margin-right:5px;padding-top:2px;width:16px" src="custom/themes/default/images/sms.png"></a>

     <div class="ellipsis_inline" data-placement="bottom" title="{{value}}">
         {{#if skypeValue}}
             <a href="callto:{{skypeValue}}">
             {{value}}
             </a>
        {{else}}
             {{value}}
        {{/if}}
     </div>
   
{{/if}}

Tevfik Tümer Ajay Kumar sidhu sidhu

  • Hi Mehul,
    You can check the edit access of model in your extended field's java-script controller like

    var editAccess = app.acl.hasAccessToModel('edit', this.model);
    and then on the base of edit access you can pass the flag value in handlebars template.

    Kind Regards,
    Rolustech Support
  • Hi Mehul,

    What Rolustech Support suggested would do the job. But I would prefer to add the same logic in a custom handlebars helper and use it your hbs file. You can pass the current model as a parameter for your helper method.

    Thanks!

  • Thanks Rolustech Support & Shijin Krishna for the reply.

    I have override the controller file phone.js

    add this line in initialize function

    this.msbacl = app.acl.hasAccess('edit','Leads');

    and used this variable in detail.hbs

    {{#if msbacl}}
    <img style="cursor:pointer;float:left;margin-right:5px;padding-top:2px;width:24px" src="custom/themes/default/images/sms.png" onclick="sendsms('{{value}}','{{module}}','{{model.id}}');">
    {{/if}}