From 0fc30827dce3d6373959b7fc28ce27d1e5dbf825 Mon Sep 17 00:00:00 2001 From: Huong Nguyen Date: Thu, 13 Jun 2019 14:49:20 +0700 Subject: [PATCH] MDL-64032 enrol_manual: Make consistent the UI for setting enrolment Add end date/duration for the UI for setting enrolment should be consistent --- enrol/editenrolment.php | 3 ++ enrol/editenrolment_form.php | 10 +++++ enrol/manual/ajax.php | 17 +++++++- enrol/manual/classes/enrol_users_form.php | 37 ++++++++++++------ enrol/manual/manage.php | 6 ++- enrol/manual/tests/behat/quickenrolment.feature | 52 +++++++++++++++++++++++-- enrol/tests/enrollib_test.php | 19 +++++++++ lang/en/enrol.php | 1 + lib/enrollib.php | 27 +++++++++++++ lib/tests/behat/behat_forms.php | 28 +++++++++++++ user/amd/build/status_field.min.js | 2 +- user/amd/src/status_field.js | 6 +++ 12 files changed, 189 insertions(+), 19 deletions(-) diff --git a/enrol/editenrolment.php b/enrol/editenrolment.php index f9f4cf4e973..8c358b21767 100644 --- a/enrol/editenrolment.php +++ b/enrol/editenrolment.php @@ -87,6 +87,9 @@ if ($mform->is_cancelled()) { redirect($returnurl); } else if ($data = $mform->get_data()) { + if ($data->duration && $data->timeend == 0) { + $data->timeend = $data->timestart + $data->duration; + } if ($manager->edit_enrolment($ue, $data)) { redirect($returnurl); } diff --git a/enrol/editenrolment_form.php b/enrol/editenrolment_form.php index d1ee2ec1e40..f90e733df51 100644 --- a/enrol/editenrolment_form.php +++ b/enrol/editenrolment_form.php @@ -22,6 +22,8 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +use core_enrol\enrol_helper; + defined('MOODLE_INTERNAL') || die(); require_once("$CFG->libdir/formslib.php"); @@ -34,6 +36,9 @@ class enrol_user_enrolment_form extends moodleform { $instancename = $this->_customdata['enrolinstancename']; $modal = !empty($this->_customdata['modal']); + $periodmenu = enrol_get_period_list(); + $duration = enrol_calculate_duration($ue->timestart, $ue->timeend); + $mform->addElement('static', 'enrolmentmethod', get_string('enrolmentmethod', 'enrol'), $instancename); $options = array(ENROL_USER_ACTIVE => get_string('participationactive', 'enrol'), @@ -44,6 +49,11 @@ class enrol_user_enrolment_form extends moodleform { $mform->addElement('date_time_selector', 'timestart', get_string('enroltimestart', 'enrol'), array('optional' => true)); + $mform->addElement('select', 'duration', get_string('enrolperiod', 'enrol'), $periodmenu); + $mform->setDefault('duration', $duration); + $mform->disabledIf('duration', 'timestart[enabled]', 'notchecked', 1); + $mform->disabledIf('duration', 'timeend[enabled]', 'checked', 1); + $mform->addElement('date_time_selector', 'timeend', get_string('enroltimeend', 'enrol'), array('optional' => true)); $mform->addElement('static', 'timecreated', get_string('enroltimecreated', 'enrol'), userdate($ue->timecreated)); diff --git a/enrol/manual/ajax.php b/enrol/manual/ajax.php index 3f182fd6bd7..5378aae6154 100644 --- a/enrol/manual/ajax.php +++ b/enrol/manual/ajax.php @@ -32,6 +32,7 @@ require_once($CFG->dirroot.'/enrol/locallib.php'); require_once($CFG->dirroot.'/group/lib.php'); require_once($CFG->dirroot.'/enrol/manual/locallib.php'); require_once($CFG->dirroot.'/cohort/lib.php'); +require_once($CFG->dirroot . '/enrol/manual/classes/enrol_users_form.php'); $id = required_param('id', PARAM_INT); // Course id. $action = required_param('action', PARAM_ALPHANUMEXT); @@ -94,6 +95,7 @@ switch ($action) { $duration = optional_param('duration', 0, PARAM_INT); $startdate = optional_param('startdate', 0, PARAM_INT); $recovergrades = optional_param('recovergrades', 0, PARAM_INT); + $timeend = optional_param_array('timeend', [], PARAM_INT); if (empty($roleid)) { $roleid = null; @@ -122,12 +124,25 @@ switch ($action) { $timestart = $today; break; } - if ($duration <= 0) { + if ($timeend) { + $timeend = make_timestamp($timeend['year'], $timeend['month'], $timeend['day'], $timeend['hour'], $timeend['minute']); + } else if ($duration <= 0) { $timeend = 0; } else { $timeend = $timestart + $duration; } + $mform = new enrol_manual_enrol_users_form(null, (object)["context" => $context]); + $userenroldata = [ + 'startdate' => $timestart, + 'timeend' => $timeend, + ]; + $mform->set_data($userenroldata); + $validationerrors = $mform->validation($userenroldata, null); + if (!empty($validationerrors)) { + throw new enrol_ajax_exception('invalidenrolduration'); + } + $instances = $manager->get_enrolment_instances(); $plugins = $manager->get_enrolment_plugins(true); // Do not allow actions on disabled plugins. if (!array_key_exists($enrolid, $instances)) { diff --git a/enrol/manual/classes/enrol_users_form.php b/enrol/manual/classes/enrol_users_form.php index 165a6e996de..b7fa663bba7 100644 --- a/enrol/manual/classes/enrol_users_form.php +++ b/enrol/manual/classes/enrol_users_form.php @@ -60,14 +60,7 @@ class enrol_manual_enrol_users_form extends moodleform { $mform = $this->_form; $mform->setDisableShortforms(); $mform->disable_form_change_checker(); - // Build the list of options for the enrolment period dropdown. - $unlimitedperiod = get_string('unlimited'); - $periodmenu = array(); - $periodmenu[''] = $unlimitedperiod; - for ($i=1; $i<=365; $i++) { - $seconds = $i * 86400; - $periodmenu[$seconds] = get_string('numdays', '', $i); - } + $periodmenu = enrol_get_period_list(); // Work out the apropriate default settings. $defaultperiod = $instance->enrolperiod; if ($instance->enrolperiod > 0 && !isset($periodmenu[$instance->enrolperiod])) { @@ -131,13 +124,15 @@ class enrol_manual_enrol_users_form extends moodleform { $mform->addElement('checkbox', 'recovergrades', get_string('recovergrades', 'enrol')); $mform->setAdvanced('recovergrades'); $mform->setDefault('recovergrades', $CFG->recovergradesdefault); - $mform->addElement('select', 'duration', get_string('defaultperiod', 'enrol_manual'), $periodmenu); - $mform->setDefault('duration', $defaultperiod); - $mform->setAdvanced('duration'); $mform->addElement('select', 'startdate', get_string('startingfrom'), $basemenu); $mform->setDefault('startdate', $extendbase); $mform->setAdvanced('startdate'); - + $mform->addElement('select', 'duration', get_string('enrolperiod', 'enrol'), $periodmenu); + $mform->setDefault('duration', $defaultperiod); + $mform->setAdvanced('duration'); + $mform->disabledIf('duration', 'timeend[enabled]', 'checked', 1); + $mform->addElement('date_time_selector', 'timeend', get_string('enroltimeend', 'enrol'), ['optional' => true]); + $mform->setAdvanced('timeend'); $mform->addElement('hidden', 'id', $course->id); $mform->setType('id', PARAM_INT); $mform->addElement('hidden', 'action', 'enrol'); @@ -145,4 +140,22 @@ class enrol_manual_enrol_users_form extends moodleform { $mform->addElement('hidden', 'enrolid', $instance->id); $mform->setType('enrolid', PARAM_INT); } + + /** + * Validate the submitted form data. + * + * @param array $data array of ("fieldname"=>value) of submitted data + * @param array $files array of uploaded files "element_name"=>tmp_file_path + * @return array of "element_name"=>"error_description" if there are errors, + * or an empty array if everything is OK (true allowed for backwards compatibility too). + */ + public function validation($data, $files) { + $errors = parent::validation($data, $files); + if (!empty($data['startdate']) && !empty($data['timeend'])) { + if ($data['startdate'] >= $data['timeend']) { + $errors['timeend'] = get_string('enroltimeendinvalid', 'enrol'); + } + } + return $errors; + } } diff --git a/enrol/manual/manage.php b/enrol/manual/manage.php index 9eb8758683d..0df80cf1fcb 100644 --- a/enrol/manual/manage.php +++ b/enrol/manual/manage.php @@ -29,6 +29,7 @@ $enrolid = required_param('enrolid', PARAM_INT); $roleid = optional_param('roleid', -1, PARAM_INT); $extendperiod = optional_param('extendperiod', 0, PARAM_INT); $extendbase = optional_param('extendbase', 0, PARAM_INT); +$timeend = optional_param_array('timeend', [], PARAM_INT); $instance = $DB->get_record('enrol', array('id'=>$enrolid, 'enrol'=>'manual'), '*', MUST_EXIST); $course = $DB->get_record('course', array('id'=>$instance->courseid), '*', MUST_EXIST); @@ -135,7 +136,10 @@ if ($canenrol && optional_param('add', false, PARAM_BOOL) && confirm_sesskey()) break; } - if ($extendperiod <= 0) { + if ($timeend) { + $timeend = make_timestamp($timeend['year'], $timeend['month'], $timeend['day'], $timeend['hour'], + $timeend['minute']); + } else if ($extendperiod <= 0) { $timeend = 0; } else { $timeend = $timestart + $extendperiod; diff --git a/enrol/manual/tests/behat/quickenrolment.feature b/enrol/manual/tests/behat/quickenrolment.feature index 2afa506adc3..a6a7af7dd0b 100644 --- a/enrol/manual/tests/behat/quickenrolment.feature +++ b/enrol/manual/tests/behat/quickenrolment.feature @@ -108,11 +108,11 @@ Feature: Teacher can search and enrol users one by one into the course | student098 | Student | 098 | student098@example.com | | student099 | Student | 099 | student099@example.com | And the following "courses" exist: - | fullname | shortname | - | Course 001 | C001 | + | fullname | shortname | format | startdate | + | Course 001 | C001 | weeks | ##1 month ago## | And the following "course enrolments" exist: - | user | course | role | - | teacher001 | C001 | editingteacher | + | user | course | role | timestart | + | teacher001 | C001 | editingteacher | ##1 month ago## | And I log in as "teacher001" And I am on "Course 001" course homepage @@ -178,3 +178,47 @@ Feature: Teacher can search and enrol users one by one into the course When I set the field "Select users" to "student100@example.com" And I click on ".form-autocomplete-downarrow" "css_element" in the "Select users" "form_row" Then I should see "student100@example.com, 1234567892, 1234567893, ABC1, ABC2" + + @javascript + Scenario: Enrol user from participants page + Given I navigate to course participants + # Enrol user to course + And I press "Enrol users" + And I set the field "Select users" to "example.com" + And I expand the "Select users" autocomplete + When I click on "Student 099" item in the autocomplete list + Then I should see "Student 099" in the list of options for the "Select users" autocomplete + And I click on "Show more" "button" + # Fill data to input duration + And "input[name='timeend[enabled]'][checked=checked]" "css_element" should not exist + And the "Enrolment duration" "select" should be enabled + And I set the field "duration" to "2" + # Fill data to input end time + And I set the field "Starting from" to "2" + And I set the field "timeend[enabled]" to "1" + And I set the field "timeend[day]" to "10" + And the "Enrolment duration" "select" should be disabled + And I click on "Enrol users" "button" in the "Enrol users" "dialogue" + And I am on "Course 001" course homepage + And I navigate to course participants + And I should see "Student 099" in the "participants" "table" + And I click on "Edit enrolment" "icon" in the "Student 099" "table_row" + And the field "timeend[day]" matches value "10" + + @javascript + Scenario: Update Enrol user + Given I am on "Course 001" course homepage + And I navigate to course participants + When I click on "Edit enrolment" "icon" in the "Teacher 001" "table_row" + Then the "Enrolment duration" "select" should be enabled + # Fill duration + And "input[name='timeend[enabled]'][checked=checked]" "css_element" should not exist + And the "Enrolment duration" "select" should be enabled + And I set the field "duration" to "2" + # Fill end time + And I set the field "timeend[enabled]" to "1" + And I set the field "timeend[day]" to "28" + And the "Enrolment duration" "select" should be disabled + And I press "Save changes" + And I click on "Edit enrolment" "icon" in the "Teacher 001" "table_row" + And the field "timeend[day]" matches value "28" diff --git a/enrol/tests/enrollib_test.php b/enrol/tests/enrollib_test.php index 801f176d802..e44cef68c11 100644 --- a/enrol/tests/enrollib_test.php +++ b/enrol/tests/enrollib_test.php @@ -1080,4 +1080,23 @@ class core_enrollib_testcase extends advanced_testcase { $this->assertArrayHasKey($roles['student'], $return[$user2->id]); $this->assertArrayNotHasKey($roles['teacher'], $return[$user2->id]); } + + /** + * Test enrol_calculate_duration function + */ + public function test_enrol_calculate_duration() { + // Start time 07/01/2019 @ 12:00am (UTC). + $timestart = 1561939200; + // End time 07/05/2019 @ 12:00am (UTC). + $timeend = 1562284800; + $duration = enrol_calculate_duration($timestart, $timeend); + $durationinday = $duration / DAYSECS; + $this->assertEquals(4, $durationinday); + + // End time 07/10/2019 @ 12:00am (UTC). + $timeend = 1562716800; + $duration = enrol_calculate_duration($timestart, $timeend); + $durationinday = $duration / DAYSECS; + $this->assertEquals(9, $durationinday); + } } diff --git a/lang/en/enrol.php b/lang/en/enrol.php index ea1bb8e32c5..bdb64e4fb76 100644 --- a/lang/en/enrol.php +++ b/lang/en/enrol.php @@ -96,6 +96,7 @@ $string['instanceadded'] = 'Method added'; $string['instanceeditselfwarning'] = 'Warning:'; $string['instanceeditselfwarningtext'] = 'You are enrolled into this course through this enrolment method, changes may affect your access to this course.'; $string['invalidenrolinstance'] = 'Invalid enrolment instance'; +$string['invalidenrolduration'] = 'Invalid enrolment duration'; $string['invalidrole'] = 'Invalid role'; $string['invalidrequest'] = 'Invalid request'; $string['manageenrols'] = 'Manage enrol plugins'; diff --git a/lib/enrollib.php b/lib/enrollib.php index 5b668941c47..007acae9620 100644 --- a/lib/enrollib.php +++ b/lib/enrollib.php @@ -1702,6 +1702,33 @@ function enrol_get_course_users($courseid = false, $onlyactive = false, $usersfi } /** + * Get the list of options for the enrolment period dropdown + * + * @return array List of options for the enrolment period dropdown + */ +function enrol_get_period_list() { + $periodmenu = []; + $periodmenu[''] = get_string('unlimited'); + for ($i = 1; $i <= 365; $i++) { + $seconds = $i * DAYSECS; + $periodmenu[$seconds] = get_string('numdays', '', $i); + } + return $periodmenu; +} + +/** + * Calculate duration base on start time and end time + * + * @param int $timestart Time start + * @param int $timeend Time end + * @return float|int Calculated duration + */ +function enrol_calculate_duration($timestart, $timeend) { + $duration = floor(($timeend - $timestart) / DAYSECS) * DAYSECS; + return $duration; +} + +/** * Enrolment plugins abstract class. * * All enrol plugins should be based on this class, diff --git a/lib/tests/behat/behat_forms.php b/lib/tests/behat/behat_forms.php index cd532a346a6..9d89a75cd45 100644 --- a/lib/tests/behat/behat_forms.php +++ b/lib/tests/behat/behat_forms.php @@ -546,4 +546,32 @@ class behat_forms extends behat_base { $csstarget = ".form-autocomplete-downarrow"; $this->execute('behat_general::i_click_on', [$csstarget, 'css_element']); } + + /** + * Expand the given autocomplete list + * + * @Given /^I expand the "(?P(?:[^"]|\\")*)" autocomplete$/ + * + * @param string $field Field name + */ + public function i_expand_the_autocomplete($field) { + $csstarget = '.form-autocomplete-downarrow'; + $node = $this->get_node_in_container('css_element', $csstarget, 'form_row', $field); + $this->ensure_node_is_visible($node); + $node->click(); + } + + /** + * Assert the given option exist in the given autocomplete list + * + * @Given /^I should see "(?P(?:[^"]|\\")*)" in the list of options for the "(?P(?:[^"]|\\")*)" autocomplete$$/ + * + * @param string $option Name of option + * @param string $field Field name + */ + public function i_should_see_in_the_list_of_option_for_the_autocomplete($option, $field) { + $xpathtarget = "//div[contains(@class, 'form-autocomplete-selection') and contains(.//div, '" . $option . "')]"; + $node = $this->get_node_in_container('xpath_element', $xpathtarget, 'form_row', $field); + $this->ensure_node_is_visible($node); + } } diff --git a/user/amd/build/status_field.min.js b/user/amd/build/status_field.min.js index a26e99fbe9d..5588775b463 100644 --- a/user/amd/build/status_field.min.js +++ b/user/amd/build/status_field.min.js @@ -1 +1 @@ -define(["core/templates","jquery","core/str","core/config","core/notification","core/modal_factory","core/modal_events","core/fragment","core/ajax"],function(a,b,c,d,e,f,g,h,i){var j={EDIT_ENROLMENT:'[data-action="editenrolment"]',SHOW_DETAILS:'[data-action="showdetails"]',UNENROL:'[data-action="unenrol"]'},k=function(a){this.contextid=a.contextid,this.courseid=a.courseid,this.bindEditEnrol(),this.bindUnenrol(),this.bindStatusDetails()};return k.prototype.courseid=0,k.prototype.bindEditEnrol=function(){var a=this;b(j.EDIT_ENROLMENT).click(function(d){d.preventDefault();var h=b(this),i=h.parent(),j=i.data("fullname"),k=h.attr("rel");b.when(c.get_string("edituserenrolment","enrol",j)).then(function(a){return f.create({large:!0,title:a,type:f.types.SAVE_CANCEL})}).done(function(b){b.getRoot().on(g.save,function(c){c.preventDefault(),a.submitEditFormAjax(b)}),b.getRoot().on(g.hidden,function(){b.destroy()}),b.setBody(a.getBody(k)),b.show()}).fail(e.exception)})},k.prototype.bindUnenrol=function(){var a=this;b(j.UNENROL).click(function(d){d.preventDefault();var h=b(this),i=h.parent(),j=[{key:"unenrol",component:"enrol"},{key:"unenrolconfirm",component:"enrol",param:{user:i.data("fullname"),course:i.data("coursename"),enrolinstancename:i.data("enrolinstancename")}}],k=f.create({type:f.types.SAVE_CANCEL});b.when(c.get_strings(j),k).done(function(c,e){var f=c[0],i=c[1];e.setTitle(f),e.setBody(i),e.setSaveButtonText(f),e.getRoot().on(g.save,function(){var c={ueid:b(h).attr("rel")};d.preventDefault(),a.submitUnenrolFormAjax(e,c)}),e.getRoot().on(g.hidden,function(){e.destroy()}),e.show()}).fail(e.exception)})},k.prototype.bindStatusDetails=function(){b(j.SHOW_DETAILS).click(function(d){d.preventDefault();var h=b(this),i=h.parent(),k={fullname:i.data("fullname"),coursename:i.data("coursename"),enrolinstancename:i.data("enrolinstancename"),status:i.data("status"),statusclass:i.find("span").attr("class"),timestart:i.data("timestart"),timeend:i.data("timeend"),timeenrolled:i.data("timeenrolled")},l=[{key:"enroldetails",component:"enrol"}],m=h.next(j.EDIT_ENROLMENT);m.length&&(k.editenrollink=b("
").append(m.clone()).html());var n=c.get_strings(l),o=f.create({large:!0,type:f.types.CANCEL});b.when(n,o).done(function(c,d){var e=a.render("core_user/status_details",k);d.setTitle(c[0]),d.setBody(e),m.length&&d.getRoot().on("click",j.EDIT_ENROLMENT,function(a){a.preventDefault(),d.hide(),b(m).trigger("click")}),d.show(),d.getRoot().on(g.hidden,function(){d.destroy()})}).fail(e.exception)})},k.prototype.submitEditFormAjax=function(a){var c=this,d=a.getRoot().find("form"),f=b(d).find('[name="ue"]').val(),g=b(d).find('[name="status"]').val(),h={courseid:this.courseid,ueid:f,status:g},j=b(d).find('[name="timestart[enabled]"]');if(j.is(":checked")){var k=b(d).find('[name="timestart[year]"]').val(),l=b(d).find('[name="timestart[month]"]').val()-1,m=b(d).find('[name="timestart[day]"]').val(),n=b(d).find('[name="timestart[hour]"]').val(),o=b(d).find('[name="timestart[minute]"]').val(),p=new Date(k,l,m,n,o);h.timestart=p.getTime()/1e3}var q=b(d).find('[name="timeend[enabled]"]');if(q.is(":checked")){var r=b(d).find('[name="timeend[year]"]').val(),s=b(d).find('[name="timeend[month]"]').val()-1,t=b(d).find('[name="timeend[day]"]').val(),u=b(d).find('[name="timeend[hour]"]').val(),v=b(d).find('[name="timeend[minute]"]').val(),w=new Date(r,s,t,u,v);h.timeend=w.getTime()/1e3}var x={methodname:"core_enrol_edit_user_enrolment",args:h};i.call([x])[0].done(function(b){if(b.result)a.hide(),"undefined"!=typeof window.M.core_formchangechecker&&window.M.core_formchangechecker.reset_form_dirty_state(),window.location.reload();else{var e=JSON.stringify(d.serialize());a.setBody(c.getBody(f,e))}}).fail(e.exception)},k.prototype.submitUnenrolFormAjax=function(a,b){var c={methodname:"core_enrol_unenrol_user_enrolment",args:b};i.call([c])[0].done(function(b){b.result?(a.hide(),"undefined"!=typeof window.M.core_formchangechecker&&window.M.core_formchangechecker.reset_form_dirty_state(),window.location.reload()):e.alert(b.errors[0].key,b.errors[0].message)}).fail(e.exception)},k.prototype.getBody=function(a,b){var c={ueid:a};return"undefined"!=typeof b&&(c.formdata=b),h.loadFragment("enrol","user_enrolment_form",this.contextid,c).fail(e.exception)},{init:function(a){new k(a)}}}); \ No newline at end of file +define(["core/templates","jquery","core/str","core/config","core/notification","core/modal_factory","core/modal_events","core/fragment","core/ajax"],function(a,b,c,d,e,f,g,h,i){var j={EDIT_ENROLMENT:'[data-action="editenrolment"]',SHOW_DETAILS:'[data-action="showdetails"]',UNENROL:'[data-action="unenrol"]'},k=function(a){this.contextid=a.contextid,this.courseid=a.courseid,this.bindEditEnrol(),this.bindUnenrol(),this.bindStatusDetails()};return k.prototype.courseid=0,k.prototype.bindEditEnrol=function(){var a=this;b(j.EDIT_ENROLMENT).click(function(d){d.preventDefault();var h=b(this),i=h.parent(),j=i.data("fullname"),k=h.attr("rel");b.when(c.get_string("edituserenrolment","enrol",j)).then(function(a){return f.create({large:!0,title:a,type:f.types.SAVE_CANCEL})}).done(function(b){b.getRoot().on(g.save,function(c){c.preventDefault(),a.submitEditFormAjax(b)}),b.getRoot().on(g.hidden,function(){b.destroy()}),b.setBody(a.getBody(k)),b.show()}).fail(e.exception)})},k.prototype.bindUnenrol=function(){var a=this;b(j.UNENROL).click(function(d){d.preventDefault();var h=b(this),i=h.parent(),j=[{key:"unenrol",component:"enrol"},{key:"unenrolconfirm",component:"enrol",param:{user:i.data("fullname"),course:i.data("coursename"),enrolinstancename:i.data("enrolinstancename")}}],k=f.create({type:f.types.SAVE_CANCEL});b.when(c.get_strings(j),k).done(function(c,e){var f=c[0],i=c[1];e.setTitle(f),e.setBody(i),e.setSaveButtonText(f),e.getRoot().on(g.save,function(){var c={ueid:b(h).attr("rel")};d.preventDefault(),a.submitUnenrolFormAjax(e,c)}),e.getRoot().on(g.hidden,function(){e.destroy()}),e.show()}).fail(e.exception)})},k.prototype.bindStatusDetails=function(){b(j.SHOW_DETAILS).click(function(d){d.preventDefault();var h=b(this),i=h.parent(),k={fullname:i.data("fullname"),coursename:i.data("coursename"),enrolinstancename:i.data("enrolinstancename"),status:i.data("status"),statusclass:i.find("span").attr("class"),timestart:i.data("timestart"),timeend:i.data("timeend"),timeenrolled:i.data("timeenrolled")},l=[{key:"enroldetails",component:"enrol"}],m=h.next(j.EDIT_ENROLMENT);m.length&&(k.editenrollink=b("
").append(m.clone()).html());var n=c.get_strings(l),o=f.create({large:!0,type:f.types.CANCEL});b.when(n,o).done(function(c,d){var e=a.render("core_user/status_details",k);d.setTitle(c[0]),d.setBody(e),m.length&&d.getRoot().on("click",j.EDIT_ENROLMENT,function(a){a.preventDefault(),d.hide(),b(m).trigger("click")}),d.show(),d.getRoot().on(g.hidden,function(){d.destroy()})}).fail(e.exception)})},k.prototype.submitEditFormAjax=function(a){var c=this,d=a.getRoot().find("form"),f=b(d).find('[name="ue"]').val(),g=b(d).find('[name="status"]').val(),h={courseid:this.courseid,ueid:f,status:g},j=b(d).find('[name="timestart[enabled]"]');if(j.is(":checked")){var k=b(d).find('[name="timestart[year]"]').val(),l=b(d).find('[name="timestart[month]"]').val()-1,m=b(d).find('[name="timestart[day]"]').val(),n=b(d).find('[name="timestart[hour]"]').val(),o=b(d).find('[name="timestart[minute]"]').val(),p=new Date(k,l,m,n,o);h.timestart=p.getTime()/1e3}var q=b(d).find('[name="timeend[enabled]"]');if(q.is(":checked")){var r=b(d).find('[name="timeend[year]"]').val(),s=b(d).find('[name="timeend[month]"]').val()-1,t=b(d).find('[name="timeend[day]"]').val(),u=b(d).find('[name="timeend[hour]"]').val(),v=b(d).find('[name="timeend[minute]"]').val(),w=new Date(r,s,t,u,v);h.timeend=w.getTime()/1e3}var x=b(d).find('[name="duration"]');x.is(":enabled")&&(h.timeend=h.timestart+parseInt(x.val()));var y={methodname:"core_enrol_edit_user_enrolment",args:h};i.call([y])[0].done(function(b){if(b.result)a.hide(),"undefined"!=typeof window.M.core_formchangechecker&&window.M.core_formchangechecker.reset_form_dirty_state(),window.location.reload();else{var e=JSON.stringify(d.serialize());a.setBody(c.getBody(f,e))}}).fail(e.exception)},k.prototype.submitUnenrolFormAjax=function(a,b){var c={methodname:"core_enrol_unenrol_user_enrolment",args:b};i.call([c])[0].done(function(b){b.result?(a.hide(),"undefined"!=typeof window.M.core_formchangechecker&&window.M.core_formchangechecker.reset_form_dirty_state(),window.location.reload()):e.alert(b.errors[0].key,b.errors[0].message)}).fail(e.exception)},k.prototype.getBody=function(a,b){var c={ueid:a};return"undefined"!=typeof b&&(c.formdata=b),h.loadFragment("enrol","user_enrolment_form",this.contextid,c).fail(e.exception)},{init:function(a){new k(a)}}}); \ No newline at end of file diff --git a/user/amd/src/status_field.js b/user/amd/src/status_field.js index 865f33c977d..438941b690b 100644 --- a/user/amd/src/status_field.js +++ b/user/amd/src/status_field.js @@ -294,6 +294,12 @@ define(['core/templates', params.timeend = timeEnd.getTime() / 1000; } + // Enrol duration. + var enrolDuration = $(form).find('[name="duration"]'); + if (enrolDuration.is(':enabled')) { + params.timeend = params.timestart + parseInt(enrolDuration.val()); + } + var request = { methodname: 'core_enrol_edit_user_enrolment', args: params -- 2.11.4.GIT