array(
* 'form' => array('buttons'=>array('SAVE','CANCEL')),
* ...
*
* The supported types are: CANCEL, DELETE, DUPLICATE, EDIT, FIND_DUPLICATES and SAVE.
* If you need to create a custom button or the button is very specific to the module and not
* provided as a supported type, then you'll need to use custom code. Instead of providing the
* key, you'll have to create an array with a 'customCode' key.
*
* ...
* $viewdefs['Accounts']['EditView'] = array(
* 'templateMeta' => array(
* 'form' => array('buttons'=>array('SAVE',
* array('customCode'=>'')
* )),
* ...
*
* Please note that you should ensure that your customCode is generic in the sense that there are no
* instance specific values created because it will cause failures should other instances also use
* the button's code. The key to remember is that we are rendering a generic template for each
* module's view and, as such, the meta-data definition should also be generic enough to support
* variable instance values for the module.
*
* In our examples, the resulting metatdata definition is passed to EditView's header.tpl
* file and the Smarty plugin (this file) is invoked as follows:
* {{sugar_button module='{{$module}}' id='{{$form.buttons[$id]}}' view='EditView'}}
*
*
* @author Collin Lee {clee@sugarcrm.com}
*/
/**
* smarty_function_sugar_button
* This is the constructor for the Smarty plugin.
*
* @param $params The runtime Smarty key/value arguments
* @param $smarty The reference to the Smarty object used in this invocation
*/
function smarty_function_sugar_button($params, &$smarty)
{
if(empty($params['module'])) {
$smarty->trigger_error("sugar_button: missing required param (module)");
} else if(empty($params['id'])) {
$smarty->trigger_error("sugar_button: missing required param (id)");
} else if(empty($params['view'])) {
$smarty->trigger_error("sugar_button: missing required param (view)");
}
$type = $params['id'];
if(!is_array($type)) {
$module = $params['module'];
$view = $params['view'];
switch(strtoupper($type)) {
case "CANCEL":
$cancelButton = '{if !empty($smarty.request.return_action) && ($smarty.request.return_action == "DetailView" && !empty($fields.id.value))}';
$cancelButton .= ' ';
$cancelButton .= '{elseif !empty($smarty.request.return_action) && ($smarty.request.return_action == "DetailView" && !empty($smarty.request.return_id))}';
$cancelButton .= ' ';
$cancelButton .= '{else}';
$cancelButton .= ' ';
$cancelButton .= '{/if}';
return $cancelButton;
break;
case "DELETE":
return '{if $bean->aclAccess("delete")}{/if} ';
break;
case "DUPLICATE":
return '{if $bean->aclAccess("edit")}{/if} ';
break;
case "EDIT";
return '{if $bean->aclAccess("edit")}{/if} ';
break;
case "FIND_DUPLICATES":
return '{if $bean->aclAccess("edit")}{/if} ';
break;
case "SAVE":
$view = ($_REQUEST['action'] == 'EditView') ? 'EditView' : (($view == 'EditView') ? 'EditView' : $view);
return '{if $bean->aclAccess("save")}{/if} ';
break;
case "SUBPANELSAVE":
$view = $view == 'QuickCreate' ? "form_SubpanelQuickCreate_{$module}" : $view;
return '{if $bean->aclAccess("save")}{/if} ';
case "SUBPANELCANCEL":
return ' ';
case "SUBPANELFULLFORM":
$html = ' ';
$html .= '';
return $html;
case "DCMENUCANCEL":
return ' ';
case "DCMENUSAVE":
$view = $view == 'QuickCreate' ? "form_DCQuickCreate_{$module}" : $view;
return '{if $bean->aclAccess("save")}{/if} ';
case "DCMENUFULLFORM":
$html = ' ';
$html .= '';
return $html;
case "AUDIT":
$popup_request_data = array(
'call_back_function' => 'set_return',
'form_name' => 'EditView',
'field_to_name_array' => array(),
);
$json = getJSONobj();
require_once('include/SugarFields/Parsers/MetaParser.php');
$encoded_popup_request_data = MetaParser::parseDelimiters($json->encode($popup_request_data));
$audit_link = '';
$view = '{if $bean->aclAccess("detail")}{if !empty($fields.id.value) && $isAuditEnabled}'.$audit_link.'{/if}{/if}';
return $view;
} //switch
} else if(is_array($type) && isset($type['customCode'])) {
return $type['customCode'];
}
}
?>