public function save()
{
// TODO: start transaction here
try {
if ($this->hook('update')) {
return $this;
}
if (!($m = $this->getModel())) {
throw new BaseException("Can't save, model not specified");
}
if (!is_null($this->get_field)) {
$this->app->stickyForget($this->get_field);
}
foreach ($this->elements as $short_name => $element) {
if ($element instanceof Form_Field) {
if (!$element->no_save) {
//if(is_null($element->get()))
$m->set($short_name, $element->get());
}
}
}
$m->save();
} catch (BaseException $e) {
if ($e instanceof Exception_ValidityCheck) {
$f = $e->getField();
if ($f && is_string($f) && ($fld = $this->hasElement($f))) {
/** @type Form_Field $fld */
$fld->displayFieldError($e->getMessage());
} else {
$this->js()->univ()->alert($e->getMessage())->execute();
}
}
if ($e instanceof Exception_ForUser) {
$this->js()->univ()->alert($e->getMessage())->execute();
}
throw $e;
}
}