PageSourceSearch

https://www.dpdparcelwizard.ie/DesktopModules/Inventise.DPD/spa/co…/pwaAddAddress.directive.js?cdv=177

js dpdparcelwizard.ie collected 2026-10-02 15:37:55 UTC 12,530 bytes, 308 lines download raw bytes

1(function () {
2	'use strict';
3
4	angular.module("pwa.directives")
5		//.run(setupTemplate)
6		.directive('pwaAddAddress', pwaAddAddress);
7
8	pwaAddAddress.$inject = ['$route', 'inUiUtils', 'pwaShared', '$timeout', "$rootScope", "$http", "WebApiUrls", "pwaProfile", "pwaUtils", "inValUtils"];
9	function pwaAddAddress($route, inUiUtils, sharedServices, $timeout, $rootScope, $http, WebApiUrls, pwaProfile, dpdUtils, inValUtils) {
10	    return {
11	        restrict: 'A',
12	        //scope: { regData: '=pwaAddAddress' },
13	        templateUrl: '/ngview.axd?directive=pwaAddAddress',
14	        //controller: function(){
15	        //    var vm = this;
16
17	        //    function init() {
18	        //        alert("initted");
19	        //    }
20
21	        //    init();
22
23	        //},
24	        link: function (scope, element, attrs) {
25
26                //bringing over functions from the add address controller
27	            scope.formVisible = true;
28	            
29
30	            scope.isNullOrEmptyString = function (str) {
31	                if (angular.isString(str) == false) {
32	                    return true;
33	                }
34
35	                str = str.trim();
36
37	                if (str.length == 0) {
38	                    return true;
39	                }
40
41	                return false;
42	            }
43
44	            //set postcode mandatory if NI county selected
45	            scope.$watch("address.addrLine4", function (newVal, oldVal) {
46	                if (newVal === oldVal) {
47	                    return;
48	                }
49	                scope.postcodeMandatory = dpdUtils.isNiCounty(newVal);
50
51	                $(scope.txtPostcode).blur();//once the county changes, force re-validation of postcode
52	            });
53
54
55	            scope.loadMap = function () {
56	                var map = scope.map;
57	                if (!map) {
58	                    var mapOptions = {
59	                        center: new google.maps.LatLng(53.4152431, -8.2390307),//default to Ireland
60	                        zoom: 6
61	                    };
62
63	                    if (scope.isAddressCoordsSet() == true) {
64	                        mapOptions.center = new google.maps.LatLng(scope.address.GPSLat, scope.address.GPSLong);
65	                        mapOptions.zoom = 12;
66	                    }
67
68	                    var canvas = $(".map-canvas")[0];
69
70	                    map = new google.maps.Map(canvas, mapOptions);
71	                    scope.map = map;
72
73	                    var marker = new google.maps.Marker({
74	                        map: map,
75	                        position: mapOptions.center,
76	                        draggable: true
77	                    });
78
79	                    google.maps.event.addListener(marker, "dragend", function (e) {
80	                        var position = marker.getPosition();
81	                        scope.address.GPSLat = position.lat();
82	                        scope.address.GPSLong = position.lng();
83	                    });
84
85	                    scope.marker = marker;
86	                }
87
88	                ////only geocode if address coords aren't set
89	                //if (that.isAddressCoordsSet() == false) {
90	                //    
91	                //}
92
93	                scope.geocodeCurrentAddress();
94	            }
95
96	            
97
98
99	            scope.geocodeCurrentAddress = function () {
100	                var map = scope.map;
101	                var address = scope.isNullOrEmptyString(scope.address.addrLine1) == false ? scope.address.addrLine1 : "";
102	                address += scope.isNullOrEmptyString(scope.address.addrLine2) == false ? ", " + scope.address.addrLine2 : "";
103	                address += scope.isNullOrEmptyString(scope.address.addrLine3) == false ? ", " + scope.address.addrLine3 : "";
104	                address += scope.isNullOrEmptyString(scope.address.addrLine4) == false ? ", " + scope.address.addrLine4 : "";
105	                address += scope.isNullOrEmptyString(scope.address.postcode) == false ? ", " + scope.address.postcode : "";
106
107	                var geocoder = new google.maps.Geocoder();
108	                geocoder.geocode({ 'address': address }, function (results, status) {
109	                    scope.$apply(function (sc) {
110
111	                        if (status == google.maps.GeocoderStatus.OK) {
112	                            map.setCenter(results[0].geometry.location);
113	                            //scope.marker.position = results[0].geometry.location;
114	                            sc.marker.setPosition(results[0].geometry.location);
115
116	                            //update the model
117	                            sc.address.GPSLat = sc.marker.position.lat();
118	                            sc.address.GPSLong = sc.marker.position.lng();
119
120	                            map.setZoom(12);
121
122	                            sc.infoMessage = results[0].formatted_address;
123
124	                        } else if (status == google.maps.GeocoderStatus.ZERO_RESULTS) {
125	                            sc.infoMessage = "Address not found";
126	                        } else if (status == google.maps.GeocoderStatus.OVER_QUERY_LIMIT) {
127	                            sharedServices.logError("EditAddress: google maps: " + status)
128	                        } else if (status == google.maps.GeocoderStatus.REQUEST_DENIED) {
129	                            sharedServices.logError("EditAddress: google maps: " + status)
130	                        } else if (status == google.maps.GeocoderStatus.INVALID_REQUEST) {
131	                            sharedServices.logError("EditAddress: google maps: " + status)
132	                        }
133	                    });
134	                });
135	            }
136
137	            scope.isAddressCoordsSet = function () {
138	                if ((!scope.address.GPSLat || isNaN(scope.address.GPSLat) == true || scope.address.GPSLat == 0) ||
139                        (!scope.address.GPSLong || isNaN(scope.address.GPSLong) == true || scope.address.GPSLong == 0)) {
140	                    return false;
141	                }
142	                return true;
143	            }
144
145	            scope.goBack = function () {
146	                //check if return URL is set and it's not the homepage, if so redirect to that URL.        
147	                if (dpdUtils.getReturnUrl() && dpdUtils.getReturnUrl() != "/") {
148	                    redirectUrl = dpdUtils.getReturnUrl();
149	                    dpdUtils.setReturnUrl();//resetting    
150	                    $location.path(redirectUrl);
151	                } else {
152	                    $location.path(dpdUtils.getNgRelativePath('#/my-addresses'));//AppUrls.addressBook.route
153	                }
154
155	            }
156
157	            scope.getPostcodeValidationData = function () {
158	                return {
159	                    key: "description",
160	                    value: $parse("address.postcode")(scope),
161	                    caption: "postcode",
162	                    dependencies: [{
163	                        key: "county",
164	                        value: $parse("address.addrLine4")(scope),
165	                        caption: "county"
166	                    }]
167	                };
168	            };
169
170	            scope.showMap = function (e) {
171	                if (!dpdUtils.isEnterOrClick(e)) {
172	                    return;
173	                }
174
175	                e.preventDefault();
176
177	                //validate the form before going to the map view
178	                if (inValUtils.isFormValid(scope.registrationForm) == false) {
179	                    return false;
180	                }
181
182	                scope.formVisible = false;
183	                scope.mapVisible = true;
184
185	                //load the map on the next $digest cycle as otherwise it won't be rendered correctly
186	                $timeout(function () { scope.loadMap(); }, 100);
187	            }
188
189	            scope.showForm = function (e) {
190	                if (e) {
191	                    e.preventDefault();
192	                }
193
194	                scope.formVisible = true;
195	                scope.mapVisible = false;
196	            }
197
198
199	            scope.start = function (e) {
200
201	                scope.showForm();
202
203	                dpdUtils.addPostcodeAjaxValidation(scope, scope.getPostcodeValidationData);
204	                dpdUtils.addFirstNameValidationMessageConfig(scope);
205	                dpdUtils.addSurnameValidationMessageConfig(scope);
206
207	                pageLoaded();
208	            }
209
210                //end bringing over functions
211
212
213	            scope.closeWindow = function closeWindow()
214	            {
215	                if ($('#autoOpen').val() > 2) {
216	                    $('#AddAddress').modal('hide');
217	                    $('#VAAddress').modal('show');
218	                } else {
219	                    $('#AddAddress').modal('toggle');
220	                    $rootScope.$broadcast('RefreshData');
221	                }
222	            }
223
224
225
226	            scope.saveAddress = function saveAddress(e) {
227	                if (!dpdUtils.isEnterOrClick(e)) {
228	                    return;
229	                }
230	                	                
231	                e.preventDefault();
232	                e.stopPropagation();
233	                //inUiUtils.showOverlay();
234	                scope.errorMessage = "";
235
236	                if (inValUtils.isFormValid(scope.registrationForm) == false) {
237	                    scope.showForm(e);
238	                    return false;
239	                }
240
241	                if (inValUtils.isFormValid(scope.addressEditMapForm) == false) {
242	                    return false;
243	                }
244
245	                if (scope.isUsingEvents) {
246	                    $emit("addressSelected", scope.address);
247	                } else {
248
249	                    
250	                    inUiUtils.hideOverlay()
251
252	                    scope.address.name = scope.regData.name;
253	                    scope.address.surname = scope.regData.surname;
254	                    scope.address.email = scope.regData.email;
255	                    scope.address.parcelID = scope.regData.parcelId;
256	                    scope.address.mobile = scope.regData.mobile;
257	                    scope.address.title = scope.regData.title;
258	                    scope.address.reference = 'Home';
259	                    scope.address.default = true;
260
261	                    
262
263	                    $http.post(WebApiUrls.addressUpdate, scope.address)
264                             .success(function (data) {
265                                 scope.errorMessage = "";
266                                 var redirectUrl = "";
267
268                                 if (!data.success) {
269                                     scope.errorMessage = (data ? data.message : "");
270                                 } else {
271                                     $rootScope.newAddress = scope.address;
272                                     $rootScope.newAddress.addressID = data.data;
273
274                                     scope.cancel(e);
275                                 }
276
277                             }).error(function (data, status) {
278                                 scope.errorMessage = (data ? data.message : "");
279                             })["finally"](function () {
280                                 inUiUtils.hideOverlay();
281                                 $rootScope.$broadcast('RefreshData');
282
283                                 redirectUrl = dpdUtils.getReturnUrl();
284                                 if (redirectUrl.length > 1) {
285                                     dpdUtils.setReturnUrl();//resetting    
286
287                                     if (!window.location.origin) {
288                                         window.location.origin = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ':' + window.location.port : '');
289                                     }
290
291                                     window.location.replace(window.location.origin + '/#' + redirectUrl);
292                                 }
293
294                             });
295	                }
296	                if ($('#autoOpen').val() > 2) {
297	                    $('#AddAddress').modal('hide');
298	                    $('#VAAddress').modal('show');
299	                } else {
300	                    $('#AddAddress').modal('toggle');
301	                    $rootScope.$broadcast('RefreshData');
302	                }
303	            }
304	        }
305		};
306	}
307
308})();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.