SugarClub
SugarClub
  • User
  • Site
  • Search
  • User
SugarClub
SugarClub
  • User
  • Site
  • Search
  • User
DevClub
DevClub
Dev Tutorials Manipulate Modules from Sidebar Nav
  • Dev Blog
  • Answers & Best Practices
  • Developer On-boarding
  • Dev Tutorials
  • Developer Events
  • Event Recaps
  • Members
  • Developer Suggestions
  • Sub-Groups
  • More
  • Cancel
  • New
Click here to join "DevClub" to engage in the conversation with this group and curate your SugarClub experience.
  • +On-Boarding Framework
  • +Customization Guides
  • -UI Redesign Technical Guide
    • +New Component Structure
    • +Component Mapping
    • -Codebase Refactor by Example
      • Add/Remove Profile Action Links
      • Manipulate Modules from Sidebar Nav
      • Moving Footer content to Sidebar Nav
      • Pinned Modules Override
    • Expected Behavior
    • How to identify customizations to Refactor
    • Troubleshooting
  • Did you know? Copying related records is a breeze!
  • How to write code for SugarCloud webinar Q&A
  • HOW TO: enforce ACL on Tags
  • Programatically manage Dropdown List
  • Remove custom fields created via package installation
  • Sugar Developer Tools
  • Tutorial:  How to register custom platforms in Sugar instances via Platform extension
  • Adding a google reCAPTCHA in a Web-to-Lead form
  • Sugar Developer Blog Style Guide

Manipulate Modules from Sidebar Nav

A common use case for creating a custom module-list layout is to alter the list of modules that appear across the top Mega Menu and More Modules layouts. This can still be accomplished with the sidebar-nav layout, but as you may have guessed, your customization will need to be moved to a different layout. By default, the list of modules in sidebar is built in the sidebar-nav-item-group-modules layout.

Example: Hide Contacts Module for Non-Admin Users

If you had a previous custom layout to hide the Contacts module for non-admin users, it may have been similar to this:

./custom/clients/base/layouts/module-list/module-list.js

({
    extendsFrom: 'ModuleListLayout',
    
    initialize: function(options) {
        this._super('initialize', [options])
    },

    _addDefaultMenus: function() {
        var moduleList = app.metadata.getModuleNames({filter: 'display_tab', access: 'read'});
        
        if (app.user.get('type') !== 'admin'){
            moduleList = _.filter(moduleList, m => { if(m !== 'Contacts') return m });
        }

        _.each(moduleList, function(module) {
            this._addMenu(module, true);
        }, this);
    },
})

As mentioned, these changes are now home in a new layout: ./clients/base/layouts/sidebar-nav-item-group-modules. Using a similar pattern as above, we can hide this module in the sidebar-nav layout. 

({
    extendsFrom: 'SidebarNavItemGroupModulesLayout',

    initialize: function(options) {
        this._super('initialize', [options])
    },

    _getDefaultModuleList: function() {
        let moduleList = app.metadata.getModuleNames({filter: 'display_tab', access: 'read'});

        if (app.user.get('type') === 'admin'){
            moduleList = _.filter(moduleList, m => { if(m !== 'Contacts') return m });
        }

        return _.without(moduleList, 'Home');
    },
})

Once these changes are added, you can run a Quick Repair and Rebuild and the list of modules will be updated. 

Note: You may need to refresh the page to see the profile menu items removed.

  • Share
  • History
  • More
  • Cancel
Anonymous
Related
Recommended