/**
  * 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);
 }
 /**
  * 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)) {
             $dao = new Tracker_FormElement_Field_List_Bind_DefaultvalueDao();
             $dao->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 = Tracker_FormElement_Field_List_BindDecorator::toHexa($decorator->r, $decorator->g, $decorator->b);
             Tracker_FormElement_Field_List_BindDecorator::save($this->field->getId(), $values[$decorator->value_id]->getId(), $hexacolor);
         }
     }
 }