1 |
0bb62f35
|
kohlicekjan
|
angular.module('pvpk')
|
2 |
|
|
.controller('searchController', ['$rootScope', '$scope', '$location', 'config', 'Device', function ($rootScope, $scope, $location, config, Device) {
|
3 |
|
|
this.$onInit = function () {
|
4 |
|
|
$scope.locations = []
|
5 |
|
|
$scope.showSearchLoading = false
|
6 |
|
|
|
7 |
|
|
$rootScope.$emit('setSearchFromUrl', null)
|
8 |
|
|
}
|
9 |
|
|
|
10 |
|
|
$scope.searchLocations = function () {
|
11 |
|
|
var params = $location.search()
|
12 |
|
|
params.q = $scope.search.q
|
13 |
|
|
params.isDirection = $scope.search.isDirection ? 1 : null
|
14 |
|
|
$location.search(params)
|
15 |
|
|
|
16 |
|
|
if (!$scope.search.q || $scope.search.q.length <= 1) {
|
17 |
|
|
$scope.locations = []
|
18 |
|
|
return
|
19 |
|
|
}
|
20 |
|
|
|
21 |
|
|
$scope.showSearchLoading = true
|
22 |
|
|
|
23 |
|
|
Device.query({
|
24 |
|
|
address: $scope.search.q,
|
25 |
|
|
showDirection: $scope.search.isDirection ? 1 : 0
|
26 |
|
|
}).$promise.then(function (dataResponse) {
|
27 |
|
|
$scope.locations = dataResponse
|
28 |
|
|
$scope.showSearchLoading = false
|
29 |
|
|
}, function (response) {
|
30 |
|
|
$scope.showSearchLoading = false
|
31 |
|
|
})
|
32 |
|
|
}
|
33 |
|
|
|
34 |
|
|
$rootScope.$on('setSearchFromUrl', function (event, args) {
|
35 |
|
|
var params = $location.search()
|
36 |
|
|
$scope.search = {
|
37 |
|
|
q: params.q,
|
38 |
|
|
isDirection: params.isDirection ? !!+params.isDirection : false
|
39 |
|
|
}
|
40 |
|
|
$scope.searchLocations()
|
41 |
|
|
})
|
42 |
|
|
|
43 |
|
|
$scope.selectDevice = function (id, direction) {
|
44 |
|
|
$rootScope.$emit('activeMarker', { id: id })
|
45 |
|
|
$rootScope.$emit('infoLocation', { id: id, direction: direction })
|
46 |
|
|
}
|
47 |
|
|
}])
|