Example #1
0
 /**
  * Perform an action on an issue type
  *
  * @param framework\Request $request
  */
 public function runConfigureIssuetypesAction(framework\Request $request)
 {
     if ($request->hasParameter('scheme_id')) {
         $this->scheme = entities\IssuetypeScheme::getB2DBTable()->selectById((int) $request['scheme_id']);
     }
     $this->forward403unless($this->access_level == framework\Settings::ACCESS_FULL);
     switch ($request['mode']) {
         case 'add':
             if ($request['name']) {
                 $issuetype = new entities\Issuetype();
                 $issuetype->setName($request['name']);
                 $issuetype->setIcon($request['icon']);
                 $issuetype->save();
                 return $this->renderJSON(array('title' => framework\Context::getI18n()->__('Issue type created'), 'content' => $this->getComponentHTML('issuetype', array('type' => $issuetype))));
             }
             $this->getResponse()->setHttpStatus(400);
             return $this->renderJSON(array('error' => framework\Context::getI18n()->__('Please provide a valid name for the issue type')));
         case 'update':
             if (($issuetype = entities\Issuetype::getB2DBTable()->selectById($request['id'])) instanceof entities\Issuetype) {
                 if ($this->scheme instanceof entities\IssuetypeScheme) {
                     $this->scheme->setIssuetypeRedirectedAfterReporting($issuetype, $request['redirect_after_reporting']);
                     $this->scheme->setIssuetypeReportable($issuetype, $request['reportable']);
                     return $this->renderJSON(array('title' => framework\Context::getI18n()->__('The issue type details were updated'), 'description' => $issuetype->getDescription(), 'name' => $issuetype->getName()));
                 } elseif ($request['name']) {
                     $issuetype->setDescription($request['description']);
                     $issuetype->setName($request['name']);
                     $issuetype->setIcon($request['icon']);
                     $issuetype->save();
                     return $this->renderJSON(array('title' => framework\Context::getI18n()->__('The issue type was updated'), 'description' => $issuetype->getDescription(), 'name' => $issuetype->getName()));
                 } else {
                     $this->getResponse()->setHttpStatus(400);
                     return $this->renderJSON(array('error' => framework\Context::getI18n()->__('Please provide a valid name for the issue type')));
                 }
             }
             $this->getResponse()->setHttpStatus(400);
             return $this->renderJSON(array('error' => framework\Context::getI18n()->__('Please provide a valid issue type')));
         case 'updatechoices':
             if (($issuetype = entities\Issuetype::getB2DBTable()->selectById($request['id'])) instanceof entities\Issuetype) {
                 $this->scheme->clearAvailableFieldsForIssuetype($issuetype);
                 foreach ($request->getParameter('field', array()) as $key => $details) {
                     $this->scheme->setFieldAvailableForIssuetype($issuetype, $key, $details);
                 }
                 return $this->renderJSON(array('title' => framework\Context::getI18n()->__('Available choices updated')));
             } else {
                 $this->getResponse()->setHttpStatus(400);
                 return $this->renderJSON(array('error' => framework\Context::getI18n()->__('Please provide a valid issue type')));
             }
         case 'delete':
             if (($issuetype = entities\Issuetype::getB2DBTable()->selectById($request['id'])) instanceof entities\Issuetype) {
                 $issuetype->delete();
                 return $this->renderJSON(array('message' => framework\Context::getI18n()->__('Issue type deleted')));
             } else {
                 $this->getResponse()->setHttpStatus(400);
                 return $this->renderJSON(array('error' => framework\Context::getI18n()->__('Please provide a valid issue type')));
             }
         case 'toggletype':
             if (($issuetype = entities\Issuetype::getB2DBTable()->selectById($request['id'])) instanceof entities\Issuetype) {
                 if ($this->scheme instanceof entities\IssuetypeScheme) {
                     $this->scheme->setIssuetypeEnabled($issuetype, $request['state'] == 'enable');
                     return $this->renderJSON(array('issuetype_id' => $issuetype->getID()));
                 }
             }
             $this->getResponse()->setHttpStatus(400);
             return $this->renderJSON(array('error' => framework\Context::getI18n()->__('Please provide a valid action for this issue type / scheme')));
         default:
             $this->getResponse()->setHttpStatus(400);
             return $this->renderJSON(array('error' => framework\Context::getI18n()->__('Please provide a valid action for this issue type')));
     }
 }