silverstripe-frameworktest/code/BasicFieldsTestPage.php

132 lines
4.4 KiB
PHP
Raw Normal View History

2008-10-03 00:05:45 +02:00
<?php
class BasicFieldsTestPage extends TestPage {
static $db = array(
'Checkbox' => 'Boolean',
'Readonly' => 'Varchar',
'Textarea' => 'Text',
'Text' => 'Varchar',
'CalendarDate' => 'Date',
'CompositeDate' => 'Date',
'Date' => 'Date',
"DateDisabled" => "Date",
'TimeDisabled' => 'Time',
'DateTimeDisabled' => 'Datetime',
2008-10-03 00:05:45 +02:00
'DMYCalendarDate' => 'Date',
'DMYDate' => 'Date',
2010-07-10 04:30:23 +02:00
'DateTime' => 'Datetime',
'DateTimeWithCalendar' => 'Datetime',
2008-10-03 00:05:45 +02:00
'Time' => 'Time',
2010-07-10 04:30:23 +02:00
'TimeWithDropdown' => 'Time',
2008-10-03 00:05:45 +02:00
'Number' => 'Int',
'Price' => 'Double',
'Email' => 'Varchar',
'Password' => 'Varchar',
'ConfirmedPassword' => 'Varchar',
'HTMLField' => 'HTMLText',
'HTMLOneLine' => 'HTMLVarchar',
'UniqueText' => 'Varchar',
'AjaxUniqueText' => 'Varchar',
'UniqueRestrictedText' => 'Varchar',
'BankNumber' => 'Varchar',
'PhoneNumber' => 'Varchar',
'Autocomplete' => 'Varchar',
'CreditCard' => 'Varchar',
'GSTNumber' => 'Varchar',
);
static $has_one = array(
'Dropdown' => 'TestCategory',
'OptionSet' => 'TestCategory',
'GroupedDropdown' => 'TestCategory',
'ListboxField' => 'TestCategory',
'Image' => 'Image',
'Image2' => 'Image',
'Image3' => 'Image',
'File' => 'File',
'File2' => 'File',
'File3' => 'File',
);
static $defaults = array(
'Readonly' => 'Default value for \'readonly\'',
"DateDisabled" => "2002-10-23",
"DateTimeDisabled" => "2002-10-23 23:59",
"TimeDisabled" => "23:59",
2008-10-03 00:05:45 +02:00
);
function getCMSFields() {
$fields = parent::getCMSFields();
2008-10-06 08:50:10 +02:00
$fields->addFieldsToTab('Root.Content.TextTests', array(
2008-10-03 00:05:45 +02:00
new ReadonlyField('Readonly', 'ReadonlyField'),
new TextareaField('Textarea', 'TextareaField - 8 rows', 8),
new TextField('Text', 'TextField'),
2008-10-06 08:50:10 +02:00
new HtmlEditorField('HTMLField', 'HtmlEditorField'),
2008-10-03 00:05:45 +02:00
new EmailField('Email', 'EmailField'),
new PasswordField('Password', 'PasswordField'),
new AjaxUniqueTextField('AjaxUniqueText', 'AjaxUniqueTextField', 'AjaxUniqueText', 'BasicFieldsTestPage'),
2008-10-06 08:50:10 +02:00
));
$fields->addFieldsToTab('Root.Content.NumericTests', array(
new NumericField('Number', 'NumericField'),
new CurrencyField('Price', 'CurrencyField'),
2008-10-03 00:05:45 +02:00
new PhoneNumberField('PhoneNumber', 'PhoneNumberField'),
new CreditCardField('CreditCard', 'CreditCardField')
2008-10-03 00:05:45 +02:00
));
2008-10-06 08:50:10 +02:00
$fields->addFieldsToTab('Root.Content.OptionTests', array(
new CheckboxField('Checkbox', 'CheckboxField'),
new DropdownField('DropdownID', 'DropdownField', TestCategory::map()),
new GroupedDropdownField('GroupedDropdownID', 'GroupedDropdown', array('Test Categorys' => TestCategory::map())),
new ListboxField('ListboxFieldID', 'ListboxField', TestCategory::map(), array(), 3),
new OptionsetField('OptionSetID', 'OptionSetField', TestCategory::map()),
));
2008-10-03 00:05:45 +02:00
// All these date/time fields generally have issues saving directly in the CMS
2010-01-27 02:40:18 +01:00
$fields->addFieldsToTab('Root.Content.DateTimeTests', array(
2010-07-10 04:30:23 +02:00
$calendarDateField = new DateField('CalendarDate','DateField with calendar'),
2008-10-03 00:05:45 +02:00
new DateField('Date','DateField'),
new DateField_Disabled("DateDisabled","DateField (disabled)"),
2010-07-10 04:30:23 +02:00
$dmyDateField = new DateField('DMYDate','DateField with separate fields'),
new TimeField('Time','TimeField'),
new TimeField_Readonly('TimeDisabled','TimeField (disabled)'),
2010-07-10 04:30:23 +02:00
$timeFieldDropdown = new TimeField('TimeDropdown','TimeField with dropdown'),
new DatetimeField('DateTime', 'DateTime'),
new DatetimeField_Readonly('DateTimeDisabled', 'DateTime (disabled)'),
2010-07-10 04:30:23 +02:00
$dateTimeShowCalendar = new DatetimeField('DateTimeWithCalendar', 'DateTime with calendar')
2010-01-27 02:40:18 +01:00
));
2010-07-10 04:30:23 +02:00
$calendarDateField->setConfig('showcalendar', true);
$dmyDateField->setConfig('dmyfields', true);
$timeFieldDropdown->setConfig('showdropdown', true);
$dateTimeShowCalendar->getDateField()->setConfig('showcalendar', true);
$dateTimeShowCalendar->getTimeField()->setConfig('showdropdown', true);
2008-10-03 00:05:45 +02:00
$fields->addFieldsToTab('Root.Content.FileTests', array(
new ImageField('Image','ImageField'),
new SimpleImageField('Image2','SimpleImageField'),
new ImageField('Image3','ImageField'),
new FileIFrameField('File','FileIFrameField'),
new FileField('File2','FileField'),
new FileIFrameField('File3','FileIFrameField'),
));
2008-11-13 22:32:37 +01:00
2008-10-03 00:05:45 +02:00
return $fields;
2008-11-13 22:32:37 +01:00
2008-10-03 00:05:45 +02:00
}
}
class BasicFieldsTestPage_Controller extends TestPage_Controller {
function AutoCompleteItems() {
$items = array(
'TestItem1',
'TestItem2',
'TestItem3',
'TestItem4',
);
return implode(',', $items);
}
}
?>