Skip to content

Commit 2b85e18

Browse files
committed
[spalenque] - #13029 * fix training course admin bug for removing all schedules
1 parent 30c26b8 commit 2b85e18

4 files changed

Lines changed: 113 additions & 51 deletions

File tree

marketplace/code/model/training/CourseManager.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ public function register(array $data){
152152
//save locations only if course is not online type
153153
if(isset($data['StartDate'])){
154154
foreach($data['StartDate'] as $K=>$C){
155+
// escape to avoid adding template
156+
if (!$data['City'][$K] || !$data['State'][$K] || !$data['Country'][$K]) continue;
157+
155158
$city = $data['City'][$K];
156159
$state = $data['State'][$K];
157160
$country = $data['Country'][$K];

registration/code/ui/EditProfilePage.php

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,7 @@ function AddTrainingCourseForm()
504504
$Paid = new CheckboxField('Paid', "Is Paid?");
505505
$Level = new DropdownField('LevelID', 'Level', TrainingCourseLevel::get()->map('ID', 'Level'));
506506
$Projects = new CheckboxSetField('Projects', '', Project::get()->map('ID', 'Name'));
507+
$Projects->setTemplate('BootstrapAwesomeCheckboxsetField');
507508

508509
$Program = new HiddenField('TrainingServiceID', "TrainingServiceID", $this->training_id);
509510
$Course = new HiddenField('ID', "course", 0);
@@ -521,7 +522,7 @@ function AddTrainingCourseForm()
521522
$State[$i] = new TextField('State[' . $i . ']', "State", $dto->getState());
522523
$State[$i]->addExtraClass('state');
523524

524-
$Country[$i] = new DropdownField('Country[' . $i . ']', $dto->getCountry(), CountryCodes::$iso_3166_countryCodes, $dto->getCountry());
525+
$Country[$i] = new DropdownField('Country[' . $i . ']', "Country", CountryCodes::$iso_3166_countryCodes, $dto->getCountry());
525526
$Country[$i]->setEmptyString('-- Select One --');
526527
$Country[$i]->addExtraClass('country');
527528

@@ -536,30 +537,29 @@ function AddTrainingCourseForm()
536537
}
537538
}
538539

539-
if ($show_blank_schedule) {
540-
$City = new TextField('City[]', "City");
541-
$City->addExtraClass('city_name');
540+
// fields for template
541+
$TemplateCity = new TextField('City[]', "City");
542+
$TemplateCity->addExtraClass('city_name');
542543

543-
$State = new TextField('State[]', "State");
544-
$State->addExtraClass('state');
544+
$TemplateState = new TextField('State[]', "State");
545+
$TemplateState->addExtraClass('state');
545546

546-
$Country = new DropdownField('Country[]', 'Country', CountryCodes::$iso_3166_countryCodes);
547-
$Country->setEmptyString('-- Select One --');
548-
$Country->addExtraClass('country');
547+
$TemplateCountry = new DropdownField('Country[]', 'Country', CountryCodes::$iso_3166_countryCodes);
548+
$TemplateCountry->setEmptyString('-- Select One --');
549+
$TemplateCountry->addExtraClass('country');
549550

550-
$StartDate = new TextField('StartDate[]', "Start Date");
551-
$StartDate->addExtraClass('dateSelector start');
552-
$EndDate = new TextField('EndDate[]', "End Date");
553-
$EndDate->addExtraClass('dateSelector end');
554-
$LinkS = new TextField('LinkS[]', "Link");
555-
$LinkS->addExtraClass('url');
556-
}
551+
$TemplateStartDate = new TextField('StartDate[]', "Start Date");
552+
$TemplateStartDate->addExtraClass('dateSelector start');
553+
$TemplateEndDate = new TextField('EndDate[]', "End Date");
554+
$TemplateEndDate->addExtraClass('dateSelector end');
555+
$TemplateLinkS = new TextField('LinkS[]', "Link");
556+
$TemplateLinkS->addExtraClass('url');
557557

558558
$fields = new FieldList(
559559
$Name,
560560
$Description,
561561
$Link,
562-
new LiteralField('break', '<hr/><div class="horizontal-fields">'),
562+
new LiteralField('break', '<br><hr/><div class="horizontal-fields">'),
563563
$Online,
564564
$Paid,
565565
$Level,
@@ -570,6 +570,7 @@ function AddTrainingCourseForm()
570570
$Projects,
571571
new LiteralField('schedule', '<h4>Schedule</h4>'),
572572
new LiteralField('instruction', '<p class="note_online">City, State and Country can\'t be edited when a course is marked <em>Online</em>.</p>'),
573+
new LiteralField('noSchedule', '<div id="no_schedules">No schedules set.</div>'),
573574
new LiteralField('scheduleDiv', '<div id="schedules">')
574575
);
575576

@@ -589,23 +590,25 @@ function AddTrainingCourseForm()
589590

590591
}
591592

592-
} else {
593-
$fields->push(new LiteralField('scheduleDiv', '<div class="scheduleRow">'));
594-
$fields->push($City);
595-
$fields->push($State);
596-
$fields->push($Country);
597-
$fields->push($StartDate);
598-
$fields->push($EndDate);
599-
$fields->push($LinkS);
600-
$fields->push(new LiteralField('scheduleDiv', '</div>'));
601593
}
602594

603595
$fields->push(new LiteralField('scheduleDivC', '</div>'));
604-
$fields->push(new LiteralField('addSchedule', '<button id="addSchedule" class="action">Add Another</button>'));
596+
$fields->push(new LiteralField('addSchedule', '<button id="addSchedule" class="btn btn-default action">Add Another</button>'));
597+
598+
// schedule template
599+
$fields->push(new LiteralField('scheduleTemplate', '<div class="schedule_template">'));
600+
$fields->push($TemplateCity);
601+
$fields->push($TemplateState);
602+
$fields->push($TemplateCountry);
603+
$fields->push($TemplateStartDate);
604+
$fields->push($TemplateEndDate);
605+
$fields->push($TemplateLinkS);
606+
$fields->push(new LiteralField('scheduleTemplate', '</div>'));
605607

606608
$actions = new FieldList(
607-
new FormAction('AddCourse', 'Submit')
609+
$submit = new FormAction('AddCourse', 'Submit')
608610
);
611+
$submit->addExtraClass('btn btn-primary');
609612
$validators = new ConditionalAndValidationRule(array(new RequiredFields('Name', 'Level'), new HtmlPurifierRequiredValidator('Description')));
610613
$form = new Form($this, 'AddTrainingCourseForm', $fields, $actions, $validators);
611614
if (isset($this->EditCourseID)) {
@@ -635,6 +638,8 @@ function AddCourse($data, $form)
635638

636639
function trainingEdit()
637640
{
641+
Requirements::css('themes/openstack/bower_assets/awesome-bootstrap-checkbox/awesome-bootstrap-checkbox.css');
642+
638643
$this->EditCourseID = intval($_GET['course_id']);
639644
return $this->renderWith(array('EditProfilePage_TrainingAddCourse', 'Page'));
640645
}

registration/javascript/edit.profile.training.form.js

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,7 @@ jQuery(document).ready(function($) {
2929
}
3030
else{
3131
// Set Required
32-
var $city_input = $('.city_name').find('input');
33-
$city_input.prop('required', true);
34-
35-
var $state_input = $('.state').find('input');
36-
37-
var $country_input = $('.country').find('select');
38-
$country_input.prop('required', true);
39-
40-
var url_input = $('.url').find('input');
41-
url_input.prop('required', true);
32+
setRequired();
4233

4334
$('#Link').hide();
4435
$online_link.prop('required', false);
@@ -124,18 +115,32 @@ jQuery(document).ready(function($) {
124115
});
125116

126117
$('.scheduleRow',$training_form).each(function(){
127-
$(this).append('<div class="remove">X</div>');
118+
$(this).append('<div class="remove"><i class="fa fa-times" aria-hidden="true"></i></div>');
128119
});
129120

121+
if($('.scheduleRow',$training_form).length == 0){
122+
$('#no_schedules').show();
123+
} else {
124+
$('#no_schedules').hide();
125+
}
126+
130127
$('.scheduleRow .remove',$training_form).live('click',function(){
131-
if($('.scheduleRow',$training_form).length>1){
128+
if($('.scheduleRow',$training_form).length > 0){
132129
$(this).parent().remove();
133130
}
131+
132+
if($('.scheduleRow',$training_form).length == 0){
133+
$('#no_schedules').show();
134+
} else {
135+
$('#no_schedules').hide();
136+
}
134137
});
135138

136139
$('#addSchedule',$training_form).click( function(){
137140

138-
var new_row = $('.scheduleRow:last',$training_form).clone();
141+
var new_row = $('.schedule_template:first').clone();
142+
143+
new_row.addClass('scheduleRow').removeClass('schedule_template');
139144

140145
new_row.find('input,select').each( function(){
141146

@@ -171,6 +176,8 @@ jQuery(document).ready(function($) {
171176
});
172177
new_row.appendTo('#schedules');
173178

179+
setRequired();
180+
174181
return false;
175182

176183
});
@@ -180,4 +187,17 @@ jQuery(document).ready(function($) {
180187
$('.course-description',$training_form).prop('required',true);
181188

182189
}
183-
});
190+
});
191+
192+
function setRequired() {
193+
var $city_input = $('.city_name','#schedules').find('input');
194+
$city_input.prop('required', true);
195+
196+
var $state_input = $('.state','#schedules').find('input');
197+
198+
var $country_input = $('.country','#schedules').find('select');
199+
$country_input.prop('required', true);
200+
201+
var url_input = $('.url','#schedules').find('input');
202+
url_input.prop('required', true);
203+
}

themes/openstack/css/profile-section.css

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ h3.section-divider:first-child {
4444
}
4545

4646
.field {
47-
margin-top: 10px;
47+
margin-top: 10px !important;
4848
}
4949

5050

@@ -56,6 +56,18 @@ h3.section-divider:first-child {
5656
height:100px;
5757
}
5858

59+
#Form_AddTrainingCourseForm_Projects {
60+
padding-top: 10px !important;
61+
}
62+
63+
#Form_AddTrainingCourseForm_Projects > .val1 {
64+
margin-top: -5px;
65+
}
66+
67+
.horizontal-fields {
68+
height: 50px;
69+
}
70+
5971
.horizontal-fields > *{
6072
float: left;
6173
width:25%;
@@ -96,36 +108,58 @@ h3.section-divider:first-child {
96108
}
97109
#Form_AddTrainingCourseForm .scheduleRow > div.remove{
98110
float:left;
99-
color:#FF0000;
111+
color: black;
100112
width:20px;
101113
margin-top:35px;
102114
padding:5px;
103115
cursor: pointer;
104116
text-align: center;
105117
height:19px;
106118
}
107-
#Form_AddTrainingCourseForm .scheduleRow > div.remove:hover{
108-
background-color: #FF0000;
109-
color:#FFF;
110-
}
119+
120+
#Form_AddTrainingCourseForm .scheduleRow > div.remove:hover{
121+
color:#FF0000;;
122+
}
123+
111124
#Form_AddTrainingCourseForm .scheduleRow > div input{
112125
width:90%;
113126
}
127+
114128
#Form_AddTrainingCourseForm .scheduleRow > div select{
115-
width:99%;
129+
width:90%;
116130
padding:5px;
117-
height:29px;
118131
}
132+
119133
#Form_AddTrainingCourseForm .city_name:disabled,
120134
#Form_AddTrainingCourseForm .state:disabled,
121-
#Form_AddTrainingCourseForm .country:disabled{
135+
#Form_AddTrainingCourseForm .country:disabled {
122136
background-color: #dedede;
123137
}
124138

125139
#Form_AddTrainingCourseForm .note_online{
126140
display:none;
127141
}
128142

143+
#addSchedule {
144+
margin-top: 20px;
145+
}
146+
147+
#schedules > .scheduleRow + .scheduleRow > .remove{
148+
margin-top: 10px;
149+
}
150+
151+
#schedules > .scheduleRow + .scheduleRow > div > label{
152+
display: none;
153+
}
154+
129155
.travel-field {
130156
min-height: 20em;
157+
}
158+
159+
#no_schedules {
160+
display: none;
161+
}
162+
163+
.schedule_template {
164+
display: none;
131165
}

0 commit comments

Comments
 (0)