MDL-69166 core_payment: display the gateways modal
[moodle.git] / payment / amd / build / gateways_modal.min.js.map
1 {"version":3,"sources":["../src/gateways_modal.js"],"names":["registerEventListeners","nodeSelector","rootNode","document","querySelector","addEventListener","e","preventDefault","show","focusOnClose","target","Templates","render","done","content","ModalFactory","create","title","body","modal","currency","dataset","gateways","context","gateway","push","html","js","replaceNodeContents","getRoot","find","Selectors","regions","gatewaysContainer","on","ModalEvents","hidden","destroy","focus"],"mappings":"wjBAwBA,OACA,OAGA,OACA,O,wmDAOsC,QAAzBA,CAAAA,sBAAyB,CAACC,CAAD,CAAkB,CACpD,GAAMC,CAAAA,CAAQ,CAAGC,QAAQ,CAACC,aAAT,CAAuBH,CAAvB,CAAjB,CAEAC,CAAQ,CAACG,gBAAT,CAA0B,OAA1B,CAAmC,SAACC,CAAD,CAAO,CACtCA,CAAC,CAACC,cAAF,GACAC,CAAI,CAACN,CAAD,CAAW,CAACO,YAAY,CAAEH,CAAC,CAACI,MAAjB,CAAX,CACP,CAHD,CAIH,C,CASD,GAAMF,CAAAA,CAAI,CAAG,SAACN,CAAD,CAEF,8DAAP,EAAO,KADPO,YACO,CADPA,CACO,YADQ,IACR,GACPE,UAAUC,MAAV,CAAiB,6BAAjB,CAAgD,EAAhD,EACKC,IADL,CACU,SAAAC,CAAO,CAAI,CACbC,UAAaC,MAAb,CAAoB,CAChBC,KAAK,CAAE,iBAAU,mBAAV,CAA+B,cAA/B,CADS,CAEhBC,IAAI,CAAEJ,CAFU,CAApB,EAICD,IAJD,CAIM,SAASM,CAAT,CAAgB,CAClB,GAAMC,CAAAA,CAAQ,CAAGlB,CAAQ,CAACmB,OAAT,CAAiBD,QAAlC,CACA,oCAA8BA,CAA9B,EACKP,IADL,CACU,SAAAS,CAAQ,CAAI,IACRC,CAAAA,CAAO,CAAG,CACZD,QAAQ,CAAE,EADE,CADF,KAKMA,CALN,QAKd,2BAA8B,IAArBE,CAAAA,CAAqB,SAC1BD,CAAO,CAACD,QAAR,CAAiBG,IAAjB,CAAsBD,CAAtB,CACH,CAPa,+BASdb,UAAUC,MAAV,CAAiB,uBAAjB,CAA0CW,CAA1C,EACKV,IADL,CACU,SAACa,CAAD,CAAOC,CAAP,CAAc,CAChBhB,UAAUiB,mBAAV,CAA8BT,CAAK,CAACU,OAAN,GAAgBC,IAAhB,CAAqBC,UAAUC,OAAV,CAAkBC,iBAAvC,CAA9B,CACIP,CADJ,CACUC,CADV,CAEH,CAJL,CAKH,CAfL,EAiBAR,CAAK,CAACU,OAAN,GAAgBK,EAAhB,CAAmBC,CAAW,CAACC,MAA/B,CAAuC,UAAW,CAE9CjB,CAAK,CAACkB,OAAN,GACA,GAAI,CACA5B,CAAY,CAAC6B,KAAb,EACH,CAAC,MAAOhC,CAAP,CAAU,CAEX,CACJ,CARD,EAUAa,CAAK,CAACX,IAAN,EACH,CAlCD,CAmCH,CArCL,CAsCH,C","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 * Contain the logic for the gateways modal.\n *\n * @module     core_payment/gateways_modal\n * @package    core_payment\n * @copyright  2019 Shamim Rezaie <shamim@moodle.com>\n * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport ModalFactory from 'core/modal_factory';\nimport Templates from 'core/templates';\nimport {get_string as getString} from 'core/str';\nimport {getGatewaysSupportingCurrency} from 'core_payment/repository';\nimport Selectors from './selectors';\nimport * as ModalEvents from 'core/modal_events';\n\n/**\n * Register event listeners for the module.\n *\n * @param {string} nodeSelector The root to listen to.\n */\nexport const registerEventListeners = (nodeSelector) => {\n    const rootNode = document.querySelector(nodeSelector);\n\n    rootNode.addEventListener('click', (e) => {\n        e.preventDefault();\n        show(rootNode, {focusOnClose: e.target});\n    });\n};\n\n/**\n * Shows the gateway selector modal.\n *\n * @param {HTMLElement} rootNode\n * @param {Object} options - Additional options\n * @param {HTMLElement} options.focusOnClose The element to focus on when the modal is closed.\n */\nconst show = (rootNode, {\n    focusOnClose = null,\n} = {}) => {\n    Templates.render('core_payment/gateways_modal', {})\n        .done(content => {\n            ModalFactory.create({\n                title: getString('selectpaymenttype', 'core_payment'),\n                body: content,\n            })\n            .done(function(modal) {\n                const currency = rootNode.dataset.currency;\n                getGatewaysSupportingCurrency(currency)\n                    .done(gateways => {\n                        const context = {\n                            gateways: []\n                        };\n\n                        for (let gateway of gateways) {\n                            context.gateways.push(gateway);\n                        }\n\n                        Templates.render('core_payment/gateways', context)\n                            .done((html, js) => {\n                                Templates.replaceNodeContents(modal.getRoot().find(Selectors.regions.gatewaysContainer),\n                                    html, js);\n                            });\n                    });\n\n                modal.getRoot().on(ModalEvents.hidden, function() {\n                    // Destroy when hidden.\n                    modal.destroy();\n                    try {\n                        focusOnClose.focus();\n                    } catch (e) {\n                        // eslint-disable-line\n                    }\n                });\n\n                modal.show();\n            });\n        });\n};\n"],"file":"gateways_modal.min.js"}