cobuild-angular-stack
Version:
Base stack angular sass jade gulp
78 lines (67 loc) • 2.46 kB
JavaScript
(function (module) {
AdminDiscountSubCategoriesController.$inject = ['$scope', '$rootScope' , '$state', '$stateParams','$translate', 'toastr', '$uibModal', 'DiscountCategory'];
module.controller('AdminDiscountSubCategoriesController', AdminDiscountSubCategoriesController);
function AdminDiscountSubCategoriesController($scope, $rootScope, $state, $stateParams, $translate, toastr, $uibModal, DiscountCategory) {
$scope.discountSubCategories = [];
$scope.filterName = '';
$scope.discountCategory = {};
$scope.loader = true;
$scope.role = $rootScope.role;
$scope.getCategory = function() {
$scope.loader = true;
DiscountCategory.findById({id: $stateParams.id, filter: {"include":{"relation":"discountSubcategories", "scope":{"include":"discountCodes"}}}}).$promise.then(function(discountCategory) {
$scope.discountCategory = discountCategory;
$scope.discountSubCategories = discountCategory.discountSubcategories;
$scope.loader = false;
}, function(err) {
console.log(err)
$scope.loader = false;
}).catch(function(err) {
console.log(err);
$scope.loader = false;
});
}
$scope.reports = function() {
var modalInstance = $uibModal.open({
animation: true,
templateUrl: 'partials/admin.discount.reports.html',
controller: 'AdminDiscountReportsController'
});
modalInstance.result.then(function() {
}, $scope.error).catch($scope.error)
}
$scope.add = function() {
var modalInstance = $uibModal.open({
animation: true,
templateUrl: 'partials/admin.discount.subcategories.add.html',
controller: 'AdminDiscountSubCategoriesAddController',
resolve: {
discountCategory: $scope.discountCategory
}
});
modalInstance.result.then(function() {
$scope.getCategory();
}, $scope.error).catch($scope.error)
}
$scope.addCodes = function() {
var modalInstance = $uibModal.open({
animation: true,
templateUrl: 'partials/admin.discount.code.add.html',
controller: 'AdminDiscountCodeAddController',
resolve: {
discountSubCategory: null,
discountCategory: $scope.discountCategory
}
});
modalInstance.result.then(function() {
$scope.getCategory();
}, $scope.error).catch($scope.error)
}
$scope.error = function(err) {
if(err == 'cancel') return false;
toastr.error(err);
}
// $scope.getDiscountSubCategories();
$scope.getCategory();
}
})(angular.module('uniko.admin.discount'));