function getCMSFields() { if ($this->ID != 0) { $totalCount = $this->getTotalVotes(); } else { $totalCount = 0; } $fields = new FieldList($rootTab = new TabSet("Root", new Tab("Main", new TextField('Title', 'Poll title (maximum 50 characters)', null, 50), new OptionsetField('MultiChoice', 'Single answer (radio buttons)/multi-choice answer (tick boxes)', array(0 => 'Single answer', 1 => 'Multi-choice answer')), new OptionsetField('IsActive', 'Poll state', array(1 => 'Active', 0 => 'Inactive')), $embargo = new DatetimeField('Embargo', 'Embargo'), $expiry = new DatetimeField('Expiry', 'Expiry'), new HTMLEditorField('Description', 'Description')))); $embargo->getDateField()->setConfig('showcalendar', true); $embargo->getTimeField()->setConfig('showdropdown', true); $embargo->getDateField()->setConfig('dateformat', 'dd/MM/YYYY'); $embargo->getTimeField()->setConfig('timeformat', 'h:m a'); $expiry->getDateField()->setConfig('showcalendar', true); $expiry->getTimeField()->setConfig('showdropdown', true); $expiry->getDateField()->setConfig('dateformat', 'dd/MM/YYYY'); $expiry->getTimeField()->setConfig('timeformat', 'h:m a'); // Add the fields that depend on the poll being already saved and having an ID if ($this->ID != 0) { $config = GridFieldConfig::create(); $config->addComponent(new GridFieldToolbarHeader()); $config->addComponent(new GridFieldAddNewButton('toolbar-header-right')); $config->addComponent(new GridFieldDataColumns()); $config->addComponent(new GridFieldEditButton()); $config->addComponent(new GridFieldDeleteAction()); $config->addComponent(new GridFieldDetailForm()); $config->addComponent(new GridFieldSortableHeader()); $pollChoicesTable = new GridField('Choices', 'Choices', $this->Choices(), $config); $fields->addFieldToTab('Root.Data', $pollChoicesTable); $fields->addFieldToTab('Root.Data', new ReadonlyField('Total', 'Total votes', $totalCount)); } else { $fields->addFieldToTab('Root.Choices', new ReadOnlyField('ChoicesPlaceholder', 'Choices', 'You will be able to add options once you have saved the poll for the first time.')); } $this->extend('updateCMSFields', $fields); return $fields; }
public function getCMSFields() { $fields = parent::getCMSFields(); Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js'); Requirements::javascript('eventmanagement/javascript/event-ticket-cms.js'); $fields->removeByName('EventID'); $fields->removeByName('StartType'); $fields->removeByName('StartDate'); $fields->removeByName('StartDays'); $fields->removeByName('StartHours'); $fields->removeByName('StartMins'); $fields->removeByName('EndType'); $fields->removeByName('EndDate'); $fields->removeByName('EndDays'); $fields->removeByName('EndHours'); $fields->removeByName('EndMins'); if (class_exists('Payment')) { $fields->insertBefore(new OptionSetField('Type', 'Ticket type', array('Free' => 'Free ticket', 'Price' => 'Fixed price ticket')), 'Price'); } else { $fields->removeByName('Type'); $fields->removeByName('Price'); } foreach (array('Start', 'End') as $type) { $fields->addFieldsToTab('Root.Main', array(new OptionSetField("{$type}Type", "{$type} sales at", array('Date' => 'A specific date and time', 'TimeBefore' => 'A time before the event starts')), $dateTime = new DatetimeField("{$type}Date", ''), $before = new FieldGroup("{$type}Offset", new NumericField("{$type}Days", 'Days'), new NumericField("{$type}Hours", 'Hours'), new NumericField("{$type}Mins", 'Minutes')))); $before->setName("{$type}Offset"); $before->setTitle(' '); $dateTime->getDateField()->setConfig('showcalendar', true); $dateTime->getTimeField()->setConfig('showdropdown', true); } $fields->addFieldsToTab('Root.Advanced', array(new TextareaField('Description', 'Description'), new NumericField('MinTickets', 'Minimum tickets per order'), new NumericField('MaxTickets', 'Maximum tickets per order'))); return $fields; }
function getCMSFields() { $fields = parent::getCMSFields(); $fields->addFieldsToTab('Root.Text', array(new ReadonlyField('Readonly', 'ReadonlyField'), new TextareaField('Textarea', 'TextareaField - 8 rows', 8), new TextField('Text', 'TextField'), new HtmlEditorField('HTMLField', 'HtmlEditorField'), new EmailField('Email', 'EmailField'), new PasswordField('Password', 'PasswordField'), new AjaxUniqueTextField('AjaxUniqueText', 'AjaxUniqueTextField', 'AjaxUniqueText', 'BasicFieldsTestPage'))); $fields->addFieldsToTab('Root.Numeric', array(new NumericField('Number', 'NumericField'), new CurrencyField('Price', 'CurrencyField'), new PhoneNumberField('PhoneNumber', 'PhoneNumberField'), new CreditCardField('CreditCard', 'CreditCardField'))); $fields->addFieldsToTab('Root.Option', array(new CheckboxField('Checkbox', 'CheckboxField'), new CheckboxSetField('CheckboxSet', 'CheckboxSetField', TestCategory::map()), 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()))); // All these date/time fields generally have issues saving directly in the CMS $fields->addFieldsToTab('Root.DateTime', array($calendarDateField = new DateField('CalendarDate', 'DateField with calendar'), new DateField('Date', 'DateField'), $dmyDateField = new DateField('DMYDate', 'DateField with separate fields'), new TimeField('Time', 'TimeField'), $timeFieldDropdown = new TimeField('TimeDropdown', 'TimeField with dropdown'), new DatetimeField('DateTime', 'DateTime'), $dateTimeShowCalendar = new DatetimeField('DateTimeWithCalendar', 'DateTime with calendar'))); $calendarDateField->setConfig('showcalendar', true); $dmyDateField->setConfig('dmyfields', true); $timeFieldDropdown->setConfig('showdropdown', true); $dateTimeShowCalendar->getDateField()->setConfig('showcalendar', true); $dateTimeShowCalendar->getTimeField()->setConfig('showdropdown', true); $fields->addFieldsToTab('Root.File', array(UploadField::create('File', 'FileUploadField'), UploadField::create('Image', 'ImageUploadField'), UploadField::create('HasManyFiles', 'HasManyFilesUploadField'), UploadField::create('ManyManyFiles', 'ManyManyFilesUploadField'))); $tabs = array('Root.Text', 'Root.Numeric', 'Root.Option', 'Root.DateTime', 'Root.File'); foreach ($tabs as $tab) { $tabObj = $fields->fieldByName($tab); foreach ($tabObj->FieldList() as $field) { $disabledField = $field->performDisabledTransformation(); $disabledField->setTitle($disabledField->Title() . ' (disabled)'); $disabledField->setName($disabledField->getName() . '_disabled'); $tabObj->insertAfter($disabledField, $field->getName()); $readonlyField = $field->performReadonlyTransformation(); $readonlyField->setTitle($readonlyField->Title() . ' (readonly)'); $readonlyField->setName($readonlyField->getName() . '_readonly'); $tabObj->insertAfter($readonlyField, $field->getName()); } } $fields->addFieldToTab('Root.Text', new TextField('Text_NoLabel', false, 'TextField without label'), 'Text_disabled'); return $fields; }
public function getFormField() { switch ($this->Type) { case 'datetime': $field = new DatetimeField($this->getFormFieldName(), $this->Title); $field->getDateField()->setConfig('showcalendar', true); $field->getTimeField()->setConfig('showdropdown', true); break; case 'date': $field = new DateField($this->getFormFieldName(), $this->Title); $field->setConfig('showcalendar', true); break; case 'time': $field = new TimeField($this->getFormFieldName(), $this->Title); $field->setConfig('showdropdown', true); break; } if ($this->DefaultType == 'created') { $field->setRightTitle('The value will default to the time this record was created.'); } return $field; }
function getCMSFields() { Requirements::javascript('blog/javascript/bbcodehelp.js'); Requirements::themedCSS('bbcodehelp'); $firstName = Member::currentUser() ? Member::currentUser()->FirstName : ''; $codeparser = new BBCodeParser(); SiteTree::disableCMSFieldsExtensions(); $fields = parent::getCMSFields(); SiteTree::enableCMSFieldsExtensions(); if (!self::$allow_wysiwyg_editing) { $fields->removeFieldFromTab("Root.Content.Main", "Content"); $fields->addFieldToTab("Root.Content.Main", new TextareaField("Content", _t("BlogEntry.CN", "Content"), 20)); } $fields->addFieldToTab("Root.Content.Main", $dateField = new DatetimeField("Date", _t("BlogEntry.DT", "Date")), "Content"); $dateField->getDateField()->setConfig('showcalendar', true); $dateField->getTimeField()->setConfig('showdropdown', true); $fields->addFieldToTab("Root.Content.Main", new TextField("Author", _t("BlogEntry.AU", "Author"), $firstName), "Content"); if (!self::$allow_wysiwyg_editing) { $fields->addFieldToTab("Root.Content.Main", new LiteralField("BBCodeHelper", "<div id='BBCode' class='field'>" . "<a id=\"BBCodeHint\" target='new'>" . _t("BlogEntry.BBH", "BBCode help") . "</a>" . "<div id='BBTagsHolder' style='display:none;'>" . $codeparser->useable_tagsHTML() . "</div></div>")); } $fields->addFieldToTab("Root.Content.Main", new TextField("Tags", _t("BlogEntry.TS", "Tags (comma sep.)")), "Content"); $this->extend('updateCMSFields', $fields); return $fields; }
/** * Form used for displaying the currently logged items */ public function LogsForm() { $fields = new FieldList(DropdownField::create('CalledMethod', _t('KapostBridgeLogViewer.CALLED_METHOD', '_Called Method'), array('blogger.getUsersBlogs' => 'blogger.getUsersBlogs', 'kapost.getPreview' => 'kapost.getPreview', 'metaWeblog.editPost' => 'metaWeblog.editPost', 'metaWeblog.getCategories' => 'metaWeblog.getCategories', 'metaWeblog.getPost' => 'metaWeblog.getPost', 'metaWeblog.newMediaObject' => 'metaWeblog.newMediaObject', 'metaWeblog.newPost' => 'metaWeblog.newPost', 'system.listMethods' => 'system.listMethods'))->setEmptyString('--- ' . _t('KapostBridgeLogViewer.FILTER_BY_METHOD', '_Filter by Method') . ' ---'), $startDate = new DatetimeField('LogStartDate', _t('KapostBridgeLogViewer.START_DATE_TIME', '_Start Date/Time')), $endDate = new DatetimeField('LogEndDate', _t('KapostBridgeLogViewer.END_DATE_TIME', '_End Date/Time'))); $startDate->getDateField()->setConfig('showcalendar', true)->setAttribute('placeholder', _t('KapostBridgeLogViewer.DATE_FORMAT', '_MMM d, y'))->setDescription(_t('KapostBridgeLogViewer.DATE_FORMAT_DESC', '_e.g. Jan 27, 2016')); $startDate->getTimeField()->setAttribute('placeholder', _t('KapostBridgeLogViewer.TIME_FORMAT', '_h:mm:ss a'))->setDescription(_t('KapostBridgeLogViewer.TIME_FORMAT_DESC', '_e.g. 12:15:13 PM')); $endDate->getDateField()->setConfig('showcalendar', true)->setAttribute('placeholder', _t('KapostBridgeLogViewer.DATE_FORMAT', '_MMM d, y'))->setDescription(_t('KapostBridgeLogViewer.DATE_FORMAT_DESC', '_e.g. Jan 27, 2016')); $endDate->getTimeField()->setAttribute('placeholder', _t('KapostBridgeLogViewer.TIME_FORMAT', '_h:mm:ss a'))->setDescription(_t('KapostBridgeLogViewer.TIME_FORMAT_DESC', '_e.g. 12:15:13 PM')); $actions = new FieldList(FormAction::create('doApplyFilters', _t('KapostBridgeLogViewer.APPLY_FILTER', '_Apply Filter'))->addExtraClass('ss-ui-action-constructive')->setUseButtonTag(true), Object::create('ResetFormAction', 'clear', _t('KapostBridgeLogViewer.RESET', '_Reset'))->setUseButtonTag(true)); $form = new Form($this, 'LogsForm', $fields, $actions); $form->addExtraClass('log-search-form')->setFormMethod('GET')->setFormAction($this->Link())->disableSecurityToken()->unsetValidator(); // Load the form with previously sent search data $getVars = $this->request->getVars(); //Workaround for start date field with no date or time if (array_key_exists('LogStartDate', $getVars)) { if (array_key_exists('date', $getVars['LogStartDate']) && !array_key_exists('time', $getVars['LogStartDate'])) { $getVars['LogStartDate']['time'] = '00:00:00'; } else { if (!array_key_exists('date', $getVars['LogStartDate']) && array_key_exists('time', $getVars['LogStartDate'])) { unset($getVars['LogStartDate']); //Remove if there is no date present } } } //Workaround for end date field with no date or time if (array_key_exists('LogEndDate', $getVars)) { if (array_key_exists('date', $getVars['LogEndDate']) && !array_key_exists('time', $getVars['LogEndDate'])) { $getVars['LogEndDate']['time'] = '23:59:59'; } else { if (!array_key_exists('date', $getVars['LogEndDate']) && array_key_exists('time', $getVars['LogEndDate'])) { unset($getVars['LogEndDate']); //Remove if there is no date present } } } $form->loadDataFrom($getVars); return $form; }
public function testTimezoneFromFormSubmission() { $oldTz = date_default_timezone_get(); date_default_timezone_set('Europe/Berlin'); // Berlin and Auckland have 12h time difference in northern hemisphere summer, but Berlin and Moscow only 2h. $f = new DatetimeField('Datetime', 'Datetime'); $f->setConfig('usertimezone', 'Pacific/Auckland'); // should be overridden by form submission $f->setValue(array('date' => '24/06/2003', 'time' => '23:59:59', 'timezone' => 'Europe/Moscow')); $this->assertEquals('24/06/2003 23:59:59', $f->Value(), 'View composite value matches user timezone'); $this->assertEquals('24/06/2003', $f->getDateField()->Value(), 'View date part matches user timezone'); $this->assertEquals('23:59:59', $f->getTimeField()->Value(), 'View time part matches user timezone'); // 2h difference to Moscow $this->assertEquals('2003-06-24 21:59:59', $f->dataValue(), 'Data value matches server timezone'); date_default_timezone_set($oldTz); }
function getCMSFields() { if ($this->FolderID) { // New token - select file: $folder = DataObject::get_by_id('Folder', $this->FolderID); $files = new DataObjectSet(); if ($folder->myChildren()) { foreach ($folder->myChildren() as $file) { if (!$file instanceof Folder) { $files->push($file); } } $files->sort('Name'); } $fileField = new DropdownField('FileID', 'File', $files->map('ID', 'Name')); } else { // Existing token: $fileField = new ReadonlyField('FileDummy', 'File', $this->File()->Name); } $fields = new FieldSet(); $fields->push($root = new TabSet('Root')); $root->push($main = new Tab('Main')); $main->push($fileField); if (ClassInfo::exists('DatetimeField')) { // 2.4.x $main->push($expiry_field = new DatetimeField('Expiry', 'Expiry')); $expiry_field->getDateField()->setConfig('showcalendar', true); $expiry_field->getTimeField()->setConfig('showdropdown', true); } else { // 2.3.x $main->push($expiry_field = new PopupDateTimeField('Expiry', 'Expiry')); } $main->push(new ReadonlyField('MemberDummyField', 'Member', $this->MemberNice())); if ($this->ID) { $main->push(new ReadonlyField('Token', 'Token')); } $this->extend('updateCMSFields', $fields); return $fields; }
public function testSetName() { $field = new DatetimeField('Datetime', 'Datetime'); $field->setName('CustomDatetime'); $this->assertEquals('CustomDatetime', $field->getName()); $this->assertEquals('CustomDatetime[date]', $field->getDateField()->getName()); $this->assertEquals('CustomDatetime[time]', $field->getTimeField()->getName()); $this->assertEquals('CustomDatetime[timezone]', $field->getTimezoneField()->getName()); }
protected function getBaseFields() { $testState = $this->environment->getState(); $fields = new FieldList($textfield = new TextField('fixture', 'Fixture YAML file path'), $datetimeField = new DatetimeField('datetime', 'Custom date'), new HiddenField('flush', null, 1)); $textfield->setAttribute('placeholder', 'Example: framework/tests/security/MemberTest.yml'); $datetimeField->getDateField()->setConfig('dateformat', 'yyyy-MM-dd')->setConfig('showcalendar', true)->setAttribute('placeholder', 'Date (yyyy-MM-dd)'); $datetimeField->getTimeField()->setConfig('timeformat', 'HH:mm:ss')->setAttribute('placeholder', 'Time (HH:mm:ss)'); $datetimeField->setValue(isset($testState->datetime) ? $testState->datetime : null); $this->extend('updateBaseFields', $fields); return $fields; }
function getHTML($page) { Requirements::css('cmsworkflow/css/FutureStateNavigatorItem.css'); Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js'); Requirements::javascript(THIRDPARTY_DIR . '/jquery-livequery/jquery.livequery.js'); Requirements::javascript('cmsworkflow/javascript/futurestate.js'); $datetimeField = new DatetimeField('FutureStateDate', 'Date'); $datetimeField->getDateField()->setConfig('showcalendar', true); $datetimeField->getTimeField()->setConfig('showdropdown', true); $datetime = SiteTreeFutureState::get_future_datetime(); if ($datetime) { $datetimeField->setValue($datetime); } $data = new ArrayData(array('Page' => $page, 'DateTimeField' => $datetimeField, 'Current' => (bool) $datetime)); return $data->renderWith(array('FutureStateNavigatorItem')); }
/** * Configures the Date and Time fields in the wrapping DatetimeField. * * @param DTField $field * @param bool $showMultipleFields */ protected function configureDateTimeField(DTField $field, $showMultipleFields = true) { if ($showMultipleFields) { $this->configureDateField($field->getDateField(), $showMultipleFields); $this->configureTimeField($field->getTimeField(), $showMultipleFields); } }