2013-07-16 15:39:47 +02:00
|
|
|
<?php
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
|
2014-08-27 12:24:11 +02:00
|
|
|
use \Zend_View_Helper_FormElement;
|
2013-08-06 19:05:16 +02:00
|
|
|
|
2013-07-16 15:39:47 +02:00
|
|
|
/**
|
2013-08-06 19:05:16 +02:00
|
|
|
* Helper to generate a "datetime" element
|
2013-07-16 15:39:47 +02:00
|
|
|
*/
|
2013-08-06 19:05:16 +02:00
|
|
|
class Zend_View_Helper_FormDateTime extends Zend_View_Helper_FormElement
|
2013-07-16 15:39:47 +02:00
|
|
|
{
|
|
|
|
/**
|
2013-08-06 19:05:16 +02:00
|
|
|
* Generate a 'datetime' element
|
2013-07-16 15:39:47 +02:00
|
|
|
*
|
2013-08-07 10:53:44 +02:00
|
|
|
* @param string $name The element name
|
|
|
|
* @param int $value The default timestamp
|
|
|
|
* @param array $attribs Attributes for the element tag
|
2013-07-16 15:39:47 +02:00
|
|
|
*
|
2013-08-06 19:05:16 +02:00
|
|
|
* @return string The element XHTML
|
2013-07-16 15:39:47 +02:00
|
|
|
*/
|
|
|
|
public function formDateTime($name, $value = null, $attribs = null)
|
|
|
|
{
|
2013-08-06 19:05:16 +02:00
|
|
|
$info = $this->_getInfo($name, $value, $attribs);
|
|
|
|
extract($info); // name, value, attribs, options, listsep, disable
|
|
|
|
// Is it disabled?
|
|
|
|
$disabled = '';
|
2013-08-22 17:27:11 +02:00
|
|
|
if ($disabled) {
|
2013-08-06 19:05:16 +02:00
|
|
|
$disabled = ' disabled="disabled"';
|
|
|
|
}
|
|
|
|
|
2013-10-20 15:30:49 +02:00
|
|
|
$jspicker = (isset($attribs['jspicker']) && $attribs['jspicker'] === true) ? true : false;
|
|
|
|
|
2013-08-06 19:05:16 +02:00
|
|
|
if (isset($value) && !empty($value)) {
|
2013-10-20 15:30:49 +02:00
|
|
|
if ($jspicker) {
|
|
|
|
$value = ' value="' . $this->view->dateFormat()->format($value, $attribs['defaultFormat']) . '"';
|
|
|
|
} else {
|
|
|
|
$value = ' value="' . $this->view->dateFormat()->formatDateTime($value) . '"';
|
|
|
|
}
|
2013-08-06 19:05:16 +02:00
|
|
|
} else {
|
|
|
|
$value = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build the element
|
2013-10-21 11:32:24 +02:00
|
|
|
$xhtml = '<div class="datetime' . (($jspicker === true) ? ' input-group' : ''). '">';
|
|
|
|
|
|
|
|
$xhtml .= '<input type="text" name="' . $name . '"'
|
2013-10-20 15:30:49 +02:00
|
|
|
. ' id="' . $name . '"'
|
2013-08-06 19:05:16 +02:00
|
|
|
. $value
|
|
|
|
. $disabled
|
2013-10-20 15:30:49 +02:00
|
|
|
. $this->_htmlAttribs($attribs);
|
|
|
|
|
|
|
|
if ($jspicker === true) {
|
|
|
|
$xhtml .= 'data-icinga-component="app/datetime"';
|
|
|
|
}
|
|
|
|
|
2013-10-21 11:32:24 +02:00
|
|
|
$xhtml .= $this->getClosingBracket();
|
|
|
|
|
|
|
|
if ($jspicker === true) {
|
|
|
|
$xhtml .= '<span class="input-group-addon">'
|
|
|
|
. '<a href="#">'
|
|
|
|
. '<i class="icinga-icon-reschedule"></i>'
|
|
|
|
. '</a>'
|
|
|
|
. '</span>';
|
|
|
|
}
|
|
|
|
|
|
|
|
$xhtml .= '</div>';
|
2013-10-20 15:30:49 +02:00
|
|
|
|
2013-08-06 19:05:16 +02:00
|
|
|
return $xhtml;
|
2013-07-16 15:39:47 +02:00
|
|
|
}
|
|
|
|
}
|