我希望在某些模块(例如联系人)的编辑视图中单击“保存”时弹出一些消息(稍后我将在该弹出窗口中获得“确定”和“取消”选项。)。
我的功能
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 中单击 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;
}