Skip to content

Commit 7b8f59f

Browse files
committed
WIP: disable date-time-selector for teachers if evaluation has already been requested
1 parent d470465 commit 7b8f59f

File tree

6 files changed

+83
-36
lines changed

6 files changed

+83
-36
lines changed

amd/src/initialize.js

+7
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ define(['jquery', 'core/notification', 'core/str'], function ($, notification, s
2020
$('[name=year_end]').last()[0].selectedIndex = end.getFullYear() - 2000;
2121
if ($('#reactivate').length > 0) {
2222
endenabled = !$('[name=minute_end]')[0].disabled;
23+
datedisabled = $('[name=minute_end]')[0].disabled && $('[name=minute_start]')[0].disabled;
2324
$(document).on("change", "#reactivate", function() {
2425
if (this.checked) {
2526
// Ask for confirmation, then enable all fields related to re-invitation.
@@ -51,6 +52,9 @@ define(['jquery', 'core/notification', 'core/str'], function ($, notification, s
5152
if ($('#only_end').length > 0) {
5253
$('#only_end').prop("value", false);
5354
}
55+
if ($('#datedisabled').length > 0) {
56+
$('#datedisabled').prop("value", false);
57+
}
5458
if ($('#evasyssubmitbutton').length > 0) {
5559
$('#evasyssubmitbutton').prop("disabled", false);
5660
$('#evasyssubmitbutton').val(s[4]);
@@ -81,6 +85,9 @@ define(['jquery', 'core/notification', 'core/str'], function ($, notification, s
8185
if ($('#only_end').length > 0) {
8286
$('#only_end').prop("value", true);
8387
}
88+
if ($('#datedisabled').length > 0) {
89+
$('#datedisabled').prop("value", true);
90+
}
8491
if ($('#evasyssubmitbutton').length > 0) {
8592
if (!endenabled) {
8693
$('#evasyssubmitbutton').prop("disabled", true);

amd/src/standardtime.js

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ define(['jquery', 'core/str'], function($, str) {
3434
$('[name=month_end]')[0].disabled = true;
3535
$('[name=year_end]')[0].disabled = true;
3636
$('#only_end').val(false);
37+
$('#datedisabled').val(true);
3738
};
3839

3940
var enable = function() {

block_evasys_sync.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ public function get_content() {
9898
$enddisabled = false;
9999
$emailsentnotice = false;
100100
$periodsetnotice = false;
101+
$datedisabled = false;
101102

102103
// Set start to today and end to a week from now.
103104
$start = time();
@@ -115,6 +116,7 @@ public function get_content() {
115116
$first = array_key_first($evaluations->evaluations);
116117
$start = $evaluations->evaluations[$first]->start;
117118
$end = $evaluations->evaluations[$first]->end;
119+
$datedisabled = true;
118120
} elseif ($evasyscategory->default_period_set()) {
119121
$start = $evasyscategory->get('standard_time_start');
120122
$end = $evasyscategory->get('standard_time_end');
@@ -186,8 +188,9 @@ public function get_content() {
186188
'usestandardtimelayout' => $standardttimemode,
187189
// Choose mode.
188190
'direct' => false,
189-
'startdisabled' => $startdisabled || $standardttimemode,
190-
'enddisabled' => $enddisabled || $standardttimemode,
191+
'startdisabled' => $startdisabled || $standardttimemode || $datedisabled,
192+
'enddisabled' => $enddisabled || $standardttimemode || $datedisabled,
193+
'datedisabled' => $datedisabled,
191194
'onlyend' => $startdisabled && !$standardttimemode,
192195
'disablesubmit' => $enddisabled,
193196
// If the evaluation hasn't ended yet, display option to restart it.

classes/evasys_synchronizer.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ static public function get_assigned_user($course) {
365365
* Set time period for evaluation.
366366
*
367367
* @param array $dates expects keys `start' and `end' with timestamp values.
368-
* @return bool true if the dates have changed or if the record is new.
368+
* @return bool true if the date record is new.
369369
* @throws \coding_exception
370370
* @throws \dml_missing_record_exception
371371
*/
@@ -375,10 +375,11 @@ public function set_evaluation_period($dates) : bool {
375375
if ($usestandardtime) {
376376
$dates = self::get_standard_timemode($course->category);
377377
}
378-
$changed = false;
378+
$new = false;
379379
$data = evaluation::for_course($this->courseid);
380380
if (!$data) {
381381
$data = new evaluation();
382+
$new = true;
382383
$data->courses = [$this->courseid];
383384
foreach ($this->courseinformation as $lsfid => $information) {
384385
$data->evaluations[$lsfid] = (object) [
@@ -392,15 +393,14 @@ public function set_evaluation_period($dates) : bool {
392393
} else {
393394
foreach ($data->evaluations as &$evaluation) {
394395
if ($evaluation->start != $dates['start'] || $evaluation->end != $dates['end']) {
395-
$changed = true;
396396
$evaluation->start = $dates['start'];
397397
$evaluation->end = $dates['end'];
398398
}
399399
}
400400
}
401401
$data->save();
402402

403-
return $changed;
403+
return $new;
404404
}
405405

406406
/**

sync.php

+43-29
Original file line numberDiff line numberDiff line change
@@ -34,37 +34,48 @@
3434
$returnurl->param('evasyssynccheck', 1);
3535

3636
if (!optional_param('activate_standard', false, PARAM_BOOL)) {
37-
if (optional_param('only_end', false, PARAM_BOOL)) {
38-
// Existing start date should not be changed; just the end date. Fetch start date from record.
37+
38+
if (optional_param('datedisabled', false, PARAM_BOOL)) {
39+
3940
$record = course_evaluation_allocation::get_record_by_course($courseid);
4041
$startdate = new \DateTime('@' . $record->get('startdate'), \core_date::get_server_timezone_object());
42+
$enddate = new \DateTime('@' . $record->get('enddate'), \core_date::get_server_timezone_object());
43+
4144
} else {
42-
$startyear = required_param('year_start', PARAM_TEXT);
43-
$startmonth = date_decoder::decode_from_localised_string(required_param('month_start', PARAM_TEXT));
44-
$startday = required_param('day_start', PARAM_TEXT);
45-
$starthour = required_param('hour_start', PARAM_TEXT);
46-
$startmin = required_param('minute_start', PARAM_TEXT);
47-
48-
$startdate = new DateTime();
49-
$startdate->setTimezone(\core_date::get_server_timezone_object());
50-
$startdate->setDate($startyear, $startmonth, $startday);
51-
$startdate->setTime($starthour, $startmin);
52-
if (time() > $startdate->getTimestamp()) {
53-
// Start date is in the past; change to now (just for the record).
54-
$startdate = new \DateTime('now', \core_date::get_server_timezone_object());
45+
46+
if (optional_param('only_end', false, PARAM_BOOL)) {
47+
// Existing start date should not be changed; just the end date. Fetch start date from record.
48+
$record = course_evaluation_allocation::get_record_by_course($courseid);
49+
$startdate = new \DateTime('@' . $record->get('startdate'), \core_date::get_server_timezone_object());
50+
} else {
51+
$startyear = required_param('year_start', PARAM_TEXT);
52+
$startmonth = date_decoder::decode_from_localised_string(required_param('month_start', PARAM_TEXT));
53+
$startday = required_param('day_start', PARAM_TEXT);
54+
$starthour = required_param('hour_start', PARAM_TEXT);
55+
$startmin = required_param('minute_start', PARAM_TEXT);
56+
57+
$startdate = new DateTime();
58+
$startdate->setTimezone(\core_date::get_server_timezone_object());
59+
$startdate->setDate($startyear, $startmonth, $startday);
60+
$startdate->setTime($starthour, $startmin);
61+
if (time() > $startdate->getTimestamp()) {
62+
// Start date is in the past; change to now (just for the record).
63+
$startdate = new \DateTime('now', \core_date::get_server_timezone_object());
64+
}
5565
}
56-
}
5766

58-
$endyear = required_param('year_end', PARAM_TEXT);
59-
$endmonth = date_decoder::decode_from_localised_string(required_param('month_end', PARAM_TEXT));
60-
$endday = required_param('day_end', PARAM_TEXT);
61-
$endhour = required_param('hour_end', PARAM_TEXT);
62-
$endmin = required_param('minute_end', PARAM_TEXT);
67+
$endyear = required_param('year_end', PARAM_TEXT);
68+
$endmonth = date_decoder::decode_from_localised_string(required_param('month_end', PARAM_TEXT));
69+
$endday = required_param('day_end', PARAM_TEXT);
70+
$endhour = required_param('hour_end', PARAM_TEXT);
71+
$endmin = required_param('minute_end', PARAM_TEXT);
72+
73+
$enddate = new DateTime();
74+
$enddate->setTimezone(\core_date::get_server_timezone_object());
75+
$enddate->setDate($endyear, $endmonth, $endday);
76+
$enddate->setTime($endhour, $endmin);
6377

64-
$enddate = new DateTime();
65-
$enddate->setTimezone(\core_date::get_server_timezone_object());
66-
$enddate->setDate($endyear, $endmonth, $endday);
67-
$enddate->setTime($endhour, $endmin);
78+
}
6879

6980
$dates = ["start" => $startdate->getTimestamp(), "end" => $enddate->getTimestamp()];
7081

@@ -79,12 +90,12 @@
7990
} else {
8091
$dates = "Standard";
8192
// We can't detect that anyways since we don't know the dates.
82-
$datechanged = false;
93+
$datenew = false;
8394
}
8495

8596
try {
8697
$evasyssynchronizer = new \block_evasys_sync\evasys_synchronizer($courseid);
87-
$datechanged = $evasyssynchronizer->set_evaluation_period($dates);
98+
$datenew = $evasyssynchronizer->set_evaluation_period($dates);
8899
} catch (\dml_missing_record_exception $e) {
89100
debugging($e);
90101
$returnurl->param('status', 'failure');
@@ -104,8 +115,11 @@
104115

105116
\block_evasys_sync\evaluation_manager::clear_error($courseid);
106117

107-
if ($newparticipantsadded || $datechanged) {
108-
$evasyssynchronizer->notify_evaluation_responsible_person($dates, $newparticipantsadded, $datechanged);
118+
if ($newparticipantsadded || $datenew) {
119+
if ($datenew) {
120+
// Only send an email if it's the first time requesting this evaluation
121+
$evasyssynchronizer->notify_evaluation_responsible_person($dates, $newparticipantsadded, $datenew);
122+
}
109123

110124
// Log event.
111125
$event = \block_evasys_sync\event\evaluation_requested::create(array(

templates/block.mustache

+23-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Example context (json):
2626
"enddisabled": false,
2727
"startoption": false,
2828
"onlyend": false,
29+
"datedisabled": false,
2930
"disablesubmit": false,
3031
"coursemappingenabled": true,
3132
"nostudents": false,
@@ -39,6 +40,7 @@ Example context (json):
3940
<input type="hidden" name="sesskey" value="{{sesskey}}">
4041
<input type="hidden" name="courseid" value="{{courseid}}">
4142
{{#onlyend}}<input id="only_end" type="hidden" name="only_end" value="true">{{/onlyend}}
43+
{{#datedisabled}}<input id="datedisabled" type="hidden" name="datedisabled" value="true">{{/datedisabled}}
4244
{{#nostudents}}<span style="color: orange; ">{{# str}}syncnostudents, block_evasys_sync{{/str}}</span>{{/nostudents}}
4345
{{#courses}}
4446
{{#.}}
@@ -121,7 +123,27 @@ Example context (json):
121123
<input id='evasyssubmitbutton' class="in_box_button" type="submit" value="{{# str}}invitestudents, block_evasys_sync{{/str}}" {{#disablesubmit}}disabled{{/disablesubmit}}/>
122124
{{/direct}}
123125
{{#direct}}
124-
<input id='evasyssubmitbutton' class="in_box_button" type="submit" value="{{# str}}planorstartevaluation, block_evasys_sync{{/str}}" {{#disablesubmit}}disabled{{/disablesubmit}}/>
126+
<input id='evasyssubmitbutton' class="in_box_button" type="submit" value="{{# str}}planorstartevaluation, block_evasys_sync{{/str}}" {{#datedisabled}}data-toggle="modal" data-target="#confirmmodal"{{/datedisabled}}{{#disablesubmit}}disabled{{/disablesubmit}}/>
125127
{{/direct}}
128+
<div class="modal fade" id="confirmmodal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
129+
<div class="modal-dialog">
130+
<div class="modal-content">
131+
<div class="modal-header">
132+
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
133+
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
134+
<span aria-hidden="true">&times;</span>
135+
</button>
136+
</div>
137+
<div class="modal-body">
138+
...
139+
</div>
140+
<div class="modal-footer">
141+
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
142+
<button type="button" class="btn btn-primary">Save changes</button>
143+
</div>
144+
</div>
145+
</div>
146+
</div>
147+
126148
{{/showcontrols}}
127149
</form>

0 commit comments

Comments
 (0)