ajax, entryPoint. . javascript ajax. ajax , . EntryPoint . , entryPoint.
custom/include/MVC/Controller/entry_point_registry.php. , .
entry_point_registry.php:
$entry_point_registry['test'] = array('file' => 'custom/test.php', 'auth' => true);
:
- . , "unique_book_value" . , .
- , . . , .
- 'auth' => true , , SugarCRM, . ( ) .
, custom/test.php ( unique_book_name.php):
global $db;
$book_name = urldecode($_REQUEST['book_name']);
$book_id = urldecode($_REQUEST['book_id']);
$sql = "SELECT id FROM book_module_table_name WHERE deleted = 0 AND name = '".$db->quote($book_name)."' AND id <> '".$db->quote($book_id)."'";
$res = $db->query($sql);
if ($db->getRowCount($res) > 0) {
echo 'exists';
}
else {
echo 'unique';
}
: api, . (: $bean-> retrieve_by_string_fields() - , : http://developer.sugarcrm.com/2012/03/23/howto-using-the-bean-instead-of- sql-all-the-time/) , API , ajax . , 99% . , PDO , , , .
, https://crm.yourdomain.com/index.php?entryPoint=test , .
, , . URL-, entryPoint, , :
- - $ entry_point_registry ['test']. , URL read index.php? EntryPoint = what_you_put_as_the_array_key
- - , crm.yourdomain.com - , yourdomain.com/sugarcrm/, , , URL, . , ... https://yourdomain.com/sugarcrm/index.php?entryPoint=test
- , - , apache . , /etc/init.d/apache2 . , - ( vps, !!!, , !)
? "s" https? http $ 9, !
, . entryPoint. . " " (, " ", ).
URL : index.php? EntryPoint = test & book_name = Art %20of %20War
, URL ! .
, "". , , -. 2 URL , , "".
: Sugar, , , mysql, . , SO: SQL MySQL?
, entryPoint, , ajaxical. , , , , .
, , : custom/modules/CUSTOM_BOOK_MODULE/views/view.edit.php (, ...
, , , :
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
class CUSTOM_BOOK_MODULEViewEdit extends ViewEdit
{
public function display()
{
$this->useForSubpanel = true;
$this->ss->assign('name_value', $this->bean->name);
$name_input_code = $this->ss->fetch('custom/modules/CUSTOM_BOOK_MODULE/tpls/unique_book_checker.tpl.js');
$this->ss->assign('custom_name_code', $name_input_code);
parent::display();
}
}
. : custom/modules/CUSTOM_BOOK_MODULE/tpls/unique_book_checker.tpl.js
:
, Sugar 6. 5+ jquery . , jquery.
. , , , javascript.
/modules/CUSTOM_BOOK_MODULE/unique_book_checker.tpl.js:
<input type="text" name="name" id="name" maxlength="255" value="{$name_value}" />
<span id="book_unique_result"></span>
{literal}
<script type="text/javascript">
$(document).ready(function() {
$('#name').blur(function(){
$('#book_unique_result').html('<strong> checking name...</strong>');
$.post('index.php?entryPoint=test', {book_name: $('#name').val(), book_id: $('[name="record"]').val()}, function(data){
if (data == 'exists') {
removeFromValidate('EditView', 'name');
addToValidate('EditView', 'name', 'float', true, 'Book Name Must be Unique.');
$('#book_unique_result').html('<strong style="color:red;"> ✗</strong>');
}
else if (data == 'unique') {
removeFromValidate('EditView', 'name');
addToValidate('EditView', 'name', '', true, 'Name Required');
$('#book_unique_result').html('<strong style="color:green;"> ✓</strong>');
}
else {
}
});
});
});
</script>
{/literal}
: , , Sugar . , , , float. , . , 3.14 - , , . , , .
! , , . : custom/modules/CUSTOM_BOOK_MODULE/metadata/editviewdefs.php. , , customCode, :
array (
'name' => 'name',
'customCode' => '{$custom_name_code}',
),
, , . Admin> > .
Boom! !


