Skip to content

Instantly share code, notes, and snippets.

@KyleGawryluk
Created November 11, 2013 19:09
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save KyleGawryluk/7418600 to your computer and use it in GitHub Desktop.
Save KyleGawryluk/7418600 to your computer and use it in GitHub Desktop.
SugarCRM - Generating custom error popup from logic hook
Create a custom view to load popup widget js
custom/modules/{module}/views/view.detail.php
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
require_once('include/json_config.php');
require_once('include/MVC/View/views/view.detail.php');
class po_purchaseOrdersViewDetail extends ViewDetail {
function po_purchaseOrdersViewDetail()
{
parent::ViewDetail();
}
function display(){
$javascript= "<script type='text/javascript' src='cache/include/javascript/sugar_grp_yui_widgets.js'></script>";
parent::display();
echo $javascript;
}
}
?>
If the condition is not met, throw new error in popup box. On clicking "OK", reload the page to view data again.
Without the reload, calling sugar_die will alter the original page.
Reference the SugarCRM Developer's Blog for more info on popups
http://developer.sugarcrm.com/2011/03/18/howto-create-nice-looking-popup-message-boxes-in-sugar/
custom/include/{module}.php
<?php
if (condition) {
# do something if true
} else {
sugar_die("
<script language='javascript'>
var handleOK = function() {
this.hide();
location.reload();
};
YAHOO.SUGAR.MessageBox.show({
msg: 'Your Error Message',
title:'Your Error Title',
close: false,
buttons:[
{ text: 'OK', handler: handleOK ,isDefault:true},
]
});
</script>
");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment