コード例 #1
0
 /**
  * Saves a bind in the database
  *
  * @return void
  */
 public function saveObject()
 {
     if (is_array($this->default_values)) {
         $t = array();
         foreach ($this->default_values as $value) {
             $t[$value->getId()] = $value;
         }
         $this->default_values = $t;
         if (count($this->default_values)) {
             $this->getDefaultValueDao()->save($this->field->getId(), array_keys($this->default_values));
         }
     }
     if (is_array($this->decorators) && !empty($this->decorators)) {
         $values = $this->getBindValues();
         foreach ($this->decorators as $decorator) {
             $hexacolor = ColorHelper::RGBtoHexa($decorator->r, $decorator->g, $decorator->b);
             Tracker_FormElement_Field_List_BindDecorator::save($this->field->getId(), $values[$decorator->value_id]->getId(), $hexacolor);
         }
     }
 }
 /**
  * Process the request
  *
  * @param array $params the request parameters
  * @param bool  $no_redirect true if we do not have to redirect the user
  *
  * @return void
  */
 public function process($params, $no_redirect = false, $redirect = false)
 {
     $hp = Codendi_HTMLPurifier::instance();
     $value_dao = $this->getValueDao();
     foreach ($params as $key => $value) {
         switch ($key) {
             case 'is_rank_alpha':
                 $is_rank_alpha = $value ? 1 : 0;
                 if ($this->is_rank_alpha != $is_rank_alpha) {
                     $this->getDao()->save($this->field->id, $this->is_rank_alpha);
                     $GLOBALS['Response']->addFeedback('info', 'Alpha ranking updated');
                 }
                 break;
             case 'delete':
                 if (($row = $value_dao->searchById((int) $value)->getRow()) && $value_dao->delete((int) $value)) {
                     $redirect = true;
                     $GLOBALS['Response']->addFeedback('info', 'Value ' . $hp->purify($row['label'], CODENDI_PURIFIER_CONVERT_HTML) . 'deleted');
                 }
                 break;
             case 'edit':
                 foreach ($value as $value_id => $info) {
                     if (isset($this->values[$value_id])) {
                         $new_label = null;
                         $new_description = null;
                         $new_is_hidden = null;
                         if (isset($info['label']) && trim($info['label']) != $this->values[$value_id]->getLabel()) {
                             $new_label = trim($info['label']);
                         }
                         if (isset($info['description']) && trim($info['description']) != $this->values[$value_id]->getDescription()) {
                             $new_description = trim($info['description']);
                         }
                         if (isset($info['is_hidden']) && trim($info['is_hidden']) != $this->values[$value_id]->isHidden()) {
                             $new_is_hidden = trim($info['is_hidden']);
                         }
                         if ($new_label !== null || $new_description !== null || $new_is_hidden !== null) {
                             //something has changed. we can save it
                             $value_dao->save($value_id, $this->field->getId(), isset($new_label) ? $new_label : $this->values[$value_id]->getLabel(), isset($new_description) ? $new_description : $this->values[$value_id]->getDescription(), $this->values[$value_id]->getRank(), isset($new_is_hidden) ? $new_is_hidden : $this->values[$value_id]->isHidden());
                             unset($new_label, $new_description);
                         }
                     }
                 }
                 break;
             case 'add':
                 $valueMapping = array();
                 foreach (explode("\n", $value) as $new_value) {
                     //remove the \r submitted by the user
                     $new_value = trim(str_replace("\r", '', $new_value));
                     if ($new_value) {
                         if ($id = $value_dao->create($this->field->getId(), $new_value, '', 'end', 0)) {
                             $this->propagateCreation($this->field, $id);
                             $redirect = true;
                             $this->values[$id] = $value_dao->searchById($id)->getRow();
                             $valueMapping[] = $id;
                         }
                     }
                 }
                 if (isset($params['decorators'])) {
                     $params['decorator'] = array();
                     foreach ($params['decorators'] as $key => $deco) {
                         $params['decorator'][$valueMapping[$key]] = Tracker_FormElement_Field_List_BindDecorator::toHexa($deco->r, $deco->g, $deco->b);
                     }
                 }
                 break;
             default:
                 break;
         }
     }
     return parent::process($params, $no_redirect, $redirect);
 }
 private function fetchAdminEditRowModifiable(Tracker_FormElement_Field_List_Value $v)
 {
     $html = '';
     $hp = Codendi_HTMLPurifier::instance();
     $is_hidden = $v->isHidden();
     $html .= '<li id="staticvalue_' . $v->getId() . '" class="' . ($is_hidden ? 'tracker_admin_static_value_hidden' : '') . '">';
     $html .= '<span class="tracker-admin-bindvalue_grip">';
     $html .= $GLOBALS['HTML']->getImage('ic/grip.png');
     $html .= '</span>';
     $html .= '<span class="tracker-admin-bindvalue_decorator">';
     if (isset($this->decorators[$v->getId()])) {
         $html .= $this->decorators[$v->getId()]->decorateEdit();
     } else {
         $html .= Tracker_FormElement_Field_List_BindDecorator::noDecoratorEdit($this->field->id, $v->getId());
     }
     $html .= '</span>';
     //{{{ Actions
     $html .= '<span class="tracker-admin-bindvalue_actions">';
     $img_params = array();
     $icon_suffix = '';
     if ($this->canValueBeHidden($v)) {
         $checked = '';
         if ($is_hidden) {
             $icon_suffix = '-half';
         } else {
             $checked = 'checked="checked"';
         }
         $html .= '<input type="hidden" name="bind[edit][' . $v->getId() . '][is_hidden]" value="1" />';
         $html .= '<input type="checkbox" name="bind[edit][' . $v->getId() . '][is_hidden]" value="0" ' . $checked . ' class="tracker_admin_static_value_hidden_chk" />';
         $img_params['alt'] = 'show/hide value';
         $img_params['title'] = $GLOBALS['Language']->getText('plugin_tracker_formelement_admin', 'hide_value');
     } else {
         $icon_suffix = '--exclamation-hidden';
         $img_params['alt'] = 'cannot hide';
         $img_params['title'] = $GLOBALS['Language']->getText('plugin_tracker_formelement_admin', 'hide_value_impossible');
     }
     $html .= $GLOBALS['HTML']->getImage('ic/eye' . $icon_suffix . '.png', $img_params);
     $html .= ' ';
     if ($this->canValueBeDeleted($v)) {
         $html .= '<a title="Delete the value"
             href="' . TRACKER_BASE_URL . '/?' . http_build_query(array('tracker' => $this->field->getTracker()->id, 'func' => 'admin-formElement-update', 'formElement' => $this->field->getId(), 'bind-update' => 1, 'bind[delete]' => $v->getId())) . '">' . $GLOBALS['HTML']->getImage('ic/cross.png') . '</a>';
     } else {
         $html .= $GLOBALS['HTML']->getImage('ic/cross-disabled.png', array('title' => "You can't delete"));
     }
     $html .= '</span>';
     //}}}
     $html .= '<span class="tracker-admin-bindvalue_label">';
     $html .= '<input type="text" name="bind[edit][' . $v->getId() . '][label]" value="' . $hp->purify($v->getLabel(), CODENDI_PURIFIER_CONVERT_HTML) . '" />';
     $placeholder = $GLOBALS['Language']->getText('plugin_tracker_formelement_admin', 'description_placeholder');
     $html .= '<textarea name="bind[edit][' . $v->getId() . '][description]" class="tracker-admin-bindvalue_description_field" placeholder="' . $placeholder . '" cols="50" rows="3">';
     $html .= $hp->purify($v->getDescription(), CODENDI_PURIFIER_CONVERT_HTML);
     $html .= '</textarea>';
     $html .= '</span>';
     $html .= '</li>';
     return $html;
 }