function updateImportForm(Form $form)
 {
     /* @var $owner ModelAdmin */
     $owner = $this->owner;
     $class = $owner->modelClass;
     // Overwrite model imports
     $importerClasses = $owner->stat('model_importers');
     if (is_null($importerClasses)) {
         $models = $owner->getManagedModels();
         foreach ($models as $modelName => $options) {
             $importerClasses[$modelName] = 'ExcelBulkLoader';
         }
         $owner->set_stat('model_importers', $importerClasses);
     }
     $modelSNG = singleton($class);
     $modelName = $modelSNG->i18n_singular_name();
     $fields = $form->Fields();
     $content = _t('ModelAdminExcelExtension.DownloadSample', '<div class="field"><a href="{link}">Download sample file</a></div>', array('link' => $owner->Link($class . '/downloadsample')));
     $file = $fields->dataFieldByName('_CsvFile');
     if ($file) {
         $file->setDescription(ExcelImportExport::getValidExtensionsText());
         $file->getValidator()->setAllowedExtensions(ExcelImportExport::getValidExtensions());
     }
     $fields->removeByName("SpecFor{$modelName}");
     $fields->insertAfter('EmptyBeforeImport', new LiteralField("SampleFor{$modelName}", $content));
     if (!$modelSNG->canDelete()) {
         $fields->removeByName('EmptyBeforeImport');
     }
     $actions = $form->Actions();
     $import = $actions->dataFieldByName('action_import');
     if ($import) {
         $import->setTitle(_t('ModelAdminExcelExtension.ImportExcel', "Import from Excel"));
     }
 }
 public function updateEditForm(Form $form)
 {
     $sng = singleton($this->modelClass());
     if ($sng->hasExtension('ScriptGenieExtension')) {
         $form->Actions()->push(FormAction::create('regenerate', 'Regenerate Data'));
     }
 }
 public function alterCommentForm(Form $form)
 {
     $form->Fields()->bootstrapify();
     $form->Actions()->bootstrapify();
     $form->setTemplate('FoundationCommentingControllerForm', 'FoundationForm');
     if ($form->hasExtension('FormSpamProtectionExtension')) {
         $form->enableSpamProtection();
     }
     Requirements::css(FOUNDATIONFORMS_DIR . '/css/foundationforms.css');
 }
 public function updateProfileForm(Form $form)
 {
     if (!Config::inst()->get('BootstrapForm', 'bootstrap_included')) {
         Requirements::css(BOOTSTRAP_FORMS_DIR . '/css/bootstrap.css');
     }
     if (!Config::inst()->get('BootstrapForm', 'jquery_included')) {
         Requirements::javascript(THIRDPARTY_DIR . "/jquery/jquery.js");
     }
     if (!Config::inst()->get('BootstrapForm', 'bootstrap_form_included')) {
         Requirements::javascript(BOOTSTRAP_FORMS_DIR . "/javascript/bootstrap_forms.js");
     }
     $form->Fields()->bootstrapify();
     $form->Actions()->bootstrapify();
     $form->addExtraClass('well');
     $form->addExtraClass('form-horizontal');
     $form->setTemplate('BootstrapForm');
 }
 /**
  * Updates the form to include an update shipping button
  * @param {Form} $form Form to update
  */
 public function updateOrderForm(Form $form)
 {
     $form->Actions()->insertBefore(FormAction::create('doUpdateShipping', _t('FedExOrderFormExtension.UPDATE_SHIPPING', '_Update Shipping'))->setForm($form), 'action_checkoutSubmit');
 }
