Skip to content

Instantly share code, notes, and snippets.

@zolotyh
Created December 19, 2014 15:16
Show Gist options
  • Save zolotyh/1b42228b4fc4153e9efa to your computer and use it in GitHub Desktop.
Save zolotyh/1b42228b4fc4153e9efa to your computer and use it in GitHub Desktop.
State
'use strict';
angular.module('client').config(function ($stateProvider, stateFactory) {
$stateProvider.state('staff.shifts', stateFactory('Shifts', {
url: '/shifts',
templateUrl: 'states/shifts/index/shift-daylist.html'
}));
}).controller('ShiftsCtrl', function ($scope, sheduleRest, MultiSidebarService) {
var PAGE_SIZE = 30;
$scope.query = {
start: moment().startOf('week').unix(),
end: moment().endOf('week').unix()
};
$scope.entities = [];
$scope.activeEnt = null;
$scope.tempEnt = null;
$scope.inProgress = false;
var getNextPage = $scope.getNextPage = function () {
if ($scope.inProgress) {
return;
}
var length = $scope.entities.length;
$scope.inProgress = true;
getEntities(length).then(function (entities) {
$scope.addEntities(entities);
$scope.inProgress = false;
});
};
$scope.addEntities = function (entities) {
$scope.entities.push.apply($scope.entities, entities);
};
$scope.getFirstPage = function () {
$scope.entities = [];
getNextPage();
};
$scope.$watch('query', function(){
$scope.getFirstPage();
});
$scope.editPositions = function(template){
MultiSidebarService.create($scope, template);
};
function getEntities(offset) {
offset = offset || 0;
return sheduleRest.query({
offset: offset,
limit: PAGE_SIZE,
companyId: 1,
start: $scope.query.start,
end: $scope.query.end
}).$promise;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment