Exemple #1
0
 /**
  * Add or delete a custom type
  *
  * @param TBGRequest $request
  */
 public function runConfigureIssuefieldsCustomTypeAction(TBGRequest $request)
 {
     switch ($request['mode']) {
         case 'add':
             if ($request['name'] != '') {
                 try {
                     $customtype = new TBGCustomDatatype();
                     $customtype->setName($request['name']);
                     $customtype->setItemdata($request['name']);
                     $customtype->setDescription($request['name']);
                     $customtype->setType($request['field_type']);
                     $customtype->save();
                     return $this->renderJSON(array('title' => TBGContext::getI18n()->__('The issue field was added'), 'content' => $this->getComponentHTML('issuefields_customtype', array('type_key' => $customtype->getKey(), 'type' => $customtype))));
                 } catch (Exception $e) {
                     $this->getResponse()->setHttpStatus(400);
                     return $this->renderJSON(array('error' => $e->getMessage()));
                 }
             }
             $this->getResponse()->setHttpStatus(400);
             return $this->renderJSON(array('error' => TBGContext::getI18n()->__('Please provide a valid name')));
             break;
         case 'update':
             if ($request['name'] != '') {
                 $customtype = TBGCustomDatatype::getByKey($request['type']);
                 if ($customtype instanceof TBGCustomDatatype) {
                     $customtype->setDescription($request['description']);
                     $customtype->setInstructions($request['instructions']);
                     $customtype->setName($request['name']);
                     $customtype->save();
                     return $this->renderJSON(array('title' => TBGContext::getI18n()->__('The custom field was updated'), 'description' => $customtype->getDescription(), 'instructions' => $customtype->getInstructions(), 'name' => $customtype->getName()));
                 }
                 $this->getResponse()->setHttpStatus(400);
                 return $this->renderJSON(array('error' => TBGContext::getI18n()->__('You need to provide a custom field key that already exists')));
             }
             $this->getResponse()->setHttpStatus(400);
             return $this->renderJSON(array('error' => TBGContext::getI18n()->__('Please provide a valid name')));
             break;
         case 'delete':
             $customtype = TBGCustomDatatype::getByKey($request['type']);
             if ($customtype instanceof TBGCustomDatatype) {
                 $customtype->delete();
                 return $this->renderJSON(array('title' => TBGContext::getI18n()->__('The custom field was deleted')));
             }
             $this->getResponse()->setHttpStatus(400);
             return $this->renderJSON(array('error' => TBGContext::getI18n()->__('You need to provide a custom field key that already exists')));
             break;
     }
 }