Current Path : /var/www/ljmtc/cbt/message/output/popup/amd/build/ |
Current File : /var/www/ljmtc/cbt/message/output/popup/amd/build/notification_area_control_area.min.js |
function _typeof(a){"@babel/helpers - typeof";if("function"==typeof Symbol&&"symbol"==typeof Symbol.iterator){_typeof=function(a){return typeof a}}else{_typeof=function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a}}return _typeof(a)}define ("message_popup/notification_area_control_area",["jquery","core/templates","core/notification","core/custom_interaction_events","message_popup/notification_repository","message_popup/notification_area_events"],function(a,b,c,d,e,f){var g={CONTAINER:"[data-region=\"notification-area\"]",CONTENT:"[data-region=\"content\"]",NOTIFICATION:"[data-region=\"notification-content-item-container\"]",CAN_RECEIVE_FOCUS:"input:not([type=\"hidden\"]), a[href], button, textarea, select, [tabindex]"},h={NOTIFICATION:"message_popup/notification_content_item"},i=function(b,c){this.root=a(b);this.container=this.root.closest(g.CONTAINER);this.userId=c;this.content=this.root.find(g.CONTENT);this.offset=0;this.limit=20;this.initialLoad=!1;this.isLoading=!1;this.loadedAll=!1;this.notifications={};this.registerEventListeners()};i.prototype.getRoot=function(){return this.root};i.prototype.getContainer=function(){return this.container};i.prototype.getUserId=function(){return this.userId};i.prototype.getContent=function(){return this.content};i.prototype.getOffset=function(){return this.offset};i.prototype.getLimit=function(){return this.limit};i.prototype.setOffset=function(a){this.offset=a};i.prototype.setLimit=function(a){this.limit=a};i.prototype.incrementOffset=function(){this.offset+=this.limit};i.prototype.startLoading=function(){this.isLoading=!0;this.getRoot().addClass("loading")};i.prototype.stopLoading=function(){this.isLoading=!1;this.getRoot().removeClass("loading")};i.prototype.hasDoneInitialLoad=function(){return this.initialLoad};i.prototype.hasLoadedAllContent=function(){return this.loadedAll};i.prototype.setLoadedAllContent=function(a){this.loadedAll=a};i.prototype.setCacheNotification=function(a){this.notifications[a.id]=a};i.prototype.getCacheNotification=function(a){return this.notifications[a]};i.prototype.getNotificationElement=function(a){var b=this.getRoot().find(g.NOTIFICATION+"[data-id=\""+a+"\"]");return 1==b.length?b:null};i.prototype.scrollNotificationIntoView=function(a){var b=a.position(),c=this.getRoot(),d=b.top-c.scrollTop();if(d>c.innerHeight()){var e=a.outerHeight();e=4*e;var f=b.top-e;c.scrollTop(f)}};i.prototype.showNotification=function(b){if("object"!==_typeof(b)){b=this.getNotificationElement(b)}if(b&&b.length){this.getRoot().find(g.NOTIFICATION).removeClass("selected");b.addClass("selected").find(g.CAN_RECEIVE_FOCUS).focus();var c=b.attr("data-id"),d=this.getCacheNotification(c);this.scrollNotificationIntoView(b);this.getContainer().trigger(f.showNotification,[a.extend({},d)])}};i.prototype.markNotificationAsRead=function(a){return e.markAsRead(a.attr("data-id")).done(function(){a.removeClass("unread")})};i.prototype.renderNotifications=function(c){var d=[],e=this.getContent();a.each(c,function(a,c){var e=c.contexturl;delete c.contexturl;var f=b.render(h.NOTIFICATION,c).then(function(a,b){c.contexturl=e;this.setCacheNotification(c);return{html:a,js:b}}.bind(this));d.push(f)}.bind(this));return a.when.apply(a,d).then(function(){a.each(arguments,function(a,c){e.append(c.html);b.runTemplateJS(c.js)})})};i.prototype.loadMoreNotifications=function(){if(this.isLoading||this.hasLoadedAllContent()){return a.Deferred().resolve()}this.startLoading();var b={limit:this.getLimit(),offset:this.getOffset(),useridto:this.getUserId()};if(!this.initialLoad){b.limit=this.getOffset()+this.getLimit();b.offset=0}var c=e.query(b).then(function(a){var b=a.notifications;this.unreadCount=a.unreadcount;this.setLoadedAllContent(!b.length||b.length<this.getLimit());this.initialLoad=!0;if(b.length){this.incrementOffset();return this.renderNotifications(b)}return!1}.bind(this)).always(function(){this.stopLoading()}.bind(this));return c};i.prototype.registerEventListeners=function(){d.define(this.getRoot(),[d.events.activate,d.events.scrollBottom,d.events.scrollLock,d.events.up,d.events.down]);this.getRoot().on(d.events.scrollBottom,function(){this.loadMoreNotifications()}.bind(this));this.getRoot().on(d.events.activate,g.NOTIFICATION,function(b){var c=a(b.target).closest(g.NOTIFICATION);this.showNotification(c)}.bind(this));this.getRoot().on(d.events.up,g.NOTIFICATION,function(b,c){var d=a(b.target).closest(g.NOTIFICATION);this.showNotification(d.prev());c.originalEvent.preventDefault()}.bind(this));this.getRoot().on(d.events.down,g.NOTIFICATION,function(b,c){var d=a(b.target).closest(g.NOTIFICATION);this.showNotification(d.next());c.originalEvent.preventDefault()}.bind(this));this.getContainer().on(f.notificationShown,function(a,b){if(!b.read){var c=this.getNotificationElement(b.id);if(c){this.markNotificationAsRead(c)}var d=this.getCacheNotification(b.id);if(d){d.read=!0}}}.bind(this))};return i}); //# sourceMappingURL=notification_area_control_area.min.js.map