/**
  * @secured
  * @param string $aclModelID
  */
 public function handleDeleteModel($aclModelID)
 {
     if ($this->user->isAllowed("permission", "delete")) {
         if (is_string($aclModelID)) {
             try {
                 $aclModelID = (array) Json::decode($aclModelID);
                 $aclModelID = array_values($aclModelID);
             } catch (JsonException $e) {
                 $this['notification']->addError($e->getMessage());
                 if ($this->isAjax()) {
                     $this['notification']->redrawControl('error');
                 }
             }
         }
         $result = $this->modelManager->remove($aclModelID);
         if ($result === TRUE) {
             $this['notification']->addSuccess("Úspěšně uloženo...");
         } else {
             if (strpos("Integrity constraint violation", $result) != -1) {
                 $this['notification']->addError("Model stále využívá některá z komponent, proto ji nebylo možné vymazat.");
             } else {
                 $this['notification']->addError($result);
             }
         }
     }
     if ($this->isAjax()) {
         $this['notification']->redrawControl('error');
         $this['notification']->redrawControl('success');
         $this['gridResource']->redrawControl();
     }
 }
Exemple #2
0
 /** Submit
  * 
  * @param \Nette\Application\UI\Form $form
  */
 public function Submit(Form $form)
 {
     $json = new \stdClass();
     $json->result = "success";
     $values = $form->getValues();
     if (array_search(TRUE, (array) $values["actions"]) === FALSE) {
         $json->result = "error";
         $json->message = "Prosím vyberte alespoň jednu akci pro modul.";
     } else {
         if (!empty($values['aclResourceID'])) {
             if ($this->user->isAllowed("permission", "edit")) {
                 $result = $this->modelManager->update($values);
             } else {
                 $result = ResourceForm::PERMISSION;
             }
         } else {
             if ($this->user->isAllowed("permission", "add")) {
                 $result = $this->modelManager->insert($values);
             } else {
                 $result = ResourceForm::PERMISSION;
             }
         }
         if ($result === TRUE) {
             $json->result = "success";
         } else {
             $json->result = "error";
             $json->message = $result;
         }
     }
     $response = new JsonResponse($json);
     $this->getPresenter()->sendResponse($response);
 }