(function(){"use strict";u8.Base.Widgets.NotificationBox=function(t,e){this.Widget(t,$.extend({},u8.Base.Widgets.NotificationBox.defaults,e));this._isCreated=false;this._create()};u8.Base.Widgets.NotificationBox.makeClass({name:"NotificationBox",deriveFrom:u8.Base.Widgets.Widget,events:["Create"]});u8.Base.Widgets.NotificationBox.defaults={};$.extend(u8.Base.Widgets.NotificationBox.prototype,{dispose:function(){if(this._isDisposed){return}var t=u8.services.notification.getItems();t.unbind("*",this.id);this.Widget_dispose()},_create:function(){Function.chain(Function.chain.onDisposedAbort,u8.using.curry({texts:["Infobox_txt","NotificationBox"]}),this._createModel,this._createView).call(this,u8.tools.createdWhenReady.curry(this))},_createModel:function(t){var e=u8.services.notification.getItems();e.bind("Change",this._onNotificationItemsChange.bind(this),this.id);t()},_createView:function(e){this.empty();var i=u8.services.notification.getItems();var a={items:[],formatDate:function(t){return u8.services.typeConverter.dateToString(t,"Date")+" "+u8.services.typeConverter.timeToString(t)}};i.each(function(e){a.items.unshift(t(e))});var o=this.$("<div class='u8-notificationbox' />").appendTo(this.element);this._grid=u8.widget("Grid",o,{model:this._createGridModel(a),header:{view:{showBorder:false}},showPaging:true,parent:this,onRowAction:this._onRowAction.bind(this),showEmptyGrid:false});if(e){e()}},_onNotificationItemsChange:function(){if(this._isActive!==false){this._createView()}},_onRowAction:function(t,e){var i=t.model.data[t.model.rows[e.rowIndex].dataKey];if(i&&i.uid){u8.services.actions.executeDefault(i.uid)}},_createGridModel:function(t){var e=t.items;var i=[];var a=[];if(e){var o=[{name:"defaultAction",image:"u8-img-quickview-s",tooltip:$t("TXT_net_ListIconLabels_3")}];var n=[false];for(var s=0;s<e.length;s++){i.push({dataSeverity:e[s].dataSeverity,actionsVisible:e[s].uid?null:n,actions:o})}}a.push({id:"subject",label:$t("TXT_NotificationBox_0")||"Subject",dataKey:function(t){return t.subjectId?u8.Base.String.format($t(t.subjectId),t.arguments):t.subject},width:"10%"});a.push({id:"message",label:$t("TXT_NotificationBox_1")||"Message",type:"HTML",dataKey:function(t){if(t.contentType=="object/utml"){return{utml:t.utml}}return t.textId?u8.Base.String.format($t(t.textId),t.arguments):t.html||t.text},cellRenderer:function(t,e){if(e.cellData&&e.cellData.utml){e.type="UTML";e.cellData=e.cellData.utml}var i=e.defaultRenderer(t,e);t.$(e.elCell).attr("data-severity",e.modelRow.dataSeverity);return i}});a.push({id:"date",dataKey:"date",label:$t("TXT_NotificationBox_2")||"Date",cellFormatter:function(e){return t.formatDate(e)},width:"15%"});return u8.create("GridModel",{data:t.items,columns:a,rows:i,pageSize:10,rowActionCount:1})}});u8.Base.WidgetBuilder.registerWidget("NotificationBox",function(t,e,i){u8.widget("NotificationBox",e,i)});function t(t){var e=t.severity;if(typeof e=="string"){e=u8.Base.Notification.severityByName[e]||100}var i=t.contentType=="object/utml"&&t.text;var a=u8.toString_(t.text)||"";var o;if(e<=100){o="error"}else if(e<=200){o="warning"}else if(e<=300){o="info"}else{o=undefined}return $.extend({},t,{text:a,utml:i,dataSeverity:o,type:t.type||"default",severity:e})}})();