/** * @param string $name The element name * @param string $value The date displayed in this widget * @param array $attributes An array of HTML attributes to be merged with the default HTML attributes * @param array $errors An array of errors for the field * * @return string An HTML tag string * * @see sfWidgetForm */ public function render($name, $value = null, $attributes = array(), $errors = array()) { $prefix = $this->generateId($name); $image = ''; if (false !== $this->getOption('image')) { $image = sprintf(', buttonImage: "%s", buttonImageOnly: true', $this->getOption('image')); } return parent::render($name, $value, $attributes, $errors) . $this->renderTag('input', array('type' => 'hidden', 'size' => 10, 'id' => $id = $this->generateId($name) . '_jquery_control', 'disabled' => 'disabled')) . sprintf(<<<EOF <script type="text/javascript"> function wfd_%s_read_linked() { jQuery("#%s").val(jQuery("#%s").val() + "-" + jQuery("#%s").val() + "-" + jQuery("#%s").val()); return {}; } function wfd_%s_update_linked(date) { jQuery("#%s").val(1*date.substring(0, 4)); jQuery("#%s").val(1*date.substring(5, 7)); jQuery("#%s").val(1*date.substring(8)); } function wfd_%s_check_linked_days() { var daysInMonth = 32 - new Date(jQuery("#%s").val(), jQuery("#%s").val() - 1, 32).getDate(); jQuery("#%s option").attr("disabled", ""); jQuery("#%s option:gt(" + (%s) +")").attr("disabled", "disabled"); if (jQuery("#%s").val() > daysInMonth) { jQuery("#%s").val(daysInMonth); } } jQuery(document).ready(function() { jQuery("#%s").datepicker(jQuery.extend({}, { minDate: new Date(%s, 1 - 1, 1), maxDate: new Date(%s, 12 - 1, 31), beforeShow: wfd_%s_read_linked, onSelect: wfd_%s_update_linked, showOn: "button" %s }, jQuery.datepicker.regional["%s"], %s, {dateFormat: "yy-mm-dd"})); }); jQuery("#%s, #%s, #%s").change(wfd_%s_check_linked_days); </script> EOF , $prefix, $id, $this->generateId($name . '[year]'), $this->generateId($name . '[month]'), $this->generateId($name . '[day]'), $prefix, $this->generateId($name . '[year]'), $this->generateId($name . '[month]'), $this->generateId($name . '[day]'), $prefix, $this->generateId($name . '[year]'), $this->generateId($name . '[month]'), $this->generateId($name . '[day]'), $this->generateId($name . '[day]'), $this->getOption('can_be_empty') ? 'daysInMonth' : 'daysInMonth - 1', $this->generateId($name . '[day]'), $this->generateId($name . '[day]'), $id, min($this->getOption('years')), max($this->getOption('years')), $prefix, $prefix, $image, $this->getOption('culture'), $this->getOption('config'), $this->generateId($name . '[day]'), $this->generateId($name . '[month]'), $this->generateId($name . '[year]'), $prefix); }
/** * Render html and javascript for current datepicker * * @param string datepicker name * @param mixed default value * @param array html attributes * @param array errors * @return string html and javascript * @author Carlos Escribano <*****@*****.**> */ public function render($name, $value = null, $attributes = array(), $errors = array()) { $sfContext = sfContext::getInstance(); $sfResponse = $sfContext->getResponse(); $html = array(); $culture = explode('_', $this->getOption('culture')); $culture = array_shift($culture); if ($culture != 'en') { $sfResponse->addJavascript("i18n/ui.datepicker-{$culture}.js", 'last'); } $ids = array('id' => $this->generateId($name), 'control' => $this->generateId($name) . '_jquery_control', 'day' => $this->generateId($name . "[day]"), 'month' => $this->generateId($name . "[month]"), 'year' => $this->generateId($name . "[year]")); $image = false !== $this->getOption('image') ? sprintf("showOn: 'button', buttonImage: '%s', buttonImageOnly: true", $this->getOption('image')) : null; $dp_culture = $culture == 'en' ? '' : $culture; $uiJs = file_get_contents(dirname(__FILE__) . DIRECTORY_SEPARATOR . basename(__FILE__, ".php") . ".js.php"); $html[] = parent::render($name, $value, $attributes, $errors); $html[] = $this->renderTag('input', array('type' => 'hidden', 'size' => 10, 'id' => $ids['control'], 'disabled' => 'disabled')); $html[] = sprintf($uiJs, $ids['id'], $ids['control'], $ids['day'], $ids['month'], $ids['year'], $dp_culture, $ids['id'], $dp_culture, $ids['day'], $ids['month'], $ids['year'], $ids['control'], min($this->getOption('years')), max($this->getOption('years')), $ids['id'], $ids['id'], ", {$image}", $culture, $this->getOption('config')); return implode("\n", $html); }
/** * @param string $name The element name * @param string $value The date displayed in this widget * @param array $attributes An array of HTML attributes to be merged with the default HTML attributes * @param array $errors An array of errors for the field * * @return string An HTML tag string * * @see sfWidgetForm */ public function render($name, $value = null, $attributes = array(), $errors = array()) { $prefix = $this->generateId($name); $image = ''; if (false !== $this->getOption('image')) { $image = sprintf(', buttonImage: %s, buttonImageOnly: true', $this->getOption('image')); } return parent::render($name, $value, $attributes, $errors) . $this->renderTag('input', array('type' => 'hidden', 'size' => 10, 'id' => $id = $this->generateId($name) . '_jquery_control', 'disabled' => 'disabled')) . sprintf(<<<EOF <script type="text/javascript"> function %s_read_linked() { \$("#%s").val(\$("#%s").val() + "/" + \$("#%s").val() + "/" + \$("#%s").val()); return {}; } function %s_update_linked(date) { \$("#%s").val(date.substring(0, 2)); \$("#%s").val(parseInt(date.substring(3, 5), 10)); \$("#%s").val(date.substring(6, 10)); } jQuery(document).ready(function() { \$("#%s").datepicker(\$.extend({}, { minDate: new Date(%s, 1 - 1, 1), maxDate: new Date(%s, 12 - 1, 31), onSelect: %s_update_linked, beforeShow: %s_read_linked, % showOn: "both" %s }, \$.datepicker.regional["%s"])); }) ; </script> EOF , $prefix, $id, $this->generateId($name . '[day]'), $this->generateId($name . '[month]'), $this->generateId($name . '[year]'), $prefix, $this->generateId($name . '[day]'), $this->generateId($name . '[month]'), $this->generateId($name . '[year]'), $id, min($this->getOption('years')), max($this->getOption('years')), $prefix, $prefix, $this->getOption('config'), $image, $this->getOption('culture')); }
* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ require_once dirname(__FILE__) . '/../../../bootstrap/unit.php'; $t = new lime_test(7); $dom = new DomDocument('1.0', 'utf-8'); $dom->validateOnParse = true; // ->configure() $t->diag('->configure()'); $w = new sfWidgetFormI18nDate(array('culture' => 'fr')); $t->is($w->getOption('format'), '%day%/%month%/%year%', '->configure() automatically changes the date format for the given culture'); $w = new sfWidgetFormI18nDate(array('culture' => 'en_US')); $t->is($w->getOption('format'), '%month%/%day%/%year%', '->configure() automatically changes the date format for the given culture'); $w = new sfWidgetFormI18nDate(array('culture' => 'sr')); $t->is($w->getOption('format'), '%day%.%month%.%year%.', '->configure() automatically changes the date format for the given culture'); $w = new sfWidgetFormI18nDate(array('culture' => 'fr', 'month_format' => 'name')); $months = $w->getOption('months'); $t->is($months[2], 'février', '->configure() automatically changes the date format for the given culture'); $w = new sfWidgetFormI18nDate(array('culture' => 'fr', 'month_format' => 'short_name')); $months = $w->getOption('months'); $t->is($months[2], 'févr.', '->configure() automatically changes the date format for the given culture'); $w = new sfWidgetFormI18nDate(array('culture' => 'fr', 'month_format' => 'number')); $months = $w->getOption('months'); $t->is($months[2], 2, '->configure() automatically changes the date format for the given culture'); try { new sfWidgetFormI18nDate(array('culture' => 'fr', 'month_format' => 'nonexistant')); $t->fail('->configure() throws an InvalidArgumentException if the month_format type does not exist'); } catch (InvalidArgumentException $e) { $t->pass('->configure() throws an InvalidArgumentException if the month_format type does not exist'); }
public function __construct($options = array(), $attributes = array()) { $years = range(date('Y'), date('Y') + 5); $options['years'] = isset($options['years']) ? $options['years'] : array_combine($years, $years); return parent::__construct(array_merge($this->_options, $options), $attributes); }
public function getStylesheets() { return array_merge(parent::getStylesheets(), array('lib.ui-datepicker' => null)); }
/** * @param string $name The element name * @param string $value The date displayed in this widget * @param array $attributes An array of HTML attributes to be merged with the default HTML attributes * @param array $errors An array of errors for the field * * @return string An HTML tag string * * @see sfWidgetForm */ protected function configure($options = array(), $attributes = array()) { $options['culture'] = isset($options['culture']) ? $options['culture'] : dm::getUser()->getCulture(); parent::configure($options, $attributes); $this->setOption('culture', $options['culture']); }
/** * @see sfWidgetFormI18nDate */ protected function getDateFormat($culture) { $result = parent::getDateFormat($culture); return str_replace('%year%', '%input_year%', $result); }