/**
  * Initiate the standard Metadata catalogue search form. The 
  * additional parameter $defaults defines the default values for the form.
  * 
  * @param Controller $controller The parent controller, necessary to create the appropriate form action tag.
  * @param String $name The method on the controller that will return this form object.
  * @param FieldSet $fields All of the fields in the form - a {@link FieldSet} of {@link FormField} objects.
  * @param FieldSet $actions All of the action buttons in the form - a {@link FieldSet} of {@link FormAction} objects
  * @param Validator $validator Override the default validator instance (Default: {@link RequiredFields})
  */
 function __construct($controller, $name, FieldSet $fields = null, FieldSet $actions = null, $validator = null)
 {
     $recaptchaField = $this->getRecaptchaField();
     if (!$fields) {
         // Create fields
         //adding extra class for custom validation
         $title = new TextField('MDTitle', "TITLE");
         $title->addExtraClass("required");
         $fields = new FieldSet(new CompositeField($title, new TextareaField('MDAbstract'), new CalendarDateField('MDDateTime1'), new DropdownField('MDDateType1', 'DateType', MDCodeTypes::get_date_types(), ""), new CalendarDateField('MDDateTime2'), new DropdownField('MDDateType2', 'DateType', MDCodeTypes::get_date_types(), ""), new CalendarDateField('MDDateTime3'), new DropdownField('MDDateType3', 'DateType', MDCodeTypes::get_date_types(), ""), new ListboxField('MDTopicCategory', 'Category', MDCodeTypes::get_categories(), "", 8, true)), new CompositeField(new DropdownField('MDSpatialRepresentationType', 'Spatial Representation Type', MDCodeTypes::get_spatial_representation_type(), ""), new TextField('MDGeographicDiscription', 'Geographic Description'), new TextField('MDWestBound'), new TextField('MDEastBound'), new TextField('MDSouthBound'), new TextField('MDNorthBound'), new DropdownField('ISOPlaces', 'ISOPlaces', MDCodeTypes::get_places(), "170;180;-52.57806;-32.41472"), new DropdownField('Places', 'Places', NewZealandPlaces::get_nzplaces(), "-141;160;-7;-90"), new DropdownField('OffshoreIslands', 'NZ Offshore islands', NewZealandPlaces::get_nzoffshoreislands(), ""), new DropdownField('Dependencies', 'NZ Dependencies in the South West Pacific', NewZealandPlaces::get_nzdependencies(), ""), new DropdownField('Regions', 'Regions', NewZealandPlaces::get_nzregions(), ""), new DropdownField('TAs', 'TAs', NewZealandPlaces::get_nzta(), "")), new CompositeField(new TextField('MDIndividualName'), new TextField('MDOrganisationName'), new TextField('MDPositionName'), new TextField('MDVoice'), new HiddenField('MDVoiceData'), new EmailField('MDElectronicMailAddress'), new HiddenField('MDElectronicMailAddressData')), new CompositeField(new DropdownField('ResourceFormatsList1', 'ResourceFormatsList1', MDCodeTypes::get_resource_formats(), ""), new TextField('MDResourceFormatName1', 'MDResourceFormatName1', ""), new TextField('MDResourceFormatVersion1', 'MDResourceFormatVersion1', "")), new CompositeField(new DropdownField('ResourceFormatsList2', 'ResourceFormatsList2', MDCodeTypes::get_resource_formats(), ""), new TextField('MDResourceFormatName2', 'MDResourceFormatName2', ""), new TextField('MDResourceFormatVersion2', 'MDResourceFormatVersion2', "")), new CompositeField(new DropdownField('ResourceFormatsList3', 'ResourceFormatsList3', MDCodeTypes::get_resource_formats(), ""), new TextField('MDResourceFormatName3', 'MDResourceFormatName3', ""), new TextField('MDResourceFormatVersion3', 'MDResourceFormatVersion3', "")), new CompositeField(new DropdownField('ResourceFormatsList4', 'ResourceFormatsList4', MDCodeTypes::get_resource_formats(), ""), new TextField('MDResourceFormatName4', 'MDResourceFormatName4', ""), new TextField('MDResourceFormatVersion4', 'MDResourceFormatVersion4', "")), new CompositeField(new DropdownField('ResourceFormatsList5', 'ResourceFormatsList5', MDCodeTypes::get_resource_formats(), ""), new TextField('MDResourceFormatName5', 'MDResourceFormatName5', ""), new TextField('MDResourceFormatVersion5', 'MDResourceFormatVersion5', "")), new CompositeField(new DropDownField('MDHierarchyLevel', 'MDHierarchyLevel', MDCodeTypes::get_scope_codes_keys(), ""), new HiddenField('MDHierarchyLevelData', 'MDHierarchyLevelData', ""), new TextField('MDHierarchyLevelName', 'MDHierarchyLevelName', ""), new HiddenField('MDHierarchyLevelNameData', 'MDHierarchyLevelNameData', ""), new TextField('MDParentIdentifier', 'MDParentIdentifier', "")), new CompositeField(new TextField('CIOnlineLinkage', 'CIOnlineLinkage', ""), new HiddenField('CIOnlineLinkageData', 'CIOnlineLinkageData', ""), new DropdownField('CIOnlineProtocol', 'CIOnlineProtocol', MDCodeTypes::get_online_resource_protocol(), ""), new TextField('CIOnlineName', 'CIOnlineName', ""), new TextField('CIOnlineDescription', 'CIOnlineDescription', ""), new DropdownField('CIOnlineFunction', 'CIOnlineFunction', MDCodeTypes::get_online_resource_function(), "")), new CompositeField(new DropdownField('useLimitation', 'License', MDCodeTypes::get_use_limitation(), "")));
     }
     if ($recaptchaField) {
         $fields->push($recaptchaField);
     }
     if (!$actions) {
         $actions = new FieldSet(new FormAction('doRegisterMetadata', 'Submit'));
     }
     if (!$validator) {
         $validator = new RequiredFields('MDTitle', 'MDAbstract', 'MDElectronicMailAddress', 'MDDateTime', 'MDTopicCategory');
     }
     $validator->setJavascriptValidationHandler('none');
     parent::__construct($controller, $name, $fields, $actions, $validator);
 }
 /**
  *                                                                                     
  * Overload the ImportForm method of the ModelAdmin class.                             
  *                                                                                     
  * Used to remove the "Clear Database" checkbox from the import form.                  
  * This allows the functionality to be hardcoded in the MenuItemCsvBulkLoader class.   
  * See the overloaded "load" method of the MenuItemCsvBulkLoader class, where          
  * "deleteExistingRecords" is set to true.                                             
  *                                                                                     
  * @return object Form                                                                 
  */
 public function ImportForm()
 {
     $modelName = $this->modelClass;
     // check if a import form should be generated
     if (!$this->showImportForm() || is_array($this->showImportForm()) && !in_array($modelName, $this->showImportForm())) {
         return false;
     }
     $importers = $this->parentController->getModelImporters();
     if (!$importers || !isset($importers[$modelName])) {
         return false;
     }
     if (!singleton($modelName)->canCreate(Member::currentUser())) {
         return false;
     }
     $fields = new FieldSet(new HiddenField('ClassName', _t('ModelAdmin.CLASSTYPE'), $modelName), new FileField('_CsvFile', false));
     // get HTML specification for each import (column names etc.)
     $importerClass = $importers[$modelName];
     $importer = new $importerClass($modelName);
     $spec = $importer->getImportSpec();
     $specFields = new DataObjectSet();
     foreach ($spec['fields'] as $name => $desc) {
         $specFields->push(new ArrayData(array('Name' => $name, 'Description' => $desc)));
     }
     $specRelations = new DataObjectSet();
     foreach ($spec['relations'] as $name => $desc) {
         $specRelations->push(new ArrayData(array('Name' => $name, 'Description' => $desc)));
     }
     $specHTML = $this->customise(array('ModelName' => Convert::raw2att($modelName), 'Fields' => $specFields, 'Relations' => $specRelations))->renderWith('ModelAdmin_ImportSpec');
     //$fields->push(new LiteralField("SpecFor{$modelName}", $specHTML));
     //$fields->push(new CheckboxField('EmptyBeforeImport', 'Clear Database before import', false));
     $actions = new FieldSet(new FormAction('import', _t('ModelAdmin.IMPORT', 'Import from CSV')));
     $validator = new RequiredFields();
     $validator->setJavascriptValidationHandler('none');
     $form = new Form($this, "ImportForm", $fields, $actions, $validator);
     $form->setHTMLID("Form_ImportForm_" . $this->modelClass);
     return $form;
 }
 /**
  * Returns a form suitable for adding a new model, falling back on the default edit form.
  * 
  * Caution: The add-form shows a DataObject's {@link DataObject->getCMSFields()} method on a record
  * that doesn't exist in the database yet, hence has no ID. This means the {@link DataObject->getCMSFields()}
  * implementation has to ensure that no fields are added which would rely on a
  * record ID being present, e.g. {@link HasManyComplexTableField}.
  * 
  * Example:
  * <code>
  * function getCMSFields() {
  *   $fields = parent::getCMSFields();
  *     if($this->exists()) {
  *       $ctf = new HasManyComplexTableField($this, 'MyRelations', 'MyRelation');
  *       $fields->addFieldToTab('Root.Main', $ctf);
  *     }
  *   return $fields;
  * }
  * </code>
  *
  * @return Form
  */
 public function AddForm()
 {
     $newRecord = new $this->modelClass();
     if ($newRecord->canCreate()) {
         if ($newRecord->hasMethod('getCMSAddFormFields')) {
             $fields = $newRecord->getCMSAddFormFields();
         } else {
             $fields = $newRecord->getCMSFields();
         }
         $validator = $newRecord->hasMethod('getCMSValidator') ? $newRecord->getCMSValidator() : null;
         if (!$validator) {
             $validator = new RequiredFields();
         }
         $validator->setJavascriptValidationHandler('none');
         $actions = new FieldSet(new FormAction("doCreate", _t('ModelAdmin.ADDBUTTON', "Add")));
         $form = new Form($this, "AddForm", $fields, $actions, $validator);
         $form->loadDataFrom($newRecord);
         return $form;
     }
 }
 public function getEditForm($id)
 {
     $record = $this->getRecord($id);
     if ($record) {
         if ($record->IsDeletedFromStage) {
             $record->Status = _t('CMSMain.REMOVEDFD', "Removed from the draft site");
         }
         $fields = $record->getCMSFields($this);
         if ($fields == null) {
             user_error("getCMSFields returned null on a '" . get_class($record) . "' object - it should return a FieldSet object. Perhaps you forgot to put a return statement at the end of your method?", E_USER_ERROR);
         }
         $fields->push($idField = new HiddenField("ID"));
         $fields->push($liveURLField = new HiddenField("LiveURLSegment"));
         $fields->push($stageURLField = new HiddenField("StageURLSegment"));
         /*if( substr($record->ID, 0, 3 ) == 'new' )*/
         $fields->push(new HiddenField('Sort', '', $record->Sort));
         $idField->setValue($id);
         if ($record->ID && is_numeric($record->ID)) {
             $liveRecord = Versioned::get_one_by_stage('SiteTree', 'Live', "\"SiteTree\".\"ID\" = {$record->ID}");
             if ($liveRecord) {
                 $liveURLField->setValue($liveRecord->AbsoluteLink());
             }
         }
         if (!$record->IsDeletedFromStage) {
             $stageURLField->setValue($record->AbsoluteLink());
         }
         // getAllCMSActions can be used to completely redefine the action list
         if ($record->hasMethod('getAllCMSActions')) {
             $actions = $record->getAllCMSActions();
         } else {
             $actions = $record->getCMSActions();
         }
         // Add a default or custom validator.
         // @todo Currently the default Validator.js implementation
         //  adds javascript to the document body, meaning it won't
         //  be included properly if the associated fields are loaded
         //  through ajax. This means only serverside validation
         //  will kick in for pages+validation loaded through ajax.
         //  This will be solved by using less obtrusive javascript validation
         //  in the future, see http://open.silverstripe.com/ticket/2915 and http://open.silverstripe.com/ticket/3386
         if ($record->hasMethod('getCMSValidator')) {
             $validator = $record->getCMSValidator();
         } else {
             $validator = new RequiredFields();
         }
         // The clientside (mainly LeftAndMain*.js) rely on ajax responses
         // which can be evaluated as javascript, hence we need
         // to override any global changes to the validation handler.
         $validator->setJavascriptValidationHandler('prototype');
         $form = new Form($this, "EditForm", $fields, $actions, $validator);
         $form->loadDataFrom($record);
         $form->disableDefaultAction();
         if (!$record->canEdit() || $record->IsDeletedFromStage) {
             $readonlyFields = $form->Fields()->makeReadonly();
             $form->setFields($readonlyFields);
         }
         $this->extend('updateEditForm', $form);
         return $form;
     }
     if ($id == 0 || $id == 'root') {
         return $this->RootForm();
     } else {
         if ($id) {
             return new Form($this, "EditForm", new FieldSet(new LabelField('PageDoesntExistLabel', _t('CMSMain.PAGENOTEXISTS', "This page doesn't exist"))), new FieldSet());
         }
     }
 }
