/
var
/
www
/
html
/
lgpd
/
lib
/
amd
/
build
/
Upload File
HOME
define ("core/notification",["core/yui","jquery","core/log","core/pending"],function(a,b,c,d){var e={types:{success:"core/notification_success",info:"core/notification_info",warning:"core/notification_warning",error:"core/notification_error"},fieldName:"user-notifications",fetchNotifications:function fetchNotifications(){var a=new d("core/notification:fetchNotifications");require(["core/ajax"],function(b){var c=b.call([{methodname:"core_fetch_notifications",args:{contextid:e.contextid}}]);c[0].then(e.addNotifications).always(a.resolve)})},addNotifications:function addNotifications(a){var c=new d("core/notification:addNotifications");if(!a){a=[]}b.each(a,function(a,b){e.renderNotification(b.template,b.variables)});c.resolve()},setupTargetRegion:function setupTargetRegion(){var a=b("#"+e.fieldName);if(a.length){return!1}var c=b("<span>").attr("id",e.fieldName);a=b("#region-main");if(a.length){return a.prepend(c)}a=b("[role=\"main\"]");if(a.length){return a.prepend(c)}a=b("body");return a.prepend(c)},addNotification:function addNotification(a){var c=new d("core/notification:addNotifications"),f=e.types.error;a=b.extend({closebutton:!0,announce:!0,type:"error"},a);if(a.template){f=a.template;delete a.template}else if(a.type){if("undefined"!=typeof e.types[a.type]){f=e.types[a.type]}delete a.type}c.resolve();return e.renderNotification(f,a)},renderNotification:function renderNotification(a,f){if("undefined"==typeof f.message||!f.message){c.debug("Notification received without content. Skipping.");return}var g=new d("core/notification:renderNotification");require(["core/templates"],function(c){c.render(a,f).then(function(a,d){b("#"+e.fieldName).prepend(a);c.runTemplateJS(d)}).then(g.resolve).catch(e.exception)})},alert:function alert(b,c,e){var f=new d("core/notification:alert");a.use("moodle-core-notification-alert",function(){var a=new M.core.alert({title:b,message:c,yesLabel:e});a.show();f.resolve()})},confirm:function confirm(b,c,e,f,g,h){var i=new d("core/notification:confirm");a.use("moodle-core-notification-confirm",function(){var a=new M.core.confirm({title:b,question:c,yesLabel:e,noLabel:f});a.on("complete-yes",function(){g()});if(h){a.on("complete-no",function(){h()})}a.show();i.resolve()})},exception:function exception(b){var c=new d("core/notification:addNotifications");if("undefined"==typeof b.stack){b.stack=""}if(b.debuginfo){b.stack+=b.debuginfo+"\n"}if(!b.backtrace&&b.stacktrace){b.backtrace=b.stacktrace}if(b.backtrace){b.stack+=b.backtrace;var e=b.backtrace.match(/line ([^ ]*) of/),f=b.backtrace.match(/ of ([^:]*): /);if(e&&e[1]){b.lineNumber=e[1]}if(f&&f[1]){b.fileName=f[1];if(30<b.fileName.length){b.fileName="..."+b.fileName.substr(b.fileName.length-27)}}}if("undefined"==typeof b.name&&b.errorcode){b.name=b.errorcode}a.use("moodle-core-notification-exception",function(){var a=new M.core.exception(b);a.show();c.resolve()})}};return{init:function init(a,b){e.contextid=a;e.setupTargetRegion();e.addNotifications(b);e.fetchNotifications()},fetchNotifications:e.fetchNotifications,addNotification:e.addNotification,alert:e.alert,confirm:e.confirm,exception:e.exception}}); //# sourceMappingURL=notification.min.js.map