This repository has been archived on 2025-01-01. You can view files and clone it, but cannot push or open issues or pull requests.
moodle-local_treestudyplan/amd/src/page-invitemanager.js
2023-12-13 23:49:06 +01:00

65 lines
2.2 KiB
JavaScript

/*eslint no-var: "error" */
/*eslint no-unused-vars: "off" */
/*eslint linebreak-style: "off" */
/*eslint-env es6*/
// Put this file in path/to/plugin/amd/src
// You can call it anything you like
import Debugger from './util/debugger';
import {get_strings} from 'core/str';
import {getStrings} from 'core/str';
import ModalFactory from 'core/modal_factory';
import ModalEvents from 'core/modal_events';
/* Determine the proper getstrings function to use (MDL4.3+ recommends use of getStrings, which is jquery independent) */
const getstr_func = (getStrings !== undefined)?getStrings:get_strings;
let debug = new Debugger("treestudyplan");
/**
* Init function for page-invitemanager
* @return undefined
*/
export function init() {
getstr_func([
{ key: 'ok', component: 'core'},
{ key: 'confirm', component: 'core'},
]).then((s) => {
const strOk = s[0];
const strConfirm = s[1];
const els = document.querySelectorAll('.path-local-treestudyplan a.m-action-confirm');
els.forEach((el) => {
el.addEventListener('click', (e) => {
e.preventDefault();
const link = e.currentTarget;
let href = link.getAttribute('data-actionhref');
let text = link.getAttribute('data-confirmtext');
let oktext = link.getAttribute('data-confirmbtn');
if (undefined == oktext) {
oktext = strOk;
}
let title = link.getAttribute('data-confirmtitle');
if (undefined == title) {
title = strConfirm;
}
ModalFactory.create({
type: ModalFactory.types.SAVE_CANCEL,
title: title,
body: text,
}).then(function (modal) {
modal.setSaveButtonText(oktext);
let root = modal.getRoot();
root.on(ModalEvents.save, function () {
window.location = href;
});
modal.modal[0].style["max-width"] = "345px";
modal.show();
return modal;
});
});
});
});
}