Example #6
0
 /**
  * Builds an item edit form.  The arguments to getCMSFields() are the popupController and
  * popupFormName, however this is an experimental API and may change.
  * 
  * @todo In the future, we will probably need to come up with a tigher object representing a partially
  * complete controller with gaps for extra functionality.  This, for example, would be a better way
  * of letting Security/login put its log-in form inside a UI specified elsewhere.
  * 
  * @return Form 
  */
 public function ItemEditForm()
 {
     $list = $this->gridField->getList();
     if (empty($this->record)) {
         $controller = $this->getToplevelController();
         $noActionURL = $controller->removeAction($_REQUEST['url']);
         $controller->getResponse()->removeHeader('Location');
         //clear the existing redirect
         return $controller->redirect($noActionURL, 302);
     }
     $canView = $this->record->canView();
     $canEdit = $this->record->canEdit();
     $canDelete = $this->record->canDelete();
     $canCreate = $this->record->canCreate();
     if (!$canView) {
         $controller = $this->getToplevelController();
         // TODO More friendly error
         return $controller->httpError(403);
     }
     $actions = new FieldList();
     if ($this->record->ID !== 0) {
         if ($canEdit) {
             $actions->push(FormAction::create('doSave', _t('GridFieldDetailForm.Save', 'Save'))->setUseButtonTag(true)->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'accept'));
         }
         if ($canDelete) {
             $actions->push(FormAction::create('doDelete', _t('GridFieldDetailForm.Delete', 'Delete'))->setUseButtonTag(true)->addExtraClass('ss-ui-action-destructive action-delete'));
         }
     } else {
         // adding new record
         //Change the Save label to 'Create'
         $actions->push(FormAction::create('doSave', _t('GridFieldDetailForm.Create', 'Create'))->setUseButtonTag(true)->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'add'));
         // Add a Cancel link which is a button-like link and link back to one level up.
         $curmbs = $this->Breadcrumbs();
         if ($curmbs && $curmbs->count() >= 2) {
             $one_level_up = $curmbs->offsetGet($curmbs->count() - 2);
             $text = sprintf("<a class=\"%s\" href=\"%s\">%s</a>", "crumb ss-ui-button ss-ui-action-destructive cms-panel-link ui-corner-all", $one_level_up->Link, _t('GridFieldDetailForm.CancelBtn', 'Cancel'));
             $actions->push(new LiteralField('cancelbutton', $text));
         }
     }
     $fields = $this->component->getFields();
     if (!$fields) {
         $fields = $this->record->getCMSFields();
     }
     // If we are creating a new record in a has-many list, then
     // pre-populate the record's foreign key. Also disable the form field as
     // it has no effect.
     if ($list instanceof HasManyList) {
         $key = $list->getForeignKey();
         $id = $list->getForeignID();
         if (!$this->record->isInDB()) {
             $this->record->{$key} = $id;
         }
         if ($field = $fields->dataFieldByName($key)) {
             $fields->makeFieldReadonly($field);
         }
     }
     // Caution: API violation. Form expects a Controller, but we are giving it a RequestHandler instead.
     // Thanks to this however, we are able to nest GridFields, and also access the initial Controller by
     // dereferencing GridFieldDetailForm_ItemRequest->getController() multiple times. See getToplevelController
     // below.
     $form = new Form($this, 'ItemEditForm', $fields, $actions, $this->component->getValidator());
     $form->loadDataFrom($this->record, $this->record->ID == 0 ? Form::MERGE_IGNORE_FALSEISH : Form::MERGE_DEFAULT);
     if ($this->record->ID && !$canEdit) {
         // Restrict editing of existing records
         $form->makeReadonly();
         // Hack to re-enable delete button if user can delete
         if ($canDelete) {
             $form->Actions()->fieldByName('action_doDelete')->setReadonly(false);
         }
     } elseif (!$this->record->ID && !$canCreate) {
         // Restrict creation of new records
         $form->makeReadonly();
     }
     // Load many_many extraData for record.
     // Fields with the correct 'ManyMany' namespace need to be added manually through getCMSFields().
     if ($list instanceof ManyManyList) {
         $extraData = $list->getExtraData('', $this->record->ID);
         $form->loadDataFrom(array('ManyMany' => $extraData));
     }
     // TODO Coupling with CMS
     $toplevelController = $this->getToplevelController();
     if ($toplevelController && $toplevelController instanceof LeftAndMain) {
         // Always show with base template (full width, no other panels),
         // regardless of overloaded CMS controller templates.
         // TODO Allow customization, e.g. to display an edit form alongside a search form from the CMS controller
         $form->setTemplate('LeftAndMain_EditForm');
         $form->addExtraClass('cms-content cms-edit-form center');
         $form->setAttribute('data-pjax-fragment', 'CurrentForm Content');
         if ($form->Fields()->hasTabset()) {
             $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet');
             $form->addExtraClass('cms-tabset');
         }
         $form->Backlink = $this->getBackLink();
     }
     $cb = $this->component->getItemEditFormCallback();
     if ($cb) {
         $cb($form, $this);
     }
     $this->extend("updateItemEditForm", $form);
     return $form;
 }
 /**
  * Add some ajax stuff to the form for renaming items
  * @param Form $form
  */
 public function updateWishListForm(Form &$form)
 {
     $form->addExtraClass('ajax');
     $form->Actions()->push(new LiteralField('ajaxindicator', Config::inst()->get('WishListAjax', 'indicator')));
 }
 /**
  * Updates the edit form to add a new form action
  *
  * @param Form $form The item edit form
  */
 public function updateItemEditForm(Form $form)
 {
     $form->Actions()->push(FormAction::create("doAddMockData", _t('MockData.FILLWITHMOCKDATA', 'Fill with mock data')));
 }
