      1 (function($, rf) {
      2
      3     rf.ui = rf.ui || {};
      4
      5     // Constructor definition
      6     rf.ui.Message = function(componentId, options) {
      7         // call constructor of parent class
      8         $super.constructor.call(this, componentId, options, defaultOptions);
      9         if (this.options.isMessages) {
     10             this.severityClasses = ["rf-msgs-inf", "rf-msgs-wrn", "rf-msgs-err", "rf-msgs-ftl"];
     11             this.summaryClass = "rf-msgs-sum";
     12             this.detailClass = "rf-msgs-det";
     13         } else {
     14             this.severityClasses = ["rf-msg-inf", "rf-msg-wrn", "rf-msg-err", "rf-msg-ftl"];
     15             this.summaryClass = "rf-msg-sum";
     16             this.detailClass = "rf-msg-det";
     17         }
     18     };
     19
     20     // Extend component class and add protected methods from parent class to our container
     21     rf.ui.Base.extend(rf.ui.Message);
     22
     23     // define super class link
     24     var $super = rf.ui.Message.$super;
     25
     26     var defaultOptions = {
     27         showSummary:true,
     28         level:0,
     29         isMessages: false,
     30         globalOnly: false
     31     };
     32
     33
     34     var onMessage = function (event, element, data) {
     35         var content = $(rf.getDomElement(this.id));
     36         var sourceId = data.sourceId;
     37         var message = data.message;
     38         if (!this.options.forComponentId) {
     39             if (!message || this.options.globalOnly) {
     40                 // rf.csv.clearMessage
     41                 var element;
     42                 while (element = rf.getDomElement(this.id + ':' + sourceId)) {
     43                     $(element).remove();
     44                 }
     45             } else {
     46                 renderMessage.call(this, sourceId, message);
     47             }
     48         } else if (this.options.forComponentId === sourceId) {
     49             content.empty();
     50             renderMessage.call(this, sourceId, message);
     51         }
     52     }
     53
     54     var renderMessage = function(index, message) {
     55         if (message && message.severity >= this.options.level) {
     56
     57             var content = $(rf.getDomElement(this.id));
     58             var msgContent = $("<span/>", {'class':(this.severityClasses)[message.severity],"id":this.id + ':' + index});
     59             if (message.summary) {
     60                 if (this.options.tooltip) {
     61                     msgContent.attr("title", message.summary);
     62                 } else if (this.options.showSummary) {
     63                     msgContent.append($("<span/>", {"class":(this.summaryClass)}).text(message.summary));
     64                 }
     65             }
     66             if (this.options.showDetail && message.detail) {
     67                 msgContent.append($("<span/>", {"class":(this.detailClass)}).text(message.detail));
     68             }
     69             content.append(msgContent);
     70         }
     71     }
     72
     73     var bindEventHandlers = function () {
     74         rf.Event.bind(window.document, rf.Event.MESSAGE_EVENT_TYPE + this.namespace, onMessage, this);
     75     };
     76
     77     $.extend(rf.ui.Message.prototype, {
     78             name: "Message",
     79             __bindEventHandlers: bindEventHandlers,
     80
     81             destroy : function() {
     82                 rf.Event.unbind(window.document, rf.Event.MESSAGE_EVENT_TYPE + this.namespace);
     83                 $super.destroy.call(this);
     84             }
     85         });
     86
     87 })(RichFaces.jQuery, window.RichFaces || (window.RichFaces = {}));
     88