Bug fix: the result of CheckToWrite() was not taken into account (action failed silently) when creating an object using the [+] button inside a form.

SVN:trunk[4056]
This commit is contained in:
Denis Flaven
2016-05-11 12:09:45 +00:00
parent 1018dc6e74
commit e388e4b163
2 changed files with 21 additions and 8 deletions

View File

@@ -505,16 +505,23 @@ EOF
*/
public function DoCreateObject($oPage)
{
$oObj = MetaModel::NewObject($this->sTargetClass);
$aErrors = $oObj->UpdateObjectFromPostedForm($this->iId);
if (count($aErrors) == 0)
try
{
$oObj->DBInsert();
return array('name' => $oObj->GetName(), 'id' => $oObj->GetKey());
$oObj = MetaModel::NewObject($this->sTargetClass);
$aErrors = $oObj->UpdateObjectFromPostedForm($this->iId);
if (count($aErrors) == 0)
{
$oObj->DBInsert();
return array('name' => $oObj->GetName(), 'id' => $oObj->GetKey());
}
else
{
return array('error' => implode(' ', $aErrors), 'id' => 0);
}
}
else
catch(Exception $e)
{
return array('name' => implode(' ', $aErrors), 'id' => 0);
return array('error' => $e->getMessage(), 'id' => 0);
}
}

View File

@@ -381,7 +381,13 @@ function ExtKeyWidget(id, sTargetClass, sFilter, sTitle, bSelectMode, oWizHelper
me.ajax_request = $.post( AddAppContext(GetAbsoluteUrlAppRoot()+'pages/ajax.render.php'), theMap,
function(data)
{
if (me.bSelectMode)
$('#fstatus_'+me.id).html('');
if (data.id == 0)
{
$('#label_'+me.id).removeClass('ac_dlg_loading');
alert(data.error);
}
else if (me.bSelectMode)
{
// Add the newly created object to the drop-down list and select it
$('<option/>', { value : data.id }).html(data.name).appendTo('#'+me.id);