Example #9
0
 public function updateEditForm(Form &$form)
 {
     $actions = $form->Actions();
     $actions->removeByName("action_addmember");
 }
 /**
  * adds the simple schedule form for the queuedjobs
  *
  * @param Form $form
  * @param string $type
  */
 protected function addSimpleScheduleForm(Form $form, $type)
 {
     if (Permission::check('ADMIN') && class_exists('AbstractQueuedJob')) {
         // add a message
         $form->Fields()->push(LiteralField::create('Message', _t('Maintenance.Message', 'Automatic checks can help to increase the security of your website!' . ' You can define a regular update schedule below.')));
         // determine the default values
         $runs = ScheduledRun::get()->filter('Type', $type);
         $interval = '';
         $unit = 'Hour';
         if ($runs->count() > 0) {
             $run = $runs->first();
             $interval = $run->ExecuteInterval;
             $unit = $run->ExecuteEvery;
         }
         // add the hidden field for the type and the interval option
         $form->Fields()->push(HiddenField::create('Type', 'Type', $type));
         $form->Fields()->push(FieldGroup::create(new NumericField('ExecuteInterval', '', $interval), new DropdownField('ExecuteEvery', '', array('Hour' => _t('ScheduledExecution.ExecuteEveryHour', 'Hour(s)'), 'Day' => _t('ScheduledExecution.ExecuteEveryDay', 'Day(s)'), 'Week' => _t('ScheduledExecution.ExecuteEveryWeek', 'Week(s)'), 'Month' => _t('ScheduledExecution.ExecuteEveryMonth', 'Month(s)'), 'Year' => _t('ScheduledExecution.ExecuteEveryYear', 'Year(s)')), $unit))->setTitle(_t('ScheduledExecution.EXECUTE_EVERY', 'Execute every')));
         // add a new action for this purpose
         $form->Actions()->push(FormAction::create('setSchedule', _t('Maintenance.SetSchedulde', 'Set scheduled execution')));
     }
 }
 /**
  * Builds an item edit form.  The arguments to getCMSFields() are the popupController and
  * popupFormName, however this is an experimental API and may change.
  *
  * @todo In the future, we will probably need to come up with a tigher object representing a partially
  * complete controller with gaps for extra functionality.  This, for example, would be a better way
  * of letting Security/login put its log-in form inside a UI specified elsewhere.
  *
  * @return Form
  */
 public function ItemEditForm()
 {
     $list = $this->gridField->getList();
     if (empty($this->record)) {
         $controller = $this->getToplevelController();
         $url = $controller->getRequest()->getURL();
         $noActionURL = $controller->removeAction($url);
         $controller->getResponse()->removeHeader('Location');
         //clear the existing redirect
         return $controller->redirect($noActionURL, 302);
     }
     $canView = $this->record->canView();
     $canEdit = $this->record->canEdit();
     $canDelete = $this->record->canDelete();
     $canCreate = $this->record->canCreate();
     if (!$canView) {
         $controller = $this->getToplevelController();
         // TODO More friendly error
         return $controller->httpError(403);
     }
     // Build actions
     $actions = $this->getFormActions();
     // If we are creating a new record in a has-many list, then
     // pre-populate the record's foreign key.
     if ($list instanceof HasManyList && !$this->record->isInDB()) {
         $key = $list->getForeignKey();
         $id = $list->getForeignID();
         $this->record->{$key} = $id;
     }
     $fields = $this->component->getFields();
     if (!$fields) {
         $fields = $this->record->getCMSFields();
     }
     // If we are creating a new record in a has-many list, then
     // Disable the form field as it has no effect.
     if ($list instanceof HasManyList) {
         $key = $list->getForeignKey();
         if ($field = $fields->dataFieldByName($key)) {
             $fields->makeFieldReadonly($field);
         }
     }
     // Caution: API violation. Form expects a Controller, but we are giving it a RequestHandler instead.
     // Thanks to this however, we are able to nest GridFields, and also access the initial Controller by
     // dereferencing GridFieldDetailForm_ItemRequest->getController() multiple times. See getToplevelController
     // below.
     $form = new Form($this, 'ItemEditForm', $fields, $actions, $this->component->getValidator());
     $form->loadDataFrom($this->record, $this->record->ID == 0 ? Form::MERGE_IGNORE_FALSEISH : Form::MERGE_DEFAULT);
     if ($this->record->ID && !$canEdit) {
         // Restrict editing of existing records
         $form->makeReadonly();
         // Hack to re-enable delete button if user can delete
         if ($canDelete) {
             $form->Actions()->fieldByName('action_doDelete')->setReadonly(false);
         }
     } elseif (!$this->record->ID && !$canCreate) {
         // Restrict creation of new records
         $form->makeReadonly();
     }
     // Load many_many extraData for record.
     // Fields with the correct 'ManyMany' namespace need to be added manually through getCMSFields().
     if ($list instanceof ManyManyList) {
         $extraData = $list->getExtraData('', $this->record->ID);
         $form->loadDataFrom(array('ManyMany' => $extraData));
     }
     // TODO Coupling with CMS
     $toplevelController = $this->getToplevelController();
     if ($toplevelController && $toplevelController instanceof LeftAndMain) {
         // Always show with base template (full width, no other panels),
         // regardless of overloaded CMS controller templates.
         // TODO Allow customization, e.g. to display an edit form alongside a search form from the CMS controller
         $form->setTemplate('LeftAndMain_EditForm');
         $form->addExtraClass('cms-content cms-edit-form center');
         $form->setAttribute('data-pjax-fragment', 'CurrentForm Content');
         if ($form->Fields()->hasTabset()) {
             $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet');
             $form->addExtraClass('cms-tabset');
         }
         $form->Backlink = $this->getBackLink();
     }
     $cb = $this->component->getItemEditFormCallback();
     if ($cb) {
         $cb($form, $this);
     }
     $this->extend("updateItemEditForm", $form);
     return $form;
 }