public function AgeGateForm()
 {
     $enter = new FormAction("EnterAgeGate", "Enter");
     $enter->setUseButtonTag(true);
     $leave = new FormAction("LeaveAgeGate", "Leave");
     $leave->setUseButtonTag(true);
     $form = new Form($this, "AgeGateForm", new FieldList(new TextField("Month", "Month", "MM", 2), new TextField("Day", "Day", "DD", 2), new TextField("Year", "Year", "YYYY", 4), new CheckboxField("itWillBecomeAMemory", "Remember Me")), new FieldList($enter, $leave));
     return $form;
 }
 /**
  * Provide an action button to be clicked per strategy
  * @return FieldList
  */
 protected function getActions()
 {
     $actions = new FieldList();
     foreach ($this->getStrategies() as $strategyClass) {
         $strategyMethod = 'handleStrategy' . $strategyClass;
         $fa = new FormAction($strategyMethod, $strategyClass);
         $fa->setUseButtonTag(true);
         $actions->push($fa);
     }
     return $actions;
 }
Beispiel #3
0
    /**
     * @return FieldList
     */
    public function getCMSFields()
    {
        $fields = new FieldList(new TabSet('Root'));
        $project = $this->Project();
        if ($project && $project->exists()) {
            $viewerGroups = $project->Viewers();
            $groups = $viewerGroups->sort('Title')->map()->toArray();
            $members = array();
            foreach ($viewerGroups as $group) {
                foreach ($group->Members()->map() as $k => $v) {
                    $members[$k] = $v;
                }
            }
            asort($members);
        } else {
            $groups = array();
            $members = array();
        }
        // Main tab
        $fields->addFieldsToTab('Root.Main', array(TextField::create('ProjectName', 'Project')->setValue(($project = $this->Project()) ? $project->Name : null)->performReadonlyTransformation(), TextField::create('Name', 'Environment name')->setDescription('A descriptive name for this environment, e.g. staging, uat, production'), $this->obj('Usage')->scaffoldFormField('Environment usage'), TextField::create('URL', 'Server URL')->setDescription('This url will be used to provide the front-end with a link to this environment'), TextField::create('Filename')->setDescription('The capistrano environment file name')->performReadonlyTransformation()));
        // Backend identifier - pick from a named list of configurations specified in YML config
        $backends = $this->config()->get('allowed_backends', Config::FIRST_SET);
        // If there's only 1 backend, then user selection isn't needed
        if (sizeof($backends) > 1) {
            $fields->addFieldToTab('Root.Main', DropdownField::create('BackendIdentifier', 'Deployment backend')->setSource($backends)->setDescription('What kind of deployment system should be used to deploy to this environment'));
        }
        $fields->addFieldsToTab('Root.UserPermissions', array($this->buildPermissionField('ViewerGroups', 'Viewers', $groups, $members)->setTitle('Who can view this environment?')->setDescription('Groups or Users who can view this environment'), $this->buildPermissionField('DeployerGroups', 'Deployers', $groups, $members)->setTitle('Who can deploy?')->setDescription('Groups or Users who can deploy to this environment'), $this->buildPermissionField('TickAllSnapshotGroups', 'TickAllSnapshot', $groups, $members)->setTitle("<em>All snapshot permissions</em>")->addExtraClass('tickall')->setDescription('UI shortcut to select all snapshot-related options - not written to the database.'), $this->buildPermissionField('CanRestoreGroups', 'CanRestoreMembers', $groups, $members)->setTitle('Who can restore?')->setDescription('Groups or Users who can restore archives from Deploynaut into this environment'), $this->buildPermissionField('CanBackupGroups', 'CanBackupMembers', $groups, $members)->setTitle('Who can backup?')->setDescription('Groups or Users who can backup archives from this environment into Deploynaut'), $this->buildPermissionField('ArchiveDeleterGroups', 'ArchiveDeleters', $groups, $members)->setTitle('Who can delete?')->setDescription("Groups or Users who can delete archives from this environment's staging area."), $this->buildPermissionField('ArchiveUploaderGroups', 'ArchiveUploaders', $groups, $members)->setTitle('Who can upload?')->setDescription('Users who can upload archives linked to this environment into Deploynaut.<br />' . 'Linking them to an environment allows limiting download permissions (see below).'), $this->buildPermissionField('ArchiveDownloaderGroups', 'ArchiveDownloaders', $groups, $members)->setTitle('Who can download?')->setDescription(<<<PHP
Users who can download archives from this environment to their computer.<br />
Since this implies access to the snapshot, it is also a prerequisite for restores
to other environments, alongside the "Who can restore" permission.<br>
Should include all users with upload permissions, otherwise they can't download
their own uploads.
PHP
), $this->buildPermissionField('PipelineApproverGroups', 'PipelineApprovers', $groups, $members)->setTitle('Who can approve pipelines?')->setDescription('Users who can approve waiting deployment pipelines.'), $this->buildPermissionField('PipelineCancellerGroups', 'PipelineCancellers', $groups, $members)->setTitle('Who can cancel pipelines?')->setDescription('Users who can cancel in-progess deployment pipelines.')));
        // The Main.DeployConfig
        if ($this->Project()->exists()) {
            $this->setDeployConfigurationFields($fields);
        }
        // The DataArchives
        $dataArchiveConfig = GridFieldConfig_RecordViewer::create();
        $dataArchiveConfig->removeComponentsByType('GridFieldAddNewButton');
        if (class_exists('GridFieldBulkManager')) {
            $dataArchiveConfig->addComponent(new GridFieldBulkManager());
        }
        $dataArchive = GridField::create('DataArchives', 'Data Archives', $this->DataArchives(), $dataArchiveConfig);
        $fields->addFieldToTab('Root.DataArchive', $dataArchive);
        // Pipeline templates
        $this->setPipelineConfigurationFields($fields);
        // Pipelines
        if ($this->Pipelines()->Count()) {
            $pipelinesConfig = GridFieldConfig_RecordEditor::create();
            $pipelinesConfig->removeComponentsByType('GridFieldAddNewButton');
            if (class_exists('GridFieldBulkManager')) {
                $pipelinesConfig->addComponent(new GridFieldBulkManager());
            }
            $pipelines = GridField::create('Pipelines', 'Pipelines', $this->Pipelines(), $pipelinesConfig);
            $fields->addFieldToTab('Root.Pipelines', $pipelines);
        }
        // Deployments
        $deploymentsConfig = GridFieldConfig_RecordEditor::create();
        $deploymentsConfig->removeComponentsByType('GridFieldAddNewButton');
        if (class_exists('GridFieldBulkManager')) {
            $deploymentsConfig->addComponent(new GridFieldBulkManager());
        }
        $deployments = GridField::create('Deployments', 'Deployments', $this->Deployments(), $deploymentsConfig);
        $fields->addFieldToTab('Root.Deployments', $deployments);
        Requirements::javascript('deploynaut/javascript/environment.js');
        // Add actions
        $action = new FormAction('check', 'Check Connection');
        $action->setUseButtonTag(true);
        $dataURL = Director::absoluteBaseURL() . 'naut/api/' . $this->Project()->Name . '/' . $this->Name . '/ping';
        $action->setAttribute('data-url', $dataURL);
        $fields->insertBefore($action, 'Name');
        // Allow extensions
        $this->extend('updateCMSFields', $fields);
        return $fields;
    }
 /**
  * Call this instead of manually creating your actions
  *
  * You can easily rename actions by calling $actions->fieldByName('action_doNext')->setTitle('...')
  *
  * @param bool $doSet
  * @return FieldList
  */
 protected function definePrevNextActions($doSet = false)
 {
     $actions = new FieldList();
     $prevClass = 'FormAction';
     // do not validate if used in conjonction with zenvalidator
     if (class_exists('FormActionNoValidation')) {
         $prevClass = 'FormActionNoValidation';
     }
     $prev = null;
     if (self::classNameNumber() > 1) {
         $actions->push($prev = new $prevClass('doPrev', _t('FormExtra.doPrev', 'Previous')));
         $prev->addExtraClass('step-prev');
         $prev->setUseButtonTag(true);
     }
     $label = _t('FormExtra.doNext', 'Next');
     $actions->push($next = new FormAction('doNext', $label));
     $next->setUseButtonTag(true);
     $next->addExtraClass('step-next');
     if (!$prev) {
         $next->addExtraClass('step-next-single');
     }
     if (self::isLastStep()) {
         $next->setTitle(_t('FormExtra.doFinish', 'Finish'));
         $next->addExtraClass('step-last');
     }
     $this->addExtraClass('form-steps');
     if (!$doSet) {
         $this->setActions($actions);
         $actions->setForm($this);
     }
     return $actions;
 }
 /**
  * creates the form's input fields and action fields and fills missing data
  * with standard values
  *
  * @return array retunrs form fields and form actions
  *      array(
  *          'fields'    => FieldList,
  *          'actions'   => FieldList
  *      )
  *
  * @author Sascha Koehler <*****@*****.**>,
  *         Sebastian Diel <*****@*****.**>
  * @since 04.07.2013
  */
 protected function getForm()
 {
     if (is_null($this->form)) {
         $fields = new FieldList();
         // --------------------------------------------------------------------
         // define meta data
         // --------------------------------------------------------------------
         if (!empty($this->customParameters)) {
             foreach ($this->customParameters as $customParameterKey => $customParameterValue) {
                 $field = new HiddenField($customParameterKey, '', $customParameterValue, null, null);
                 $fields->push($field);
             }
         }
         $field = new HiddenField('CustomHtmlFormName', '', $this->getCustomHtmlFormName(), null, null);
         $fields->push($field);
         // --------------------------------------------------------------------
         // create field set from definition
         // --------------------------------------------------------------------
         foreach ($this->fieldGroups as $groupFields) {
             foreach ($groupFields as $fieldName => $fieldDefinition) {
                 $field = $this->getFormField($fieldName, $fieldDefinition);
                 $fields->push($field);
             }
         }
         $formAction = new FormAction($this->getSubmitAction(), $this->getSubmitButtonTitle(), $this);
         $formAction->description = $this->getSubmitButtonToolTip();
         if ($this->getPreference('submitButtonUseButtonTag')) {
             $formAction->setUseButtonTag(true);
         }
         $extraClasses = $this->getPreference('submitButtonExtraClasses');
         if (is_array($extraClasses)) {
             foreach ($extraClasses as $extraClass) {
                 $formAction->addExtraClass($extraClass);
             }
         }
         $actions = new FieldList($formAction);
         $this->form = array('fields' => $fields, 'actions' => $actions);
     }
     return $this->form;
 }
Beispiel #6
0
 /**
  *
  * @return FieldList
  */
 public function getCMSFields()
 {
     $fields = parent::getCMSFields();
     $members = array();
     foreach ($this->Project()->Viewers() as $group) {
         foreach ($group->Members()->map() as $k => $v) {
             $members[$k] = $v;
         }
     }
     asort($members);
     $fields->fieldByName("Root")->removeByName("Deployers");
     $fields->fieldByName("Root")->removeByName("CanRestoreMembers");
     $fields->fieldByName("Root")->removeByName("CanBackupMembers");
     $fields->fieldByName("Root")->removeByName("ArchiveUploaders");
     $fields->fieldByName("Root")->removeByName("ArchiveDownloaders");
     $fields->fieldByName("Root")->removeByName("ArchiveDeleters");
     // The Main.ProjectID
     $projectField = $fields->fieldByName('Root.Main.ProjectID')->performReadonlyTransformation();
     $fields->insertBefore($projectField, 'Name');
     // The Main.Name
     $nameField = $fields->fieldByName('Root.Main.Name');
     $nameField->setTitle('Environment name');
     $nameField->setDescription('A descriptive name for this environment, e.g. staging, uat, production');
     $fields->insertAfter($nameField, 'ProjectID');
     // The Main.Filename
     $fileNameField = $fields->fieldByName('Root.Main.Filename')->performReadonlyTransformation();
     $fileNameField->setTitle('Filename');
     $fileNameField->setDescription('The capistrano environment file name');
     $fields->insertAfter($fileNameField, 'Name');
     // The Main.Deployers
     $deployers = new CheckboxSetField("Deployers", "Who can deploy?", $members);
     $deployers->setDescription('Users who can deploy to this environment');
     $fields->insertAfter($deployers, 'URL');
     // A box to tick all snapshot boxes.
     $tickAll = new CheckboxSetField("TickAllSnapshot", "<em>All snapshot permissions</em>", $members);
     $tickAll->setDescription('UI shortcut to tick all snapshot-related boxes - not written to the database.');
     $fields->insertAfter($tickAll, 'Deployers');
     // The Main.CanRestoreMembers
     $canRestoreMembers = new CheckboxSetField('CanRestoreMembers', 'Who can restore?', $members);
     $canRestoreMembers->setDescription('Users who can restore archives from Deploynaut into this environment');
     $fields->insertAfter($canRestoreMembers, 'TickAllSnapshot');
     // The Main.CanBackupMembers
     $canBackupMembers = new CheckboxSetField('CanBackupMembers', 'Who can backup?', $members);
     $canBackupMembers->setDescription('Users who can backup archives from this environment into Deploynaut');
     $fields->insertAfter($canBackupMembers, 'CanRestoreMembers');
     // The Main.ArchiveDeleters
     $archiveDeleters = new CheckboxSetField('ArchiveDeleters', 'Who can delete?', $members);
     $archiveDeleters->setDescription('Users who can delete archives from this environment\'s staging area.');
     $fields->insertAfter($archiveDeleters, 'CanBackupMembers');
     // The Main.ArchiveUploaders
     $archiveUploaders = new CheckboxSetField('ArchiveUploaders', 'Who can upload?', $members);
     $archiveUploaders->setDescription('Users who can upload archives linked to this environment into Deploynaut.<br>' . 'Linking them to an environment allows limiting download permissions (see below).');
     $fields->insertAfter($archiveUploaders, 'ArchiveDeleters');
     // The Main.ArchiveDownloaders
     $archiveDownloaders = new CheckboxSetField('ArchiveDownloaders', 'Who can download?', $members);
     $archiveDownloaders->setDescription('Users who can download archives from this environment to their computer.<br>' . 'Since this implies access to the snapshot, it is also a prerequisite for restores to other environments,' . ' alongside the "Who can restore" permission.<br>' . 'Should include all users with upload permissions, otherwise they can\'t download their own uploads.');
     $fields->insertAfter($archiveDownloaders, 'ArchiveUploaders');
     // The Main.DeployConfig
     if ($this->Project()->exists()) {
         $this->setDeployConfigurationFields($fields);
     }
     // The Main.URL field
     $urlField = $fields->fieldByName('Root.Main.URL');
     $urlField->setTitle('Server URL');
     $fields->removeByName('Root.Main.URL');
     $urlField->setDescription('This url will be used to provide the front-end with a link to this environment');
     $fields->insertAfter($urlField, 'Name');
     // The Extra.GraphiteServers
     $graphiteServerField = $fields->fieldByName('Root.Main.GraphiteServers');
     $fields->removeByName('Root.Main.GraphiteServers');
     $graphiteServerField->setDescription('Find the relevant graphite servers at ' . '<a href="http://graphite.silverstripe.com/" target="_blank">graphite.silverstripe.com</a>' . ' and enter them one per line, e.g. "server.wgtn.oscar"');
     $fields->addFieldToTab('Root.Extra', $graphiteServerField);
     Requirements::javascript('deploynaut/javascript/environment.js');
     // Add actions
     $action = new FormAction('check', 'Check Connection');
     $action->setUseButtonTag(true);
     $action->setAttribute('data-url', Director::absoluteBaseURL() . 'naut/api/' . $this->Project()->Name . '/' . $this->Name . '/ping');
     $fields->insertBefore($action, 'Name');
     return $fields;
 }