Last active
June 30, 2016 23:49
-
-
Save dmulvi/559c192189c9d2d09b93 to your computer and use it in GitHub Desktop.
SugarCRM - Add item to action menu on Record View
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 | |
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); | |
class CustomMODULE_NAMEApi extends SugarApi | |
{ | |
public function registerApiRest() { | |
return array( | |
'CasesLinkedTestsEndpoint' => array( | |
'reqType' => 'POST', | |
'path' => array('MODULE_NAME','?', 'do-custom-stuff'), | |
'pathVars' => array('module', 'record'), | |
'method' => 'doCustomStuff', | |
'shortHelp' => 'Do some custom backend stuff intiated from action menu on frontend', | |
'longHelp' => '', | |
), | |
); | |
} | |
public function doCustomStuff($api, $args) { | |
$record_id = $args['record']; | |
// do some stuff | |
// api handles json_encoding, just return the object | |
return $results; | |
} | |
} |
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
({ | |
extendsFrom: 'RecordView', | |
// if you are extending the record view for a core module that has an existing record.js you must extend that view | |
// extendsFrom: 'ContactsRecordView', | |
initialize: function(options) { | |
this._super('initialize', [options]); | |
// generate client pdfs | |
this.context.on('button:do_custom_stuff:click', this.do_custom_stuff, this); | |
}, | |
do_custom_stuff: function() { | |
var extra_info_obj = { | |
prop_1: 'some info', | |
prop_2: 'some more info', | |
} | |
app.api.call('create', app.api.buildURL('MODULE_NAME/'+this.model.id+'/do-custom-stuff'), | |
{ | |
extra_info: extra_info_obj, | |
}, | |
{ | |
success: function(data) { | |
console.log(data); | |
} | |
}); | |
}, | |
}) |
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 | |
// this is the file located in custom/modules/MODULE_NAME/clients/base/views/record/ | |
$viewdefs['MODULE_NAME'] = | |
array ( | |
'base' => | |
array ( | |
'view' => | |
array ( | |
'record' => | |
array ( | |
'buttons' => | |
array ( | |
0 => | |
array ( | |
'type' => 'button', | |
'name' => 'cancel_button', | |
'label' => 'LBL_CANCEL_BUTTON_LABEL', | |
'css_class' => 'btn-invisible btn-link', | |
'showOn' => 'edit', | |
), | |
1 => | |
array ( | |
'type' => 'rowaction', | |
'event' => 'button:save_button:click', | |
'name' => 'save_button', | |
'label' => 'LBL_SAVE_BUTTON_LABEL', | |
'css_class' => 'btn btn-primary', | |
'showOn' => 'edit', | |
'acl_action' => 'edit', | |
), | |
2 => | |
array ( | |
'type' => 'actiondropdown', | |
'name' => 'main_dropdown', | |
'primary' => true, | |
'showOn' => 'view', | |
'buttons' => | |
array ( | |
0 => | |
array ( | |
'type' => 'rowaction', | |
'event' => 'button:edit_button:click', | |
'name' => 'edit_button', | |
'label' => 'LBL_EDIT_BUTTON_LABEL', | |
'primary' => true, | |
'acl_action' => 'edit', | |
), | |
// THIS IS THE CUSTOM ACTION ITEM | |
1 => // you can get rid of all the numeric indexes to avoid re-typing them if you want | |
array ( | |
'type' => 'rowaction', | |
'event' => 'button:do_custom_stuff:click', // method name to call in record.js | |
'name' => 'do_custom_stuff', // name attribute of your button | |
'label' => 'Do Custom Stuff', | |
'acl_action' => 'edit', | |
), | |
// END CUSTOM ACTION ITEM | |
// REMOVED all the other junk in this file, you should keep it :-) | |
), | |
), | |
), | |
), | |
), | |
), | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment