Новые субпанели Sugar выглядят великолепно, но они занимают довольно много места,
без возможности удалить субпанели через студию. Мне пришлось
придумать несколько способов их скрыть.

Примечание. Оригинальные реквизиты принадлежат Робину Ларссону, написавшему оригинал в Sugar Community.

Код Робина, по сути, скрывает поля на основе определенного значения
в записи, мне эта способность особо не нужна, поэтому я
изменил его код на основе вариантов использования, с которыми я сталкивался. .

  1. Связанный тип, то есть скрыть все субпанели, скажем, типа "Учетная запись" или
    Контакт
  2. Имя отношения, поэтому, если вы хотите скрыть связанный модуль с помощью определенной связи
    . Например аккаунты \ _contacts
  3. Если конкретная связь не имеет связанных записей. Скажем, если в учетной записи
    нет контактов, скройте эту подпанель.

Поместите этот код в
custom / modules / ‹YOUR_MODULE› /clients/base/layouts/subpanels/subpanels.js и
просто заполните hide_variables тем, что вы хотите скрыть!

({
},
 /**
 * 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);
 component.show();
 }
 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 = field_collection.link.name;
 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;
 },
 })