2007-07-19 12:40:28 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* This field creates a date field that shows a calendar on pop-up
|
2008-01-09 05:18:36 +01:00
|
|
|
* @package forms
|
|
|
|
* @subpackage fields-datetime
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
|
|
|
class CalendarDateField extends DateField {
|
2007-11-02 04:20:05 +01:00
|
|
|
|
2009-11-21 03:30:31 +01:00
|
|
|
protected $futureOnly;
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
function Field() {
|
2009-11-21 03:30:31 +01:00
|
|
|
// javascript: core
|
|
|
|
Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery/jquery.js');
|
|
|
|
Requirements::javascript(SAPPHIRE_DIR . '/javascript/jquery_improvements.js');
|
|
|
|
Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery-ui/ui.core.js');
|
|
|
|
Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery-ui/ui.datepicker.js');
|
|
|
|
Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery-metadata/jquery.metadata.js');
|
2007-07-19 12:40:28 +02:00
|
|
|
|
2009-11-21 03:30:31 +01:00
|
|
|
// javascript: localized datepicker
|
|
|
|
// Include
|
|
|
|
$candidates = array(
|
|
|
|
i18n::convert_rfc1766(i18n::get_locale()),
|
|
|
|
i18n::get_lang_from_locale(i18n::get_locale())
|
|
|
|
);
|
|
|
|
foreach($candidates as $candidate) {
|
|
|
|
$datePickerI18nPath = sprintf(SAPPHIRE_DIR . '/thirdparty/jquery-ui/i18n/ui.datepicker-%s.js', $candidate);
|
|
|
|
if(Director::fileExists($datePickerI18nPath)) Requirements::javascript($datePickerI18nPath);
|
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
|
2007-11-02 04:20:05 +01:00
|
|
|
|
2009-11-21 03:30:31 +01:00
|
|
|
// javascript: concrete
|
|
|
|
Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery-concrete/jquery.class.js');
|
|
|
|
Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery-concrete/jquery.selector.js');
|
|
|
|
Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery-concrete/jquery.selector.specifity.js');
|
|
|
|
Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery-concrete/jquery.selector.matches.js');
|
|
|
|
Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery-concrete/jquery.dat.js');
|
|
|
|
Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery-concrete/jquery.concrete.js');
|
|
|
|
|
|
|
|
// javascript: custom
|
|
|
|
Requirements::javascript(SAPPHIRE_DIR . '/javascript/CalendarDateField.js');
|
|
|
|
|
|
|
|
// css: core
|
|
|
|
Requirements::css(SAPPHIRE_DIR . '/thirdparty/jquery-ui-themes/smoothness/ui.all.css');
|
|
|
|
|
|
|
|
// clientside config
|
|
|
|
// TODO Abstract this into FormField to make generic configuration interface
|
|
|
|
$jsConfig = Convert::raw2json(array(
|
|
|
|
'minDate' => $this->futureOnly ? SSDatetime::now()->format('m/d/Y') : null
|
|
|
|
));
|
|
|
|
|
|
|
|
$this->addExtraClass($jsConfig);
|
|
|
|
|
|
|
|
return parent::Field();
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-11-21 03:30:31 +01:00
|
|
|
* Sets the field so that only future dates can be set on them.
|
|
|
|
* Only applies for JavaScript value, no server-side validation.
|
|
|
|
*
|
|
|
|
* @deprecated 2.4
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
|
|
|
function futureDateOnly() {
|
|
|
|
$this->futureOnly = true;
|
|
|
|
}
|
2009-11-21 03:30:31 +01:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
?>
|