Refactor Search widget

This commit is contained in:
Samuel Georges 2015-02-28 13:45:14 +11:00
parent bb8292d883
commit a57505b227
1 changed files with 30 additions and 33 deletions

View File

@ -1,6 +1,6 @@
<?php namespace Backend\Widgets;
use Input;
use Lang;
use Backend\Classes\WidgetBase;
/**
@ -12,30 +12,38 @@ use Backend\Classes\WidgetBase;
*/
class Search extends WidgetBase
{
/**
* {@inheritDoc}
*/
protected $defaultAlias = 'search';
//
// Configurable properties
//
/**
* @var string Search placeholder text.
*/
public $placeholder;
public $prompt;
/**
* @var bool Field show grow when selected.
*/
public $growable = true;
/**
* @var string Active search term pulled from session data.
*/
public $activeTerm;
/**
* @var string Custom partial file definition, in context of the controller.
*/
public $customPartial;
public $partial;
//
// Object properties
//
/**
* {@inheritDoc}
*/
protected $defaultAlias = 'search';
/**
* @var string Active search term pulled from session data.
*/
protected $activeTerm;
/**
* @var array List of CSS classes to apply to the list container element.
@ -43,26 +51,15 @@ class Search extends WidgetBase
public $cssClasses = [];
/**
* Constructor.
* Initialize the widget, called by the constructor and free from its parameters.
*/
public function __construct($controller, $configuration = [])
public function init()
{
parent::__construct($controller, $configuration);
/*
* Process configuration
*/
if (isset($this->config->prompt)) {
$this->placeholder = trans($this->config->prompt);
}
if (isset($this->config->partial)) {
$this->customPartial = $this->config->partial;
}
if (isset($this->config->growable)) {
$this->growable = $this->config->growable;
}
$this->fillFromConfig([
'prompt',
'partial',
'growable',
]);
/*
* Add CSS class styles
@ -81,8 +78,8 @@ class Search extends WidgetBase
{
$this->prepareVars();
if ($this->customPartial) {
return $this->controller->makePartial($this->customPartial);
if ($this->partial) {
return $this->controller->makePartial($this->partial);
}
else {
return $this->makePartial('search');
@ -95,7 +92,7 @@ class Search extends WidgetBase
public function prepareVars()
{
$this->vars['cssClasses'] = implode(' ', $this->cssClasses);
$this->vars['placeholder'] = $this->placeholder;
$this->vars['placeholder'] = Lang::get($this->prompt);
$this->vars['value'] = $this->getActiveTerm();
}