-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
executable file
·71 lines (57 loc) · 1.59 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
65
66
67
68
69
70
71
'use strict';
// Declare app level module which depends on views, and components
angular.module('myApp', ['ngRoute']).
config(['$routeProvider', function ($routeProvider) {
$routeProvider
.when('/view1', { templateUrl: 'view1/view1.html', controller: ViewController })
.when('/view2', { templateUrl: 'view2/view2.html', controller: ViewController })
.otherwise({redirectTo: '/view1'});
}]).
factory('List', function($q, $http) {
var factory = {};
// var rows = [{}];
factory.get = function() {
var deferred = $q.defer();
$http.get('//server.kscmasonlibrary.org:8080/', {cache:true}).
success(function(data, status) {
// console.log(status, data);
// factory.rows = data;
deferred.resolve(data);
}).
error(function(data, status) {
console.log(status, data);
deferred.reject(data);
});
return deferred.promise;
};
factory.post = function(msg) {
var deferred = $q.defer();
$http.post('//server.kscmasonlibrary.org:8080/', msg).
success(function(data, status) {
console.log(status, data);
factory.rows = data;
deferred.resolve(data);
}).
error(function(data, status) {
console.log(status, data);
deferred.reject(data);
});
return deferred.promise;
};
return factory;
});
function ViewController($scope, List) {
List.get().then(function(data) {
List.rows = data;
$scope.rows = List.rows;
});
$scope.doPost = function() {
var obj = {
assetid: $scope.assetid,
location: $scope.location
};
List.post(obj).then(function(data) { $scope.rows = data; });
$scope.assetid = "";
$scope.location = "";
};
}