_options) { $this->_options = Qs_Array::exclude($this->getElement()->getAttribs(), 'helper', 'options'); } return $this->_options; } public function setOptions(array $options) { if (isset($options['options'])) { unset($options['options']); } foreach ($options as $key => $value) { $method = 'set' . ucfirst($key); if (method_exists($this, $method)) { $this->$method($value); } else { $this->_options[$key] = $value; } } return $this; } public function initRender() { $doc = Zend_Registry::get('doc'); $doc->addScript('js/jquery-ui.js') ->addScript('js/jquery-qtip.js') ->addScript('js/jquery-qtip-extended.js') ->addScript('js/lib/form-element-date.js') ->addStylesheet('css/thirdpart/jquery-ui.css'); $id = $this->getElement()->getId(); $doc->addInitFunction('Qs_Form_Element_Date.init', array($id, $this->_getScriptOptions(), $this->_getQtipOptions())); $value = $this->getElement()->getValue(); $date = strtotime($value); if ($date) { $doc->addInitFunction( 'Qs_Form_Element_Date.callMethod', array( $id, 'setDate', new Zend_Json_Expr('new Date(' . date('Y', $date) . ', ' . (date('n', $date) - 1) . ', ' . date('j', $date) . ')') ) ); } return $this; } public function render($content) { // init options $this->getOptions(); $tag = $this->getTag(); $element = $this->getElement(); $id = $element->getId(); $view = $element->getView(); $placement = $this->getPlacement(); $separator = $this->getSeparator(); $name = $element->getFullyQualifiedName(); $elementContent = $view->formHidden($name, $element->getValue(), array('id' => $id)); if (false !== ($pos = strrpos($name, '['))) { $pos++; $_name = substr($name, 0, $pos) . '_' . substr($name, $pos); } else { $_name = '_' . $name; } if (false !== ($pos = strrpos($id, '-'))) { $pos++; $_id = substr($id, 0, $pos) . '_' . substr($id, $pos); } else { $_id = '_' . $id; } $elementContent .= $view->formText($_name, '', array('class' => 'date', 'id' => $_id)); switch ($placement) { case self::APPEND: return $content . $separator . $elementContent; case self::PREPEND: return $elementContent . $separator . $content; } } protected function _renderScriptOptions() { $options = $this->_getScriptOptions(); return json_encode($options); } protected function _getQtipOptions() { $qtipOptions = Qs_Array::get($this->getOptions(), 'qtip'); return $qtipOptions; } protected function _getScriptOptions() { $options = array( 'altField' => '#' . $this->getElement()->getId(), 'altFormat' => 'yy-mm-dd', 'dateFormat' => $this->getElement()->getFormat(), 'duration' => 0, 'changeMonth' => true, 'changeYear' => true, 'showOn' => 'button', 'buttonImage' => 'images/calendar.gif', 'buttonText' => 'Click to open/close Calendar', 'buttonImageOnly' => true ); $allowedOptions = array( 'altField', 'altFormat', 'appendText', 'buttonImage', 'buttonImageOnly', 'buttonText', 'changeMonth', 'changeYear', 'closeText', 'constrainInput', 'currentText', 'dateFormat', 'dayNames', 'dayNamesMin', 'dayNamesShort', 'defaultDate', 'duration', 'firstDay', 'gotoCurrent', 'hideIfNoPrevNext', 'isRTL', 'maxDate', 'minDate', 'monthNames', 'monthNamesShort', 'navigationAsDateFormat', 'nextText', 'numberOfMonths', 'prevText', 'shortYearCutoff', 'showAnim', 'showButtonPanel', 'showCurrentAtPos', 'showMonthAfterYear', 'showOn', 'showOptions', 'showOtherMonths', 'stepMonths', 'yearRange', ); foreach ($this->getOptions() as $name => $value) { if (false !== array_search($name, $allowedOptions)) { $options[$name] = $value; } } return $options; } }