Ejemplo n.º 5
0
 /**
  * Calls {@link SiteTree->getCMSFields()}
  */
 public function getEditForm($id = null)
 {
     // Include JavaScript to ensure HtmlEditorField works.
     HtmlEditorField::include_js();
     $form = parent::getEditForm($id);
     // TODO Duplicate record fetching (see parent implementation)
     if (!$id) {
         $id = $this->currentPageID();
     }
     $record = $id && $id != "root" ? $this->getRecord($id) : null;
     $fields = $form->Fields();
     $actions = $form->Actions();
     if ($record) {
         $fields->push($idField = new HiddenField("ID", false, $id));
         // Necessary for different subsites
         $fields->push($liveURLField = new HiddenField("AbsoluteLink", false, $record->AbsoluteLink()));
         $fields->push($liveURLField = new HiddenField("LiveURLSegment"));
         $fields->push($stageURLField = new HiddenField("StageURLSegment"));
         $fields->push(new HiddenField("TreeTitle", false, $record->TreeTitle));
         $fields->push(new HiddenField('Sort', '', $record->Sort));
         if ($record->ID && is_numeric($record->ID)) {
             $liveRecord = Versioned::get_one_by_stage('SiteTree', 'Live', "\"SiteTree\".\"ID\" = {$record->ID}");
             if ($liveRecord) {
                 $liveURLField->setValue($liveRecord->AbsoluteLink());
             }
         }
         if (!$record->IsDeletedFromStage) {
             $stageURLField->setValue($record->AbsoluteLink());
         }
         // getAllCMSActions can be used to completely redefine the action list
         if ($record->hasMethod('getAllCMSActions')) {
             $actions = $record->getAllCMSActions();
         } else {
             $actions = $record->getCMSActions();
         }
         // Add a default or custom validator.
         // @todo Currently the default Validator.js implementation
         //  adds javascript to the document body, meaning it won't
         //  be included properly if the associated fields are loaded
         //  through ajax. This means only serverside validation
         //  will kick in for pages+validation loaded through ajax.
         //  This will be solved by using less obtrusive javascript validation
         //  in the future, see http://open.silverstripe.com/ticket/2915 and http://open.silverstripe.com/ticket/3386
         if ($record->hasMethod('getCMSValidator')) {
             $validator = $record->getCMSValidator();
         } else {
             $validator = new RequiredFields();
         }
         // The clientside (mainly LeftAndMain*.js) rely on ajax responses
         // which can be evaluated as javascript, hence we need
         // to override any global changes to the validation handler.
         $validator->setJavascriptValidationHandler('prototype');
         $form = new Form($this, "EditForm", $fields, $actions, $validator);
         $form->loadDataFrom($record);
         $form->disableDefaultAction();
         if (!$record->canEdit() || $record->IsDeletedFromStage) {
             $readonlyFields = $form->Fields()->makeReadonly();
             $form->setFields($readonlyFields);
         }
         $this->extend('updateEditForm', $form);
         return $form;
     }
     if ($id == 0 || $id == 'root') {
         return $this->RootForm();
     } else {
         if ($id) {
             return new Form($this, "EditForm", new FieldSet(new LabelField('PageDoesntExistLabel', _t('CMSMain.PAGENOTEXISTS', "This page doesn't exist"))), new FieldSet());
         }
     }
 }