      1 (function($, rf) {
      2
      3     rf.ui = rf.ui || {};
      4
      5     // Constructor definition
      6     rf.ui.NotifyMessage = function(componentId, options, notifyOptions) {
      7         // call constructor of parent class
      8         $super.constructor.call(this, componentId, options, defaultOptions);
      9         this.notifyOptions = notifyOptions;
     10     };
     11
     12     // Extend component class and add protected methods from parent class to our container
     13     rf.ui.Base.extend(rf.ui.NotifyMessage);
     14
     15     // define super class link
     16     var $super = rf.ui.NotifyMessage.$super;
     17
     18     var defaultOptions = {
     19         showSummary:true,
     20         level:0,
     21         isMessages: false,
     22         globalOnly: false
     23     };
     24
     25
     26     var onMessage = function (event, element, data) {
     27         var sourceId = data.sourceId;
     28         var message = data.message;
     29         if (!this.options.forComponentId) {
     30             if (!this.options.globalOnly && message) {
     31                 renderMessage.call(this, sourceId, message);
     32             }
     33         } else if (this.options.forComponentId === sourceId) {
     34             renderMessage.call(this, sourceId, message);
     35         }
     36     }
     37
     38     var renderMessage = function(index, message) {
     39         if (message && message.severity >= this.options.level) {
     40             showNotification.call(this, message);
     41         }
     42     }
     43
     44     var showNotification = function(message) {
     45         rf.ui.Notify($.extend({}, this.notifyOptions, {
     46             'summary': this.options.showSummary ? message.summary : undefined,
     47             'detail': this.options.showDetail ? message.detail : undefined,
     48             'severity': message.severity
     49         }));
     50     }
     51
     52     var bindEventHandlers = function () {
     53         rf.Event.bind(window.document, rf.Event.MESSAGE_EVENT_TYPE + this.namespace, onMessage, this);
     54     };
     55
     56     $.extend(rf.ui.NotifyMessage.prototype, {
     57             name: "NotifyMessage",
     58             __bindEventHandlers: bindEventHandlers,
     59
     60             destroy : function() {
     61                 rf.Event.unbind(window.document, rf.Event.MESSAGE_EVENT_TYPE + this.namespace);
     62                 $super.destroy.call(this);
     63             }
     64         });
     65
     66 })(RichFaces.jQuery, window.RichFaces || (window.RichFaces = {}));