|
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-2015 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
|
1 |
|
public function __construct($caption, $name = null, $value = null) |
|
34
|
|
|
{ |
|
35
|
1 |
|
if (is_array($caption)) { |
|
36
|
1 |
|
parent::__construct($caption); |
|
37
|
1 |
|
$this->setIfNotSet('size', 15); |
|
38
|
1 |
|
$this->setIfNotSet('value', 0); |
|
39
|
1 |
|
$this->set('value', \Xoops\Core\Locale\Time::cleanTime($this->get('value', null))); |
|
40
|
|
|
} else { |
|
41
|
1 |
|
parent::__construct([]); |
|
42
|
1 |
|
$this->setCaption($caption); |
|
43
|
1 |
|
$this->setName($name); |
|
44
|
1 |
|
$this->set('size', 15); |
|
45
|
1 |
|
$this->setValue(\Xoops\Core\Locale\Time::cleanTime($value)); |
|
46
|
|
|
} |
|
47
|
1 |
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* render |
|
51
|
|
|
* |
|
52
|
|
|
* @return string rendered form element |
|
53
|
|
|
*/ |
|
54
|
2 |
|
public function render() |
|
55
|
|
|
{ |
|
56
|
2 |
|
$xoops = \Xoops::getInstance(); |
|
57
|
|
|
|
|
58
|
2 |
|
$display_value = \Xoops\Core\Locale\Time::formatDate($this->getValue(false)); |
|
59
|
|
|
|
|
60
|
2 |
|
$dataList = $this->isDatalist(); |
|
61
|
2 |
|
if (!empty($dataList)) { |
|
62
|
|
|
$this->add('list', 'list_' . $this->getName()); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
2 |
|
$this->themeDecorateElement(); |
|
66
|
2 |
|
$this->suppressRender(['value']); |
|
67
|
2 |
|
$attributes = $this->renderAttributeString(); |
|
68
|
|
|
|
|
69
|
2 |
|
$xoops->theme()->addBaseStylesheetAssets('@jqueryuicss'); |
|
70
|
2 |
|
$xoops->theme()->addBaseScriptAssets('@jqueryui'); |
|
71
|
2 |
|
\Xoops\Core\Locale\Time::localizeDatePicker(); |
|
72
|
|
|
|
|
73
|
2 |
|
$xoops->theme()->addScript( |
|
74
|
2 |
|
'', |
|
75
|
2 |
|
'', |
|
76
|
2 |
|
' $(function() { $( "#' . $this->get('id') . '" ).datepicker({' . |
|
77
|
2 |
|
'showOn: "button", buttonImageOnly: false, changeYear: true, constrainInput: false, ' . |
|
78
|
2 |
|
'buttonImage: "' . $xoops->url('media/xoops/images/icons/calendar.png') .'", ' . |
|
79
|
2 |
|
'buttonImageOnly: false, buttonText: "' . \XoopsLocale::A_SELECT . '" }); }); ' |
|
80
|
|
|
); |
|
81
|
|
|
|
|
82
|
2 |
|
return '<input ' . $attributes . 'value="' . $display_value . '" ' |
|
83
|
2 |
|
. $this->getExtra() .' >'; |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|