Skip to content

Instantly share code, notes, and snippets.

@cmourizard
Created January 7, 2014 12:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmourizard/8298641 to your computer and use it in GitHub Desktop.
Save cmourizard/8298641 to your computer and use it in GitHub Desktop.
Managing custom buttons (render and action) with custom logic on Sugar 7
<?php
$viewdefs['Accounts'] =
array (
'base' =>
array (
'view' =>
array (
'record' =>
array (
'buttons' =>
....
array (
'type' => 'actiondropdown',
'name' => 'main_dropdown',
'primary' => true,
'showOn' => 'view',
'buttons' =>
array (
....
array (
'type' => 'myaction',
'name' => 'myaction',
'label' => 'LBL_MYACTION_LABEL_1',
'action' => 'changeAccountType',
'acl_action' => 'edit',
),
array (
'type' => 'myaction',
'name' => 'myaction',
'label' => 'LBL_MYACTION_LABEL_2',
'action' => 'changeName',
'acl_action' => 'edit',
),
({
extendsFrom: 'RowactionField',
initialize: function(options) {
app.view.invokeParent(this, {type: 'field', name: 'rowaction', method: 'initialize', args: [options]});
this.type = 'rowaction';
},
/**
* {@inheritDoc}
* @private
*/
_render: function() {
switch (this.def.action) {
case 'changeAccountType':
if (this.model.get('account_type') == 'Customer') {
this.hide();
} else {
this._super('_render');
}
break;
case 'changeName':
default:
this._super('_render');
break;
}
},
/**
* Triggers event provided at this.def.event on the view's context object by default.
* Can be configured to trigger events on 'view' itself or the view's 'layout'.
* @param evt
*/
rowActionSelect: function() {
if(this.isDisabled()){
return;
}
switch (this.def.action) {
case 'changeAccountType':
this.model.set('account_type', 'Customer');
this.model.save();
break;
case 'changeName':
var dateModified = new Date();
this.model.set('name', 'New Name ' + app.date.format(dateModified, app.user.getPreference('datepref') + ' ' + app.user.getPreference('timepref')));
this.model.save();
break;
default:
break;
}
return;
},
bindDataChange: function() {
if (this.model) {
this.model.on('change', this.render, this);
}
}
})
Managing custom buttons (render and action) with custom logic on Sugar 7
* Step 1: Add button to the metadata
* Step 2: Define a new field which contains:
* Rendering logic in method _render
* Action logic in method rowActionSelect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment