UNPKG

acha-framework

Version:

is a modular framework on both client (angular.js) and server (node.js) side, it provides security, orm, ioc, obfuscation and ...

84 lines 3.07 kB
(function ($, angular, underscore, window, document, undefined) { 'use strict'; angular.module('frontend.directives').directive('actionBar', [ 'identityService', 'actionBarService', 'layoutTogglers', 'cultureService', function (identityService, actionBarService, layoutTogglers, culture) { return { restrict: 'E', replace: true, scope: {}, templateUrl: '/templates/framework/panel/directives/action-bar/template.html', link: function (scope, element, attr) { scope.vm = { dataSource: actionBarService, currentSet: [], page: 1 }; scope.vm.init = function () { scope.vm.bind(); }; scope.vm.logout = function () { identityService.clearToken(); window.location = identityService.accountPath.format([culture.lang]); }; scope.vm.onAction = function (button) { if (button.action) { button.action(button); } }; scope.vm.getNotificationClass = function (notification, index) { if (index === 0) return 'notification-upperbody ' + notification.cssClass; return 'notification-lowerbody'; }; scope.vm.collapseMenu = function () { layoutTogglers.toggleMenu(); }; scope.vm.onNotificationsChanged = function () { scope.vm.page = 1; scope.vm.setNotificationPage(); }; scope.vm.prev = function ($event) { $event.stopPropagation(); $event.preventDefault(); if (scope.vm.page === 1) return; scope.vm.page--; scope.vm.setNotificationPage(); }; scope.vm.next = function ($event) { $event.stopPropagation(); $event.preventDefault(); var maxPage = Math.ceil((actionBarService.notifications || []).length % 3); if (scope.vm.page >= maxPage) return; scope.vm.page++; scope.vm.setNotificationPage(); }; scope.vm.setNotificationPage = function () { if (actionBarService.notifications.length <= 3) { scope.vm.currentSet = actionBarService.notifications.concat([]); return; } var result = []; var start = (scope.vm.page - 1) * 3; var end = start + 3; if (end > actionBarService.notifications.length) end = actionBarService.notifications.length; for (start; start < end; start++) { result.push(actionBarService.notifications[start]); } scope.vm.currentSet = result; }; scope.vm.bind = function () { scope.$watchCollection('vm.dataSource.notifications', scope.vm.onNotificationsChanged); }; scope.vm.init(); } }; } ]); }(jQuery, angular, _, window, document));