我正在尝试删除Lead的详细视图中的按钮,如果它已被转换。
我看到了类似的question,它使用javascript来隐藏按钮。我试图通过php获得相同的结果。
这是view.detail.php
文件夹中的custom\modules\Leads\views\
class LeadsViewDetail extends ViewDetail {
function __construct(){
parent::__construct();
}
function preDisplay() {
parent::preDisplay();
if($this->bean->converted==1) {
echo "hide";
foreach ($this->dv->defs['templateMeta']['form']['buttons'] as $key => $value) {
unset($this->dv->defs['templateMeta']['form']['buttons'][$key]);
}
} else {
echo "show";
}
}
}
使用此代码后,快速修复&重建后,我根据潜在客户状态正确显示“隐藏”或“显示”,但按钮未正确更新。
如果我在QR& R之后打开转换后的Lead,我将永远不会看到按钮。
如果我在QR& R之后打开未转换的潜水员,我会一直看到这些按钮。
我坚持这种情况。任何人都可以解释我的问题在哪里?我怎么解决呢? 非常感谢每一位帮助。
答案 0 :(得分:1)
您可以在custom/modules/Leads/metadata/detailviewdefs.php
中使用Smarty逻辑(" customCode")而不扩展ViewDetail的情况下处理此问题。看起来转换按钮仅在用户具有编辑权限时才会呈现,因此向其添加一个条件并不是什么大事......
$viewdefs['Leads']['DetailView']['templateMeta']['form]['buttons'][] = array('customCode' => '
{if $bean->aclAccess("edit") && $bean->converted}
<input title="{$MOD.LBL_CONVERTLEAD_TITLE}"
accessKey="{$MOD.LBL_CONVERTLEAD_BUTTON_KEY}"
type="button"
class="button"
name="convert"
value="{$MOD.LBL_CONVERTLEAD}"
onClick="document.location=\'index.php?module=Leads&action=ConvertLead&record={$fields.id.value}\'" />
{/if}');
或者,如果你确实有几个条件并且它们太麻烦或太难以使Smarty逻辑合理,我们可以将少量的Smarty Logic与扩展的ViewDetail结合起来。
除了custom/modules/Leads/metadata/detailviewdefs.php
之外,这实际上是来自SugarCRM CE 6.5.24的开箱即用文件,看起来他们实际上试图通过提供Smarty var来简化这种定制$DISABLE_CONVERT_ACTION
。作为参考,它只需要设置和启用全局配置变量disable_convert_lead
,但我怀疑这是一个相对较新的功能,不包含在早期版本中。尽管如此,它仍然是使用View设置一个我们可以转向的简单Smarty变量的一个很好的例子:
<?php
$viewdefs['Leads']['DetailView'] = array (
'templateMeta' => array (
'form' => array (
'buttons' => array (
'EDIT',
'DUPLICATE',
'DELETE',
array (
'customCode' => '{if $bean->aclAccess("edit") && !$DISABLE_CONVERT_ACTION}<input title="{$MOD.LBL_CONVERTLEAD_TITLE}" accessKey="{$MOD.LBL_CONVERTLEAD_BUTTON_KEY}" type="button" class="button" onClick="document.location=\'index.php?module=Leads&action=ConvertLead&record={$fields.id.value}\'" name="convert" value="{$MOD.LBL_CONVERTLEAD}">{/if}',
//Bug#51778: The custom code will be replaced with sugar_html. customCode will be deplicated.
'sugar_html' => array(
'type' => 'button',
'value' => '{$MOD.LBL_CONVERTLEAD}',
'htmlOptions' => array(
'title' => '{$MOD.LBL_CONVERTLEAD_TITLE}',
'accessKey' => '{$MOD.LBL_CONVERTLEAD_BUTTON_KEY}',
'class' => 'button',
'onClick' => 'document.location=\'index.php?module=Leads&action=ConvertLead&record={$fields.id.value}\'',
'name' => 'convert',
'id' => 'convert_lead_button',
),
'template' => '{if $bean->aclAccess("edit") && !$DISABLE_CONVERT_ACTION}[CONTENT]{/if}',
),
),
我们可以将此$DISABLE_CONVERT_ACTION
引用与custom/modules/Leads/views/view.detail.php
结合使用,如下所示根据我们想要的条件进行设置:
<?php
require_once('modules/Leads/views/view.detail.php');
class CustomLeadsViewDetail extends LeadsViewDetail {
/*
* while we might normally like to call parent::display() in this method to
* best emulate what the parnts will do, we instead here copy-and-paste the
* parent methods' content because LeadsViewDetail::display() will set the
* DISABLE_CONVERT_ACTION Smarty var differently than we want.
*/
public function display(){
global $sugar_config;
// Example One: Disable Conversion when status is Converted
$disableConvert = ($this->bean->status == 'Converted');
// Example Two: Disable Conversion when there is at lead one related Call
// where the status is Held
$disableConvert = FALSE;
$this->bean->load_relationships('calls');
foreach($this->bean->calls->getBeans() as $call){
if($call->status == 'Held'){
$disableConvert = TRUE;
break; // exit foreach()
}
}
// Example Three: Disable Conversion if the User is in a specific Role, e.g.
// Interns who are great for data entry in Leads but shouldn't be making
// actual sales
global $current_user;
$disableConvert = $current_user->check_role_membership('No Lead Conversions');
// In any of the above examples, once we have $disableConvert set up
// as we want, let the Smarty template know.
$this->ss->assign("DISABLE_CONVERT_ACTION", $disableConvert);
// copied from ViewDetail::display();
if(empty($this->bean->id)) {
sugar_die($GLOBALS['app_strings']['ERROR_NO_RECORD']);
}
$this->dv->process();
echo $this->dv->display();
}
}