|
| 1 | +###global angular:true, google:true ### |
1 | 2 | angular.module('uiGmapgoogle-maps.directives.api.models.parent') |
2 | | -.factory 'uiGmapSearchBoxParentModel', ['uiGmapBaseObject', 'uiGmapLogger', |
3 | | -'uiGmapEventsHelper', '$timeout', '$http', '$templateCache', |
4 | | -(BaseObject, Logger, EventsHelper, $timeout, $http, $templateCache) -> |
5 | | - class SearchBoxParentModel extends BaseObject |
6 | | - @include EventsHelper |
7 | | - constructor: (@scope, @element, @attrs, @gMap, @ctrlPosition, @template, @$log = Logger) -> |
8 | | - unless @attrs.template? |
9 | | - @$log.error 'template attribute for the search-box directive is mandatory. Places Search Box creation aborted!!' |
10 | | - return |
11 | | - |
12 | | - if angular.isUndefined @scope.options |
13 | | - @scope.options = {} |
14 | | - @scope.options.visible = true |
15 | | - |
16 | | - if angular.isUndefined @scope.options.visible |
17 | | - @scope.options.visible = true |
18 | | - |
19 | | - if angular.isUndefined @scope.options.autocomplete |
20 | | - @scope.options.autocomplete = false |
21 | | - |
22 | | - @visible = @scope.options.visible |
23 | | - @autocomplete = @scope.options.autocomplete |
24 | | - |
25 | | - controlDiv = angular.element '<div></div>' |
26 | | - controlDiv.append @template |
27 | | - @input = controlDiv.find('input')[0] |
28 | | - |
29 | | - @init() |
30 | | - |
31 | | - init: => |
32 | | - @createSearchBox() |
33 | | - |
34 | | - @scope.$watch('options', (newValue, oldValue) => |
35 | | - if angular.isObject newValue |
36 | | - if newValue.bounds? |
37 | | - @setBounds(newValue.bounds) |
38 | | - if newValue.visible? |
39 | | - if @visible != newValue.visible |
40 | | - @setVisibility(newValue.visible) |
41 | | - , true) |
42 | | - |
43 | | - if @attrs.parentdiv? |
44 | | - @addToParentDiv() |
45 | | - else |
46 | | - @addAsMapControl() |
47 | | - |
48 | | - if not @visible |
49 | | - @setVisibility(@visible) |
50 | | - |
51 | | - if @autocomplete |
52 | | - @listener = google.maps.event.addListener @gObject, 'place_changed', => |
53 | | - @places = @gObject.getPlace() |
54 | | - else |
55 | | - @listener = google.maps.event.addListener @gObject, 'places_changed', => |
56 | | - @places = @gObject.getPlaces() |
57 | | - |
58 | | - @listeners = @setEvents @gObject, @scope, @scope |
59 | | - @$log.info @ |
60 | | - |
61 | | - @scope.$on '$stateChangeSuccess', => |
62 | | - @addToParentDiv() if @attrs.parentdiv? |
63 | | - |
64 | | - @scope.$on '$destroy', => |
65 | | - @gObject = null |
66 | | - |
67 | | - addAsMapControl: => |
68 | | - @gMap.controls[google.maps.ControlPosition[@ctrlPosition]].push(@input) |
69 | | - |
70 | | - addToParentDiv: => |
71 | | - @parentDiv = angular.element document.getElementById(@scope.parentdiv) |
72 | | - @parentDiv.append @input if !@parentDiv[0]?.firstChild? |
73 | | - |
74 | | - createSearchBox: => |
75 | | - if @autocomplete |
76 | | - @gObject = new google.maps.places.Autocomplete @input, @scope.options |
77 | | - else |
78 | | - @gObject = new google.maps.places.SearchBox @input, @scope.options |
79 | | - |
80 | | - setBounds: (bounds) => |
81 | | - if angular.isUndefined bounds.isEmpty |
82 | | - @$log.error 'Error: SearchBoxParentModel setBounds. Bounds not an instance of LatLngBounds.' |
83 | | - return |
84 | | - else |
85 | | - if bounds.isEmpty() == false |
86 | | - if @gObject? |
87 | | - @gObject.setBounds(bounds) |
88 | | - |
89 | | - getBounds: => |
90 | | - @gObject.getBounds() |
91 | | - |
92 | | - setVisibility: (val) => |
93 | | - if @attrs.parentdiv? |
94 | | - if val == false then @parentDiv.addClass "ng-hide" else @parentDiv.removeClass "ng-hide" |
95 | | - else |
96 | | - if val == false then @gMap.controls[google.maps.ControlPosition[@ctrlPosition]].clear() else @gMap.controls[google.maps.ControlPosition[@ctrlPosition]].push(@input) |
97 | | - @visible = val |
98 | | - |
99 | | - |
100 | | - |
101 | | - SearchBoxParentModel |
| 3 | +.factory 'uiGmapSearchBoxParentModel', [ |
| 4 | + 'uiGmapBaseObject', 'uiGmapLogger','uiGmapEventsHelper', |
| 5 | +(BaseObject, Logger, EventsHelper) -> |
| 6 | + class SearchBoxParentModel extends BaseObject |
| 7 | + @include EventsHelper |
| 8 | + constructor: (@scope, @element, @attrs, @gMap, @ctrlPosition, @template, @$log = Logger) -> |
| 9 | + unless @attrs.template? |
| 10 | + @$log.error 'template attribute for the search-box directive is mandatory. Places Search Box creation aborted!!' |
| 11 | + return |
| 12 | + |
| 13 | + if angular.isUndefined @scope.options |
| 14 | + @scope.options = {} |
| 15 | + @scope.options.visible = true |
| 16 | + |
| 17 | + if angular.isUndefined @scope.options.visible |
| 18 | + @scope.options.visible = true |
| 19 | + |
| 20 | + if angular.isUndefined @scope.options.autocomplete |
| 21 | + @scope.options.autocomplete = false |
| 22 | + |
| 23 | + @visible = @scope.options.visible |
| 24 | + @autocomplete = @scope.options.autocomplete |
| 25 | + |
| 26 | + controlDiv = angular.element '<div></div>' |
| 27 | + controlDiv.append @template |
| 28 | + @input = controlDiv.find('input')[0] |
| 29 | + |
| 30 | + @init() |
| 31 | + |
| 32 | + init: => |
| 33 | + @createSearchBox() |
| 34 | + |
| 35 | + @scope.$watch('options', (newValue, oldValue) => |
| 36 | + if angular.isObject newValue |
| 37 | + if newValue.bounds? |
| 38 | + @setBounds(newValue.bounds) |
| 39 | + if newValue.visible? |
| 40 | + if @visible != newValue.visible |
| 41 | + @setVisibility(newValue.visible) |
| 42 | + , true) |
| 43 | + |
| 44 | + if @attrs.parentdiv? |
| 45 | + @addToParentDiv() |
| 46 | + else |
| 47 | + @addAsMapControl() |
| 48 | + |
| 49 | + if not @visible |
| 50 | + @setVisibility(@visible) |
| 51 | + |
| 52 | + if @autocomplete |
| 53 | + @listener = google.maps.event.addListener @gObject, 'place_changed', => |
| 54 | + @places = @gObject.getPlace() |
| 55 | + else |
| 56 | + @listener = google.maps.event.addListener @gObject, 'places_changed', => |
| 57 | + @places = @gObject.getPlaces() |
| 58 | + |
| 59 | + @listeners = @setEvents @gObject, @scope, @scope |
| 60 | + @$log.info @ |
| 61 | + |
| 62 | + @scope.$on '$stateChangeSuccess', => |
| 63 | + @addToParentDiv() if @attrs.parentdiv? |
| 64 | + |
| 65 | + @scope.$on '$destroy', => |
| 66 | + @gObject = null |
| 67 | + |
| 68 | + addAsMapControl: => |
| 69 | + @gMap.controls[google.maps.ControlPosition[@ctrlPosition]].push(@input) |
| 70 | + |
| 71 | + addToParentDiv: => |
| 72 | + @parentDiv = angular.element document.getElementById(@scope.parentdiv) |
| 73 | + @parentDiv.append @input if @parentDiv?.length |
| 74 | + |
| 75 | + createSearchBox: => |
| 76 | + if @autocomplete |
| 77 | + @gObject = new google.maps.places.Autocomplete @input, @scope.options |
| 78 | + else |
| 79 | + @gObject = new google.maps.places.SearchBox @input, @scope.options |
| 80 | + |
| 81 | + setBounds: (bounds) => |
| 82 | + if angular.isUndefined bounds.isEmpty |
| 83 | + @$log.error 'Error: SearchBoxParentModel setBounds. Bounds not an instance of LatLngBounds.' |
| 84 | + return |
| 85 | + else |
| 86 | + if bounds.isEmpty() == false |
| 87 | + if @gObject? |
| 88 | + @gObject.setBounds(bounds) |
| 89 | + |
| 90 | + getBounds: => |
| 91 | + @gObject.getBounds() |
| 92 | + |
| 93 | + setVisibility: (val) => |
| 94 | + if @attrs.parentdiv? |
| 95 | + if val == false then @parentDiv.addClass "ng-hide" else @parentDiv.removeClass "ng-hide" |
| 96 | + else |
| 97 | + if val == false then @gMap.controls[google.maps.ControlPosition[@ctrlPosition]].clear() else @gMap.controls[google.maps.ControlPosition[@ctrlPosition]].push(@input) |
| 98 | + @visible = val |
| 99 | + |
| 100 | + |
| 101 | + |
| 102 | + SearchBoxParentModel |
102 | 103 | ] |
0 commit comments