public function doSend($data, $form)
 {
     try {
         $this->record->doSend();
     } catch (PushException $ex) {
         return new SS_HTTPResponse($this->ItemEditForm()->forAjaxTemplate(), 400, $ex->getMessage());
     }
     $response = new SS_HTTPResponse($this->ItemEditForm()->forAjaxTemplate());
     $response->setStatusDescription(_t('Push.PUSHSENT', 'The push notification has been sent'));
     return $response;
 }
Esempio n. 2
0
 /**
  * Action to handle removing a single file from the db relation
  * 
  * @param SS_HTTPRequest $request
  * @return SS_HTTPResponse
  */
 public function remove(SS_HTTPRequest $request)
 {
     // Check form field state
     if ($this->parent->isDisabled() || $this->parent->isReadonly()) {
         return $this->httpError(403);
     }
     // Protect against CSRF on destructive action
     $token = $this->parent->getForm()->getSecurityToken();
     if (!$token->checkRequest($request)) {
         return $this->httpError(400);
     }
     $response = new SS_HTTPResponse();
     $response->setStatusCode(500);
     $fieldName = $this->parent->getName();
     $record = $this->parent->getRecord();
     $id = $this->getItem()->ID;
     if ($id && $record && $record->exists()) {
         if (($record->has_many($fieldName) || $record->many_many($fieldName)) && ($file = $record->{$fieldName}()->byID($id))) {
             $record->{$fieldName}()->remove($file);
             $response->setStatusCode(200);
         } elseif ($record->has_one($fieldName) && $record->{$fieldName . 'ID'} == $id) {
             $record->{$fieldName . 'ID'} = 0;
             $record->write();
             $response->setStatusCode(200);
         }
     }
     if ($response->getStatusCode() != 200) {
         $response->setStatusDescription(_t('UploadField.REMOVEERROR', 'Error removing file'));
     }
     return $response;
 }