Skip to content

Instantly share code, notes, and snippets.

@elchele
Created May 15, 2015 18:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elchele/a7aef72e0f9a3ec54958 to your computer and use it in GitHub Desktop.
Save elchele/a7aef72e0f9a3ec54958 to your computer and use it in GitHub Desktop.
Customization for adding "alias" NavBar links to Sugar 7
({
/* File: ./custom/clients/base/layouts/module-list/module-list.js */
extendsFrom: 'ModuleListLayout',
_addDefaultMenus: function() {
var moduleList = app.metadata.getModuleNames({filter: 'display_tab', access: 'read'});
moduleList.push('Custom1');
_.each(moduleList, function(module) {
this._addMenu(module, true);
}, this);
},
_addMenu: function(module, sticky) {
var menu = {};
var filter = 'favorites';
var alias = false;
switch(module) {
case 'Custom1':
filter = 'all_records';
alias = true;
break;
}
var def = {
view: {
filter: filter,
alias: alias,
name: 'module-menu',
sticky: sticky,
short: false
}
};
menu.long = this.createComponentFromDef(def, null, module);
this.addComponent(menu.long, def);
if (!sticky) {
return menu;
}
def = {
view: {
filter: filter,
alias: alias,
name: 'module-menu',
short: true
}
};
menu.short = this.createComponentFromDef(def, null, module);
this.addComponent(menu.short, def);
return menu;
},
})
{{!--
/*
* Your installation or use of this SugarCRM file is subject to the applicable
* terms available at
* http://support.sugarcrm.com/06_Customer_Center/10_Master_Subscription_Agreements/.
* If you do not agree to all of the applicable terms or do not have the
* authority to bind the entity as an authorized representative, then do not
* install or use this SugarCRM file.
*
* Copyright (C) SugarCRM Inc. All rights reserved.
*/
--}}
{{#if meta.short}}
<a class="module-list-link" href="#{{buildRoute module=module}}" data-route="#{{buildRoute module=module}}" track="click:{{module}}" tabindex="-1"><span class="label label-module label-module-mini label-{{module}}" {{#if meta.alias}} title="{{module}} {{else}} title="{{str 'LBL_MODULE_NAME' module}} {{/if}}">{{moduleIconLabel module}}</span>{{#if meta.alias}} {{module}} {{else}} {{str 'LBL_MODULE_NAME' module}} {{/if}}</a>
{{else}}
<a class="btn btn-invisible btn-link module-name" href="#{{buildRoute module=module}}" data-route="#{{buildRoute module=module}}" track="click:{{module}}" aria-label="{{str 'LBL_MODULE_NAME' module}}">{{str 'LBL_MODULE_NAME' module}}</a>
{{#if actions}}
<button type="button" title="{{str 'LBL_LINK_MORE' module}}" data-toggle="dropdown" class="btn btn-invisible dropdown-toggle" track="click:{{name}}-dropdown" aria-label="{{str 'LBL_MODULE_NAME' module}} - {{str 'LBL_LINK_MORE' module}}"><i class="icon-caret-down"></i></button>
<div class="dropdown-menu scroll">
<ul role="menu">
{{#each actions}}
<li><a class="ellipsis_inline" tabindex="-1"
data-navbar-menu-item="{{label}}"
{{#if event}}
href="javascript:void(0);"
data-event="{{event}}"
track="click:{{event}}"
{{else}}
href="{{route}}"
data-route="{{route}}"
track="click:{{route}}"
{{/if}}>{{#if icon}}<i class="{{icon}}"></i>{{/if}}{{str label ../module}}</a>
</li>
{{/each}}
<li class="divider" data-container="recently-viewed"></li>
<li class="divider" data-container="favorites"></li>
</ul>
</div>
{{/if}}
{{/if}}
({
/* File: ./custom/clients/base/views/module-menu/module-menu.js */
extendsFrom: 'ModuleMenuView',
handleRouteEvent: function(event) {
var currentRoute,
$currentTarget = this.$(event.currentTarget),
route = $currentTarget.data('route');
switch (route) {
case '#Custom1':
route = '#Leads';
app.user.lastState.set('Leads:filter:last-Leads-records', this.meta.filter);
break;
}
event.preventDefault();
if ((!_.isUndefined(event.button) && event.button !== 0) || event.ctrlKey || event.metaKey) {
event.stopPropagation();
window.open(route, '_blank');
return false;
}
currentRoute = '#' + Backbone.history.getFragment();
(currentRoute === route) ? app.router.refresh() : app.router.navigate(route, {trigger: true});
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment