Projekt

Obecné

Profil

<?php defined('SYSPATH') or die('No direct script access.');
/**
* FORGE dropdown input library.
*
* $Id: Form_Dropdown.php 1923 2008-02-05 14:49:08Z Shadowhand $
*
* @package Forge
* @author Kohana Team
* @copyright (c) 2007-2008 Kohana Team
* @license http://kohanaphp.com/license.html
*
* @method Form_Dropdown label(string $label)
* @method Form_Dropdown rules(string $rules)
* @method Form_Dropdown class(string $class)
* @method Form_Dropdown options(array $options)
* @method Form_Dropdown selected(int $selected_index)
*/
class Form_Dropdown extends Form_Input {

protected $data = array
(
'type' => 'dropdown',
'class' => 'dropdown',
'name' => '',
);

protected $protec = array('type');

public function __get($key)
{
if ($key == 'value')
{
return $this->selected;
}

return parent::__get($key);
}

public function html_element()
{
// Import base data
$base_data = $this->data;
if (in_array ("required", $this->rules))
$base_data['class'] .= " required";

// Get the options and default selection
$options = arr::remove('options', $base_data);
$selected = arr::remove('selected', $base_data);
arr::remove('label', $base_data);
$add_button = arr::remove('add_button', $base_data);
$add_button_title = arr::remove('add_button_title', $base_data);

$html = form::dropdown($base_data, $options, $selected);
if ($add_button)
{
$html .= '&nbsp;' . html::anchor(
url_lang::base().$this->data['add_button'],
html::image(array
(
'src' => url::base() . 'media/images/ico_add.gif',
'class' => 'ico_add',
'id' => $this->data['name'] . '_add_button'
)), array
(
'class' => 'ico_add',
'title' => $add_button_title
)
);
}
return $html;
}

/**
* Add button for adding object to drobbox
*
* @example Example format for town:
* Format string: '{town} - {quarter}, {zip_code}'
* Object has to have name $object_name and pushed into views variable and
* properties town, quarter and zip_code
*
* @author Onřej Fibich
* @param string $controller Controller to add
* @param string $format Format string of text output
* @param string $object_name Name of added object posted back from controller
* @param string $method Method of controller
* @param string $args Other arguments of controller
*/
public function add_button(
$controller = NULL, $format = '{name}', $object_name = '',
$method = 'add', $args = '')
{
if (empty($controller))
{
return;
}
$url = $controller.'/'.$method;
if (!empty($args))
{
$url .= '/'.$args;
}
$url .= '?popup=1';
$url .= '&amp;drop_down_dom_id='.str_replace('[]', '', $this->name());

if ($object_name)
{
$url .= '&amp;object_name='.$object_name;
}
else
{
$url .= '&amp;object_name='.inflector::singular($controller);
}

$url .= '&amp;el_format='.$format;
$this->data['add_button'] = $url;
$this->data['add_button_title'] = __('Add '.inflector::singular($controller));
}
/**
* Add button for adding object to drobbox
*
* @example Example format for town:
* Format string: '{town} - {quarter}, {zip_code}'
* Object has to have name $object_name and pushed into views variable and
* properties town, quarter and zip_code
*
* @author Onřej Fibich
* @param string $controller Controller to add
* @param string $format Format string of text output
* @param string $object_name Name of added object posted back from controller
* @param string $method Method of controller
* @param string $args Other arguments of controller
*/
public function add_simple_button($controller = NULL, $method = 'add', $args = '')
{
if (empty($controller))
{
return;
}
$url = $controller.'/'.$method;
if (!empty($args))
{
$url .= '/'.$args;
}
$url .= '?popup=1';
$this->data['add_button'] = $url;
$this->data['add_button_title'] = __('Add '.inflector::singular($controller));
}

protected function load_value()
{
if (is_bool($this->valid))
return;

$this->data['selected'] = $this->input_value($this->name);
}

} // End Form Dropdown
(16-16/50)