var ozbetNotifications=ozbetNotifications||{},OzbetNotificationsViewModel;ozbetNotifications.Constants={align:{bottomleft:"bottom-left",bottomright:"bottom-right",topleft:"top-left",topright:"top-right"},messageType:{systemMessage:0,userMessage:1,errorMessage:2,sucessMessage:3,blackbookMessage:4},defaultTitle:"TABtouch",notificationChannelName:"my-notifications"};ozbetNotifications.Notification=function(n,t,i,r,u){var f=this,e,o;f.title=t||ozbetNotifications.Constants.defaultTitle;f.text=i;f.messageType=r||ozbetNotifications.Constants.messageType.systemMessage;f.isSticky=u||!1;f.messageId=n;e=!1;this.getIsReadValue=function(){return e};this.setIsReadValue=function(n){e=n||!1};this.getClientMessageIdValue=function(){return o};this.setClientMessageIdValue=function(n){o=n}};ozbetNotifications.NotificationsSettings={position:ozbetNotifications.Constants.align.bottomright,class_name:"my-sticky-class",fade_in_speed:100,fade_out_speed:100,timeout:6e3,title:ozbetNotifications.Constants.defaultTitle,maxNumberOfNotificationsOnScreen:5};ozbetNotifications=ozbetNotifications||{};ozbetNotifications.queuedservice=function(){var n=this,i=postal.channel(ozbetNotifications.Constants.notificationChannelName),t;n.notificationsqueue=ko.observableArray();n.init=function(){$.extend($.gritter.options,{class_name:ozbetNotifications.NotificationsSettings.class_name,position:ozbetNotifications.NotificationsSettings.position,fade_in_speed:ozbetNotifications.NotificationsSettings.fade_out_speed,fade_out_speed:ozbetNotifications.NotificationsSettings.fade_in_speed,time:ozbetNotifications.NotificationsSettings.timeout,parent_element:$("#notificationsId")})};t=locking.shared_lock("notifications-service");n.beforeOpen=function(){if($(".gritter-item-wrapper").length==ozbetNotifications.NotificationsSettings.maxNumberOfNotificationsOnScreen)return!1};n.afterOpen=function(){};n.beforeClose=function(){};n.afterClose=function(t,r){var f=t[0].id,u,e;if(t&&r&&i.publish({topic:"Notificationservice.NotificationRemoved",data:f}),u=_.find(n.notificationsqueue(),function(n){return f==n.clientMessageId}),u&&n.notificationsqueue.remove(u),$(".gritter-item-wrapper").length<ozbetNotifications.NotificationsSettings.maxNumberOfNotificationsOnScreen){if(n.notificationsqueue().length==0)return;e=n.notificationsqueue.shift();n.addToGritter(e)}};n.addNotification=function(t){if(t){if($(".gritter-item-wrapper").length==ozbetNotifications.NotificationsSettings.maxNumberOfNotificationsOnScreen){n.notificationsqueue.push(t);return}return n.addToGritter(t),t}};n.addToGritter=function(i){var r,u;if(t.trylock()){r=null;switch(i.messageType){case ozbetNotifications.Constants.messageType.blackbookMessage:r="image-matrix note-type black-books"}return u=$.gritter.add({title:i.title,text:i.text,sticky:i.isSticky,before_open:n.beforeOpen,after_open:n.afterOpen,before_close:n.beforeClose,after_close:n.afterClose,image:r}),i.clientMessageId="gritter-item-"+u,t.unlock(),i}};n.removeFromGritter=function(i){if(t.trylock()){var r=i.clientMessageId;$.gritter.remove(r,{before_close:n.beforeClose,after_close:n.afterClose})}};n.removeNotification=function(t){t&&n.removeFromGritter(t)};n.removeAllNotification=function(){t.trylock()&&$.gritter.removeAll({before_close:n.beforeClose,after_close:n.afterClose})};n.init()};ozbetNotifications=ozbetNotifications||{};OzbetNotificationsViewModel=function(){var n=this,t=postal.channel(ozbetNotifications.Constants.notificationChannelName);n.notifications=ko.observableArray();n.ozbetNotificationsService=new ozbetNotifications.queuedservice;n.addNotification=function(t,i,r,u){var f=n.ozbetNotificationsService.addNotification(new ozbetNotifications.Notification("",i,t,r,u));f&&n.notifications.push(f)};n.removeNotification=function(t){n.ozbetNotificationsService.removeNotification(new ozbetNotifications.Notification({clientMessageId:t}));n.removeNotificationFromClientCache(t)};n.removeNotificationFromClientCache=function(t){var i=_.find(n.notifications(),function(n){return t==n.clientMessageId});i&&n.notifications.remove(i)};t.subscribe({topic:"ozbetNotifications.removenotification",callback:function(t){t&&n.removeNotification(t)}});t.subscribe({topic:"ozbetNotifications.addnotification",callback:function(t){t&&n.addNotification(t.text,t.title,t.messageType,t.isSticky)}});t.subscribe({topic:"Notificationservice.NotificationRemoved",callback:function(t){n.removeNotificationFromClientCache(t)}})}