mirror of
https://github.com/moodle/moodle.git
synced 2025-07-18 21:01:27 +02:00
3 lines
2.7 KiB
JavaScript
3 lines
2.7 KiB
JavaScript
define ("core/notification",["core/yui","jquery","core/log"],function(a,b,c){var d={types:{success:"core/notification_success",info:"core/notification_info",warning:"core/notification_warning",error:"core/notification_error"},fieldName:"user-notifications",fetchNotifications:function fetchNotifications(){require(["core/ajax"],function(a){var b=a.call([{methodname:"core_fetch_notifications",args:{contextid:d.contextid}}]);b[0].done(d.addNotifications)})},addNotifications:function addNotifications(a){if(!a){a=[]}b.each(a,function(a,b){d.renderNotification(b.template,b.variables)})},setupTargetRegion:function setupTargetRegion(){var a=b("#"+d.fieldName);if(a.length){return!1}var c=b("<span>").attr("id",d.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=d.types.error;a=b.extend({closebutton:!0,announce:!0,type:"error"},a);if(a.template){c=a.template;delete a.template}else if(a.type){if("undefined"!=typeof d.types[a.type]){c=d.types[a.type]}delete a.type}return d.renderNotification(c,a)},renderNotification:function renderNotification(a,e){if("undefined"==typeof e.message||!e.message){c.debug("Notification received without content. Skipping.");return}require(["core/templates"],function(c){c.render(a,e).done(function(a,e){b("#"+d.fieldName).prepend(a);c.runTemplateJS(e)}).fail(d.exception)})},alert:function alert(b,c,d){a.use("moodle-core-notification-alert",function(){var a=new M.core.alert({title:b,message:c,yesLabel:d});a.show()})},confirm:function confirm(b,c,d,e,f,g){a.use("moodle-core-notification-confirm",function(){var a=new M.core.confirm({title:b,question:c,yesLabel:d,noLabel:e});a.on("complete-yes",function(){f()});if(g){a.on("complete-no",function(){g()})}a.show()})},exception:function exception(b){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 c=b.backtrace.match(/line ([^ ]*) of/),d=b.backtrace.match(/ of ([^:]*): /);if(c&&c[1]){b.lineNumber=c[1]}if(d&&d[1]){b.fileName=d[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()})}};return{init:function init(a,b){d.contextid=a;d.setupTargetRegion();d.addNotifications(b);d.fetchNotifications()},fetchNotifications:d.fetchNotifications,addNotification:d.addNotification,alert:d.alert,confirm:d.confirm,exception:d.exception}});
|
|
//# sourceMappingURL=notification.min.js.map
|