Skip to content

Instantly share code, notes, and snippets.

@mmarum-sugarcrm
Last active December 14, 2015 15:35
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 mmarum-sugarcrm/fd1173fdcff223351646 to your computer and use it in GitHub Desktop.
Save mmarum-sugarcrm/fd1173fdcff223351646 to your computer and use it in GitHub Desktop.
Custom Button event handling code
<?php
/**
* Copyright 2015 SugarCRM Inc. Licensed by SugarCRM under the Apache 2.0 license.
*/
//Loop through the groupings to find grouping file you want to append to
foreach ($js_groupings as $key => $groupings)
{
foreach ($groupings as $file => $target)
{
//if the target grouping is found
if ($target == 'include/javascript/sugar_grp7.min.js')
{
//append the custom JavaScript file to existing grouping
$js_groupings[$key]['custom/modules/Accounts/myCustomButton.js'] = 'include/javascript/sugar_grp7.min.js';
}
break;
}
}
(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(){
//When a record layout is loaded...
app.router.on('route:record', function(module){
//AND the module is Accounts...
if(module === 'Accounts') {
//AND the 'button:custom_button:click' event occurs on the current Context
app.controller.context.on('button:custom_button:click', function(model){
console.log("Custom Button event triggered on: " + model.get("name"));
//Show an alert on screen
app.alert.show('custom-message-id', {
level: 'success',
messages: 'It worked!',
autoClose: true
});
});
//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