Advertisement
Guest User

Untitled

a guest
Dec 19th, 2014
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. 'use strict';
  2. angular.module('client').config(function ($stateProvider, stateFactory) {
  3. $stateProvider.state('staff.shifts', stateFactory('Shifts', {
  4. url: '/shifts',
  5. templateUrl: 'states/shifts/index/shift-daylist.html'
  6. }));
  7. }).controller('ShiftsCtrl', function ($scope, sheduleRest, MultiSidebarService) {
  8. var PAGE_SIZE = 30;
  9.  
  10. $scope.query = {
  11. start: moment().startOf('week').unix(),
  12. end: moment().endOf('week').unix()
  13. };
  14.  
  15. $scope.entities = [];
  16. $scope.activeEnt = null;
  17. $scope.tempEnt = null;
  18. $scope.inProgress = false;
  19.  
  20. var getNextPage = $scope.getNextPage = function () {
  21. if ($scope.inProgress) {
  22. return;
  23. }
  24. var length = $scope.entities.length;
  25.  
  26. $scope.inProgress = true;
  27.  
  28. getEntities(length).then(function (entities) {
  29. $scope.addEntities(entities);
  30. $scope.inProgress = false;
  31. });
  32. };
  33.  
  34. $scope.addEntities = function (entities) {
  35. $scope.entities.push.apply($scope.entities, entities);
  36. };
  37.  
  38. $scope.getFirstPage = function () {
  39. $scope.entities = [];
  40. getNextPage();
  41. };
  42.  
  43. $scope.$watch('query', function(){
  44. $scope.getFirstPage();
  45. });
  46.  
  47. $scope.editPositions = function(template){
  48. MultiSidebarService.create($scope, template);
  49. };
  50.  
  51. function getEntities(offset) {
  52. offset = offset || 0;
  53. return sheduleRest.query({
  54. offset: offset,
  55. limit: PAGE_SIZE,
  56. companyId: 1,
  57. start: $scope.query.start,
  58. end: $scope.query.end
  59. }).$promise;
  60. }
  61. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement