如何:改变SugarCRM中的下拉值

时间:2016-07-20 07:05:41

标签: javascript php jquery sugarcrm

我试图通过点击按钮来更改下拉列表的值,我使用SugarCRM CE 6.5,这就是我遇到的问题:

enter image description here

以下是我的代码:

- detailviewdefs.php

<?php
$module_name = 'UA_Quotes';
$viewdefs [$module_name] = 
array (
'DetailView' => 
array (
 'templateMeta' => 
array (
  'include' => 
   array (
    0 =>
    array (
      'file' => 
      'custom/modules/UA_Quotes/JS/clickPayment.js',
      ),
    ),
  'form' => 
  array (
    'closeFormBeforeCustomButtons' => true,
    'buttons' => 
    array (
      0 => 'EDIT',  
      1 => 'DELETE',
      2 => 
      array (
        'customCode' => '{$Monthly_Payment}',
      ),
    ),
    'footerTpl' => 'modules/UA_Quotes/tpls/DetailViewFooter.tpl',
  ),
  'maxColumns' => '2',
  'widths' => 
  array (
    0 => 
    array (
      'label' => '10',
      'field' => '30',
    ),
    1 => 
    array (
      'label' => '10',
      'field' => '30',
    ),
  ),
  'useTabs' => false,
  'tabDefs' => 
  array (
    'LBL_EDITVIEW_PANEL2' => 
    array (
      'newTab' => false,
      'panelDefault' => 'expanded',
    ),
  ),
),
'panels' => 
array (
  'lbl_editview_panel2' => 
  array (
    0 => 
    array (
      0 => 'name',
      1 => 
      array (
        'name' => 'ua_contracts_ua_quotes_1_name',
      ),
    ),
    1 => 
    array (
      0 => 
      array (
        'name' => 'monthlystart_c',
        'label' => 'LBL_MONTHLYSTART',
      ),
      1 => 
      array (
        'name' => 'quote_stage',
        'studio' => 'visible',
        'label' => 'LBL_QUOTE_STAGE',
      ),
    ),
    2 => 
    array (
      0 => 
      array (
        'name' => 'monthlydeadline_c',
        'label' => 'LBL_MONTHLYDEADLINE',
      ),
    ),
  ),
),
),
);
?>

- view.detail.php

<?php


require_once('include/MVC/View/views/view.detail.php');

class UA_QuotesViewDetail extends ViewDetail
{
public function __construct()
{
    parent::ViewDetail();
}

public function display()
{
    echo '<script type="text/javascript"    src="custom/modules/UA_Quotes/js/clickPayment.js"></script>';
    $groups = $this->bean->Get_Products($this->bean->id, true);
    $this->ss->assign('GROUPS', $groups);

    $this->ss->assign('NET_TOTAL', currency_format_number($this->bean->net_total_amount));
    $this->ss->assign('TOTAL', currency_format_number($this->bean->total_amount));
    $this->ss->assign('Monthly_Payment', '<input type="button" onclick="GetPayment();" value="Monthly Payment"/>');
    /*
    $this->dv->ss->assign('Monthly_Payment', '<input type="button" 
    onclick="alert(\'How to change status :(\')" value="Monthly Payment"/>');*/

    parent::display();
}
}

- clickPayment.js

function GetPayment(){

var record = $("#record").val();
// var pathArray = window.location.href.split("=");
var fdata = { 'record':record };   
// console.log(pathArray[3]," - your Record ID");
$.ajax({
                    type: 'POST',                 
                    url: "custom/modules/UA_Quotes/js/changestatus.php?&fdata="+fdata+"",
                    data: fdata, //{recordID: pathArray[3]},
                    dataType: 'html',
                    async: false,
                    error: function(resp){},
                    success: function(resp){
                        location.reload(true);
                    }                     
                    /*  success:function(fdata){                     
                        console.log("Customer Status Change"); 
                         location.reload(true);        
                    },
                    error: function(fdata) {
                        // if error occured
                        console.log(" NA ");                     
                    }   */
                });
}

- 最后,我的changestatus.php

<?php

$myrecordID = $_POST['record'];
$focus = new UA_Quotes();
$focus->retrieve($myrecordID);
$focus->quote_stage_dom = 'Paid';

?>

我很遗憾这长长的代码,我现在已经和他们打了几天了,似乎没有运气。 :( 任何帮助都不胜感激!谢谢!

2 个答案:

答案 0 :(得分:1)

您报告的错误似乎是由于错误使用了入口点。

请尝试在custom/include/MVC/Controller/entry_point_registry.php中注册自定义入口点,如下所示:

$entry_point_registry['ChangeStatus'] = array('file' => 'modules/UA_Quotes/entrypoint/changestatus.php' , 'auth' => '1');

只需在入口点注册表中添加该行,如果该文件尚不存在,请在该位置添加名称文件。

数组中的文件部分指向代码的位置,auth部分允许您指定是否需要对用户进行身份验证以访问入口点。

然后通过:index.php?entryPoint=ChangeStatus&id=...(&to_pdf=true)

调用它

如果您希望响应为json或text,则可能需要最后一个参数&to_pdf=true。如果没有它,您将在答案中获得整个html页面。

你可以在没有入口点的情况下通过添加一个控制器,然后通过脚本从你的脚本中调用它:index.php?module = UA_Quotes&amp; action = changestatus

顺便提一下,您在元数据和视图中加载javascript文件。在详细视图中应该足够了。

答案 1 :(得分:1)

同意第一个答案。您可以尝试使用控制器为您的端点更改changestatus.php上的文件 例如:

http://techs.studyhorror.com/sugarcrm-how-add-custom-actions-i-46