-->

SugarCRM-如何获得POPUP当点击保存按钮?(SugarCRM- How to get PO

2019-07-21 02:44发布

我想在某些模块(例如联系人),编辑,查看点击保存时,得到了一些消息弹出(以后我会选择确定,对弹出取消)。

我的功能

YAHOO.SUGAR.MessageBox.show({msg: 'Foo'} );

工作时,我把它放在editviewdefs.php的顶部(我还必须包括cache/include/javascript/sugar_grp_yui_widgets.js ))文件,并打开该视图,当我得到那个弹出。 但我想它弹出的保存,不打开EditView中时(这只是测试一个给我看, YAHOO功能工作)。 所以我尝试创建单独的customJavascript.js文件custom/modules/Contacts

    //<script type="text/javascript"
 src="cache/include/javascript/sugar_grp_yui_widgets.js"></script>
    function check_custom_data()
    {
    YAHOO.SUGAR.MessageBox.show({msg: 'Foo'} );

    }

我修改custom/modules/Contacts/metadata/editviewdefs.php

<?php
$module_name = 'Contacts';
$viewdefs ['Contacts'] = 
array (
  'EditView' => 
  array (
    'templateMeta' => 
    array (
      'form' => 
      array (
        'hidden' => 
        array (
          0 => '<input type="hidden" name="opportunity_id" value="{$smarty.request.opportunity_id}">',
          1 => '<input type="hidden" name="case_id" value="{$smarty.request.case_id}">',
          2 => '<input type="hidden" name="bug_id" value="{$smarty.request.bug_id}">',
          3 => '<input type="hidden" name="email_id" value="{$smarty.request.email_id}">',
          4 => '<input type="hidden" name="inbound_email_id" value="{$smarty.request.inbound_email_id}">',
        ),
      ),

      array(
         'buttons' =>
        array (
         0 =>
          array(
           'customCode' =>
            '<input title="Save [Alt+S]" accessKey="S" onclick="this.form.action.value=\'Save\'; return check_custom_data();" type="submit" name="button" value="'.$GLOBALS['app_strings']['LBL_SAVE_BUTTON_LABEL'].'">',
          ),
         1 =>'Cancel'
        )
      ),
        'includes'=> array(
   array('file'=>'custom/modules/Contacts/customJavascript.js'),
      ),
..........
.......

但是当我点击保存在EditView中什么也没有发生,但我想在那一刻得到弹出与消息(后面我会补充确定和取消选项)。

我究竟做错了什么? 谢谢

已更新,可弹出只有一些条件代码:

....
     window.formToCheck = formname;

        var contactTypeField = document.getElementById('first_name');
        if (contactTypeField.value == 'Tori')
        {
        if (confirm("This dialog will pop-up whenever the user click on the Save button. "
                + "If you click OK, then you can execute some custom code, and then "
                + "execute the old form check function, which will process and submit "
                + "the form, using SugarCRM's standard behavior.")) {

            var customCodeVariable = 5;
            customCodeVariable = 55 + (customCodeVariable * 5);

            return window.old_check_form(formname);
        }

        return false;
        }

Answer 1:

有许多方法可以做到的事情在SugarCRM的,这使得它都非常强大,有时很难定义 - 因为有提供给你这么多不同的选择。

为了使某种弹出,或任何自定义日志,在点击“保存”按钮发生,我建议下面的解决方案,而不是改变editviewdefs

下面的解决方案不需要修改任何核心SugarCRM的文件,因此它是安全的升级,可以很容易地在另一个实例安装。

你将需要做的是创建一个自定义安装包,并使用模块加载器将其安装到SugarCRM的。

这是目录结构,你将最终需要与最终的布局:

SugarModuelPopUp
   ->custom
      ->include
         ->customPopUps
            ->custom_popup_js_include.php
            ->customPopUpContacts.js
   ->manifest.php

创建SugarModuelPopUp文件夹,将服务器作为该自定义包的根。

里面的SugarModuelPopUp ,创建名为新的PHP文件manifest.php 。 此文件告诉SugarCRM的如何安装包。

manifest.php ,粘贴以下代码:

<?php
$manifest = array(
        array(
                'acceptable_sugar_versions' => array()
        ),
        array(
                'acceptable_sugar_flavors' => array()
        ),
        'readme' => 'Please consult the operating manual for detailed installation instructions.',
        'key' => 'customSugarMod1',
        'author' => 'Kyle Lowry',
        'description' => 'Adds pop-up dialog on save on Contacts module.',
        'icon' => '',
        'is_uninstallable' => true,
        'name' => 'Pop-Up Dialog On Save',
        'published_date' => '2013-03-06 12:00:00',
        'type' => 'module',
        'version' => 'v1',
        'remove_tables' => 'prompt'
);

$installdefs = array(
        'id' => 'customSugarMod1',
        'copy' => array(
                array(
                        'from' => '<basepath>/custom/',
                        'to' => 'custom/'
                )
        ),
        'logic_hooks' => array(
                array(
                        'module' => 'Contacts',
                        'hook' => 'after_ui_frame',
                        'order' => 1,
                        'description' => 'Creates pop-up dialog on save action.',
                        'file' => 'custom/include/customPopUps/custom_popup_js_include.php',
                        'class' => 'CustomPopJs',
                        'function' => 'getContactJs'
                )
        )
);

接下来,您将要作出的custom文件夹。 里面的那个,创建include文件夹。 里面的那个,创建customPopUps文件夹。

接下来,您将要创建的custom_popup_js_include.php文件。 此文件控制在何时何地您的自定义JavaScript被包含在页面上。 粘贴下面的代码:

<?php
// prevent people from accessing this file directly
if (! defined('sugarEntry') || ! sugarEntry) {
    die('Not a valid entry point.');
}
class CustomPopJs {
    function getContactJs($event, $arguments) {
        // Prevent this script from being injected anywhere but the EditView.
        if ($_REQUEST['action'] != 'EditView') {
            // we are not in the EditView, so simply return without injecting
            // the Javascript
            return;
        }
        echo '<script type="text/javascript" src="custom/include/customPopUps/customPopUpContacts.js"></script>';
    }
}

接下来,您将需要创建customPopUpContacts.js文件,该文件将创建在点击联系人模块保存按钮自定义弹出EditView 。 粘贴下面的代码:

function override_check_form() {
    // store a reference to the old form checking function
    window.old_check_form = window.check_form;
    // set the form checking function equal to something custom
    window.check_form = function(formname) {
        window.formToCheck = formname;
        // you can create the dialog however you wish, but for simplicity I am
        // just using standard javascript functions
        if (confirm("This dialog will pop-up whenever the user click on the Save button. "
                + "If you click OK, then you can execute some custom code, and then "
                + "execute the old form check function, which will process and submit "
                + "the form, using SugarCRM's standard behavior.")) {
            // you have clicked OK, so do some custom code here,
            // replace this code with whatever you really want to do.
            var customCodeVariable = 5;
            customCodeVariable = 55 + (customCodeVariable * 5);
            // now that your custom code has executed, you can let
            // SugarCRM take control, process the form, and submit
            return window.old_check_form(formname);
        }
        // the user clicked on Cancel, so you can either just return false
        // and leave the person on the form, or you can execute some custom
        // code or do whatever else you want.
        return false;
    }
}

// call the override function, which will replace the old form checker
// with something custom
override_check_form();

一旦你创建了上述目录结构,并在正确的文件夹中的文件,你可以创建一个项目的ZIP文件。 要注意,对于SugarCRM的安装包,你的ZIP文件必须包含在项目目录中的一切是非常重要的。 也就是说,你将不会被压缩和解了SugarModuelPopUp文件夹,而是一切都在它的内部。

接下来,您将要安装使用SugarCRM公司的模块加载定制包。 你可以这样做:

  1. 进入SugarCRM的管理页面。
  2. 点击“模块加载器”。
  3. 点击“浏览”,选择ZIP包。
  4. 点击“上传”按钮。
  5. 一旦包被上载,找到其在安装包的列表项,然后单击“安装”; 与标准SugarCRM的安装过程中进行。

在安装了此定制包,只要你点击“保存”按钮,在联系人模块EditView ,出现一个对话框弹出。 您可以用您想要的任何东西的对话框代码,所以日志,你不修改代码框架吧。

此外,你应该能够使用这个项目作为未来的功能补充,SugarCRM的基础EditViews 。 它使用的任何模块check_form在“保存”按钮的点击方法可以有这种执行自定义逻辑的。

要为帐户这样做,例如,你会做以下几点:

添加一个条目logic_hooks在manifest.php的账户数组元素。

'logic_hooks' => array(
                array(
                        'module' => 'Contacts',
                        'hook' => 'after_ui_frame',
                        'order' => 1,
                        'description' => 'Creates pop-up dialog on save action.',
                        'file' => 'custom/include/customPopUps/custom_popup_js_include.php',
                        'class' => 'CustomPopJs',
                        'function' => 'getContactJs'
                ),
                array(
                        'module' => 'Accounts',
                        'hook' => 'after_ui_frame',
                        'order' => 1,
                        'description' => 'Creates pop-up dialog on save action.',
                        'file' => 'custom/include/customPopUps/custom_popup_js_include.php',
                        'class' => 'CustomPopJs',
                        'function' => 'getAccountJs'
                )
        )

添加一个新的方法将CustomPopJscustom_popup_js_include.php的帐户JavaScript文件。

function getAccountJs($event, $arguments) {
        // Prevent this script from being injected anywhere but the EditView.
        if ($_REQUEST['action'] != 'EditView') {
            // we are not in the EditView, so simply return without injecting
            // the Javascript
            return;
        }
        echo '<script type="text/javascript" src="custom/include/customPopUps/customPopUpAccounts.js"></script>';
    }

创建customPopUpAccounts.js文件,并使用customPopUpContacts.js代码为你想要的功能的基础。

有在SugarCRM的完成你的目标的其他方式,但是这是一个我个人使用的,它具有可升级的安全,方便地迁移到其他SugarCRM的情况下受益。



Answer 2:

我有SugarCRM的CE 6.5,该方法没有工作给我(我的意思是创建新的模块)。 但是,我修改了logic_hook,直接把文件中的自定义/ include文件夹和它的作品!



文章来源: SugarCRM- How to get POPUP when click on Save button?