예제 #1
0
 /**
  * Creates a NewNoteForm.
  * @param int|NULL $pad Id of the default pad. Can be NULL.
  * @return Form
  */
 public function create($pad)
 {
     $form = new Form();
     $form->addText('name', 'Name')->setRequired('%label is required');
     $form->addTextArea('text', 'Text')->setRequired('%label is required');
     $form->addSelect('pad', 'Pad', $this->padManager->findAll()->fetchPairs('id', 'name'))->setPrompt('Select pad')->setDefaultValue($pad);
     $form->addSubmit('submit', 'Save');
     $form->onSuccess[] = [$this, 'formSucceeded'];
     return $form;
 }
예제 #2
0
 /**
  * Creates an EditPadForm.
  * @param int    $id   Id of the pad to be edited.
  * @param string $name Current name of the pad.
  * @return Form
  */
 public function create($id, $name)
 {
     $form = new Form();
     $form->addText('name', 'Name')->setDefaultValue($name)->setRequired('%label is required');
     $form->addSubmit('submit', 'Save');
     $form->onSuccess[] = function (Form $form, $values) use($id) {
         if (!$this->padManager->update($id, $values->name)) {
             $form->addError("Failed to edit pad");
         }
     };
     return $form;
 }
예제 #3
0
 /**
  * Creates a DeletePadForm.
  * @param int $id Id of the pad to be deleted.
  * @return Form
  */
 public function create($id)
 {
     $form = new Form();
     $form->addProtection();
     // Adds CSRF protection
     $form->addSubmit('submit', 'Yes, I want to delete this pad');
     $form->onSuccess[] = function (Form $form) use($id) {
         if (!$this->padManager->delete($id)) {
             $form->addError("Failed to delete pad");
         }
     };
     return $form;
 }
예제 #4
0
 /**
  * Creates an EditNoteForm.
  * @param int    $id
  * @param string $name
  * @param string $text
  * @param int    $pad
  * @return Form
  */
 public function create($id, $name, $text, $pad)
 {
     $form = new Form();
     $form->addText('name', 'Name')->setDefaultValue($name)->setRequired('%label is required');
     $form->addTextArea('text', 'Text')->setDefaultValue($text)->setRequired('%label is required');
     $form->addSelect('pad', 'Pad', $this->padManager->findAll()->fetchPairs('id', 'name'))->setPrompt('Select pad')->setDefaultValue($pad);
     $form->addSubmit('submit', 'Save');
     $form->onSuccess[] = function (Form $form, $values) use($id) {
         if (!$this->noteManager->update($id, $values->name, $values->text, $values->pad)) {
             $form->addError("Failed to edit pad");
         }
     };
     return $form;
 }
예제 #5
0
 /**
  * Loads pad with given id and if not found, throws BadRequestException.
  * @param int $id
  * @throws BadRequestException
  */
 private function loadPad($id)
 {
     $this->id = $id;
     $this->pad = $this->padManager->find($this->id);
     if (!$this->pad) {
         throw new BadRequestException("Pad with given id not found");
     }
 }
예제 #6
0
 /**
  * Callback for NewPadForm onSuccess event.
  * @param Form      $form
  * @param ArrayHash $values
  */
 public function formSucceeded(Form $form, $values)
 {
     if (!$this->padManager->add($values->name)) {
         $form->addError("Failed to create new pad");
     }
 }
예제 #7
0
 /**
  * @return \App\Components\Pads\Pads
  */
 protected function createComponentPads()
 {
     $this->pads = $this->padManager->findAll();
     return $this->padsFactory->create($this->pads);
 }