2008-09-29 03:18:23 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* EditableDateField
|
2009-04-17 02:26:40 +00:00
|
|
|
*
|
2012-04-14 18:36:50 +12:00
|
|
|
* Allows a user to add a date field.
|
2010-05-31 07:57:00 +00:00
|
|
|
*
|
2009-04-17 02:26:40 +00:00
|
|
|
* @package userforms
|
2008-09-29 03:18:23 +00:00
|
|
|
*/
|
2009-12-07 02:04:20 +00:00
|
|
|
|
2008-09-29 03:18:23 +00:00
|
|
|
class EditableDateField extends EditableFormField {
|
2009-04-21 03:44:13 +00:00
|
|
|
|
2013-04-02 18:34:43 -07:00
|
|
|
private static $singular_name = 'Date Field';
|
2009-04-21 03:44:13 +00:00
|
|
|
|
2013-04-02 18:34:43 -07:00
|
|
|
private static $plural_name = 'Date Fields';
|
2008-09-29 03:18:23 +00:00
|
|
|
|
2012-05-04 13:39:08 +12:00
|
|
|
public function getFieldConfiguration() {
|
2012-04-14 18:36:50 +12:00
|
|
|
$default = ($this->getSetting('DefaultToToday')) ? $this->getSetting('DefaultToToday') : false;
|
|
|
|
$label = _t('EditableFormField.DEFAULTTOTODAY', 'Default to Today?');
|
2010-11-15 23:23:11 +00:00
|
|
|
|
2012-04-22 16:17:42 -03:00
|
|
|
return new FieldList(
|
2012-04-14 18:36:50 +12:00
|
|
|
new CheckboxField($this->getSettingName("DefaultToToday"), $label, $default)
|
2010-05-31 09:43:25 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-05-04 13:39:08 +12:00
|
|
|
public function populateFromPostData($data) {
|
2008-09-29 03:18:23 +00:00
|
|
|
$fieldPrefix = 'Default-';
|
|
|
|
|
2009-05-06 03:34:40 +00:00
|
|
|
if(empty($data['Default']) && !empty($data[$fieldPrefix.'Year']) && !empty($data[$fieldPrefix.'Month']) && !empty($data[$fieldPrefix.'Day'])) {
|
|
|
|
$data['Default'] = $data['Year'] . '-' . $data['Month'] . '-' . $data['Day'];
|
|
|
|
}
|
|
|
|
|
|
|
|
parent::populateFromPostData($data);
|
2008-09-29 03:18:23 +00:00
|
|
|
}
|
|
|
|
|
2009-04-21 03:44:13 +00:00
|
|
|
/**
|
2012-05-10 17:44:41 +12:00
|
|
|
* Return the form field
|
2009-04-21 03:44:13 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function getFormField() {
|
2012-05-10 17:44:41 +12:00
|
|
|
$defaultValue = ($this->getSetting('DefaultToToday')) ? date('Y-m-d') : $this->Default;
|
2014-08-11 11:09:31 +12:00
|
|
|
$field = new EditableDateField_FormField( $this->Name, $this->Title, $defaultValue);
|
2012-05-10 17:44:41 +12:00
|
|
|
$field->setConfig('showcalendar', true);
|
2014-08-11 11:09:31 +12:00
|
|
|
|
2012-05-10 17:44:41 +12:00
|
|
|
return $field;
|
2009-04-21 03:44:13 +00:00
|
|
|
}
|
2012-07-17 16:09:31 +12:00
|
|
|
}
|
2014-08-11 11:09:31 +12:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @package userforms
|
|
|
|
*/
|
|
|
|
class EditableDateField_FormField extends DateField {
|
|
|
|
|
|
|
|
public function Type() {
|
|
|
|
return "date-alt text";
|
|
|
|
}
|
|
|
|
}
|