-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlistingController.js
More file actions
65 lines (56 loc) · 2.51 KB
/
listingController.js
File metadata and controls
65 lines (56 loc) · 2.51 KB
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
angular.module('listings').controller('ListingsController', ['$scope', 'Listings',
function($scope, Listings) {
$scope.listings = Listings;
$scope.detailedInfo = undefined;
/*
Implement these functions in the controller to make your application function
as described in the assignment spec.
*/
$scope.addListing = function() {
//var list = JSON.parse(Listings);
var name, code, lat, long, addr;
name = document.getElementById("nameInput").value;
code = document.getElementById("codeInput").value.toUpperCase();
lat = document.getElementById("latInput").value;
long = document.getElementById("longInput").value;
addr = document.getElementById("addressInput").value;
document.getElementById("nameInput").value = '';
document.getElementById("codeInput").value = '';
document.getElementById("latInput").value = '';
document.getElementById("longInput").value = '';
document.getElementById("addressInput").value = '';
$scope.listings.push({"code":code,"name":name, "coordinates":{"latitude":lat, "longitude":long}, "address":addr});
//$scope.listings = JSON.stringify(list);
};
$scope.deleteListing = function(index) {
$scope.listings.splice(index, 1);
};
$scope.showDetails = function(index) {
var details = $scope.listings[index];
var detailedInfo = '';
detailedInfo += 'Code: ' + details.code;
detailedInfo += '\nName: ' + details.name;
detailedInfo += '\nCoordinates: \n\tLatitude: ' + details.coordinates.latitude + '\n\tLongitude: ' + details.coordinates.longitude;
detailedInfo += '\nAddress: ' + details.address;
$scope.detailedInfo = detailedInfo;
};
$scope.filterSearch = function(){
var input, filter, table, tr, td, i;
input = document.getElementById("searchInput");
filter = input.value.toUpperCase();
table = document.getElementById("myTable");
tr = table.getElementsByTagName("tr");
for (i = 0; i < tr.length; i++) {
td0 = tr[i].getElementsByTagName("td")[0];
td1 = tr[i].getElementsByTagName("td")[1];
if (td0) {
if ((td0.innerHTML.toUpperCase().indexOf(filter) > -1) || (td1.innerHTML.toUpperCase().indexOf(filter) > -1)) {
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
}
}
};
}
]);