Skip to content

Instantly share code, notes, and snippets.

@chadhutchins
Created December 13, 2012 15:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save chadhutchins/4277013 to your computer and use it in GitHub Desktop.
Save chadhutchins/4277013 to your computer and use it in GitHub Desktop.
An easy way to add items to the action buttons used throughout the SugarCRM UI.
<?php
class AccountButtons {
function add()
{
// Based on what action we're in, add some buttons!
switch ($GLOBALS['app']->controller->action)
{
case "DetailView": // Add buttons to Detail View
$button_code = <<<EOQ
<script type="text/javascript">
$(document).ready(function(){
var button = $('<li><a href="javascript:void(0)" onclick="alert(\'Hello, world!\')">New Button!</a></li>")');
// Add item to action dropdown on a detail view
$("#detail_header_action_menu").sugarActionMenu('addItem',{item:button});
// Add item to action dropdown for all subpanel records on the detail view
$("#subpanel_list ul.records").each(function(){
var button = $('<li><a href="javascript:void(0)" onclick="alert(\'Hello, world!\')">New Button!</a></li>")');
$(this).sugarActionMenu('addItem',{item:button});
});
});
</script>
EOQ;
echo $button_code;
break;
case "listview": // Add buttons to List View
$button_code = <<<EOQ
<script type="text/javascript">
$(document).ready(function(){
var button = $('<li><a href="javascript:void(0)" onclick="alert(\'Hello, world!\')">New Button!</a></li>")');
// Add item to "select all" dropdown button on list view
$("#selectLinkTop").sugarActionMenu('addItem',{item:button});
$("#selectLinkBottom").sugarActionMenu('addItem',{item:button});
// Add item to the first slot of the "select all" dropdown button on list view
$("#selectLinkTop").sugarActionMenu('addItem',{item:button,index:1});
$("#selectLinkBottom").sugarActionMenu('addItem',{item:button,index:1});
});
</script>
EOQ;
echo $button_code;
break;
}
}
}
$(document).ready(function(){
// The button we're adding to the dropdowns
var button = $('<li><a href="javascript:void(0)" onclick="alert(\'Hello, world!\')">New Button!</a></li>")');
// Add item to "select all" dropdown button on list view
$("#selectLinkTop").sugarActionMenu('addItem',{item:button});
$("#selectLinkBottom").sugarActionMenu('addItem',{item:button});
// Add item to the first slot of the "select all" dropdown button on list view
$("#selectLinkTop").sugarActionMenu('addItem',{item:button,index:1});
$("#selectLinkBottom").sugarActionMenu('addItem',{item:button,index:1});
// Add item to action dropdown for selected items on list view
$("#actionLinkTop").sugarActionMenu('addItem',{item:button});
$("#actionLinkBottom").sugarActionMenu('addItem',{item:button});
// Add item to action dropdown on a detail view
$("#detail_header_action_menu").sugarActionMenu('addItem',{item:button});
// Add item to action dropdown for select items for all subpanels on detail view
$("#subpanel_list ul.SugarActionMenu:not(.records)").each(function(){
// need to recreate button variable for scope issues
var button = $('<li><a href="javascript:void(0)" onclick="alert(\'Hello, world!\')">New Button!</a></li>")');
$(this).sugarActionMenu('addItem',{item:button});
});
// Add item to action dropdown for select items for a specific subpanel on detail view
// (activities subpanel on account detail view)
$("#list_subpanel_activities ul.SugarActionMenu:not(.records)").sugarActionMenu('addItem',{item:button});
// Add item to action dropdown for all subpanel records on the detail view
$("#subpanel_list ul.records").each(function(){
var button = $('<li><a href="javascript:void(0)" onclick="alert(\'Hello, world!\')">New Button!</a></li>")');
$(this).sugarActionMenu('addItem',{item:button});
});
// Add item to action dropdown for all subpanel records on a specific detail view
// (activities subpanel records)
$("#list_subpanel_activities ul.records").each(function(){
var button = $('<li><a href="javascript:void(0)" onclick="alert(\'Hello, world!\')">New Button!</a></li>")');
$(this).sugarActionMenu('addItem',{item:button});
});
// Add item to action dropdown for all subpanel records on the detail view (lookup by id)
// may have issues if record appears in mulitple subpanels on same page
$("ul#38455ab8-bd8f-6ecb-213c-50c9eb8eb3d5").sugarActionMenu('addItem',{item:button});
});
$('#selector').sugarActionMenu('addItem',{
item: $('<li><a href="#">New Item!</a></li>'), // a jquery element to add,
index: 1 // (optional) set the exact order the new option will show in the list (1 being the first item)
});
<?php
$hook_version = 1;
$hook_array = array();
$hook_array['after_ui_frame'] = array();
$hook_array['after_ui_frame'][] = Array(1, 'Accounts InsideView frame', 'modules/Connectors/connectors/sources/ext/rest/insideview/InsideViewLogicHook.php','InsideViewLogicHook', 'showFrame');
// Add the new hook
$hook_array['after_ui_frame'][] = Array(2, 'Add Buttons to Account Module Views', 'custom/modules/Accounts/AccountButtons.php','AccountButtons', 'add');
@francescor
Copy link

there is a security issue on this code, have a look at salesagility/SuiteCRM#8752

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment