/** * Edit a component * * @param TBGRequest $request The request object */ public function runEditComponent(TBGRequest $request) { $i18n = TBGContext::getI18n(); if ($this->access_level == TBGSettings::ACCESS_FULL) { try { $theComponent = TBGContext::factory()->TBGComponent($request->getParameter('component_id')); if ($request->getParameter('mode') == 'update') { if (($c_name = $request->getParameter('c_name')) && trim($c_name) != '') { if ($c_name == $theComponent->getName()) { return $this->renderJSON(array('failed' => false, 'newname' => $c_name)); } if (in_array($c_name, $theComponent->getProject()->getComponents())) { throw new Exception($i18n->__('This component already exists for this project')); } $theComponent->setName($c_name); return $this->renderJSON(array('failed' => false, 'newname' => $theComponent->getName())); } else { throw new Exception($i18n->__('You need to specify a name for this component')); } } elseif ($request->getParameter('mode') == 'delete') { $project = $theComponent->getProject(); $theComponent->delete(); $count = count(TBGComponent::getAllByProjectID($project->getID())); return $this->renderJSON(array('failed' => false, 'deleted' => true, 'itemcount' => $count, 'message' => TBGContext::getI18n()->__('Component deleted'))); } } catch (Exception $e) { return $this->renderJSON(array('failed' => true, "error" => TBGContext::getI18n()->__('Could not edit this component') . ", " . $e->getMessage())); } } return $this->renderJSON(array('failed' => true, "error" => $i18n->__("You don't have access to modify components"))); }
break; case TBGCustomDatatype::COMPONENTS_CHOICE: ?> <a href="javascript:void(0);" onclick="setField('<?php echo make_url('issue_setfield', array('project_key' => $issue->getProject()->getKey(), 'issue_id' => $issue->getID(), 'field' => $field, $field . '_value' => "")); ?> ', '<?php echo $field; ?> ');"><?php echo $info['clear']; ?> </a><br> <ul class="choices"> <?php foreach (TBGComponent::getAllByProjectID($issue->getProject()->getID()) as $choice) { ?> <li> <?php echo image_tag('icon_components.png', array('style' => 'float: left; margin-right: 5px;')); ?> <a href="javascript:void(0);" onclick="setField('<?php echo make_url('issue_setfield', array('project_key' => $issue->getProject()->getKey(), 'issue_id' => $issue->getID(), 'field' => $field, $field . '_value' => $choice->getID())); ?> ', '<?php echo $field; ?> ');"><?php echo $choice->getName(); ?> </a>
/** * Populates components inside the project * * @return void */ protected function _populateComponents() { if ($this->_components === null) { $this->_components = TBGComponent::getAllByProjectID($this->getID()); } }
<?php break; case TBGCustomDatatype::COMPONENTS_CHOICE: ?> <select name="<?php echo $customdatatype->getKey(); ?> _id" id="<?php echo $customdatatype->getKey(); ?> _id_additional"> <?php if ($selected_project instanceof TBGProject) { ?> <?php foreach (TBGComponent::getAllByProjectID($selected_project->getID()) as $option) { ?> <option value="<?php echo $option->getID(); ?> "<?php if ($selected_customdatatype[$customdatatype->getKey()] == $option->getID()) { ?> selected<?php } ?> ><?php echo $option->getName(); ?> </option> <?php