1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
You may not change or alter any portion of this comment or credits |
4
|
|
|
of supporting developers from this source code or any supporting source code |
5
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
6
|
|
|
|
7
|
|
|
This program is distributed in the hope that it will be useful, |
8
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
9
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Xoops\Form; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* DateSelect - date entry element with calendar popup |
16
|
|
|
* |
17
|
|
|
* @category Xoops\Form\DateSelect |
18
|
|
|
* @package Xoops\Form |
19
|
|
|
* @author Kazumi Ono <[email protected]> |
20
|
|
|
* @copyright 2001-2016 XOOPS Project (http://xoops.org) |
21
|
|
|
* @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html) |
22
|
|
|
* @link http://xoops.org |
23
|
|
|
*/ |
24
|
|
|
class DateSelect extends Text |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* __construct |
28
|
|
|
* |
29
|
|
|
* @param string|array $caption caption or array of all attributes |
30
|
|
|
* @param string $name name |
31
|
|
|
* @param integer|\DateTime $value unix timestamp or DateTime object |
32
|
|
|
*/ |
33
|
7 |
|
public function __construct($caption, $name = null, $value = null) |
34
|
|
|
{ |
35
|
7 |
|
if (is_array($caption)) { |
36
|
5 |
|
parent::__construct($caption); |
37
|
5 |
|
$this->setIfNotSet('size', 15); |
38
|
5 |
|
$this->setIfNotSet('value', 0); |
39
|
5 |
|
$this->set('value', \Xoops\Core\Locale\Time::cleanTime($this->get('value', null))); |
40
|
|
|
} else { |
41
|
3 |
|
parent::__construct([]); |
42
|
3 |
|
$this->setCaption($caption); |
43
|
3 |
|
$this->setName($name); |
44
|
3 |
|
$this->set('size', 15); |
45
|
3 |
|
$this->setValue(\Xoops\Core\Locale\Time::cleanTime($value)); |
46
|
|
|
} |
47
|
7 |
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* defaultRender |
51
|
|
|
* |
52
|
|
|
* @return string rendered form element |
53
|
|
|
*/ |
54
|
4 |
|
public function defaultRender() |
55
|
|
|
{ |
56
|
4 |
|
$xoops = \Xoops::getInstance(); |
57
|
|
|
|
58
|
4 |
|
$display_value = \Xoops\Core\Locale\Time::formatDate($this->getValue(false)); |
59
|
|
|
|
60
|
4 |
|
$dataList = $this->isDatalist(); |
61
|
4 |
|
if (!empty($dataList)) { |
62
|
|
|
$this->add('list', 'list_' . $this->getName()); |
63
|
|
|
} |
64
|
|
|
|
65
|
4 |
|
$this->suppressRender(['value']); |
66
|
4 |
|
$attributes = $this->renderAttributeString(); |
67
|
4 |
|
|
68
|
|
|
$xoops->theme()->addBaseStylesheetAssets('@jqueryuicss'); |
|
|
|
|
69
|
4 |
|
$xoops->theme()->addBaseScriptAssets('@jqueryui'); |
|
|
|
|
70
|
4 |
|
\Xoops\Core\Locale\Time::localizeDatePicker(); |
71
|
4 |
|
|
72
|
|
|
$xoops->theme()->addScript( |
73
|
4 |
|
'', |
74
|
4 |
|
'', |
|
|
|
|
75
|
4 |
|
' $(function() { $( "#' . $this->get('id') . '" ).datepicker({' . |
|
|
|
|
76
|
4 |
|
'showOn: "focus", changeYear: true, constrainInput: false ' . |
77
|
4 |
|
' }); }); ' |
78
|
4 |
|
); |
79
|
|
|
$ret = '<div>'; |
80
|
|
|
$ret .= '<input ' . $attributes . ' value="' . $display_value . '" ' . $this->getExtra() .' >'; |
81
|
4 |
|
$ret .= '<span>'; |
82
|
4 |
|
$ret .= '<button type="button" '; |
83
|
4 |
|
$ret .= 'data-toggle="tooltip" data-placement="left" title="' . \XoopsLocale::A_SELECT . '" '; |
84
|
4 |
|
$ret .= 'onclick="$( \'#' . $this->get('id') . '\' ).datepicker( \'show\' );"> '; |
85
|
4 |
|
$ret .= '<span>...</span></button>'; |
86
|
4 |
|
$ret .= '</span></div>'; |
87
|
4 |
|
|
88
|
4 |
|
return $ret; |
89
|
4 |
|
//'<input ' . $attributes . 'value="' . $display_value . '" ' . $this->getExtra() .' >'; |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|