/** * Renders the widget. * * @param string $name The element name * @param string $value The value selected 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()) { if (is_null($value)) { $value = array(); } $choices = $this->getOption('choices'); if ($choices instanceof sfCallable) { $choices = $choices->call(); } $associated = array(); $unassociated = array(); foreach ($choices as $key => $option) { if (in_array(strval($key), $value)) { $associated[$key] = $option; } else { $unassociated[$key] = $option; } } // we sort unassociated array by name //asort($unassociated); array_multisort(array_map('strtolower', $unassociated), $unassociated); $size = isset($attributes['size']) ? $attributes['size'] : (isset($this->attributes['size']) ? $this->attributes['size'] : 10); $associatedWidget = new sfWidgetFormSelect(array('multiple' => true, 'choices' => $associated), array('size' => $size, 'class' => $this->getOption('class_select') . '-selected')); $unassociatedWidget = new sfWidgetFormSelect(array('multiple' => true, 'choices' => $unassociated), array('size' => $size, 'class' => $this->getOption('class_select'))); return strtr($this->getOption('template'), array('%class%' => $this->getOption('class'), '%class_select%' => $this->getOption('class_select'), '%id%' => $this->generateId($name), '%label_associated%' => $this->getOption('label_associated'), '%label_unassociated%' => $this->getOption('label_unassociated'), '%associate%' => sprintf('<a href="#" onclick="%s">%s</a>', 'sfDoubleList.move(\'unassociated_' . $this->generateId($name) . '\', \'' . $this->generateId($name) . '\'); return false;', $this->getOption('associate')), '%unassociate%' => sprintf('<a href="#" onclick="%s">%s</a>', 'sfDoubleList.move(\'' . $this->generateId($name) . '\', \'unassociated_' . $this->generateId($name) . '\'); return false;', $this->getOption('unassociate')), '%associated%' => $associatedWidget->render($name), '%unassociated%' => $unassociatedWidget->render('unassociated_' . $name))); }
protected function renderThemeSelect() { if ($this->container->getService('theme_manager')->getNbThemesEnabled() > 1) { $themeSelect = new sfWidgetFormSelect(array('choices' => $this->container->getService('theme_manager')->getThemesEnabled())); return $this->helper->tag('div.widget16.mt3', $themeSelect->render('dm_select_theme', $this->user->getTheme()->getName())); } }
/** * @param string $name The element name * @param string $value The time 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()) { // convert value to an array $default = array('hour' => null, 'minute' => null, 'second' => null); if (is_array($value)) { $value = array_merge($default, $value); } else { $value = ctype_digit($value) ? (int) $value : strtotime($value); if (false === $value) { $value = $default; } else { // int cast required to get rid of leading zeros $value = array('hour' => (int) date('H', $value), 'minute' => (int) date('i', $value), 'second' => (int) date('s', $value)); } } $time = array(); $emptyValues = $this->getOption('empty_values'); // hours $widget = new sfWidgetFormSelect(array('choices' => $this->getOption('can_be_empty') ? array('' => $emptyValues['hour']) + $this->getOption('hours') : $this->getOption('hours')), array_merge($this->attributes, $attributes)); $time['%hour%'] = $widget->render($name . '[hour]', $value['hour']); // minutes $widget = new sfWidgetFormSelect(array('choices' => $this->getOption('can_be_empty') ? array('' => $emptyValues['minute']) + $this->getOption('minutes') : $this->getOption('minutes')), array_merge($this->attributes, $attributes)); $time['%minute%'] = $widget->render($name . '[minute]', $value['minute']); if ($this->getOption('with_seconds')) { // seconds $widget = new sfWidgetFormSelect(array('choices' => $this->getOption('can_be_empty') ? array('' => $emptyValues['second']) + $this->getOption('seconds') : $this->getOption('seconds')), array_merge($this->attributes, $attributes)); $time['%second%'] = $widget->render($name . '[second]', $value['second']); } return strtr($this->getOption('with_seconds') ? $this->getOption('format') : $this->getOption('format_without_seconds'), $time); }
public function render($name, $value = null, $attributes = array(), $errors = array()) { if ($value && is_string($value)) { $value = PetitionText::getHashForId($value); } return parent::render($name, $value, $attributes, $errors); }
/** * @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()) { // convert value to an array $default = array('year' => null, 'month' => null, 'day' => null); if (is_array($value)) { $value = array_merge($default, $value); } else { $value = (string) $value == (string) (int) $value ? (int) $value : strtotime($value); if (false === $value) { $value = $default; } else { $value = array('year' => date('Y', $value), 'month' => date('n', $value), 'day' => date('j', $value)); } } $date = array(); $emptyValues = $this->getOption('empty_values'); // days $widget = new sfWidgetFormSelect(array('choices' => $this->getOption('can_be_empty') ? array('' => $emptyValues['day']) + $this->getOption('days') : $this->getOption('days')), array_merge($this->attributes, $attributes)); $date['%day%'] = $widget->render($name . '[day]', $value['day']); // months $widget = new sfWidgetFormSelect(array('choices' => $this->getOption('can_be_empty') ? array('' => $emptyValues['month']) + $this->getOption('months') : $this->getOption('months')), array_merge($this->attributes, $attributes)); $date['%month%'] = $widget->render($name . '[month]', $value['month']); // years $widget = new sfWidgetFormSelect(array('choices' => $this->getOption('can_be_empty') ? array('' => $emptyValues['year']) + $this->getOption('years') : $this->getOption('years')), array_merge($this->attributes, $attributes)); $date['%year%'] = $widget->render($name . '[year]', $value['year']); return strtr($this->getOption('format'), $date); }
public function executeDcWidgetFormSelectDoubleListFinderPropel(sfWebRequest $request) { $widget = unserialize(base64_decode($request->getParameter('widget'))); $values = unserialize(base64_decode($request->getParameter('values'))); $values = is_null($values) ? array() : $values; $size = $request->getParameter('size'); $letter = $request->getParameter('letter'); $name = $request->getParameter('name'); $method = $widget->getOption('method'); $key_method = $widget->getOption('key_method'); $column = strtoupper($widget->getOption('column')); $model = $widget->getOption('model') . 'Peer'; $peer_method = $widget->getOption('peer_method'); $connection = $widget->getOption('connection'); if ($request->hasParameter('custom_handler')) { $handler = unserialize(base64_decode($request->getParameter('custom_handler'))); @call_user_func($handler, $widget, $values); } $c = $widget->getOption('criteria'); $c->add(constant($model . '::' . $column), $letter . '%', Criteria::LIKE); $choices = array(); foreach (call_user_func(array($model, $peer_method), $c, $connection) as $choice) { if (!in_array($choice->getPrimaryKey(), $values)) { $choices[$choice->{$key_method}()] = $choice->{$method}(); } } $widget = new sfWidgetFormSelect(array('multiple' => true, 'choices' => $choices), array('size' => $size, 'class' => $widget->getOption('class_select'))); return $this->renderText($widget->render($name)); }
public function render($name, $value = 0, $attributes = array(), $errors = array()) { if ($this->getOption('type') != 'select') { $radioWidget = new sfExtraWidgetFormSelectRadio(array('choices' => $this->getOption('choices'))); return $radioWidget->render($name, $value, $attributes, $errors); } else { $selectWidget = new sfWidgetFormSelect(array('choices' => $this->getOption('choices'))); return $selectWidget->render($name, $value, $attributes, $errors); } }
/** * render * * @param string $name * @param array $value * @param array $attributes * @param array $errors * * @return string * * @see sfWidgetForm */ public function render($name, $value = array(), $attributes = array(), $errors = array()) { if (!is_array($value)) { $value = array('value' => $value, 'public_flag' => ProfileTable::PUBLIC_FLAG_SNS); } else { $value = array_merge(array('value' => null, 'public_flag' => ProfileTable::PUBLIC_FLAG_SNS), $value); } $input = $this->getOption('widget')->render($name . '[value]', $value['value'], $attributes, $errors); if (!$this->getOption('is_edit_public_flag')) { return $input; } $publicFlagWidget = new sfWidgetFormSelect(array('choices' => Doctrine::getTable('Profile')->getPublicFlags())); return strtr($this->getOption('template'), array('%input%' => $input, '%public_flag%' => $publicFlagWidget->render($name . '[public_flag]', $value['public_flag'], $attributes, $errors))); }
/** * Renders the widget. * * @param string $name The element name * @param string $value The value selected 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()) { sfContext::getInstance()->getConfiguration()->loadHelpers(array('I18N')); $attributes['class'] = 'chzn-select'; if (false !== ($default_text = $this->getOption('default_text'))) { $attributes['data-placeholder'] = __($default_text); } else { $text = $this->getOption('multiple') ? 'Select Some Options' : 'Select Some Option'; $attributes['data-placeholder'] = __($text); } $no_results_text = $this->getOption('no_results_text') ? $this->getOption('no_results_text') : 'No results matches'; $this->setOption('no_results_text', $this->translate($no_results_text)); $rendered_widget = parent::render($name, $value, $attributes, $errors); return strtr('%rendered_widget%%chosen_initialization%', array('%rendered_widget%' => $rendered_widget, '%chosen_initialization%' => $this->getChosenInitialization($this->generateId($name)))); }
public function render($name, $value = null, $attributes = array(), $errors = array()) { $emptyValue = $this->getOption('empty_value'); if ($this->getOption('use') == 'days') { $widget = new sfWidgetFormSelect(array('choices' => $this->getOption('can_be_empty') ? array('' => $emptyValue) + $this->getOption('days') : $this->getOption('days')), array_merge($this->attributes, $attributes)); $result = $widget->render($name, $value); } if ($this->getOption('use') == 'months') { $widget = new sfWidgetFormSelect(array('choices' => $this->getOption('can_be_empty') ? array('' => $emptyValue) + $this->getOption('months') : $this->getOption('months')), array_merge($this->attributes, $attributes)); $result = $widget->render($name, $value); } if ($this->getOption('use') == 'years') { $widget = new sfWidgetFormSelect(array('choices' => $this->getOption('can_be_empty') ? array('' => $emptyValue) + $this->getOption('years') : $this->getOption('years')), array_merge($this->attributes, $attributes)); $result = $widget->render($name, $value); } return $result; }
/** * @param string $name The element name * @param string $value The value 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()) { $input = parent::render($name, $value, $attributes, $errors); if (!$this->getOption('edit_mode')) { return $input; } if ($this->getOption('with_delete')) { $deleteName = ']' == substr($name, -1) ? substr($name, 0, -1) . '_delete]' : $name . '_delete'; $delete = $this->renderTag('input', array_merge(array('type' => 'checkbox', 'name' => $deleteName), $attributes)); $deleteLabel = $this->translate($this->getOption('delete_label')); $deleteLabel = $this->renderContentTag('label', $deleteLabel, array_merge(array('for' => $this->generateId($deleteName)))); } else { $delete = ''; $deleteLabel = ''; } return strtr($this->getOption('template'), array('%input%' => $input, '%delete%' => $delete, '%delete_label%' => $deleteLabel)); }
/** * @see sfWidgetFormDate */ public function render($name, $value = null, $attributes = array(), $errors = array()) { $dateTimeValue = is_array($value) ? sprintf('%04d-%02d-%02d', $value['year'], $value['month'], $value['day']) : $value; try { $dateTime = new DateTime($dateTimeValue); } catch (Exception $e) { $dateTime = new DateTime(); $dateTimeValue = null; } $dayDefault = $dateTime->format('j'); $monthDefault = $dateTime->format('n'); $year = $dateTime->format('Y'); $days = $this->getOption('days'); $months = $this->getOption('months'); if ($this->getOption('can_be_empty')) { $emptyValues = $this->getOption('empty_values'); $days = array('' => $emptyValues['day']) + $days; $months = array('' => $emptyValues['month']) + $months; if (!$dateTimeValue) { $dayDefault = $emptyValues['day']; $monthDefault = $emptyValues['month']; $year = $emptyValues['year']; } } if (is_array($value) && !checkdate((int) $value['month'], (int) $value['day'], (int) $value['year'])) { $dayDefault = $value['day']; $monthDefault = $value['month']; $year = $value['year']; } // days $widget = new sfWidgetFormSelect(array('choices' => $days), array_merge($this->attributes, $attributes)); $date['%day%'] = $widget->render($name . '[day]', $dayDefault); // months $widget = new sfWidgetFormSelect(array('choices' => $months), array_merge($this->attributes, $attributes)); $date['%month%'] = $widget->render($name . '[month]', $monthDefault); // years $attributes['size'] = '5'; $widget = new sfWidgetFormInput(array(), array_merge(array('class' => 'input_text'), $this->attributes, $attributes)); if ('mobile_frontend' === sfConfig::get('sf_app')) { opToolkit::appendMobileInputModeAttributesForFormWidget($widget, 'numeric'); } $date['%input_year%'] = $widget->render($name . '[year]', $year); return strtr($this->getOption('format'), $date); }
/** * @param string $name * @param string $value * @param array $options * @param array $attributes * @return string rendered widget */ protected function renderYearWidget($name, $value, $options, $attributes) { $widget = new sfWidgetFormSelect($options, $attributes); return $widget->render($name, $value); }
<?php $select = new sfWidgetFormSelect(array('choices' => $buses)); $result = $select->render('buses_from_route'); echo json_encode(array('buses' => $result));
/** * @see sfWidgetFormSelect */ public function render($name, $value = null, $attributes = array(), $errors = array()) { return parent::render($name . '[text]', $value, $attributes = array(), $errors = array()); }
/** * Render function * * @param string $name * @param string $value * @param array $attributes * @param array $errors * @return mixed */ public function render($name, $value = null, $attributes = array(), $errors = array()) { $string = parent::render($name, $value, $attributes, $errors); $country_id = str_replace('[', '_', $name); $country_id = str_replace(']', '', $country_id); $state_id = str_replace('country', 'state', $country_id); $state_name = str_replace('country', 'state', $name); $route = sfContext::getInstance()->getController()->genUrl('rtAdmin/stateInput'); $js = <<<EOS <script type="text/javascript"> \$(function() { \$('#{$country_id}').change(function() { var holder = \$('#{$state_id}').parent(); holder.html('<span class="loading">Loading states...</span>'); \$('#{$state_id}').remove(); \$.ajax({ type: "POST", url: '{$route}', data: ({ country : \$(this).find('option:selected').attr('value'), id : '{$state_id}', name : '{$state_name}' }), dataType: "html", success: function(data) { holder.html(data); } }); }); }); </script> EOS; return $js . $string; }
/** * Renders the widget. * * @param string $name The element name * @param string $value The value selected 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()) { if (is_null($value)) { $value = array(); } $choices = $this->getOption('choices'); if ($choices instanceof sfCallable) { $choices = $choices->call(); } $associated = array(); $unassociated = array(); if (!is_array($value)) { $value = array($value); } foreach ($choices as $key => $option) { if (in_array(strval($key), $value)) { $associated[$key] = $option; } else { $unassociated[$key] = $option; } } $size = isset($attributes['size']) ? $attributes['size'] : (isset($this->attributes['size']) ? $this->attributes['size'] : 10); $id = $this->generateId($name); $error_id = 'error_' . $id; // The two select boxes $associatedWidget = new sfWidgetFormSelect(array('multiple' => true, 'choices' => $associated), array('size' => $size, 'class' => $this->getOption('class_select') . '-selected')); $unassociatedWidget = new sfWidgetFormSelect(array('multiple' => true, 'choices' => $unassociated), array('size' => $size, 'class' => $this->getOption('class_select'))); // The input box used to filter content of unassociated select box $filterWidget = new sfWidgetFormInputText(array(), array('class' => $this->getOption('filter_class'))); // Options to be passed to the renderTag of reset filter image $filterResetOptions = array('src' => '/images/remove.png', 'id' => 'filter_' . $id . "_clear", 'class' => 'filter_clear', 'alt' => __('Reset filter'), 'title' => __('Reset filter')); $addOptionHTML = ''; // If add of a value in distant table is possible and activated if ($this->getOption('add_active')) { // Define the add value input box $addOptionWidget = new sfWidgetFormInputText(array(), array('id' => 'add_' . $id, 'class' => $this->getOption('add_class'))); $addOptionWidget->setLabel(__('Add new value:')); // Options to be passed to the renderTag of add option image $addImageOptions = array('src' => '/images/add_green.png', 'id' => 'add_' . $id . '_image', 'class' => 'add_option', 'alt' => __('Add value'), 'title' => __('Add value')); // Options to be passed to the timer displayed while tryin' to insert a value $addTimerImageOptions = array('src' => '/images/loader.gif', 'id' => 'add_' . $id . '_loader', 'style' => 'display:none;'); $addLinkOptions = array('id' => 'add_' . $id . '_link', 'class' => 'add_option', 'href' => url_for($this->getOption('add_url'))); $addOptionHTML = $this->renderContentTag('label', $addOptionWidget->getLabel(), array('for' => 'add_' . $id)) . $addOptionWidget->render('add_' . $name) . $this->renderContentTag('a', $this->renderTag('img', $addImageOptions), $addLinkOptions) . $this->renderTag('img', $addTimerImageOptions); } return strtr($this->getOption('template'), array('%class%' => $this->getOption('class'), '%class_select%' => $this->getOption('class_select'), '%id%' => $id, '%label_associated%' => $this->getOption('label_associated'), '%label_unassociated%' => $this->getOption('label_unassociated'), '%associate%' => sprintf('<a href="#" id="associate_' . $id . '">%s</a>', $this->getOption('associate')), '%unassociate%' => sprintf('<a href="#" id="unassociate_' . $id . '">%s</a>', $this->getOption('unassociate')), '%associated%' => $associatedWidget->render($name), '%unassociated%' => $unassociatedWidget->render('unassociated_' . $name), '%filter%' => $filterWidget->render('filter_' . $name), '%filter_reset%' => $this->renderTag('img', $filterResetOptions), '%add_option%' => $addOptionHTML, '%error_id%' => $error_id)); }
/** * Renders the widget. * * @param string $name The element name * @param string $value The time 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()) { if (array_key_exists('class', $attributes)) { $attributes['class'] .= ' timepicker'; } else { $attributes['class'] = 'timepicker'; } // convert value to an array $default = array('hour' => null, 'minute' => null); if (is_array($value)) { $value = array_merge($default, $value); } else { $value = ctype_digit($value) ? (int) $value : strtotime($value); if (false === $value) { $value = $default; } else { // int cast required to get rid of leading zeros $value = array('hour' => (int) date('H', $value), 'minute' => (int) date('i', $value)); } } $widget = new sfWidgetFormSelect(array('choices' => $this->getChoices(), 'id_format' => $this->getOption('id_format')), array_merge($this->attributes, $attributes)); if (is_numeric($value['hour']) && is_numeric($value['minute'])) { $value = sprintf('%02d', $value['hour']) . ':' . sprintf('%02d', $value['minute']); } else { $value = ''; } return $widget->render($name, $value); }
$t->diag('choices as a callable'); function choice_callable() { return array(1, 2, 3); } $w = new sfWidgetFormSelect(array('choices' => new sfCallable('choice_callable'))); $dom->loadHTML($w->render('foo')); $css = new sfDomCssSelector($dom); $t->is(count($css->matchAll('#foo option')->getNodes()), 3, '->render() accepts a sfCallable as a choices option'); // attributes $t->diag('attributes'); $w = new sfWidgetFormSelect(array('choices' => array(0, 1, 2))); $dom->loadHTML($w->render('foo', null, array('disabled' => 'disabled'))); $css = new sfDomCssSelector($dom); $t->is(count($css->matchAll('select[disabled="disabled"]')->getNodes()), 1, '->render() does not pass the select HTML attributes to the option tag'); $t->is(count($css->matchAll('option[disabled="disabled"]')->getNodes()), 0, '->render() does not pass the select HTML attributes to the option tag'); $w = new sfWidgetFormSelect(array('choices' => array(0, 1, 2)), array('disabled' => 'disabled')); $dom->loadHTML($w->render('foo')); $css = new sfDomCssSelector($dom); $t->is(count($css->matchAll('select[disabled="disabled"]')->getNodes()), 1, '->render() does not pass the select HTML attributes to the option tag'); $t->is(count($css->matchAll('option[disabled="disabled"]')->getNodes()), 0, '->render() does not pass the select HTML attributes to the option tag'); // __clone() $t->diag('__clone()'); $w = new sfWidgetFormSelect(array('choices' => new sfCallable(array($w, 'foo')))); $w1 = clone $w; $callable = $w1->getOption('choices')->getCallable(); $t->is(spl_object_hash($callable[0]), spl_object_hash($w1), '__clone() changes the choices is a callable and the object is an instance of the current object'); $w = new sfWidgetFormSelect(array('choices' => new sfCallable(array($a = new stdClass(), 'foo')))); $w1 = clone $w; $callable = $w1->getOption('choices')->getCallable(); $t->is(spl_object_hash($callable[0]), spl_object_hash($a), '__clone() changes nothing if the choices is a callable and the object is not an instance of the current object');
protected function renderHiddenInput($name, $value) { $hidden = new sfWidgetFormSelect(array('multiple' => $this->getOption('multiple'), 'is_hidden' => true, 'choices' => $this->getOption('choices')), array('style' => 'display: none')); return $hidden->render($name, $value); }
?> <?php echo 'Online information of routes and itineraries - NoJam'; end_slot(); ?> <h1>Routes</h1> <div class="column span-8 box"> <div class="filter"> <?php $select = new sfWidgetFormDoctrineChoice(array('model' => 'NjRoute', 'add_empty' => 'Select a route'), array('class' => 'select-box')); echo $select->render('nj_route_id'); ?> <?php $select = new sfWidgetFormSelect(array('choices' => $buses), array('class' => 'select-box')); echo $select->render('buses_from_route'); ?> </div> <br /> <hr class="space"/> <div> <table> <thead> <th colspan="100%"><h2>Schedules</h2></th> </thead> <tfoot> <th colspan="100%">Schedules</th> </tfoot> <tbody> <?php for ($i = 0; $i < 10; $i++) {
/** * Renders the widget. * * @param string $name The element name * @param string $value The value selected 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()) { $attributes["class"] = "select_jquery_autocomplete"; return parent::render($name, $value, $attributes, $errors); }
/** * @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()) { if (is_null($value)) { $value = array(); } $choices = $this->getChoices(); $associated = array(); foreach ($choices as $key => $option) { if (in_array(strval($key), $value)) { $associated[$key] = $option; } } $url = str_replace('%model%', $this->getOption('model'), $this->getOption('json_url')); $json_url = 'json_url : "' . $url . '",'; $cache = $this->getOption('cache') ? 'cache : true,' : ''; $newel = $this->getOption('newel') ? 'newel : true,' : ''; $firstselected = $this->getOption('firstselected') ? 'firstselected : "' . $this->getOption('firstselected') . '",' : ''; $filter_case = $this->getOption('filter_case') ? 'filter_case : true,' : ''; $filter_hide = $this->getOption('filter_hide') ? 'filter_hide : true,' : ''; $filter_selected = $this->getOption('filter_selected') ? 'filter_selected : true,' : ''; $complete_text = $this->getOption('complete_text') ? 'complete_text : "' . $this->getOption('complete_text') . '",' : ''; $maxshownitems = $this->getOption('maxshownitems') ? 'maxshownitems : "' . $this->getOption('maxshownitems') . '",' : ''; $maxitems = $this->getOption('maxitems') ? 'maxitems : "' . $this->getOption('maxitems') . '",' : ''; $onselect = $this->getOption('onselect') ? 'onselect : "' . $this->getOption('onselect') . '",' : ''; $onremove = $this->getOption('onremove') ? 'onremove : "' . $this->getOption('onremove') . '",' : ''; $delay = $this->getOption('delay') ? 'delay : "' . $this->getOption('delay') . '",' : ''; $config = $json_url . $cache . $newel . $firstselected . $filter_case . $filter_hide . $filter_selected . $complete_text . $maxshownitems . $maxitems . $onselect . $onremove . $delay; $config = substr($config, 0, -1); $associatedWidget = new sfWidgetFormSelect(array('multiple' => true, 'choices' => $associated)); return strtr($this->getOption('template'), array('%id%' => $this->generateId($name), '%config%' => $config, '%associated%' => $associatedWidget->render($name))); }
public function render($name, $value = null, $attributes = array(), $errors = array()) { if (empty($value) || !is_array($value)) { $value = array(); } $defaultDuration = $this->getOption('default_duration'); if (!isset($value['duration'])) { $value['duration'] = $defaultDuration; } if (!isset($value['ampm'])) { $value['ampm'] = self::HALF_DAY_AM; } if (!isset($value['time'])) { $value['time'] = $this->getDefaultTimeRangeValues(); } $durationChoices = array(); if ($this->getOption('enable_full_day')) { $durationChoices['full_day'] = __('Full Day'); } if ($this->getOption('enable_half_day')) { $durationChoices['half_day'] = __('Half Day'); } if ($this->getOption('enable_specify_time')) { $durationChoices['specify_time'] = __('Specify Time'); } $hideCss = 'style="display:none"'; $durationWidget = new sfWidgetFormSelect(array('choices' => $durationChoices), array('class' => 'leave_duration_dropdown')); $halfDayWidget = new sfWidgetFormSelect(array('choices' => array(self::HALF_DAY_AM => __('Morning'), self::HALF_DAY_PM => __('Afternoon'))), array('class' => 'leave_duration_ampm')); // if $timeWidget = new ohrmWidgetFormTimeRange(array('from_time' => new ohrmWidgetTimeDropDown(), 'to_time' => new ohrmWidgetTimeDropDown())); // IDs $fullDayContentId = $this->generateId($name . '[full_day_content]'); $halfDayContentId = $this->generateId($name . '[half_day_content]'); $specifyTimeContentId = $this->generateId($name . '[specify_time_content]'); $fullDayContent = strtr($this->getOption('full_day_template'), array('%full_day_content_id%' => $fullDayContentId, '%display%' => $defaultDuration == 'full_day' ? '' : $hideCss)); $halfDayContent = strtr($this->getOption('half_day_template'), array('%half_day_content_id%' => $halfDayContentId, '%am_pm%' => $halfDayWidget->render($name . '[ampm]', $value['ampm']), '%display%' => $defaultDuration == 'half_day' ? '' : $hideCss)); $specifyTimeContent = strtr($this->getOption('specify_time_content'), array('%specify_time_content_id%' => $specifyTimeContentId, '%time_range%' => $timeWidget->render($name . '[time]', $value['time']), '%display%' => $defaultDuration == 'specify_time' ? '' : $hideCss)); $html = strtr($this->getOption('template'), array('%duration%' => $durationWidget->render($name . '[duration]', $value['duration']), '%full_day_content%' => $fullDayContent, '%half_day_content%' => $halfDayContent, '%specify_time_content%' => $specifyTimeContent)); $javaScript = <<<EOF <script type="text/javascript"> \$(document).ready(function(){ orangehrm.widgets.formLeaveDuration.handleDurationChange(\$("#%duration_id%").val(), '%full_day_content_id%', '%half_day_content_id%', '%specify_time_content_id%'); \$("#%duration_id%").change(function() { orangehrm.widgets.formLeaveDuration.handleDurationChange(\$(this).val(), '%full_day_content_id%', '%half_day_content_id%', '%specify_time_content_id%'); }); }); </script> EOF; $javaScript = strtr($javaScript, array('%duration_id%' => $this->generateId($name . '[duration]'), '%full_day_content_id%' => $fullDayContentId, '%half_day_content_id%' => $halfDayContentId, '%specify_time_content_id%' => $specifyTimeContentId)); return $html . $javaScript; }