Ocultar campo en editviewsdef en función de un valor del CurrentUser

Buenas.

Tengo un listener en un js

document.addEventListener( 'DOMContentLoaded', function() {
   showHidePanelContacts();
});

Como podría pasarle un valor del CurrentUser para ocultar un campo de edirviewdet?

O como se haría sin el listener. El listener lo tengo para ocultar ciertos paneles en el detalviewdefs en función de ciertos valores de campos.

Un saludo.

  • Óscar del Río

    Cómo y dónde está escribiendo su código js.

    ¿Puede compartir su código js y explicar su requisito en detalle.

    Atentamente

    S Ramana Raju

  • Hi Oscar 

                Do you want to show or hide contacts sub panel based on current user or what? thoda english mein samjovo bhai...

    Regards

    Sidhu

  • Community  mein answer karke kuch tho seekhna chahtayuin mein..

    Community mein answer karke kuch tho seekhna chahtayuin mein..

    Agar mujhe samajme na aaya tho kya karron 

    Agar mujhe samajme na aaya tho kya karron 

    Sirf All Out lagake machar baga saktha huin mein...

    Regards

    Sidhu

  • Hi all

    Sorry about this. Our idea is to have a field inside the Contacts module called "Personal Information" that only users working in a specific department will be able to check. I mean users with a given role, which in the users' department field (field you can find in the Admin Users module) have a value set to "Value1" they will be able to see the field, and users which do not have this value in the "$user->department" field can not.

    My first idea was to use the global variable GLOBAL $current_user and accesing to the value of the department of the current user that is logged

    $value= $current_user->department

    Then check if "$value=='value1' the application will show the field, and if not will hide it.

    The thin is that to show/hide fields or pannels in the DetailView I am using a JS code that is called "on page load" but most of the times I use current values of fields of the Contact... but how can I use the current user's department value to show hide a field?. I mean $current_user is a global variable that can be used in PHP, but my code to show/hide pannels is a JS file.... how can I pass this argument to the JS file??

    Other option would be using the role of the current user, but would be the same, wouldnt it?

    My JS code to hide fields or panels inside the Contacts DetailView is this one

    document.addEventListener( 'DOMContentLoaded', function() {
       showHidePanelContacts();
    });

    function showHidePanelContacts() {
          /*document.getElementById('LBL_EDITVIEW_PANEL3').style.display = 'none';
            document.getElementById('detailpanel_4').style.display = 'none';
            $('detailpanel_4').closest('a').hide(); */

        switch (document.getElementById('lead_source').value) {
        case 'Miembro':
            //Mostramos Panel Miembro    
            document.getElementById('detailpanel_2').style.display = 'block';
            //document.getElementById('otras_observaciones_c').style.visibility = 'hidden';
            //Ocultamos Panel Amigo
            document.getElementById('detailpanel_3').style.visibility = 'none';
            //Ocultamos Panel Capellan
            document.getElementById('detailpanel_4').style.display = 'none';
            //Ocultamos Panel Voluntario
            document.getElementById('detailpanel_5').style.display = 'none';
            //Ocultamos Panel Beneficiario
            document.getElementById('detailpanel_6').style.display = 'none';
            break;
        case 'Amigo':
            //Ocultamos Panel Miembro    
            document.getElementById('detailpanel_2').style.display = 'none';
            //document.getElementById('otras_observaciones_c').style.visibility = 'visible';
            //Mostramos Panel Amigo
            document.getElementById('detailpanel_3').style.display = 'block';
            //Ocultamos Panel Capellan
            document.getElementById('detailpanel_4').style.display = 'none';
            //Ocultamos Panel Voluntario
            document.getElementById('detailpanel_5').style.display = 'none';
            //Ocultamos Panel Beneficiario
            document.getElementById('detailpanel_6').style.display = 'none';
            break;
        case 'Capellan':
            //Ocultamos Panel Miembro
            document.getElementById('detailpanel_2').style.display = 'none';
            //Ocultamos Panel Amigo
            document.getElementById('detailpanel_3').style.display = 'none';
            //Mostramos Panel Capellan
            document.getElementById('detailpanel_4').style.display = 'block';
            //Ocultamos Panel Voluntario
            document.getElementById('detailpanel_5').style.display = 'none';
            //Ocultamos Panel Beneficiario
            document.getElementById('detailpanel_6').style.display = 'none';
            break;
        case 'Voluntario':
            //Ocultamos Panel Miembro
            document.getElementById('detailpanel_2').style.display = 'none';
            //Ocultamos Panel Amigo
            document.getElementById('detailpanel_3').style.display = 'none';
            //Ocultamos Panel Capellan
            document.getElementById('detailpanel_4').style.display = 'none';
            //Mostramos Panel Voluntario
            document.getElementById('detailpanel_5').style.display = 'block';
            //Ocultamos Panel Beneficiario
            document.getElementById('detailpanel_6').style.display = 'none';
            break;
        case 'Beneficiario':
            //Ocultamos Panel Miembro
            document.getElementById('detailpanel_2').style.display = 'none'
            //Ocultamos Panel Amigo
            document.getElementById('detailpanel_3').style.display = 'none';
            //Ocultamos Panel Capellan
            document.getElementById('detailpanel_4').style.display = 'none';
            //Ocultamos Panel Voluntario
            document.getElementById('detailpanel_5').style.display = 'none';
            //Mostramos Panel Beneficiario
            document.getElementById('detailpanel_6').style.display = 'block';
            break;

        default:
            //Ocultamos Panel Miembro
            document.getElementById('detailpanel_2').style.display = 'none';
            //Ocultamos Panel Amigo
            document.getElementById('detailpanel_3').style.display = 'none';
            //Ocultamos Panel Capellan
            document.getElementById('detailpanel_4').style.display = 'none';
            //Ocultamos Panel Voluntario
            document.getElementById('detailpanel_5').style.display = 'none';
            //Ocultamos Panel Beneficiario
            document.getElementById('detailpanel_6').style.display = 'none';
            break;
        }

        if (document.getElementById('lead_source').value == 'Miembro') {
                if (document.getElementById('es_amigo_c').checked == true )
                    //Mostramos Panel Amigo
                    console.log(document.getElementById('detailpanel_3').style.display = 'block');
                else
                    //Ocultamos Panel Amigo
                    document.getElementById('detailpanel_3').style.display = 'none';
            }
    }

  • Kabhi Kabhi Good Night Active+ lagake bhi try kar liya karo.

    Jab kam machar ho to Normal mode,

    Jab jyada machar ho to Active mode.

    Push karo, khush raho.

  • Hola Óscar del Río,

    Te contesto en inglés, así el resto de la comunidad puede entender mejor la respuesta.

    I would recommend you doing this through an after_ui_frame LogicHook triggered on the module you want to make the customization.

    The code of the LogicHook would be like the following:

    class LoadUserInEditView {

       function loadUserRolesInEditView( $bean, $event, $arguments ) {

           if( !$bean ) {
             return;
           }

           global $current_user;

           $department = $current_user->department;

           $departmentHtml = '<input type="hidden" style="display: none" id="user_department">' . $department . '</input>';

           echo $departmentHtml;

       }

    }

    This would set in the DOM a hidden input element which will store the department of the current user.

    Then in your javascript:

    document.addEventListener( 'DOMContentLoaded', function() {
       showHidePanelContacts();

       var department = $('#user_department').html();

       if( department !== 'my_desired_department' ) {
          $('#field_to_hide').hide();
       }
      
    });

    Espero que te sirva. Cualquier duda me dices!

    Saludos/Regards,

    David.

  • Why not use field level permissions based on Roles?

    https://support.sugarcrm.com/Knowledge_Base/Users_Teams_Roles/Making_a_Field_Read-Only/ 

    Set field level permission to None for those Roles that should not see it.

    HTH

    FrancescaS