Skip to content

Commit

Permalink
Merge branch '3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Harvey committed Oct 14, 2012
2 parents 7023669 + 574c53d commit f6a9046
Show file tree
Hide file tree
Showing 22 changed files with 492 additions and 57 deletions.
12 changes: 12 additions & 0 deletions CONTRIBUTING.md
@@ -0,0 +1,12 @@
# Contributing

Any open source product is only as good as the community behind it. You can participate by sharing code, ideas, or simply helping others. No matter what your skill level is, every contribution counts.

See our [high level overview](http://silverstripe.org/contributing-to-silverstripe) on silverstripe.org on how you can help out.

Or, for more detailed guidance, read one of the following pages:

* [Sharing your opinion and raising issues](http://doc.silverstripe.org/framework/en/trunk/misc/contributing/issues)
* [Providing code, whether it's creating a feature or fixing a bug](http://doc.silverstripe.org/framework/en/trunk/misc/contributing/code)
* [Writing and translating documentation](http://doc.silverstripe.org/framework/en/trunk/misc/contributing/documentation)
* [Translating user-interface elements](http://doc.silverstripe.org/framework/en/trunk/misc/contributing/translation)
2 changes: 1 addition & 1 deletion dev/BulkLoader.php
Expand Up @@ -135,7 +135,7 @@ public function __construct($objectClass) {
* @return BulkLoader_Result See {@link self::processAll()}
*/
public function load($filepath) {
ini_set('max_execution_time', 3600);
increase_time_limit_to(3600);
increase_memory_limit_to('512M');

//get all instances of the to be imported data object
Expand Down
6 changes: 3 additions & 3 deletions docs/en/installation/from-source.md
Expand Up @@ -148,7 +148,7 @@ Now you need to add the original repository as `upstream`, so you can keep your
(cd cms && git remote add upstream git://github.com/silverstripe/silverstripe-cms.git && git fetch upstream)
(cd themes/simple && git remote add upstream git://github.com/silverstripe-themes/silverstripe-simple.git)

Now that you're set up, please read our ["Collaboration on Git"](../misc/collaboration-on-git) guide,
Now that you're set up, please read our ["Contributing Code"](../misc/contributing/code) guide,
as well as our general ["Contributor guidelines"](../misc/contributing).
Please read ["Module installation"](/topics/modules) to find out how to install additional modules like `blog` or `forum` from source.

Expand Down Expand Up @@ -271,8 +271,8 @@ See [piston.rubyforge.org](http://piston.rubyforge.org/import.html).

## Related ##

* [Contributing: Submitting patches](/misc/contributing)
* [Collaboration on Git](/misc/collaboration-on-git)
* [Contributing](/misc/contributing)
* [Contributing Code](/misc/contributing/code)
* [Pro git - free online book](http://progit.org/book/)
* [Git cheat sheet - github.com](https://github.com/guides/git-cheat-sheet)
* [Git - SVN Crash Course - git.or.cz](http://git.or.cz/course/svn.html)
131 changes: 131 additions & 0 deletions docs/en/reference/datefield.md
@@ -0,0 +1,131 @@
# DateField

## Introduction

This `FormField` subclass lets you display an editable date, either in
a single text input field, or in three separate fields for day, month and year.
It also provides a calendar datepicker.

## Adding a DateField

The following example will add a simple DateField to your Page, allowing you to
enter a date manually.

:::php
class Page extends SiteTree {
static $db = array(
'MyDate' => 'Date',
);

public function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab(
'Root.Main',
$myDate = new DateField('MyDate', 'Enter a date')
);
return $fields;
}
}

## Custom Dateformat

You can define a custom dateformat for your Datefield based on [Zend_Date constants](http://framework.zend.com/manual/1.12/en/zend.date.constants.html).

:::php
// will display a date in the following format: 31-06-2012
DateField::create('MyDate')->setConfig('dateformat', 'dd-MM-yyyy');


## Min and Max Dates

Set the minimum and maximum allowed datevalues using the `min` and `max`
configuration settings (in ISO format or strtotime() compatible). Example:

:::php
DateField::create('MyDate')
->setConfig('min', '-7 days')
->setConfig('max', '2012-12-31')
## Separate Day/Month/Year Fields

The following setting will display your DateField as `three input fields` for
day, month and year separately. Any custom dateformat settings will be ignored.
HTML5 placeholders 'day', 'month' and 'year' are enabled by default.

:::php
DateField::create('MyDate')
->setConfig('dmyfields', true);
->setConfig('dmyseparator', '/') // set the separator
->setConfig('dmyplaceholders', 'true'); // enable HTML 5 Placeholders

## Calendar Field

The following setting will add a Calendar to a single DateField, using the
`jQuery UI DatePicker widget`

:::php
DateField::create('MyDate')->setConfig('showcalendar', true);


### 'Safe' Dateformats to Use with the Calendar

The jQuery DatePicker doesn't support every constant available for Zend_Date.
If you choose to use the calendar, the following constants should at least be safe:

Constant | xxxxx
-------- | -----
d | numeric day of the month (without leading zero)
dd | numeric day of the month (with leading zero)
EEE | dayname, abbreviated
EEEE | dayname
M | numeric month of the year (without leading zero)
MM | numeric month of the year (with leading zero)
MMM | monthname, abbreviated
MMMM | monthname
y | year (4 digits)
yy | year (2 digits)
yyyy | year (4 digits)

### Calendar localization issues

Unfortunately the day- and monthname values in Zend Date do not always match
those in the existing jQuery UI locale files, so constants like `EEE` or `MMM`,
for day and monthnames could break validation. To fix this we had to slightly
alter the jQuery locale files, situated in
*/framework/thirdparty/jquery-ui/datepicker/i18n/*, to match Zend_Date.

At this moment not all locale files may be present. If a locale file is
missing, the DatePicker calendar will fallback to 'yyyy-MM-dd' whenever day-
and/or monthnames are used. After saving, the correct format will be displayed.

## Contributing jQuery Locale Files

If you find the jQuery locale file for your chosen locale is missing, the
following section will explain how to create one. If you wish to contribute
your file to the SilverStripe core, please check out the guide on
['contributing code'](http://doc.silverstripe.org/framework/en/trunk/misc/contributing/code).

### 1. Get the Sourcefile

You can find a list of locale files for the jQuery UI DatePicker
[in the jQuery source code](https://github.com/jquery/jquery-ui/tree/master/ui/i18n).

### 2. Find your Zend Locale File

The Zend locale files are located in */framework/thirdparty/Zend/Locale/Data/*.
Find the one that has the information for your locale.

### 3. Find the Date Values

You're looking for the `Gregorian` date values for monthnames and daynames in
the Zend locale file. Edit the DatePicker locale File so your *full day- and
monthnames* and *short monthnames* match. For your *short daynames*, use the
first three characters of the full name. Note that Zend dates are `case
sensitive`!

### 4. Filename

Use the original jQuery UI filename 'jquery.ui.datepicker-xx.js', where xx
stands for the locale.
70 changes: 48 additions & 22 deletions forms/DateField.php
Expand Up @@ -113,12 +113,26 @@ public function __construct($name, $title = null, $value = null) {
}

public function FieldHolder($properties = array()) {
// TODO Replace with properly extensible view helper system
$d = DateField_View_JQuery::create($this);
$d->onBeforeRender();
if ($this->getConfig('showcalendar')) {
// TODO Replace with properly extensible view helper system
$d = DateField_View_JQuery::create($this);
if(!$d->regionalSettingsExist()) {
$dateformat = $this->getConfig('dateformat');

// if no localefile is present, the jQuery DatePicker
// month- and daynames will default to English, so the date
// will not pass Zend validatiobn. We provide a fallback
if (preg_match('/(MMM+)|(EEE+)/', $dateformat)) {
$this->setConfig('dateformat', $this->getConfig('datavalueformat'));
}
}
$d->onBeforeRender();
}
$html = parent::FieldHolder();
$html = $d->onAfterRender($html);


if(!empty($d)) {
$html = $d->onAfterRender($html);
}
return $html;
}

Expand Down Expand Up @@ -207,9 +221,6 @@ public function setValue($val) {
$this->value = null;
$this->valueObj = null;
} else {
// Quick fix for overzealous Zend validation, its case sensitive on month names (see #5990)
if(is_string($val)) $val = ucwords(strtolower($val));

if($this->getConfig('dmyfields')) {
// Setting in correct locale
if(is_array($val) && $this->validateArrayValue($val)) {
Expand Down Expand Up @@ -488,6 +499,11 @@ class DateField_View_JQuery extends Object {

protected $field;

/*
* the current jQuery UI DatePicker locale file
*/
protected $jqueryLocaleFile = '';

/**
* @var array Maps values from {@link i18n::$all_locales()} to
* localizations existing in jQuery UI.
Expand All @@ -496,7 +512,7 @@ class DateField_View_JQuery extends Object {
'en_GB' => 'en-GB',
'en_US' => 'en',
'en_NZ' => 'en-GB',
'fr_CH' => 'fr-CH',
'fr_CH' => 'fr',
'pt_BR' => 'pt-BR',
'sr_SR' => 'sr-SR',
'zh_CN' => 'zh-CN',
Expand All @@ -517,7 +533,24 @@ public function __construct($field) {
public function getField() {
return $this->field;
}


/**
* Check if jQuery UI locale settings exists for the current locale
* @return boolean
*/
function regionalSettingsExist() {
$lang = $this->getLang();
$localeFile = THIRDPARTY_DIR . "/jquery-ui/datepicker/i18n/jquery.ui.datepicker-{$lang}.js";
if (file_exists(Director::baseFolder() . '/' .$localeFile)){
$this->jqueryLocaleFile = $localeFile;
return true;
} else {
// file goes before internal en_US settings,
// but both will validate
return ($lang == 'en');
}
}

public function onBeforeRender() {
}

Expand All @@ -532,16 +565,9 @@ public function onAfterRender($html) {
Requirements::javascript(FRAMEWORK_DIR . '/thirdparty/jquery-ui/jquery-ui.js');

// Include language files (if required)
$lang = $this->getLang();
if($lang != 'en') {
// TODO Check for existence of locale to avoid unnecessary 404s from the CDN
Requirements::javascript(
sprintf(
THIRDPARTY_DIR . '/jquery-ui/minified/i18n/jquery.ui.datepicker-%s.min.js',
// can be a mix between names (e.g. 'de') and combined locales (e.g. 'zh-TW')
$lang
));
}
if ($this->jqueryLocaleFile){
Requirements::javascript($this->jqueryLocaleFile);
}

Requirements::javascript(FRAMEWORK_DIR . "/javascript/DateField.js");
}
Expand Down Expand Up @@ -586,12 +612,12 @@ public static function convert_iso_to_jquery_format($format) {
'/^d([^d])/' => 'd$1',
'/([^d])d$/' => '$1d',
'/dd/' => 'dd',
'/EEEE/' => 'DD',
'/EEE/' => 'D',
'/SS/' => '',
'/eee/' => 'd',
'/e/' => 'N',
'/D/' => '',
'/EEEE/' => 'DD',
'/EEE/' => 'D',
'/w/' => '',
// make single "M" lowercase
'/([^M])M([^M])/' => '$1m$2',
Expand Down
2 changes: 1 addition & 1 deletion forms/ImageField.php
Expand Up @@ -20,7 +20,7 @@
* $myField->setFolderName('myFolder');
* </code>
*
* @deprecated 3.0 Use UploadField with $myField->allowedExtensions = array('jpg', 'gif', 'png')
* @deprecated 3.0 Use UploadField with $myField->getValidator()->setAllowedExtensions(array('jpg', 'gif', 'png'));
*
* @package forms
* @subpackage fields-files
Expand Down
4 changes: 2 additions & 2 deletions forms/SimpleImageField.php
Expand Up @@ -64,14 +64,14 @@
*/

/**
* @deprecated 3.0 Use UploadField with $myField->allowedExtensions = array('jpg', 'gif', 'png')
* @deprecated 3.0 Use UploadField with $myField->getValidator()->setAllowedExtensions(array('jpg', 'gif', 'png'));
*/
class SimpleImageField extends FileField {

public function __construct($name, $title = null, $value = null) {
Deprecation::notice('3.0',
"SimpleImageField is deprecated. Use UploadField with "
. "\$myField->allowedExtensions = array('jpg', 'gif', 'png')",
. "\$myField->getValidator()->setAllowedExtensions(array('jpg', 'gif', 'png'))",
Deprecation::SCOPE_CLASS);

if(count(func_get_args()) > 3) {
Expand Down

0 comments on commit f6a9046

Please sign in to comment.