forked from QuanEnPan/iaeste-lc-intraweb-ClientAngular
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
executable file
·64 lines (52 loc) · 2.02 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
(function(){
var app = angular.module("companiesJS", ["companyTab","companyForm"]);
app.controller("CompaniesController", ["$http",
function($http) {
this.COMPANIES_API = "http://localhost:8080/api/companies";
this.SEARCH_API = "http://localhost:8080/api/companies/results/json";
this.loading = false;
this.deleteloading = false;
this.newCompany = {};
var companyCtrl = this;
this.title = "";
this.isLoading = function(){
return this.loading;
};
this.noCompany = function(){
return this.companies === undefined;
}
this.listCompanies = function(){
this.loading = true;
companyCtrl.result = {};
$http.get(this.COMPANIES_API)
.success(function (data) {
if(data!=""){
companyCtrl.companies = data;
}
});
};
this.searchCompany = function(){
companyCtrl.companies = {};
$http.get(this.SEARCH_API+"?name="+this.title)
.success(function (data) {
companyCtrl.result = data;
});
};
this.addCompany = function(){
$http.post(this.COMPANIES_API, this.newCompany)
.then(function(){
companyCtrl.listCompanies();
companyCtrl.newCompany={};
});
};
this.deleteCompany = function(id){
this.deleteloading = true;
this.loading = true;
$http.delete(this.COMPANIES_API+"/"+id)
.then(function () {
this.deleteloading = false;
});
window.location.reload(false);
};
}]);
}());