Skip to content

Commit

Permalink
Merge branch 'master' of github.com:bostelm/moodle-mod_scheduler into…
Browse files Browse the repository at this point in the history
… MOODLE_403_DEV
  • Loading branch information
JohnOLane committed Jul 26, 2024
2 parents 69cfaac + 858153b commit 3d5c562
Show file tree
Hide file tree
Showing 36 changed files with 209 additions and 525 deletions.
11 changes: 11 additions & 0 deletions amd/build/delselected.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions amd/build/delselected.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions amd/build/saveseen.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions amd/build/saveseen.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions amd/build/studentlist.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions amd/build/studentlist.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 62 additions & 0 deletions amd/src/delselected.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* TODO describe module delselected
*
* @module mod_scheduler/delselected
* @copyright 2024 ISB Bayern
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

/**
* Selectors used by the module.
*/
export const SELECTORS = {
DELACTION: 'div.commandbar a#delselected',
SELECTBOX: 'table#slotmanager input.slotselect',
};

/**
* Add event listener to the delete link.
* @param {*} baseurl
*/
export const init = (baseurl) => {
let link = document.querySelector(SELECTORS.DELACTION);
if (link !== null) {
link.addEventListener('click', function() {
collect_selection(link, baseurl);
});
}
};

/**
* Copy the selected boxes into an input parameter of the respective form
*
* @param {String} link
* @param {String} baseurl
*/
export const collect_selection = (link, baseurl) => {
let sellist = '';
document.querySelectorAll(SELECTORS.SELECTBOX).forEach(function(box) {
if (box.checked) {
if (sellist.length > 0) {
sellist += ',';
}
sellist += box.getAttribute('value');
}
});
link.setAttribute('href', baseurl + '&items=' + sellist);
};
70 changes: 70 additions & 0 deletions amd/src/saveseen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@

export const SELECTORS = {CHECKBOXES: 'table#slotmanager form.studentselectform input.studentselect'};
export const MOD = {};

/**
* Save the "seen" status.
*
* @param {Number} cmid the coursemodule id
* @param {Number} appid the id of the relevant appointment
* @param {Boolean} newseen
* @param {Object} spinner The spinner icon shown while saving
*/
export const save_status = (cmid, appid, newseen, spinner, ) => {
const url = M.cfg.wwwroot + '/mod/scheduler/ajax.php';
// The request paramaters.
const params = 'action=saveseen&id='+cmid+'&appointmentid='+appid+'&seen='+newseen+'&sesskey='+M.cfg.sesskey;
const xhr = new XMLHttpRequest();

// 5 seconds of timeout.
xhr.timeout = 5000;

xhr.onloadstart = () => {
spinner.style.visibility = 'visible';
};

xhr.onload = () => {
if (xhr.status >= 200 && xhr.status < 300) {
setTimeout(() => {
spinner.style.visibility = 'hidden';
const parent = spinner.parentNode;
parent.removeChild(spinner);

}, 250);
} else {
const msg = {
name: xhr.status + ' ' + xhr.statusText,
message: xhr.responseText
};
spinner.style.visibility = 'hidden';
const parent = spinner.parentNode;
parent.removeChild(spinner);
throw new Error(JSON.stringify(msg));
}
};

xhr.onerror = () => {
spinner.style.visibility = 'hidden';
const parent = spinner.parentNode;
parent.removeChild(spinner);
throw new Error('Network request failed');
};

xhr.open('POST', url, true);
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xhr.send(params);
};

export const init = (cmid) => {
document.querySelectorAll(SELECTORS.CHECKBOXES).forEach(function(box) {
box.addEventListener('change', function() {
var div = document.createElement('div');
var span = document.createElement('span');
div.classList.add('spinner-border', 'spinner-border-sm');
span.classList.add('sr-only');
div.appendChild(span);
box.closest('div').appendChild(div);
save_status(cmid, box.value, box.checked, div);
});
});
};
32 changes: 32 additions & 0 deletions amd/src/studentlist.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

export const CSS = {
EXPANDED: 'expanded',
COLLAPSED: 'collapsed'
};

export const setState = (id, expanded) => {
var image = document.getElementById(id);
var content = document.getElementById('list' + id);
if (expanded) {
content.removeClass(CSS.COLLAPSED);
content.addClass(CSS.EXPANDED);
image.set('src', M.util.image_url('t/expanded'));
} else {
content.removeClass(CSS.EXPANDED);
content.addClass(CSS.COLLAPSED);
image.set('src', M.util.image_url('t/collapsed'));
}
};

export const toggleState = (id) => {
var content = document.getElementById('list' + id);
var isVisible = content.hasClass(CSS.EXPANDED);
setState(id, !isVisible);
};

export const init = (imageid, expanded) => {
setState(imageid, expanded);
document.getElementById(imageid).addEventListener('click', () => {
toggleState(imageid);
});
};
2 changes: 1 addition & 1 deletion classes/model/appointment.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function is_attended() {
* @return boolean
*/
public function has_studentnotes() {
return $this->get_scheduler()->uses_studentnotes() &&
return $this->get_scheduler()->uses_studentnotes() && !empty($this->studentnote) &&
strlen(trim(strip_tags($this->studentnote))) > 0;
}

Expand Down
5 changes: 3 additions & 2 deletions classes/model/slot.php
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,9 @@ private function update_calendar() {
$courseid = $scheduler->get_courseid();

$baseevent = new \stdClass();
$baseevent->description = "$schedulername<br/><br/>$schedulerdescription";
$baseevent->format = 1;
$baseevent->description = "$schedulername<br/><br/>"
.format_module_intro('scheduler', $scheduler, $scheduler->get_cmid(), false);
$baseevent->format = FORMAT_HTML;
$baseevent->modulename = 'scheduler';
$baseevent->courseid = 0;
$baseevent->instance = $this->get_parent_id();
Expand Down
3 changes: 2 additions & 1 deletion exportlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,8 @@ public function get_header(scheduler $scheduler) {
* @return string the value of this field for the given data
*/
public function get_value(slot $slot, $appointment) {
if (!$appointment instanceof appointment || $appointment->studentid == 0) {
if (!$appointment instanceof appointment || $appointment->studentid == 0
|| !context_user::instance($appointment->studentid, IGNORE_MISSING)) {
return '';
}
$this->field->set_userid($appointment->studentid);
Expand Down
2 changes: 1 addition & 1 deletion mod_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ public function save_mod_data(stdClass $data, context_module $context) {
global $DB;

$editor = $data->bookinginstructions_editor;
if ($editor) {
if ($editor && array_key_exists('text', $editor)) {
$data->bookinginstructions = file_save_draft_area_files($editor['itemid'], $context->id,
'mod_scheduler', 'bookinginstructions', 0,
$this->editoroptions, $editor['text']);
Expand Down
Loading

0 comments on commit 3d5c562

Please sign in to comment.