{"version":3,"sources":["https:\/\/vlm2.ub.ac.id\/lib\/amd\/src\/notification.js"],"names":["define","Y","$","log","Pending","notificationModule","types","fieldName","fetchNotifications","pendingPromise","require","ajax","promises","call","methodname","args","contextid","then","addNotifications","always","resolve","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","catch","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,CAAmC,cAAnC,CAAD,CACN,SAASC,CAAT,CAAYC,CAAZ,CAAeC,CAAf,CAAoBC,CAApB,CAA6B,CACzB,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,CAC3B,GAAIC,CAAAA,CAAc,CAAG,GAAIL,CAAAA,CAAJ,CAAY,sCAAZ,CAArB,CAEAM,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,CAAEX,CAAkB,CAACW,SAD5B,CAFgB,CAAD,CAAV,CAAf,CASAJ,CAAQ,CAAC,CAAD,CAAR,CACCK,IADD,CACMZ,CAAkB,CAACa,gBADzB,EAECC,MAFD,CAEQV,CAAc,CAACW,OAFvB,CAGH,CAbM,CAcV,CA3BoB,CA6BrBF,gBAAgB,CAAE,0BAASG,CAAT,CAAwB,C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CAAE,CAACY,SAAxC,CAAmD,CAC\/CZ,CAAE,CAACW,IAAH,CAAUX,CAAE,CAACY,SAChB,CAED1E,CAAC,CAACmD,GAAF,CAAM,oCAAN,CAA4C,UAAW,CACnD,GAAIS,CAAAA,CAAK,CAAG,GAAIR,CAAAA,CAAC,CAACC,IAAF,CAAON,SAAX,CAAqBe,CAArB,CAAZ,CAEAF,CAAK,CAACN,IAAN,GAEA9C,CAAc,CAACW,OAAf,EACH,CAND,CAOH,CAnMoB,CAAzB,CAsMA,MAA6C,CACzCwD,IAAI,CAAE,cAAS5D,CAAT,CAAoBK,CAApB,CAAmC,CACrChB,CAAkB,CAACW,SAAnB,CAA+BA,CAA\/B,CAGAX,CAAkB,CAACuB,iBAAnB,GAGAvB,CAAkB,CAACa,gBAAnB,CAAoCG,CAApC,EAGAhB,CAAkB,CAACG,kBAAnB,EACH,CAZwC,CAmBzCA,kBAAkB,CAAEH,CAAkB,CAACG,kBAnBE,CAiCzC0B,eAAe,CAAE7B,CAAkB,CAAC6B,eAjCK,CA2CzCe,KAAK,CAAE5C,CAAkB,CAAC4C,KA3Ce,CAwDzCO,OAAO,CAAEnD,CAAkB,CAACmD,OAxDa,CAgEzCR,SAAS,CAAE3C,CAAkB,CAAC2C,SAhEW,CAkEhD,CA1QK,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', 'core\/pending'],\nfunction(Y, $, log, Pending) {\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 var pendingPromise = new Pending('core\/notification:fetchNotifications');\n\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 \/\/ This currently fails when not logged in.\n \/\/ eslint-disable-next-line promise\/catch-or-return\n promises[0]\n .then(notificationModule.addNotifications)\n .always(pendingPromise.resolve);\n });\n },\n\n addNotifications: function(notifications) {\n var pendingPromise = new Pending('core\/notification:addNotifications');\n\n if (!notifications) {\n notifications = [];\n }\n\n $.each(notifications, function(i, notification) {\n notificationModule.renderNotification(notification.template, notification.variables);\n });\n\n pendingPromise.resolve();\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 pendingPromise = new Pending('core\/notification:addNotifications');\n\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 pendingPromise.resolve();\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\n var pendingPromise = new Pending('core\/notification:renderNotification');\n\n require(['core\/templates'], function(templates) {\n templates.render(template, variables)\n .then(function(html, js) {\n $('#' + notificationModule.fieldName).prepend(html);\n templates.runTemplateJS(js);\n\n return;\n })\n .then(pendingPromise.resolve)\n .catch(notificationModule.exception);\n });\n },\n\n alert: function(title, message, yesLabel) {\n var pendingPromise = new Pending('core\/notification:alert');\n\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 pendingPromise.resolve();\n });\n },\n\n confirm: function(title, question, yesLabel, noLabel, yesCallback, noCallback) {\n var pendingPromise = new Pending('core\/notification:confirm');\n\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 pendingPromise.resolve();\n });\n },\n\n exception: function(ex) {\n var pendingPromise = new Pending('core\/notification:addNotifications');\n\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 pendingPromise.resolve();\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"}