2007-11-05 00:01:55 +01:00
|
|
|
<?php
|
2008-01-09 05:18:36 +01:00
|
|
|
/**
|
|
|
|
* Field for entering a date/time pair.
|
2009-04-02 19:17:04 +02:00
|
|
|
*
|
|
|
|
* @todo Add localization support, see http://open.silverstripe.com/ticket/2931
|
|
|
|
*
|
2008-01-09 05:18:36 +01:00
|
|
|
* @package forms
|
|
|
|
* @subpackage fields-datetime
|
|
|
|
*/
|
2007-11-05 00:01:55 +01:00
|
|
|
class PopupDateTimeField extends CalendarDateField {
|
|
|
|
|
2009-02-02 00:49:53 +01:00
|
|
|
/**
|
|
|
|
* @todo js validation needs to be implemented.
|
|
|
|
* @see sapphire/forms/DateField#jsValidation()
|
|
|
|
*/
|
|
|
|
function jsValidation() {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @todo php validation needs to be implemented.
|
|
|
|
* @see sapphire/forms/DateField#validate($validator)
|
|
|
|
*/
|
|
|
|
function validate() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-11-05 00:01:55 +01:00
|
|
|
function Field() {
|
|
|
|
|
ENHANCEMENT Introduced constants for system paths like /sapphire in preparation for a more flexible directory reorganisation. Instead of hardcoding your path, please use the following constants: BASE_PATH, BASE_URL, SAPPHIRE_DIR, SAPPHIRE_PATH, CMS_DIR, CMS_PATH, THIRDPARTY_DIR, THIRDPARTY_PATH, ASSETS_DIR, ASSETS_PATH, THEMES_DIR, THEMES_PATH
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@63154 467b73ca-7a2a-4603-9d3b-597d59a354a9
2008-09-27 18:02:38 +02:00
|
|
|
Requirements::css( SAPPHIRE_DIR . '/css/PopupDateTimeField.css' );
|
2007-11-05 00:01:55 +01:00
|
|
|
|
|
|
|
$field = parent::Field();
|
|
|
|
|
|
|
|
DropdownTimeField::Requirements();
|
|
|
|
|
|
|
|
$id = $this->id();
|
|
|
|
$val = $this->attrValue();
|
|
|
|
|
|
|
|
$date = $this->attrValueDate();
|
|
|
|
$time = $this->attrValueTime();
|
|
|
|
|
|
|
|
$futureClass = $this->futureOnly ? ' futureonly' : '';
|
|
|
|
|
|
|
|
$innerHTMLDate = parent::HTMLField( $id . '_Date', $this->name . '[Date]', $date );
|
|
|
|
$innerHTMLTime = DropdownTimeField::HTMLField( $id . '_Time', $this->name . '[Time]', $time );
|
|
|
|
|
|
|
|
return <<<HTML
|
|
|
|
<div class="popupdatetime">
|
|
|
|
<ul>
|
|
|
|
<li class="calendardate$futureClass">$innerHTMLDate</li>
|
|
|
|
<li class="dropdowntime">$innerHTMLTime</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
HTML;
|
|
|
|
}
|
|
|
|
|
|
|
|
function attrValueDate() {
|
|
|
|
if( $this->value )
|
|
|
|
return date( 'd/m/Y', strtotime( $this->value ) );
|
|
|
|
else
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
function attrValueTime() {
|
|
|
|
if( $this->value )
|
|
|
|
return date( 'h:i a', strtotime( $this->value ) );
|
|
|
|
else
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
function setValue( $val ) {
|
|
|
|
if( is_array( $val ) ) {
|
|
|
|
|
|
|
|
// 1) Date
|
|
|
|
|
|
|
|
if( $val[ 'Date' ] && preg_match( '/^([\d]{1,2})\/([\d]{1,2})\/([\d]{2,4})/', $val[ 'Date' ], $parts ) )
|
|
|
|
$date = "$parts[3]-$parts[2]-$parts[1]";
|
|
|
|
else
|
|
|
|
$date = null;
|
|
|
|
|
|
|
|
// 2) Time
|
|
|
|
|
|
|
|
$time = $val[ 'Time' ] ? date( 'H:i:s', strtotime( $val[ 'Time' ] ) ) : null;
|
|
|
|
|
|
|
|
if( $date == null )
|
|
|
|
$this->value = $time;
|
|
|
|
else if( $time == null )
|
|
|
|
$this->value = $date;
|
|
|
|
else
|
|
|
|
$this->value = $date . ' ' . $time;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
$this->value = $val;
|
|
|
|
}
|
|
|
|
|
|
|
|
function dataValue() {
|
|
|
|
return $this->value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|