Proyectos de Subversion Moodle

Rev

Autoría | Ultima modificación | Ver Log |

{"version":3,"file":"recalculate.min.js","sources":["../src/recalculate.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Allows to recalculate a single value on demand\n *\n * @module     customfield_number/recalculate\n * @author     2024 Marina Glancy\n * @copyright  2024 Moodle Pty Ltd <support@moodle.com>\n * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport Ajax from 'core/ajax';\nimport Notification from 'core/notification';\nimport {addIconToContainer} from 'core/loadingicon';\nimport Pending from 'core/pending';\n\nconst SELECTORS = {\n    wrapper: '[data-fieldtype=\"wrapper\"]',\n    value: '[data-fieldtype=\"value\"]',\n    link: '[data-fieldtype=\"link\"]',\n};\n\nlet initialised = false;\n\n/**\n * Init\n */\nexport function init() {\n    if (initialised) {\n        return;\n    }\n\n    document.addEventListener('click', (e) => {\n        const target = e.target.closest(SELECTORS.wrapper + \" \" + SELECTORS.link);\n        if (!target) {\n            return;\n        }\n        const el = target.closest(SELECTORS.wrapper).querySelector(SELECTORS.value);\n        if (!el) {\n            return;\n        }\n        e.preventDefault();\n\n        const {fieldid, instanceid} = target.dataset;\n\n        const pendingPromise = new Pending('recalculate_customfield_number');\n        addIconToContainer(el).then(() => {\n            return Ajax.call([{\n                methodname: 'customfield_number_recalculate_value',\n                args: {fieldid, instanceid}\n            }])[0];\n        }).then((data) => {\n            el.innerHTML = data.value;\n            return pendingPromise.resolve();\n        }).catch(Notification.exception);\n    });\n\n    initialised = true;\n}\n"],"names":["initialised","document","addEventListener","e","target","closest","SELECTORS","el","querySelector","preventDefault","fieldid","instanceid","dataset","pendingPromise","Pending","then","Ajax","call","methodname","args","data","innerHTML","value","resolve","catch","Notification","exception"],"mappings":";;;;;;;;yFAyCQA,mBAIJC,SAASC,iBAAiB,SAAUC,UAC1BC,OAASD,EAAEC,OAAOC,QAAQC,kBAAoB,IAAMA,oBACrDF,oBAGCG,GAAKH,OAAOC,QAAQC,mBAAmBE,cAAcF,qBACtDC,UAGLJ,EAAEM,uBAEIC,QAACA,QAADC,WAAUA,YAAcP,OAAOQ,QAE/BC,eAAiB,IAAIC,iBAAQ,sEAChBP,IAAIQ,MAAK,IACjBC,cAAKC,KAAK,CAAC,CACdC,WAAY,uCACZC,KAAM,CAACT,QAAAA,QAASC,WAAAA,eAChB,KACLI,MAAMK,OACLb,GAAGc,UAAYD,KAAKE,MACbT,eAAeU,aACvBC,MAAMC,sBAAaC,cAG1B1B,aAAc,2IAzCZM,kBACO,6BADPA,gBAEK,2BAFLA,eAGI,8BAGNN,aAAc"}