/**
  * @param FieldList $fields
  * @return FieldList|void
  */
 public function updateCMSFields(FieldList $fields)
 {
     $oldFields = $fields->toArray();
     foreach ($oldFields as $field) {
         $fields->remove($field);
     }
     $fields->push(new LiteralField("Title", "<h2>Training</h2>"));
     $fields->push(new TextField("Name", "Name"));
     $fields->push(new HtmlEditorField("Overview", "Overview"));
     $fields->push(new CheckboxField("Active", "Active"));
     $types = TrainingCourseType::get();
     $levels = TrainingCourseLevel::get();
     $companies = Company::get();
     if ($companies) {
         $fields->push(new DropdownField('CompanyID', 'Company', $companies->map("ID", "Name", "Please Select a Company")));
     }
     if ($types && $levels && $this->owner->ID > 0) {
         $config = GridFieldConfig_RecordEditor::create();
         $courses = new GridField('Courses', 'Courses', $this->owner->Courses(), $config);
         $fields->push($courses);
     } else {
         $fields->push(new LiteralField("Warning", "** You can not add any Training Course until you create some Training Course Levels and Training Course Types!."));
     }
     return $fields;
 }
 /**
  * @param IQuerySpecification $specification
  * @return IQueryResult
  */
 public function handle(IQuerySpecification $specification)
 {
     $levels = array();
     $result = TrainingCourseLevel::get();
     if ($result) {
         foreach ($result->toArray() as $r) {
             array_push($levels, new SearchDTO($r->Level, $r->Level));
         }
     }
     return new OpenStackImplementationNamesQueryResult($levels);
 }
 public function updateCMSFields(FieldList $fields)
 {
     $oldFields = $fields->toArray();
     foreach ($oldFields as $field) {
         $fields->remove($field);
     }
     $fields->push(new LiteralField("Title", "<h2>Training Course</h2>"));
     $fields->push(new TextField("Name", "Name"));
     $fields->push(new CheckboxField("Online", "Online"));
     //only for online
     $fields->push(new TextField("Link", "Link"));
     $fields->push(new HtmlEditorField("Description", "Description", null));
     $fields->push(new CheckboxField("Paid", "Is Paid"));
     $levels = TrainingCourseLevel::get();
     if ($levels) {
         $level = new DropdownField("LevelID", "Level", TrainingCourseLevel::get()->map("ID", 'Level', '--Select Level--'));
         $fields->push($level);
     }
     if ($this->owner->ID > 0) {
         $config = GridFieldConfig_RecordEditor::create();
         $config->getComponentByType('GridFieldDataColumns')->setDisplayFields(array('City' => 'City', 'State' => 'State', 'Country' => 'Country'));
         $config->removeComponentsByType('GridFieldAddExistingAutocompleter');
         $schedule = new GridField("Schedules", "Schedules", $this->owner->Schedules(), $config);
         $fields->push($schedule);
         $config = GridFieldConfig_RelationEditor::create();
         $config->getComponentByType('GridFieldDataColumns')->setDisplayFields(array('Name' => 'Name'));
         $config->removeComponentsByType('GridFieldAddNewButton');
         $config->removeComponentsByType('GridFieldEditButton');
         $projects = new GridField('Projects', 'Projects', $this->owner->Projects(), $config);
         $config = GridFieldConfig_RelationEditor::create();
         $config->removeComponentsByType('GridFieldAddNewButton');
         $config->removeComponentsByType('GridFieldEditButton');
         $config->getComponentByType('GridFieldDataColumns')->setDisplayFields(array('Name' => 'Name'));
         $prerequisite = new GridField('Prerequisites', 'Prerequisites', $this->owner->Prerequisites(), $config);
         $fields->push($projects);
         $fields->push($prerequisite);
     }
     return $fields;
 }
 function AddTrainingCourseForm()
 {
     Requirements::css(THIRDPARTY_DIR . '/jquery-ui-themes/smoothness/jquery-ui.css');
     Requirements::javascript(THIRDPARTY_DIR . '/jquery-ui/jquery-ui.js');
     Requirements::javascript("datepicker/javascript/datepicker.js");
     Requirements::javascript('registration/javascript/edit.profile.training.form.js');
     // Name Set
     $Name = new TextField('Name', "Name");
     $Name->addExtraClass('course-name');
     $Link = new TextField('Link', "Link");
     $Link->addExtraClass('course-online-link url');
     $Description = new TextareaField('Description', "Description");
     $Description->addExtraClass('course-description');
     $Online = new CheckboxField('Online', "Is Online?");
     $Online->addExtraClass('course-online-checkbox');
     $Paid = new CheckboxField('Paid', "Is Paid?");
     $Level = new DropdownField('LevelID', 'Level', TrainingCourseLevel::get()->map('ID', 'Level'));
     $Projects = new CheckboxSetField('Projects', '', Project::get()->map('ID', 'Name'));
     $Program = new HiddenField('TrainingServiceID', "TrainingServiceID", $this->training_id);
     $Course = new HiddenField('ID', "course", 0);
     $show_blank_schedule = true;
     if (isset($this->EditCourseID)) {
         $locations_dto = $this->course_repository->getLocations($this->EditCourseID);
         for ($i = 0; $i < count($locations_dto); $i++) {
             $dto = $locations_dto[$i];
             $show_blank_schedule = false;
             $City[$i] = new TextField('City[' . $i . ']', "City", $dto->getCity());
             $City[$i]->addExtraClass('city_name');
             $State[$i] = new TextField('State[' . $i . ']', "State", $dto->getState());
             $State[$i]->addExtraClass('state');
             $Country[$i] = new DropdownField('Country[' . $i . ']', $dto->getCountry(), CountryCodes::$iso_3166_countryCodes, $dto->getCountry());
             $Country[$i]->setEmptyString('-- Select One --');
             $Country[$i]->addExtraClass('country');
             $LinkS[$i] = new TextField('LinkS[' . $i . ']', "Link", $dto->getLink());
             $LinkS[$i]->addExtraClass('url');
             $StartDate[$i] = new TextField('StartDate[' . $i . ']', "Start Date", is_null($dto->getStartDate()) ? '' : $dto->getStartDate());
             $StartDate[$i]->addExtraClass('dateSelector start');
             $EndDate[$i] = new TextField('EndDate[' . $i . ']', "End Date", is_null($dto->getEndDate()) ? '' : $dto->getEndDate());
             $EndDate[$i]->addExtraClass('dateSelector end');
         }
     }
     if ($show_blank_schedule) {
         $City = new TextField('City[]', "City");
         $City->addExtraClass('city_name');
         $State = new TextField('State[]', "State");
         $State->addExtraClass('state');
         $Country = new DropdownField('Country[]', 'Country', CountryCodes::$iso_3166_countryCodes);
         $Country->setEmptyString('-- Select One --');
         $Country->addExtraClass('country');
         $StartDate = new TextField('StartDate[]', "Start Date");
         $StartDate->addExtraClass('dateSelector start');
         $EndDate = new TextField('EndDate[]', "End Date");
         $EndDate->addExtraClass('dateSelector end');
         $LinkS = new TextField('LinkS[]', "Link");
         $LinkS->addExtraClass('url');
     }
     $fields = new FieldList($Name, $Description, $Link, new LiteralField('break', '<hr/><div class="horizontal-fields">'), $Online, $Paid, $Level, $Program, $Course, new LiteralField('break', '</div><hr/>'), new LiteralField('projects', '<h4>Projects</h4>'), $Projects, new LiteralField('schedule', '<h4>Schedule</h4>'), new LiteralField('instruction', '<p class="note_online">City, State and Country can\'t be edited when a course is marked <em>Online</em>.</p>'), new LiteralField('scheduleDiv', '<div id="schedules">'));
     if (!$show_blank_schedule) {
         for ($j = 0; $j < $i; $j++) {
             $fields->push(new LiteralField('scheduleDiv', '<div class="scheduleRow">'));
             $fields->push($City[$j]);
             $fields->push($State[$j]);
             $fields->push($Country[$j]);
             $fields->push($StartDate[$j]);
             $fields->push($EndDate[$j]);
             $fields->push($LinkS[$j]);
             $fields->push(new LiteralField('scheduleDiv', '</div>'));
         }
     } else {
         $fields->push(new LiteralField('scheduleDiv', '<div class="scheduleRow">'));
         $fields->push($City);
         $fields->push($State);
         $fields->push($Country);
         $fields->push($StartDate);
         $fields->push($EndDate);
         $fields->push($LinkS);
         $fields->push(new LiteralField('scheduleDiv', '</div>'));
     }
     $fields->push(new LiteralField('scheduleDivC', '</div>'));
     $fields->push(new LiteralField('addSchedule', '<button id="addSchedule" class="action">Add Another</button>'));
     $actions = new FieldList(new FormAction('AddCourse', 'Submit'));
     $validators = new ConditionalAndValidationRule(array(new RequiredFields('Name', 'Level'), new HtmlPurifierRequiredValidator('Description')));
     $form = new Form($this, 'AddTrainingCourseForm', $fields, $actions, $validators);
     if (isset($this->EditCourseID)) {
         $form->loadDataFrom($this->course_repository->getById($this->EditCourseID));
         unset($this->EditCourseID);
     } else {
         $form->loadDataFrom($this->request->postVars());
     }
     return $form;
 }