Dej*_*jan 2 popup sugarcrm editview
我想在单击某个模块的编辑视图中保存(示例联系人)以弹出一些消息(稍后我会在弹出窗口中获得选项确定和取消.).
我的功能
YAHOO.SUGAR.MessageBox.show({msg: 'Foo'} );
Run Code Online (Sandbox Code Playgroud)
我把它放在editviewdefs.php(我也必须包括cache/include/javascript/sugar_grp_yui_widgets.js))文件的顶部工作
,当打开该视图时,我正在弹出.但是我希望它在Save上弹出,而不是在打开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'} );
}
Run Code Online (Sandbox Code Playgroud)
我修改了 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'),
),
..........
.......
Run Code Online (Sandbox Code Playgroud)
但是当我在EditView中单击Save时没有任何反应,但我想在那一刻弹出消息(稍后我将添加OK和Cancel选项).
我究竟做错了什么?谢谢
更新了代码,仅在某些条件下弹出:
....
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;
}
Run Code Online (Sandbox Code Playgroud)
Kyl*_*wry 11
在SugarCRM中有很多方法可以做到这一点,这使得它既强大又有时很难定制 - 因为有很多不同的选择可供选择.
要点击"保存"按钮进行某种弹出或任何自定义日志,我建议使用以下解决方案,而不是更改editviewdefs.
以下解决方案不需要您修改任何核心SugarCRM文件,因此它是升级安全的,可以轻松安装在另一个实例上.
您需要做的是创建一个自定义可安装包,并使用Module Loader将其安装到SugarCRM中.
这是您最终需要最终得到的目录结构的布局:
SugarModuelPopUp
->custom
->include
->customPopUps
->custom_popup_js_include.php
->customPopUpContacts.js
->manifest.php
Run Code Online (Sandbox Code Playgroud)
创建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'
)
)
);
Run Code Online (Sandbox Code Playgroud)
接下来,您将要创建该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>';
}
}
Run Code Online (Sandbox Code Playgroud)
接下来,您需要创建该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();
Run Code Online (Sandbox Code Playgroud)
创建上述目录结构和正确文件夹中的文件后,即可创建项目的ZIP文件.请务必注意,对于SugarCRM可安装程序包,ZIP文件必须包含项目目录中的所有内容.也就是说,你不会压缩SugarModuelPopUp文件夹,而是内部的所有内容.
接下来,您将需要使用SugarCRM的模块加载器安装自定义程序包.你可以这样做:
安装此自定义程序包后,只要单击"联系人"模块中的"保存"按钮,EditView就会弹出一个对话框.您可以将对话框代码替换为您想要的任何内容,以便将日志替换为不修改代码框架的日志.
此外,您应该能够将此项目用作SugarCRM未来功能添加的基础EditViews.check_form单击"保存"按钮时使用该方法的任何模块都可以执行这种自定义逻辑.
例如,要对帐户执行此操作,您将执行以下操作:
logic_hooks在manifest.php中为Accounts 添加一个条目到数组元素.
'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'
)
)
Run Code Online (Sandbox Code Playgroud)
在Accounts JavaScript CustomPopJs的custom_popup_js_include.php文件中添加一个新方法.
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>';
}
Run Code Online (Sandbox Code Playgroud)
创建customPopUpAccounts.js文件,并使用customPopUpContacts.js代码作为所需功能的基础.
还有其他方法可以在SugarCRM中实现您的目标,但这是我个人使用的方法,它具有升级安全且易于迁移到其他SugarCRM实例的好处.