Shane Dowling : SugarCRM 7 — Hiding subpanels based on specific criteria

The new Sugar subpanels look great but they do take up quite a lot space, without any ability to remove Subpanels via studio I've had to come up with a few ways to hide them.

Note: Original Props go to Robin Larsson who wrote the original on the Sugar Community.

What Robin's code does is essentially hide fields based on a specific value within a record, I didn't really need that ability much so I've altered his code based on use cases I've come across.

  1. The related type, meaning hide all subpanels of say type Account or Contact
  2. The relationship name, so if you want to hide a related module by a specific relationship. For example accounts_contacts
  3. If a specific relationship has no related records. So say if an account has no contacts, hide that subpanel.

Place this code in custom/modules//clients/base/layouts/subpanels/subpanels.js and simply populate the hide_variables with whatever you wish to hide! ```javascript ({

}, /* * Show the subpanel for the given linkName and hide all others * @param {String} linkName name of subpanel link / var self = this, //this.layout is the filter layout which subpanels is child of; we //use it here as it has a last_state key in its meta cacheKey = app.user.lastState.key('subpanels-last', this.layout);

// wait for the model to load self.model.on("change", function () {

if (linkName) { app.user.lastState.set(cacheKey, linkName); }

_.each(self._components, function (component) { var hide_subpanel = self._checkIfHideSubpanel(component.module.toLowerCase(), component.collection);

var link = component.context.get('link'); if (!hide_subpanel && ( !linkName || linkName === link )) { component.context.set("hidden", false);; } else { component.context.set("hidden", true); component.hide(); } }); }); },

/* * Check if the subpanel is on the hiding list and if the watched field has a specific value. * @param {Boolean} subpanel name of the module for the subpanel / var relationship =; var self = this; var hide_subpanel = false; if (( jQuery.inArray(type, self.hide_subpanel_by_type) !== -1 )) { hide_subpanel = true; } if (( jQuery.inArray(relationship, self.hide_subpanel_by_empty) !== -1 ) && (field_collection.models.length === 0)) { hide_subpanel = true; } if (( jQuery.inArray(relationship, self.hide_subpanel_by_relationship) !== -1 )) { hide_subpanel = true; }

return hide_subpanel; }, }) ```