Instantly share code, notes, and snippets.
Last active
December 14, 2015 15:35
Custom Button event handling code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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