Created
January 7, 2014 12:32
-
-
Save cmourizard/8298641 to your computer and use it in GitHub Desktop.
Managing custom buttons (render and action) with custom logic on Sugar 7
This file contains hidden or 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 | |
$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', | |
), |
This file contains hidden or 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: '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); | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment