/** * @param $data * @param $form * @return bool|SS_HTTPResponse */ public function doDelete($data, $form) { VersionedReadingMode::setStageReadingMode(); $value = parent::doDelete($data, $form); VersionedReadingMode::restoreOriginalReadingMode(); return $value; }
/** * @return {Form} */ public function ItemEditForm() { //Timepicker Requirements::css('calendar/thirdparty/timepicker/jquery.timepicker.css'); //Requirements::javascript('calendar/thirdparty/timepicker/jquery.timepicker.js'); //modification to allow timepicker and timeentry to work in tandem: Requirements::javascript('calendar/thirdparty/timepicker/jquery.timepicker-timeentry.js'); //Timeentry Requirements::javascript('calendar/thirdparty/timeentry/jquery.timeentry.js'); //CSS/JS Dependencies Requirements::css("calendar/css/admin/CalendarEventGridFieldDetailForm.css"); Requirements::javascript("calendar/javascript/events/EventFields.js"); Requirements::javascript("calendar/javascript/admin/CalendarEventGridFieldDetailForm.js"); $form = parent::ItemEditForm(); if (!$form instanceof Form) { return $form; } $form->addExtraClass('CalendarEventGridfieldDetailForm'); if ($this->record->ID !== 0) { $actionFields = $form->Actions(); $link = Controller::join_links($this->gridField->Link('item'), 'new'); $actionFields->push(new LiteralField('addNew', '<a href="' . $link . '" class="action action-detail ss-ui-action-constructive ' . 'ss-ui-button ui-button ui-widget ui-state-default ui-corner-all new new-link" data-icon="add">Add new ' . $this->record->i18n_singular_name() . '</a>')); } return $form; }
protected function getFormActions() { $actions = parent::getFormActions(); // Check if record is versionable $record = $this->getRecord(); if (!$record || !$record->has_extension('Versioned')) { return $actions; } // Save & Publish action if ($record->canPublish()) { // "publish", as with "save", it supports an alternate state to show when action is needed. $publish = FormAction::create('doPublish', _t('VersionedGridFieldItemRequest.BUTTONPUBLISH', 'Publish'))->setUseButtonTag(true)->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'accept'); // Insert after save if ($actions->fieldByName('action_doSave')) { $actions->insertAfter('action_doSave', $publish); } else { $actions->push($publish); } } // Unpublish action $isPublished = $record->isPublished(); if ($isPublished && $record->canUnpublish()) { $actions->push(FormAction::create('doUnpublish', _t('VersionedGridFieldItemRequest.BUTTONUNPUBLISH', 'Unpublish'))->setUseButtonTag(true)->setDescription(_t('VersionedGridFieldItemRequest.BUTTONUNPUBLISHDESC', 'Remove this record from the published site'))->addExtraClass('ss-ui-action-destructive')); } // Archive action if ($record->canArchive()) { // Replace "delete" action $actions->removeByName('action_doDelete'); // "archive" $actions->push(FormAction::create('doArchive', _t('VersionedGridFieldItemRequest.ARCHIVE', 'Archive'))->setDescription(_t('VersionedGridFieldItemRequest.BUTTONARCHIVEDESC', 'Unpublish and send to archive'))->addExtraClass('delete ss-ui-action-destructive')); } return $actions; }
function ItemEditForm() { $form = parent::ItemEditForm(); $actions = $form->Actions(); $majorActions = CompositeField::create()->setName('MajorActions')->setTag('fieldset')->addExtraClass('ss-ui-buttonset'); $rootTabSet = new TabSet('ActionMenus'); $moreOptions = new Tab('MoreOptions', _t('SiteTree.MoreOptions', 'More options', 'Expands a view for more buttons')); $rootTabSet->push($moreOptions); $rootTabSet->addExtraClass('ss-ui-action-tabset action-menus'); // Render page information into the "more-options" drop-up, on the top. $baseClass = ClassInfo::baseDataClass($this->record->class); $live = Versioned::get_one_by_stage($this->record->class, 'Live', "\"{$baseClass}\".\"ID\"='{$this->record->ID}'"); $existsOnLive = $this->record->getExistsOnLive(); $published = $this->record->isPublished(); $moreOptions->push(new LiteralField('Information', $this->record->customise(array('Live' => $live, 'ExistsOnLive' => $existsOnLive))->renderWith('SiteTree_Information'))); $actions->removeByName('action_doSave'); $actions->removeByName('action_doDelete'); if ($this->record->canEdit()) { if ($this->record->IsDeletedFromStage) { if ($existsOnLive) { $majorActions->push(FormAction::create('revert', _t('CMSMain.RESTORE', 'Restore'))); if ($this->record->canDelete() && $this->record->canDeleteFromLive()) { $majorActions->push(FormAction::create('unpublish', _t('CMSMain.DELETEFP', 'Delete'))->addExtraClass('ss-ui-action-destructive')); } } else { if (!$this->record->isNew()) { $majorActions->push(FormAction::create('restore', _t('CMSMain.RESTORE', 'Restore'))->setAttribute('data-icon', 'decline')); } else { $majorActions->push(FormAction::create('save', _t('SiteTree.BUTTONSAVED', 'Saved'))->addExtraClass('ss-ui-alternate ss-ui-action-constructive')->setAttribute('data-icon', 'accept')->setAttribute('data-icon-alternate', 'addpage')->setAttribute('data-text-alternate', _t('CMSMain.SAVEDRAFT', 'Save draft'))->setUseButtonTag(true)); $majorActions->push(FormAction::create('publish', _t('SiteTree.BUTTONPUBLISHED', 'Published'))->addExtraClass('ss-ui-alternate ss-ui-action-constructive')->setAttribute('data-icon', 'accept')->setAttribute('data-icon-alternate', 'disk')->setAttribute('data-text-alternate', _t('SiteTree.BUTTONSAVEPUBLISH', 'Save & publish'))->setUseButtonTag(true)); } } } else { if ($this->record->canDelete() && !$published) { $moreOptions->push(FormAction::create('delete', _t('SiteTree.BUTTONDELETE', 'Delete draft'))->addExtraClass('ss-ui-action-destructive')->setUseButtonTag(true)); } $majorActions->push(FormAction::create('save', _t('SiteTree.BUTTONSAVED', 'Saved'))->setAttribute('data-icon', 'accept')->setAttribute('data-icon-alternate', 'addpage')->setAttribute('data-text-alternate', _t('CMSMain.SAVEDRAFT', 'Save draft'))->setUseButtonTag(true)); } } $publish = FormAction::create('publish', $published ? _t('SiteTree.BUTTONPUBLISHED', 'Published') : _t('SiteTree.BUTTONSAVEPUBLISH', 'Save & publish'))->setAttribute('data-icon', 'accept')->setAttribute('data-icon-alternate', 'disk')->setAttribute('data-text-alternate', _t('SiteTree.BUTTONSAVEPUBLISH', 'Save & publish'))->setUseButtonTag(true); if (!$published || $this->record->stagesDiffer('Stage', 'Live') && $published) { $publish->addExtraClass('ss-ui-alternate'); } if ($this->record->canPublish() && !$this->record->IsDeletedFromStage) { $majorActions->push($publish); } if ($published && $this->record->canPublish() && !$this->record->IsDeletedFromStage && $this->record->canDeleteFromLive()) { $moreOptions->push(FormAction::create('unpublish', _t('SiteTree.BUTTONUNPUBLISH', 'Unpublish'), 'delete')->addExtraClass('ss-ui-action-destructive')->setUseButtonTag(true)); } if ($this->record->stagesDiffer('Stage', 'Live') && !$this->record->IsDeletedFromStage && $this->record->isPublished() && $this->record->canEdit()) { $moreOptions->push(FormAction::create('rollback', _t('SiteTree.BUTTONCANCELDRAFT', 'Cancel draft changes'))->setDescription(_t('SiteTree.BUTTONCANCELDRAFTDESC', 'Delete your draft and revert to the currently published page'))->setUseButtonTag(true)); } $actions->push($majorActions); $actions->push($rootTabSet); if ($this->record->hasMethod('getCMSValidator')) { $form->setValidator($this->record->getCMSValidator()); } return $form; }
public function ItemEditForm() { $form = parent::ItemEditForm(); if ($this->record->isInDB() && $this->record->canGenerate()) { $form->Actions()->merge(array(FormAction::create('reportpreview', '')->setTitle(_t('AdvancedReport.PREVIEW', 'Preview'))->setAttribute('target', '_blank')->setAttribute('data-icon', 'preview'), FormAction::create('generate', '')->setTitle(_t('AdvancedReport.GENERATE', 'Generate')))); } return $form; }
function ItemEditForm() { $form = parent::ItemEditForm(); if ($this->record->getCMSActions() && $this->record->getCMSActions()->count()) { $form->setActions($this->record->getCMSActions()); } return $form; }
public function Link($action = null) { if ($this->record->ID) { return parent::Link($action); } else { return Controller::join_links($this->gridField->Link(), 'add-multi-class', get_class($this->record)); } }
function ItemEditForm() { $form = parent::ItemEditForm(); if ($this->record->ID) { $form->Actions()->push($action = FormAction::create('previewpdf', 'Preview')->setAttribute('data-link', $this->Link() . '/previewpdf')); $form->Actions()->push($action = FormAction::create('compose', 'Compose')); } return $form; }
/** * Add print button to order detail form */ public function ItemEditForm() { $form = parent::ItemEditForm(); $printlink = $this->Link('printorder') . "?print=1"; $printwindowjs = <<<JS \t\t\twindow.open('{$printlink}', 'print_order', 'toolbar=0,scrollbars=1,location=1,statusbar=0,menubar=0,resizable=1,width=800,height=600,left = 50,top = 50');return false; JS; $form->Actions()->push(new LiteralField("PrintOrder", "<button class=\"no-ajax grid-print-button\" data-icon=\"grid_print\" onclick=\"javascript:{$printwindowjs}\">" . _t("Order.PRINT", "Print") . "</button>")); return $form; }
/** * adds a new button allowing users * to add a new record directly from the edit screen * @return {Form} */ public function ItemEditForm() { $form = parent::ItemEditForm(); if ($this->record->ID !== 0) { $actionFields = $form->Actions(); $link = Controller::join_links($this->gridField->Link('item'), 'new'); $actionFields->push(new LiteralField('addNew', '<a href="' . $link . '" class="action action-detail ss-ui-action-constructive ss-ui-button ui-button ui-widget ui-state-default ui-corner-all new new-link" data-icon="add">' . _t("GridFieldDetailFormAddNew.ADD", "_Add") . ' ' . $this->record->i18n_singular_name() . '</a>')); } return $form; }
function doSave($data, $form) { $new_record = $this->record->ID == 0; if ($new_record && isset($data['TemplateID']) && !empty($data['TemplateID'])) { $template = Subsite::get()->byID(intval($data['TemplateID'])); if ($template) { $this->record = $template->duplicate(); } } return parent::doSave($data, $form); }
function ItemEditForm() { $form = parent::ItemEditForm(); $actions = $this->record->getCMSActions(); $oldActions = $form->Actions(); foreach ($actions as $action) { $oldActions->push($action); } $form->setActions($oldActions); return $form; }
public function ItemEditForm() { $form = parent::ItemEditForm(); $action = 'Save'; if (!$this->record->ID) { $action = 'Create'; } $form->Actions()->push(FormAction::create('SaveAndClose', $action . ' & Close')); $form->Actions()->push(FormAction::create('SaveAndAdd', $action . ' & Add Another')); return $form; }
/** * @param $data * @param $form * @return bool|SS_HTTPResponse */ public function doDelete($data, $form) { $currentStage = Versioned::current_stage(); if ($this->record->isPublished()) { $this->unpublish($data, $form); } Versioned::reading_stage('Stage'); $action = parent::doDelete($data, $form); Versioned::reading_stage($currentStage); return $action; }
public function ItemEditForm() { $form = parent::ItemEditForm(); if ($this->record->ID !== 0) { $form->Actions()->insertAfter(FormAction::create('doPublish', 'Save & Publish')->setUseButtonTag(true)->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'accept'), 'action_doSave'); if ($this->record->isPublished()) { $form->Actions()->push(FormAction::create('doUnpublish', 'Un-publish')->setUseButtonTag(true)->addExtraClass('ss-ui-action-destructive action-unpublished')); } } return $form; }
function ItemEditForm() { $form = parent::ItemEditForm(); //add a data attribute specifying how many pages this document is referenced on if ($record = $this->record) { $numberOfPageRelations = $record->Pages()->Count(); $relations = new ShortCodeRelationFinder(); $numberOfInlineRelations = $relations->findPageCount($record->ID); //add the number of pages attached to this field as a data-attribute $form->setAttribute('data-pages-count', $numberOfPageRelations); $form->setAttribute('data-relation-count', $numberOfInlineRelations); } return $form; }
public function ItemEditForm() { $form = parent::ItemEditForm(); // Do these action update only when the current record is_a newsletter if ($this->record && $this->record instanceof Newsletter) { $form->setActions($this->updateCMSActions($form->Actions())); $form->Fields()->push(new HiddenField("PreviewURL", "PreviewURL", $this->LinkPreview())); // Added in-line to the form, but plucked into different view by LeftAndMain.Preview.js upon load $navField = new LiteralField('SilverStripeNavigator', $this->getSilverStripeNavigator()); $navField->setAllowHTML(true); $form->Fields()->push($navField); } return $form; }
/** * @return Form */ public function ItemEditForm() { if (!$this->record->isPublished()) { Versioned::reading_stage('Stage'); } if (!$this->record->ParentID) { // set a parent id for the record, even if it will change $parents = $this->record->getCatalogParents(); if ($parents && $parents->count()) { $this->record->ParentID = $parents->first()->ID; } } return parent::ItemEditForm(); }
public function ItemEditForm() { $form = parent::ItemEditForm(); if (!$this->record->ID) { return $form; } $formActions = $form->Actions(); if ($actions = $this->record->getCMSActions()) { foreach ($actions as $action) { $formActions->push($action); } } return $form; }
public function ItemEditForm() { Requirements::css('silverstripe-postmarked/css/messages.css'); Requirements::javascript('silverstripe-postmarked/javascript/Messages.js'); $form = parent::ItemEditForm(); $form->setTemplate('PostmarkEditorTemplate'); if ($this->record) { $message = PostmarkMessage::get()->byID($this->record->ID); if (!$message->Read) { $message->Read = 1; $message->write(); } } return $form; }
public function ItemEditForm() { $form = parent::ItemEditForm(); $formActions = $form->Actions(); if ($actions = $this->record->getCMSActions()) { foreach ($actions as $action) { $formActions->push($action); } } $dataObjectName = $this->record->ClassName; if ($dataObjectName == 'Subscription' || $dataObjectName == 'CreditCard') { $formActions->removeByName('action_doSave'); $formActions->removeByName('action_doDelete'); } return $form; }
public function ItemEditForm() { $form = parent::ItemEditForm(); $fields = $form->Fields(); $actions = $form->Actions(); if ($this->record->ID !== 0 && $this->record->canEdit()) { // Remove the disabled field $fields->removeByName("Disabled"); if ($this->record->isEnabled()) { $actions->insertBefore(FormAction::create('doDisable', _t('Catalogue.Disable', 'Disable'))->setUseButtonTag(true)->addExtraClass('ss-ui-action-destructive'), "action_doDelete"); } elseif ($this->record->isDisabled()) { $actions->insertBefore(FormAction::create('doEnable', _t('Catalogue.Enable', 'Enable'))->setUseButtonTag(true), "action_doDelete"); } } return $form; }
/** * Builds an item edit form. The arguments to getCMSFields() are the popupController and popupFormName, however this is an experimental API and may change. * @return {Form} */ public function ItemEditForm() { $form = parent::ItemEditForm(); if ($form) { if ($this->record && $this->record->exists()) { $kapostBase = KapostAdmin::config()->kapost_base_url; if ($kapostBase[strlen($kapostBase) - 1] != '/') { $kapostBase .= '/'; } $form->Fields()->addFieldToTab('Root.Main', $field = ReadonlyField::create('KapostRefID_linked', $this->record->fieldLabel('KapostRefID'), !empty($kapostBase) ? '<a href="' . htmlentities($kapostBase . 'posts/' . $this->record->KapostRefID) . '" target="_blank">' . htmlentities($this->record->KapostRefID) . '</a>' : $this->record->KapostRefID)->setForm($form)); $field->dontEscape = true; $form->Actions()->insertBefore(FormAction::create('doConvertPost', _t('KapostAdmin.CONVERT_OBJECT', '_Convert Object'))->setUseButtonTag(true)->addExtraClass('ss-ui-action-constructive kapost-action-convert')->setAttribute('data-icon', 'kapost-convert')->setForm($form), 'action_doDelete'); } $form->addExtraClass('KapostAdmin'); } return $form; }
public function doSave($data, $form) { if ($this->record->ID == 0 && $this->component instanceof LRGridFieldDetailForm && $this->component->getItemLimit() > 0 && $this->gridField->getList()->count() + 1 > $this->component->getItemLimit()) { $form->sessionMessage(_t('LimitedRelationsGridField.ITEM_LIMIT_REACHED', '_You cannot add any more items, you can only add {count} items. Please remove one then try again.', array('count' => $this->component->getItemLimit())), 'bad'); $responseNegotiator = new PjaxResponseNegotiator(array('CurrentForm' => function () use(&$form) { return $form->forTemplate(); }, 'default' => function () use(&$controller) { return $controller->redirectBack(); })); $controller = Controller::curr(); if ($controller->getRequest()->isAjax()) { $controller->getRequest()->addHeader('X-Pjax', 'CurrentForm'); } return $responseNegotiator->respond($controller->getRequest()); } return parent::doSave($data, $form); }
public function ItemEditForm() { $form = parent::ItemEditForm(); if ($form instanceof Form) { $actions = $form->Actions(); $record = $this->record; $actions->insertBefore('action_doDelete', $btnPublish = FormAction::create('doPublish', 'Save & Publish')); $btnPublish->addExtraClass('ss-ui-action-constructive'); if (!empty($record->ID)) { if ($record->isPublished()) { $actions->removeByName('action_doDelete'); $actions->push(FormAction::create('doUnpublish', 'Unpublish')->addExtraClass('ss-ui-action-destructive')); } } $form->setActions($actions); } return $form; }
/** * Chechs the current object in SEO Admin and creats publish and draft buttons if * the current object is an instance of Page * * @since version 1.0.2 * * @return object Returns a record FieldList **/ public function ItemEditForm() { $form = parent::ItemEditForm(); if ($this->record instanceof Page) { $actions = $form->Actions(); $actions->removeByName('action_doSave'); $button = FormAction::create('doDraft'); $button->setTitle('Save as Draft'); $button->addExtraClass('ss-ui-action '); $actions->push($button); $button = FormAction::create('doPublish'); $button->setTitle('Save & Publish'); $button->addExtraClass('ss-ui-action-constructive ui-button-text-icon-primary'); $actions->push($button); $form->setActions($actions); } return $form; }
/** * Takes the action at /customaction/my-action-name and feeds it to the DataObject. * Checks to see if the method is allowed to be invoked first. * * @param SS_HTTPRequest $r * @return SS_HTTPResponse */ public function handleCustomAction(SS_HTTPRequest $r) { $action = $r->param('Action'); if (!$this->record->isCustomActionAllowed($action)) { return $this->httpError(403); } $formAction = $this->record->findActionByName($action); if (!$formAction) { return $this->httpError(403, "Action {$action} doesn't exist"); } $message = $this->record->{$action}($formAction, $this->controller, $r); Controller::curr()->getResponse()->addHeader("X-Pjax", "Content"); Controller::curr()->getResponse()->addHeader('X-Status', $message); if ($formAction->getRedirectURL()) { return Controller::curr()->redirect($formAction->getRedirectURL()); } if ($formAction->getRedirectType() == BetterButtonCustomAction::GOBACK) { return Controller::curr()->redirect(preg_replace('/\\?.*/', '', $this->parent->getBackLink())); } return Controller::curr()->redirect($this->controller->getEditLink($this->record->ID)); }
public function ItemEditForm() { $form = parent::ItemEditForm(); $actions = $this->getCMSActions(); $form->setActions($actions); return $form; }
public function testItemEditFormCallback() { $this->logInWithPermission('ADMIN'); $category = new GridFieldDetailFormTest_Category(); $component = new GridFieldDetailForm(); $component->setItemEditFormCallback(function ($form, $component) { $form->Fields()->push(new HiddenField('Callback')); }); // Note: A lot of scaffolding to execute the tested logic, // due to the coupling of form creation with request handling (and its context) $request = new GridFieldDetailForm_ItemRequest(GridField::create('Categories', 'Categories'), $component, $category, new Controller(), 'Form'); $form = $request->ItemEditForm(); $this->assertNotNull($form->Fields()->fieldByName('Callback')); }
public function edit($request) { Requirements::javascript(USERFORMS_DIR . '/javascript/Recipient.js'); return parent::edit($request); }