cobuild-angular-stack
Version:
Base stack angular sass jade gulp
161 lines (146 loc) • 6 kB
JavaScript
/**
* Created by garusis on 8/04/16.
*/
(function (module) {
AdminCashoutListController.$inject = ['$scope', '$http', 'CashOutInformation', 'AdminAuth', '$translate', 'toastr'];
module.controller('AdminCashoutListController', AdminCashoutListController);
function AdminCashoutListController($scope, $http, CashOutInformation, Auth, $translate, toastr) {
$scope.curPage = 0;
$scope.pageSize = 20;
$scope.pageDirect = 1;
$scope.data = {
years: []
}
$scope.sortBy = {
fields: [
{label: 'Fecha', name: 'date'}
],
order: [
{label: 'Ascendente', name: 'ASC'},
{label: 'Descendente', name: 'DESC'}
]
};
// $scope.cashouts = CashOutInformation.customFind({
// filter: {
// include: 'coupleAccount',
// limit:$scope.pageSize,
// skip:$scope.curPage * $scope.pageSize,
// },
// });
$scope.sortBy.selected = {
field: $scope.sortBy.fields[0].name,
order: $scope.sortBy.order[1].name
};
$scope.filterName = '';
$scope.getData = function(isLoad) {
$scope.$watch('filterName', function (newValue, oldValue) {
if (newValue !== '' || oldValue !== '' || isLoad) {
console.log($scope.curPage, $scope.pageSize);
var sortBy = $scope.sortBy.selected;
$scope.cashouts = CashOutInformation.customFind({
filter: {
include: 'coupleAccount',
order: 'date DESC',
where: $scope.filterName,
limit:$scope.pageSize,
skip: ($scope.curPage > 0 ? ($scope.curPage - 1) : ($scope.curPage)) * $scope.pageSize
}
});
}
});
}
$scope.updateCashout = function (cashout) {
CashOutInformation
.update({where: {id: cashout.id}}, cashout)
.$promise
.then(function () {
$translate('retirement-success').then(function (translation) {
toastr.success(translation);
});
})
};
$scope.getPages = function() {
var total = $scope.numberOfPages;
var page = $scope.curPage == 0 ? 1 : $scope.curPage;
$scope.pageMax = !$scope.pageMax ? 1 : $scope.pageMax;
$scope.pageMin = !$scope.pageMin ? 1 : $scope.pageMin;
if((page < $scope.pageMin || page > $scope.pageMax) || $scope.pageMax == 1) {
$scope.pageMax = $scope.pageMax >= page ? (page + 2) : $scope.pageMax;
$scope.pageMax = $scope.pageMax > total ? total : (page == (total - 1) ? (total - 1) : $scope.pageMax);
$scope.arrayPages = [];
if($scope.pageMax > 1 && total > 1) {
$scope.pageMin = $scope.pageMax - 2;
if($scope.pageMin < 1) {
$scope.pageMin = 1;
}
for(var pageMin = $scope.pageMax - 2;pageMin <= $scope.pageMax; pageMin ++ ) {
if(pageMin > 0) $scope.arrayPages.push(pageMin);
};
}
}
}
$scope.getYears = function() {
var date = new Date();
var finish = date.getFullYear() + 1;
var start = finish - 10;
$scope.data.years = _.rangeRight(start, finish);
}
$scope.pageDirect = 1;
$scope.goToPagedirect = function(page){
console.log('$scope.pageDirect = ',$scope.pageDirect);
if (!page){
$scope.pageDirect = 1;
} else {
$scope.pageDirect = page;
$scope.curPage = page;
$scope.getData(true);
}
}
var totalCashouts = CashOutInformation.countAlternative().$promise.then(function(value, value2) {
$scope.numberOfPages = Math.ceil(value.count / $scope.pageSize);
console.log($scope.numberOfPages);
$scope.getData(true);
$scope.getPages();
}, function(err) {
console.log(err);
});
$scope.goToPage = function(isNext){
if (isNext){
$scope.curPage = $scope.curPage + 1;
}else{
$scope.curPage = $scope.curPage - 1;
}
$scope.getData(true);
}
$scope.getYears();
$scope.exportData = function () {
$http({
url: "http://uniko.co:3000/api/v2/cashouts/listasxlsx?access_token=" + Auth.getAuthData().accessTokenId,
method: 'post',
responseType: "blob",
data: {
filter: {
include: {
relation: 'coupleAccount',
scope: {
fields: ['fakeid','weddingData','payInformationData']
}
},
where: $scope.filterName
}
}
}).then(function (data) {
var a = document.createElement("a");
document.body.appendChild(a);
a.style = "display: none";
var blob = data.data,
url = window.URL.createObjectURL(blob);
a.href = url;
a.download = 'cashoutslist.xlsx';
a.click();
window.URL.revokeObjectURL(url);
$(a).remove();
});
};
}
})(angular.module('uniko.admin.cashouts'));