Commit be783fc2 authored by Côme Chilliet's avatar Côme Chilliet
Browse files

feat(simpleplugin) Add default date parameter to DateAttribute

This only makes sense when default value is empty

issue #5908
parent 6e539aca
...@@ -8,6 +8,10 @@ ...@@ -8,6 +8,10 @@
* Modified 10.06.2008 * Modified 10.06.2008
* by Manu <manu@bytefresser.de> * by Manu <manu@bytefresser.de>
* *
* Modified 15.10.2018
* by FusionDirectory Project
* -> Add defaultDate/_default_date
*
*/ */
/** /**
...@@ -200,6 +204,7 @@ DatePicker.prototype = { ...@@ -200,6 +204,7 @@ DatePicker.prototype = {
_disablePastDate : false, _disablePastDate : false,
_disableFutureDate : false, _disableFutureDate : false,
_oneDayInMs : 24 * 3600 * 1000, _oneDayInMs : 24 * 3600 * 1000,
_default_date : null,
/* positionning */ /* positionning */
_topOffset : 20, _topOffset : 20,
...@@ -240,7 +245,10 @@ DatePicker.prototype = { ...@@ -240,7 +245,10 @@ DatePicker.prototype = {
if (! this._df.match(this._current_date)) { if (! this._df.match(this._current_date)) {
this._current_date = this._df.current_date(); if (this._default_date != null) {
this._current_date = this._default_date;
} else
this._current_date = this._df.current_date();
/* set the field value ? */ /* set the field value ? */
if (!this._keepFieldEmpty) if (!this._keepFieldEmpty)
...@@ -292,6 +300,8 @@ DatePicker.prototype = { ...@@ -292,6 +300,8 @@ DatePicker.prototype = {
this._externalControl = h_p["externalControl"]; this._externalControl = h_p["externalControl"];
if (!Object.isUndefined(h_p["dateFormat"])) if (!Object.isUndefined(h_p["dateFormat"]))
this._dateFormat = h_p["dateFormat"]; this._dateFormat = h_p["dateFormat"];
if (!Object.isUndefined(h_p["defaultDate"]))
this._default_date = h_p["defaultDate"];
if (Object.isFunction(h_p["cellCallback"])) if (Object.isFunction(h_p["cellCallback"]))
this._cellCallback = h_p["cellCallback"]; this._cellCallback = h_p["cellCallback"];
if (!Object.isUndefined(h_p["enableCloseOnBlur"]) && h_p["enableCloseOnBlur"]) if (!Object.isUndefined(h_p["enableCloseOnBlur"]) && h_p["enableCloseOnBlur"])
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
class DateAttribute extends Attribute class DateAttribute extends Attribute
{ {
protected $format; protected $format;
protected $defaultDate;
/*! \brief The constructor of DateAttribute /*! \brief The constructor of DateAttribute
* *
...@@ -34,12 +35,22 @@ class DateAttribute extends Attribute ...@@ -34,12 +35,22 @@ class DateAttribute extends Attribute
* \param boolean $required Is this attribute mandatory or not * \param boolean $required Is this attribute mandatory or not
* \param string $format The date format. It can be any format recognized by DateTime::format. see http://www.php.net/manual/fr/function.date.php * \param string $format The date format. It can be any format recognized by DateTime::format. see http://www.php.net/manual/fr/function.date.php
* \param mixed $defaultValue The default value for this attribute * \param mixed $defaultValue The default value for this attribute
* \param mixed $defaultDate The default date for the date picker when attribute is empty
* \param string $acl The name of the acl for this attribute if he does not use its own. (Leave empty if he should use its own like most attributes do) * \param string $acl The name of the acl for this attribute if he does not use its own. (Leave empty if he should use its own like most attributes do)
*/ */
function __construct ($label, $description, $ldapName, $required, $format, $defaultValue = 'now', $acl = "") function __construct ($label, $description, $ldapName, $required, $format, $defaultValue = 'now', $defaultDate = NULL, $acl = '')
{ {
parent::__construct($label, $description, $ldapName, $required, $defaultValue, $acl); parent::__construct($label, $description, $ldapName, $required, $defaultValue, $acl);
$this->format = $format; $this->format = $format;
if ($defaultDate !== NULL) {
try {
$date = new DateTime($defaultDate, new DateTimeZone('UTC'));
$defaultDate = $date->format('d.m.Y');
} catch (Exception $e) {
$defaultDate = NULL;
}
}
$this->defaultDate = $defaultDate;
} }
function inputValue ($value) function inputValue ($value)
...@@ -151,7 +162,16 @@ class DateAttribute extends Attribute ...@@ -151,7 +162,16 @@ class DateAttribute extends Attribute
$display .= '{if $'.$this->getAcl().'ACL|regex_replace:"/[cdmr]/":"" == "w"}'. $display .= '{if $'.$this->getAcl().'ACL|regex_replace:"/[cdmr]/":"" == "w"}'.
'<script type="text/javascript"> '<script type="text/javascript">
{literal} {literal}
var datepicker = new DatePicker({ relative : \''.$id.'\', language : \'{/literal}{$lang}{literal}\', keepFieldEmpty : true, enableCloseEffect : false, enableShowEffect : false }); var datepicker = new DatePicker('.
'{ '.
'relative : \''.$id.'\', '.
(($this->defaultDate !== NULL) ? 'defaultDate : \''.$this->defaultDate.'\', ' : '').
'language : \'{/literal}{$lang}{literal}\', '.
'keepFieldEmpty : true, '.
'enableCloseEffect : false, '.
'enableShowEffect : false '.
'}'.
');
{/literal} {/literal}
</script> </script>
{/if}'; {/if}';
...@@ -164,9 +184,9 @@ class DateAttribute extends Attribute ...@@ -164,9 +184,9 @@ class DateAttribute extends Attribute
*/ */
class GeneralizedTimeDateAttribute extends DateAttribute class GeneralizedTimeDateAttribute extends DateAttribute
{ {
function __construct ($label, $description, $ldapName, $required, $defaultValue = 'now', $acl = "") function __construct ($label, $description, $ldapName, $required, $defaultValue = 'now', $defaultDate = NULL, $acl = '')
{ {
parent::__construct($label, $description, $ldapName, $required, '', $defaultValue, $acl); parent::__construct($label, $description, $ldapName, $required, '', $defaultValue, $defaultDate, $acl);
} }
protected function ldapToDate($ldapValue) protected function ldapToDate($ldapValue)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment