有许多方法可以做到的事情在SugarCRM的,这使得它都非常强大,有时很难定制 - 因为你有很多不同的选择。
为了使点击“保存”按钮时发生某种弹出或任何自定义日志,我建议下面的解决方案,而不是改变editviewdefs
。
以下解决方案不需要您修改任何核心SugarCRM文件,因此它是安全升级的,可以很容易地安装在另一个实例上。
您需要做的是创建一个自定义可安装包,并使用Module Loader将其安装到SugarCRM中。
这是目录结构的布局,你将最终需要与结束:
SugarModuelPopUp
->custom
->include
->customPopUps
->custom_popup_js_include.php
->customPopUpContacts.js
->manifest.php
创建SugarModuelPopUp
文件夹,将服务器作为该自定义包的根。
在SugarModuelPopUp
的内部,创建一个名为manifest.php
的新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的模块加载器来安装自定义软件包。你可以这样做:
- 转到SugarCRM管理页面。
- 点击“模块加载器”。
- 点击“浏览”并选择ZIP包。
- 点击“上传”按钮。
- 上传包后,在可安装包列表中找到它的条目,然后单击“安装”;继续进行标准的SugarCRM安装过程。
安装此自定义软件包后,无论何时点击联系人模块EditView
中的“保存”按钮,都会弹出一个对话框。你可以用你想要的任何东西代替对话框代码,因为你不需要修改框架代码就可以登录。
此外,您应该能够使用该项目作为SugarCRM未来功能添加的基础EditViews
。点击“保存”按钮后,任何使用check_form
方法的模块都可以执行这种定制逻辑。
要为帐户这样做,例如,你会做以下几点:
添加在manifest.php对账户的条目到logic_hooks
数组元素。
'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'
)
)
在custom_popup_js_include.php
文件帐户的JavaScript添加一个新方法到CustomPopJs
。
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实例的优点。
男人你是天才!希望你知道:)不能够感谢你足够...正是我想要的。 - 在确定保存它取消不保存!还有一件小事 - 如果我希望只有在示例字段类型的联系人是“业务”时才弹出此警告。在哪里输入该条件?在一些PHP文件或JavaScript文件?如果你能告诉我那个额外的事情。预先感谢您 – Dejan 2013-03-07 01:11:11
在'window.formToCheck = formname;'后面的'customPopUpContacts.js'中,您可以将这个'confirm'代码块封装在一个if语句中,以使其仅出现有条件。就个人而言,我使用SugarCRM的jQuery,因为我发现它更直接。但是你可以像'var contactTypeField = document.getElementById('contact_type');如果(contactTypeField.value =='Business'){//确认块将会在这里}' – 2013-03-07 01:15:43
我试着用first_field进行测试。如果Tori出现,我进入了。如果我点击与托里联系作为名字,一切都很好。但是,如果我尝试点击带有其他名称的联系人(李)保存没有任何反应 - 它不会保存我的记录,但它应该保存记录,只是不显示弹出。在first_name!= Tori的情况下,我只能做取消,保存没有任何反应。请看看我的代码,我将它添加到原始文章。非常感谢 – Dejan 2013-03-07 01:30:45