Skip to content

Instantly share code, notes, and snippets.

@cAstraea
Created February 19, 2016 16:23
Show Gist options
  • Save cAstraea/af6519e1f2ebb1e910e3 to your computer and use it in GitHub Desktop.
Save cAstraea/af6519e1f2ebb1e910e3 to your computer and use it in GitHub Desktop.
Sidebar toggle with button override on Accounts record view using localstorage
//add this with jsgrouping
(function(app){
/**
* Copyright 2015 SugarCRM Inc. Licensed by SugarCRM under the Apache 2.0 license.
*/
//Run callback when Sidecar metadata is fully initialized
app.events.on('app:sync:complete', function(){
// localStorage.setItem('prod:SugarCRM:1:last-state:Accounts:default:hide', '1');
//When a record layout is loaded...
app.router.on('route:record', function(module){
//hide the sidepanel by default
//AND the 'button:sidebar_button:click' event occurs on the current Context
app.controller.context.on('button:sidebar_button:click', function(model){
// console.log(module);
if (localStorage.getItem('prod:SugarCRM:1:last-state:'+module+':default:hide') == '1')
{
localStorage.setItem('prod:SugarCRM:1:last-state:'+module+':default:hide','0');
//
}
else if((localStorage.getItem('prod:SugarCRM:1:last-state:'+module+':default:hide') === null) || (localStorage.getItem('prod:SugarCRM:1:last-state:'+module+':default:hide') == '0') || (typeof localStorage.getItem('prod:SugarCRM:1:last-state:'+module+':default:hide') === 'undefined'))
{
localStorage.setItem('prod:SugarCRM:1:last-state:'+module+':default:hide', '1');
}
var sidebarGet = localStorage.getItem('prod:SugarCRM:1:last-state:'+module+':default:hide');
//Show an alert on screen
console.log(sidebarGet);
app.alert.show('sidebar_confirmation', {
level: 'success',
messages: 'Changed sidebar state to '+sidebarGet,
autoClose: true
});
// app.router.navigate(model.module + '/' + model.id, {trigger: true});
app.router.refresh();
// location.reload();
});
//No off() needed. See note later in blog post.
});
});
})(SUGAR.App);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment