-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
… MOODLE_403_DEV
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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); | ||
}; |
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); | ||
}); | ||
}); | ||
}; |
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); | ||
}); | ||
}; |