addScript('js/jquery-ui.js'); $this->addScript('js/lib/form/element/date.js'); $this->addStylesheet('css/thirdpart/jquery-ui.css'); } public function getOptions() { if (null === $this->_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 getDisplayId() { $id = $this->getElement()->getId(); if (false !== strpos($this->getElement()->getFullyQualifiedName(), '[')) { $name = $this->getElement()->getName(); if ('[]' == substr($name, -2)) { $name = substr($name, 0, strlen($name) - 2); } $pos = strrpos($id, $name); $id = substr($id, 0, $pos) . '_' . substr($id, $pos); } else { $id = '_' . $id; } return $id; } public function getDisplayName() { $name = $this->getElement()->getFullyQualifiedName(); if (false !== ($pos = strrpos($name, '['))) { $pos++; $name = substr($name, 0, $pos) . '_' . substr($name, $pos); } else { $name = '_' . $name; } return $name; } public function render($content) { $this->_initScripts(); // init options $this->getOptions(); $element = $this->getElement(); /** @var Qs_View $view */ $view = $element->getView(); $placement = $this->getPlacement(); $separator = $this->getSeparator(); $name = $element->getFullyQualifiedName(); $id = $element->getId(); $elementContent = $view->formHidden($name, $element->getValue(), ['id' => $id]); $_name = $this->getDisplayName(); $_id = $this->getDisplayId(); $attribs = Qs_Array::excludeKey($element->getAttribs(), $this->_allowedOptions); $attribs['id'] = $_id; $elementContent .= $view->formText($_name, '', $attribs); switch ($placement) { case self::APPEND: $content = $content . $separator . $this->getHtmlBeforeElement() . $elementContent . $this->getHtmlAfterElement(); break; case self::PREPEND: $content = $this->getHtmlBeforeElement() . $elementContent . $this->getHtmlAfterElement() . $separator . $content; break; } return $content; } protected function _renderScriptOptions() { $options = $this->_getScriptOptions(); return json_encode($options); } protected function _getScriptOptions() { $options = [ 'altField' => '#' . $this->getElement()->getId(), 'altFormat' => 'yy-mm-dd', 'dateFormat' => $this->getElement()->getFormat(), 'duration' => 0, 'changeMonth' => true, 'changeYear' => true, 'showOn' => 'button', 'buttonImage' => 'images/calendar.svg', 'buttonText' => 'Click to open/close Calendar', 'buttonImageOnly' => true, ]; foreach ($this->getOptions() as $name => $value) { if (false !== array_search($name, $this->_allowedOptions)) { $options[$name] = $value; } } return $options; } private function _initScripts() { /** @var $doc Qs_Doc */ $doc = Zend_Registry::get('doc'); $doc->addResources($this->getResources()); $id = $this->getElement()->getId(); $displayId = $this->getDisplayId(); $options = $this->_getScriptOptions(); $doc->addInitObject('lib.form.element.Date', [$id, $displayId, $options]); return $this; } }