{"version":3,"sources":["https:\/\/virtual.arte.unicen.edu.ar\/lib\/amd\/src\/notification.js"],"names":["define","Y","$","log","notificationModule","types","fieldName","fetchNotifications","require","ajax","promises","call","methodname","args","contextid","done","addNotifications","notifications","each","i","notification","renderNotification","template","variables","setupTargetRegion","targetRegion","length","newRegion","attr","prepend","addNotification","error","extend","closebutton","announce","type","message","debug","templates","render","html","js","runTemplateJS","fail","exception","alert","title","yesLabel","use","M","core","show","confirm","question","noLabel","yesCallback","noCallback","modal","on","ex","stack","debuginfo","backtrace","stacktrace","ln","match","fn","lineNumber","fileName","substr","name","errorcode","init"],"mappings":"AA4BAA,OAAM,qBAAC,CAAC,UAAD,CAAa,QAAb,CAAuB,UAAvB,CAAD,CACN,SAASC,CAAT,CAAYC,CAAZ,CAAeC,CAAf,CAAoB,CAChB,GAAIC,CAAAA,CAAkB,CAAG,CACrBC,KAAK,CAAE,CACH,QAAY,2BADT,CAEH,KAAY,wBAFT,CAGH,QAAY,2BAHT,CAIH,MAAY,yBAJT,CADc,CAQrBC,SAAS,CAAE,oBARU,CAUrBC,kBAAkB,CAAE,6BAAW,CAC3BC,OAAO,CAAC,CAAC,WAAD,CAAD,CAAgB,SAASC,CAAT,CAAe,CAClC,GAAIC,CAAAA,CAAQ,CAAGD,CAAI,CAACE,IAAL,CAAU,CAAC,CACtBC,UAAU,CAAE,0BADU,CAEtBC,IAAI,CAAE,CACFC,SAAS,CAAEV,CAAkB,CAACU,SAD5B,CAFgB,CAAD,CAAV,CAAf,CAOAJ,CAAQ,CAAC,CAAD,CAAR,CACKK,IADL,CACUX,CAAkB,CAACY,gBAD7B,CAGH,CAXM,CAYV,CAvBoB,CAyBrBA,gBAAgB,CAAE,0BAASC,CAAT,CAAwB,CACtC,GAAI,CAACA,CAAL,CAAoB,CAChBA,CAAa,CAAG,EACnB,CAEDf,CAAC,CAACgB,IAAF,CAAOD,CAAP,CAAsB,SAASE,CAAT,CAAYC,CAAZ,CAA0B,CAC5ChB,CAAkB,CAAC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,CAACwC,SAhEW,CAkEhD,CA7OK,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 * A system for displaying notifications to users from the session.\n *\n * Wrapper for the YUI M.core.notification class. Allows us to\n * use the YUI version in AMD code until it is replaced.\n *\n * @module core\/notification\n * @class notification\n * @package core\n * @copyright 2015 Damyon Wiese \n * @license http:\/\/www.gnu.org\/copyleft\/gpl.html GNU GPL v3 or later\n * @since 2.9\n *\/\ndefine(['core\/yui', 'jquery', 'core\/log'],\nfunction(Y, $, log) {\n var notificationModule = {\n types: {\n 'success': 'core\/notification_success',\n 'info': 'core\/notification_info',\n 'warning': 'core\/notification_warning',\n 'error': 'core\/notification_error',\n },\n\n fieldName: 'user-notifications',\n\n fetchNotifications: function() {\n require(['core\/ajax'], function(ajax) {\n var promises = ajax.call([{\n methodname: 'core_fetch_notifications',\n args: {\n contextid: notificationModule.contextid\n }\n }]);\n\n promises[0]\n .done(notificationModule.addNotifications)\n ;\n });\n },\n\n addNotifications: function(notifications) {\n if (!notifications) {\n notifications = [];\n }\n\n $.each(notifications, function(i, notification) {\n notificationModule.renderNotification(notification.template, notification.variables);\n });\n },\n\n setupTargetRegion: function() {\n var targetRegion = $('#' + notificationModule.fieldName);\n if (targetRegion.length) {\n return false;\n }\n\n var newRegion = $('').attr('id', notificationModule.fieldName);\n\n targetRegion = $('#region-main');\n if (targetRegion.length) {\n return targetRegion.prepend(newRegion);\n }\n\n targetRegion = $('[role=\"main\"]');\n if (targetRegion.length) {\n return targetRegion.prepend(newRegion);\n }\n\n targetRegion = $('body');\n return targetRegion.prepend(newRegion);\n },\n\n addNotification: function(notification) {\n var template = notificationModule.types.error;\n\n notification = $.extend({\n closebutton: true,\n announce: true,\n type: 'error'\n }, notification);\n\n if (notification.template) {\n template = notification.template;\n delete notification.template;\n } else if (notification.type) {\n if (typeof notificationModule.types[notification.type] !== 'undefined') {\n template = notificationModule.types[notification.type];\n }\n delete notification.type;\n }\n\n return notificationModule.renderNotification(template, notification);\n },\n\n renderNotification: function(template, variables) {\n if (typeof variables.message === 'undefined' || !variables.message) {\n log.debug('Notification received without content. Skipping.');\n return;\n }\n require(['core\/templates'], function(templates) {\n templates.render(template, variables)\n .done(function(html, js) {\n $('#' + notificationModule.fieldName).prepend(html);\n templates.runTemplateJS(js);\n })\n .fail(notificationModule.exception)\n ;\n });\n },\n\n alert: function(title, message, yesLabel) {\n \/\/ Here we are wrapping YUI. This allows us to start transitioning, but\n \/\/ wait for a good alternative without having inconsistent dialogues.\n Y.use('moodle-core-notification-alert', function() {\n var alert = new M.core.alert({\n title: title,\n message: message,\n yesLabel: yesLabel\n });\n\n alert.show();\n });\n },\n\n confirm: function(title, question, yesLabel, noLabel, yesCallback, noCallback) {\n \/\/ Here we are wrapping YUI. This allows us to start transitioning, but\n \/\/ wait for a good alternative without having inconsistent dialogues.\n Y.use('moodle-core-notification-confirm', function() {\n var modal = new M.core.confirm({\n title: title,\n question: question,\n yesLabel: yesLabel,\n noLabel: noLabel\n });\n\n modal.on('complete-yes', function() {\n yesCallback();\n });\n if (noCallback) {\n modal.on('complete-no', function() {\n noCallback();\n });\n }\n modal.show();\n });\n },\n\n exception: function(ex) {\n \/\/ Fudge some parameters.\n if (typeof ex.stack == 'undefined') {\n ex.stack = '';\n }\n if (ex.debuginfo) {\n ex.stack += ex.debuginfo + '\\n';\n }\n if (!ex.backtrace && ex.stacktrace) {\n ex.backtrace = ex.stacktrace;\n }\n if (ex.backtrace) {\n ex.stack += ex.backtrace;\n var ln = ex.backtrace.match(\/line ([^ ]*) of\/);\n var fn = ex.backtrace.match(\/ of ([^:]*): \/);\n if (ln && ln[1]) {\n ex.lineNumber = ln[1];\n }\n if (fn && fn[1]) {\n ex.fileName = fn[1];\n if (ex.fileName.length > 30) {\n ex.fileName = '...' + ex.fileName.substr(ex.fileName.length - 27);\n }\n }\n }\n if (typeof ex.name == 'undefined' && ex.errorcode) {\n ex.name = ex.errorcode;\n }\n\n Y.use('moodle-core-notification-exception', function() {\n var modal = new M.core.exception(ex);\n\n modal.show();\n });\n }\n };\n\n return \/** @alias module:core\/notification *\/{\n init: function(contextid, notifications) {\n notificationModule.contextid = contextid;\n\n \/\/ Setup the message target region if it isn't setup already\n notificationModule.setupTargetRegion();\n\n \/\/ Add provided notifications.\n notificationModule.addNotifications(notifications);\n\n \/\/ Poll for any new notifications.\n notificationModule.fetchNotifications();\n },\n\n \/**\n * Poll the server for any new notifications.\n *\n * @method fetchNotifications\n *\/\n fetchNotifications: notificationModule.fetchNotifications,\n\n \/**\n * Add a notification to the page.\n *\n * Note: This does not cause the notification to be added to the session.\n *\n * @method addNotification\n * @param {Object} notification The notification to add.\n * @param {string} notification.message The body of the notification\n * @param {string} notification.type The type of notification to add (error, warning, info, success).\n * @param {Boolean} notification.closebutton Whether to show the close button.\n * @param {Boolean} notification.announce Whether to announce to screen readers.\n *\/\n addNotification: notificationModule.addNotification,\n\n \/**\n * Wrap M.core.alert.\n *\n * @method alert\n * @param {string} title\n * @param {string} message\n * @param {string} yesLabel\n *\/\n alert: notificationModule.alert,\n\n \/**\n * Wrap M.core.confirm.\n *\n * @method confirm\n * @param {string} title\n * @param {string} question\n * @param {string} yesLabel\n * @param {string} noLabel\n * @param {function} yesCallback\n * @param {function} noCallback Optional parameter to be called if the user presses cancel.\n *\/\n confirm: notificationModule.confirm,\n\n \/**\n * Wrap M.core.exception.\n *\n * @method exception\n * @param {Error} ex\n *\/\n exception: notificationModule.exception\n };\n});\n"],"file":"notification.min.js"}