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