Skip to content

Instantly share code, notes, and snippets.

@wharley
Last active November 7, 2016 11:32
Show Gist options
  • Save wharley/993cdeaea526b407503271f41e504bb3 to your computer and use it in GitHub Desktop.
Save wharley/993cdeaea526b407503271f41e504bb3 to your computer and use it in GitHub Desktop.
'use strict';
app.controller('HeritageClassCtrl', function($rootScope, $location, $window, $scope, $http, $q)
{
$scope.currentPage = 1;
$scope.numPerPage = 10;
$scope.maxSize = 5;
$scope.fullPage = 4;
$scope.home = () => {
$location.path('/page')
}
$scope.addData = () => {
$location.$$search.param['id'] = undefined
$location.path("/heritageClassInclusion");
}
$scope.editData = (row) => {
$location.$$search.param['id'] = $scope.expenditureClasss[row].seq_classe_patrimonio
$location.path('/heritageClassInclusion')
}
$scope.deleteData = (row) => {
const data = {
id: $scope.expenditureClasss[row].seq_classe_patrimonio,
num_filial: $location.$$search.param.cod_filial_corrente
}
deletedData(data)
.then(requestHeritageClass)
.then((data) => {
if(data){
$scope.heritageClasss = data.data
window.alert("Registro deletado com sucesso")
}
})
}
$scope.init = () => {
if(!$location.$$search.param.cod_filial_corrente){
window.alert("Por favor logar novamente")
$location.path("/");
}
const data = {
num_filial: $location.$$search.param.cod_filial_corrente
}
requestHeritageClass(data)
.then( (data) => {
if(data)
$scope.heritageClasss = data.data
})
}
function deletedData(data){
return $q( (resolve, reject) => {
$http.post("/deleteClPatrimonio", {
data: data,
headers: {'Content-Type': 'application/json'}
})
.then( (response) => {
const data = {
num_filial: $location.$$search.param.cod_filial_corrente
}
resolve(data)
}, (err) => {
reject(err)
})
})
}
function requestHeritageClass(data){
return $q( (resolve, reject) => {
$http.post("/byClPatrimonio", {
data: data,
headers: {'Content-Type': 'application/json'}
})
.then( (response) => {
resolve(response)
}, (err) => {
reject(err)
})
})
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment