'Amount (min)', 'amount_max' => 'Amount (max)', 'match' => 'Matches on', 'repeat_freq' => 'Repetition', 'account_from_id' => 'Account from', 'account_to_id' => 'Account to', 'account_id' => 'Asset account' ]; return isset($labels[$name]) ? $labels[$name] : str_replace('_', ' ', ucfirst($name)); } /** * Return buttons for update/validate/return. * * @param $type * @param $name */ public static function ffOptionsList($type, $name) { $previousValue = \Input::old('post_submit_action'); $previousValue = is_null($previousValue) ? 'store' : $previousValue; /* * Store. */ $store = ''; switch ($type) { case 'create': $store = '
'; $store .= '
'; break; case 'update': $store = '
'; $store .= '
'; break; default: throw new FireflyException('Cannot create ffOptionsList for option (store) ' . $type); break; } /* * validate is always the same: */ $validate = '
'; /* * Store & return: */ switch ($type) { case 'create': $return = '
'; break; case 'update': $return = '
'; break; default: throw new FireflyException('Cannot create ffOptionsList for option (store+return) ' . $type); break; } return $store . $validate . $return; } /** * @param $type * @param $name * @param null $value * @param array $options * @param array $list * * @return string * @throws FireflyException */ public static function ffInput($type, $name, $value = null, array $options = array(), $list = []) { /* * add some defaults to this method: */ $options['class'] = 'form-control'; $options['id'] = 'ffInput_' . $name; $options['autocomplete'] = 'off'; $label = self::label($name, $options); /* * Make label and placeholder look nice. */ $options['placeholder'] = ucfirst($name); /* * Get prefilled value: */ if (\Session::has('prefilled')) { $prefilled = \Session::get('prefilled'); $value = isset($prefilled[$name]) && is_null($value) ? $prefilled[$name] : $value; } /* * Get the value. */ if (!is_null(\Input::old($name))) { /* * Old value overrules $value. */ $value = \Input::old($name); } /* * Get errors, warnings and successes from session: */ /** @var MessageBag $errors */ $errors = \Session::get('errors'); /** @var MessageBag $warnings */ $warnings = \Session::get('warnings'); /** @var MessageBag $successes */ $successes = \Session::get('successes'); /* * If errors, add some more classes. */ switch (true) { case (!is_null($errors) && $errors->has($name)): $classes = 'form-group has-error has-feedback'; break; case (!is_null($warnings) && $warnings->has($name)): $classes = 'form-group has-warning has-feedback'; break; case (!is_null($successes) && $successes->has($name)): $classes = 'form-group has-success has-feedback'; break; default: $classes = 'form-group'; break; } /* * Add some HTML. */ $html = '
'; $html .= ''; $html .= '
'; /* * Switch input type: */ unset($options['label']); switch ($type) { case 'text': $html .= \Form::input('text', $name, $value, $options); break; case 'amount': $html .= '
'; $html .= \Form::input('number', $name, $value, $options); $html .= '
'; break; case 'number': $html .= \Form::input('number', $name, $value, $options); break; case 'checkbox': $checked = $options['checked']; unset($options['checked'], $options['placeholder'], $options['autocomplete'], $options['class']); $html .= '
'; break; case 'date': $html .= \Form::input('date', $name, $value, $options); break; case 'select': $html .= \Form::select($name, $list, $value, $options); break; default: throw new FireflyException('Cannot handle type "' . $type . '" in FFFormBuilder.'); break; } /* * If errors, respond to them: */ if (!is_null($errors)) { if ($errors->has($name)) { $html .= ''; $html .= '

' . e($errors->first($name)) . '

'; } } unset($errors); /* * If warnings, respond to them: */ if (!is_null($warnings)) { if ($warnings->has($name)) { $html .= ''; $html .= '

' . e($warnings->first($name)) . '

'; } } unset($warnings); /* * If successes, respond to them: */ if (!is_null($successes)) { if ($successes->has($name)) { $html .= ''; $html .= '

' . e($successes->first($name)) . '

'; } } unset($successes); $html .= '
'; $html .= '
'; return $html; } }