2017-03-23 4 views
0

リードの詳細ビューでボタンを削除しようとしています。SugarCRM 6.5 CE:条件に応じてdetailviewのボタンを削除する方法

私は同様のquestionを見ました。ボタンを隠すにはjavascriptを使用しました。私はPHPを介して同じ結果を取得しようとしている。

これはview.detail.phpフォルダ

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"; 
     } 
    } 
} 

クイック修復&を再構築した後、私は「隠す」または「ショー」を参照してください、このコードを使用してcustom\modules\Leads\views\で私を正しくリード状態に応じてですが、ボタンが正しく更新されていません。

QR & Rの後に変換済みのリードを開くと、ボタンが表示されません。

QR & Rの後に変換されていないリードを開いた場合は、常にボタンが表示されます。

私はこの状況に固執しています。誰が問題をどこに教えてくれますか?どのように私はそれを解決することができます? すべての援助は非常に高く評価されています。

答えて

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は、実際にはSmartChar $DISABLE_CONVERT_ACTIONを提供して実際にこのカスタマイズを簡単にしようとしたように見えるSugarCRM CE 6.5.24のすぐに使用できるファイルです。参考のためには、グローバル設定変数disable_convert_leadを設定して有効にするだけで済みますが、これは以前のバージョンには含まれていなかった比較的新しい機能だと思われます。それでも、それは私たちが旋回することができるシンプルなSmartyの変数を設定するには、[View]を使用しての良い例です:

<?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}', 
     ), 
     ), 

私たちは、私たちが望むものは何でも条件に基づいて、それを設定するには、次のようcustom/modules/Leads/views/view.detail.phpでこれ$DISABLE_CONVERT_ACTION参照を組み合わせることができます:

<?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(); 
    } 
} 
+0

これは問題ありません。しかし、条件が、例えば関連する豆の畑を評価する必要がある場合はどうでしょうか? – Lipsyor

+1

さて、より多くの状況では、より面倒になるでしょう。その場合、あなたは正しいと思って、私は 'ViewDetail'を拡張します。私は私の答えを改めるつもりです。 –

+1

私はまた良いアイデアだと思います。ビューから割り当てられたSmarty変数を使用するのはもっともです。 – Lipsyor

関連する問題