{"version":3,"sources":["https:\/\/virtual.arte.unicen.edu.ar\/lib\/amd\/src\/modal_factory.js"],"names":["define","$","ModalEvents","ModalRegistry","Modal","ModalSaveCancel","ModalCancel","Templates","Notification","CustomEvents","TEMPLATES","DEFAULT","SAVE_CANCEL","CANCEL","TYPES","register","setUpTrigger","modalPromise","triggerElement","modalConfig","actualTriggerElement","hasPreShowCallback","preShowCallback","triggeredCallback","e","data","currentTarget","then","modal","show","originalEvent","preventDefault","Array","isArray","selector","events","activate","on","getRoot","hidden","focus","createFromElement","registryConf","modalElement","module","createFromType","templateContext","templateName","template","render","html","fail","exception","create","type","isLarge","large","get","message","title","setTitle","body","setBody","footer","setFooter","setLarge","types"],"mappings":"AAwBAA,OAAM,sBAAC,CAAC,QAAD,CAAW,mBAAX,CAAgC,qBAAhC,CAAuD,YAAvD,CACC,wBADD,CAC2B,mBAD3B,CAEC,gBAFD,CAEmB,mBAFnB,CAEwC,gCAFxC,CAAD,CAGF,SAASC,CAAT,CAAYC,CAAZ,CAAyBC,CAAzB,CAAwCC,CAAxC,CAA+CC,CAA\/C,CACIC,CADJ,CACiBC,CADjB,CAC4BC,CAD5B,CAC0CC,CAD1C,CACwD,IAGpDC,CAAAA,CAAS,CAAG,CACZC,OAAO,CAAE,YADG,CAEZC,WAAW,CAAE,wBAFD,CAGZC,MAAM,CAAE,mBAHI,CAHwC,CAUpDC,CAAK,CAAG,CACRH,OAAO,CAAE,SADD,CAERC,WAAW,CAAE,aAFL,CAGRC,MAAM,CAAE,QAHA,CAV4C,CAiBxDV,CAAa,CAACY,QAAd,CAAuBD,CAAK,CAACH,OAA7B,CAAsCP,CAAtC,CAA6CM,CAAS,CAACC,OAAvD,EACAR,CAAa,CAACY,QAAd,CAAuBD,CAAK,CAACF,WAA7B,CAA0CP,CAA1C,CAA2DK,CAAS,CAACE,WAArE,EACAT,CAAa,CAACY,QAAd,CAAuBD,CAAK,CAACD,MAA7B,CAAqCP,CAArC,CAAkDI,CAAS,CAACG,MAA5D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AAmB,CACflC,CAAY,CAAC4C,SAAb,CAAuB,CAACM,OAAO,CAAE,iCAAmCJ,CAA7C,CAAvB,CACH,CAED,GAA0C,WAAtC,QAAOnC,CAAAA,CAAW,CAAC2B,eAAvB,CAAuD,CACnDA,CAAe,CAAG3B,CAAW,CAAC2B,eACjC,CAED,GAAI7B,CAAAA,CAAY,CAAG4B,CAAc,CAACH,CAAD,CAAeI,CAAf,CAAd,CACdnB,IADc,CACT,SAASC,CAAT,CAAgB,CAClB,GAAgC,WAA5B,QAAOT,CAAAA,CAAW,CAACwC,KAAvB,CAA6C,CACzC\/B,CAAK,CAACgC,QAAN,CAAezC,CAAW,CAACwC,KAA3B,CACH,CAED,GAA+B,WAA3B,QAAOxC,CAAAA,CAAW,CAAC0C,IAAvB,CAA4C,CACxCjC,CAAK,CAACkC,OAAN,CAAc3C,CAAW,CAAC0C,IAA1B,CACH,CAED,GAAiC,WAA7B,QAAO1C,CAAAA,CAAW,CAAC4C,MAAvB,CAA8C,CAC1CnC,CAAK,CAACoC,SAAN,CAAgB7C,CAAW,CAAC4C,MAA5B,CACH,CAED,GAAIR,CAAJ,CAAa,CACT3B,CAAK,CAACqC,QAAN,EACH,CAED,MAAOrC,CAAAA,CACV,CAnBc,CAAnB,CAqBA,GAA6B,WAAzB,QAAOV,CAAAA,CAAX,CAA0C,CACtCF,CAAY,CAACC,CAAD,CAAeC,CAAf,CAA+BC,CAA\/B,CACf,CAED,MAAOF,CAAAA,CACV,CAEM,CAEHiD,KAAK,CAAEpD,CAFJ,CAIV,CAlLK,CAAN","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 .\n\n\/**\n * Create a modal.\n *\n * @module core\/modal_factory\n * @class modal_factory\n * @package core\n * @copyright 2016 Ryan Wyllie \n * @license http:\/\/www.gnu.org\/copyleft\/gpl.html GNU GPL v3 or later\n *\/\ndefine(['jquery', 'core\/modal_events', 'core\/modal_registry', 'core\/modal',\n 'core\/modal_save_cancel', 'core\/modal_cancel',\n 'core\/templates', 'core\/notification', 'core\/custom_interaction_events'],\n function($, ModalEvents, ModalRegistry, Modal, ModalSaveCancel,\n ModalCancel, Templates, Notification, CustomEvents) {\n\n \/\/ The templates for each type of modal.\n var TEMPLATES = {\n DEFAULT: 'core\/modal',\n SAVE_CANCEL: 'core\/modal_save_cancel',\n CANCEL: 'core\/modal_cancel',\n };\n\n \/\/ The available types of modals.\n var TYPES = {\n DEFAULT: 'DEFAULT',\n SAVE_CANCEL: 'SAVE_CANCEL',\n CANCEL: 'CANCEL',\n };\n\n \/\/ Register the common set of modals.\n ModalRegistry.register(TYPES.DEFAULT, Modal, TEMPLATES.DEFAULT);\n ModalRegistry.register(TYPES.SAVE_CANCEL, ModalSaveCancel, TEMPLATES.SAVE_CANCEL);\n ModalRegistry.register(TYPES.CANCEL, ModalCancel, TEMPLATES.CANCEL);\n\n \/**\n * Set up the events required to show the modal and return focus when the modal\n * is closed.\n *\n * @method setUpTrigger\n * @param {Promise} modalPromise The modal instance\n * @param {object} triggerElement The jQuery element to open the modal\n * @param {object} modalConfig The modal configuration given to the factory\n *\/\n var setUpTrigger = function(modalPromise, triggerElement, modalConfig) {\n \/\/ The element that actually shows the modal.\n var actualTriggerElement = null;\n \/\/ Check if the client has provided a callback function to be called\n \/\/ before the modal is displayed.\n var hasPreShowCallback = (typeof modalConfig.preShowCallback == 'function');\n \/\/ Function to handle the trigger element being activated.\n var triggeredCallback = function(e, data) {\n actualTriggerElement = $(e.currentTarget);\n modalPromise.then(function(modal) {\n if (hasPreShowCallback) {\n \/\/ If the client provided a pre-show callback then execute\n \/\/ it now before showing the modal.\n modalConfig.preShowCallback(actualTriggerElement, modal);\n }\n\n modal.show();\n\n return modal;\n });\n data.originalEvent.preventDefault();\n };\n\n \/\/ The trigger element can either be a single element or it can be an\n \/\/ element + selector pair to create a delegated event handler to trigger\n \/\/ the modal.\n if (Array.isArray(triggerElement)) {\n var selector = triggerElement[1];\n triggerElement = triggerElement[0];\n\n CustomEvents.define(triggerElement, [CustomEvents.events.activate]);\n triggerElement.on(CustomEvents.events.activate, selector, triggeredCallback);\n } else {\n CustomEvents.define(triggerElement, [CustomEvents.events.activate]);\n triggerElement.on(CustomEvents.events.activate, triggeredCallback);\n }\n\n modalPromise.then(function(modal) {\n modal.getRoot().on(ModalEvents.hidden, function() {\n \/\/ Focus on the trigger element that actually launched the modal.\n if (actualTriggerElement !== null) {\n actualTriggerElement.focus();\n }\n });\n\n return modal;\n });\n };\n\n \/**\n * Create the correct instance of a modal based on the givem type. Sets up\n * the trigger between the modal and the trigger element.\n *\n * @method createFromElement\n * @param {object} registryConf A config from the ModalRegistry\n * @param {object} modalElement The modal HTML jQuery object\n * @return {object} Modal instance\n *\/\n var createFromElement = function(registryConf, modalElement) {\n modalElement = $(modalElement);\n var module = registryConf.module;\n var modal = new module(modalElement);\n\n return modal;\n };\n\n \/**\n * Create the correct modal instance for the given type, including loading\n * the correct template.\n *\n * @method createFromType\n * @param {object} registryConf A config from the ModalRegistry\n * @param {object} templateContext The context to render the template with\n * @return {promise} Resolved with a Modal instance\n *\/\n var createFromType = function(registryConf, templateContext) {\n var templateName = registryConf.template;\n\n var modalPromise = Templates.render(templateName, templateContext)\n .then(function(html) {\n var modalElement = $(html);\n return createFromElement(registryConf, modalElement);\n })\n .fail(Notification.exception);\n\n return modalPromise;\n };\n\n \/**\n * Create a Modal instance.\n *\n * @method create\n * @param {object} modalConfig The configuration to create the modal instance\n * @param {object} triggerElement The trigger HTML jQuery object\n * @return {promise} Resolved with a Modal instance\n *\/\n var create = function(modalConfig, triggerElement) {\n var type = modalConfig.type || TYPES.DEFAULT;\n var isLarge = modalConfig.large ? true : false;\n var registryConf = null;\n var templateContext = {};\n\n registryConf = ModalRegistry.get(type);\n\n if (!registryConf) {\n Notification.exception({message: 'Unable to find modal of type: ' + type});\n }\n\n if (typeof modalConfig.templateContext != 'undefined') {\n templateContext = modalConfig.templateContext;\n }\n\n var modalPromise = createFromType(registryConf, templateContext)\n .then(function(modal) {\n if (typeof modalConfig.title != 'undefined') {\n modal.setTitle(modalConfig.title);\n }\n\n if (typeof modalConfig.body != 'undefined') {\n modal.setBody(modalConfig.body);\n }\n\n if (typeof modalConfig.footer != 'undefined') {\n modal.setFooter(modalConfig.footer);\n }\n\n if (isLarge) {\n modal.setLarge();\n }\n\n return modal;\n });\n\n if (typeof triggerElement != 'undefined') {\n setUpTrigger(modalPromise, triggerElement, modalConfig);\n }\n\n return modalPromise;\n };\n\n return {\n create: create,\n types: TYPES,\n };\n});\n"],"file":"modal_factory.min.js"}