PageSourceSearch

https://campinsco.com/resources/assets/themes/asset-common-files/c…/ourlistingscontroller.js?v=1789109828

js campinsco.com collected 2026-10-09 23:20:11 UTC 204,833 bytes, 4,400 lines download raw bytes

1"use strict";
2
3angular
4    .module("dpiApp")
5    .controller(
6        "OurListingsController",
7        function (
8            $scope,
9            $timeout,
10            $http,
11            configService,
12            $rootScope,
13            $location,
14            $route,
15            $routeParams,
16            $localStorage,
17            $window,
18            location,
19            BookingService, // for slot booking
20            $compile, // for slot booking
21            polygonFilter
22        ) {
23            $scope.member_details = {};
24            $scope.search_by_polygon = 0;
25            $rootScope.using_saved_zip = true; //use it skip saved search zip if user enter in location
26            $rootScope.ignore_watcher = false;
27            $scope.is_coming_from_home = 0;
28            $scope.shareMail = { subject: "", msg: "" };
29            $scope.show_advanced_text = "Show Advanced Search";
30            $scope.page_heading = "";
31            $scope.userid = isNaN(current_theme) ? user_id : current_theme;
32            $scope.mls_ids = mls_ids != undefined ? mls_ids : [];
33            $scope.show_default = 1; // For default website show  default list
34            $scope.property_list = {};
35            $scope.recordLimit = 20;
36            $scope.currentPage = 1;
37            $scope.newCurrentPage = 1;
38            $scope.property_found = 0;
39            $scope.visible_property_found = 0;
40            $scope.totalItemsProp = 0;
41            $scope.search_but_show_hide = 1;
42            $scope.fb_button_visible = 0; // Facebook Share button
43            $scope.visited = {};
44            $scope.search = {};
45            $scope.bedrating = 0;
46            $scope.bathrating = 0;
47            $scope.search.property_type = "";
48            $scope.property_types_array = [];
49            $scope.pageChanged = false;
50            $scope.propertyTypeDropdownText = "";
51            $scope.nextPropertyMl = null;
52            $scope.previousPropertyMl = null;
53            // Modal close with route handling
54            $scope.goingToLogin = false;
55            //$scope.search.min_price = '150000'; // For V2 Release no default search is required as per client thats why commented and set those fields value ='' below
56            //$scope.search.max_price = '500000'; // For V2 Release no default search is required as per client thats why commented and set those fields value ='' below
57            $scope.search.min_price = "";
58            $scope.search.max_price = "";
59            $scope.search_listing_sort = "listprice_asc";
60            $rootScope.our_listing_page_sort = "listprice_asc";
61            $scope.sethbaths = {};
62            $scope.all_bound = {}; // lat lng boundary
63            $scope.front_spinner = 0;
64            $scope.search_loader = 0;
65            $scope.advance_open = 0;
66            $scope.fivehundred_msg_status = 0;
67            $scope.property_ml_id = $routeParams.property_ml_id;
68            $scope.latitude = 27.6648;
69            $scope.longitude = -81.5158;
70            $scope.address = "";
71            $scope.filter_data = {};
72            $scope.furnished_active =
73                $scope.water_front_active =
74                $scope.water_access_active =
75                $scope.view_active =
76                $scope.pool_active =
77                $scope.pet_active =
78                $scope.hbaths_active =
79                $scope.complex_name_active =
80                $scope.subdivision_name_active =
81                $scope.development_name_active =
82                $scope.county_active =
83                $scope.zip_code_active =
84                $scope.foreclosure_active =
85                $scope.short_sale_active =
86                "";
87            $scope.hopa = "";
88            $scope.advanced_search = {};
89            $scope.optionsFromQuery = []; // Filter Value array
90            $scope.show_loader = 1; // Search property loader
91            $scope.searchLoaderCount = 0;
92            $scope.sqft_footage_active = "";
93            $scope.polygoncount = 0;
94            $scope.modal_loader = 1; // Modal Pop up loader
95            $scope.price_view_value = "Enter Price";
96            $scope.hitsavedsearch = 0;
97            $scope.copyright = Date.now();
98            $scope.priceRanges = [
99                0, 100000, 200000, 300000, 400000, 500000, 600000, 700000, 800000,
100                900000, 1000000, 1250000, 1500000, 1750000, 2000000, 2250000, 2500000,
101                2750000,
102            ];
103            $scope.priceRangesLabel = [
104                "$0",
105                "100,000",
106                "$200,000",
107                "$300,000",
108                "$400,000",
109                "$500,000",
110                "$600,000",
111                "$700,000",
112                "$800,000",
113                "$900,000",
114                "$1M",
115                "$1.25M",
116                "$1.5M",
117                "$1.75M",
118                "$2M",
119                "$2.25M",
120                "$2.5M",
121                "$2.75M",
122            ];
123            $scope.minSelectedIndex = 0;
124            $scope.maxSelectedIndex = 0;
125            $scope.priceMinLimitStart = 0;
126            $scope.priceMinLimitTotal = 10;
127            $scope.priceMaxLimitTotal = 10;
128            $scope.showMinPriceList = true;
129            $scope.showMaxPriceList = false;
130            $scope.realtorMedias = [];
131            $scope.realtorSlides = [];
132            $scope.slideDescription = "";
133            $scope.activeFolderSlide = null;
134            $scope.activeFileSlide = null;
135            $scope.menu_id =
136                typeof $routeParams.menu_id == "undefined" ? 2 : $routeParams.menu_id;
137            $scope.searchCondition = "";
138            $scope.quickSearchCalled = false;
139
140            // Image category search
141            $scope.image_category = "";
142            $rootScope.image_category = "";
143            $scope.image_category_options = [];
144            $scope.fetchImageCategories = function() {
145                var httpRequest = $http({
146                    method: "POST",
147                    url: base_url + "/shared/image-categories",
148                }).success(function (data, status) {
149                    $scope.image_category_options = data.image_categories;
150                }).error(function (data, status) {
151                    console.error(data);
152                });
153            }
154
155            $scope.fetchImageCategories();
156
157            // Property Details Map
158            $scope.mapLoaded = false;
159
160            $scope.captchaRegistry = {};
161            // $scope.selectedBedRating = 0;
162
163            // PIT for pagination
164            $scope.pit = {};
165            $scope.propertyDetailsFetching = true;
166            $scope.property_det = {};
167            $scope.callingSearchProperty = false;
168
169            $scope.request = {};
170
171            $scope.relatedPropertiesLoaded = false;
172            $scope.makeToFavClicked = false;
173            $scope.hasPolygon = false;
174            $scope.localBedRating = 0;
175            $scope.localBathRating = 0;
176            $scope.localHbathRating = 0;
177            // $rootScope.firstSearchLoading = true;
178            $rootScope.advanceSearchWatcherEnabled = true;
179            $scope.bedStarRating = 4;
180            $scope.bathStarRating = 4;
181            $scope.hBathStarRating = 4;
182            $scope.resetFilterTimeThreshold = 30; // In minutes
183
184            $scope.page_name = $rootScope.page_name;
185            $scope.menu_id = $rootScope.menu_id;
186            $scope.criteria_id = $rootScope.criteria_id;
187
188            /****** Get Current Route Name ******/
189            $scope.location = $location.path();
190            $scope.routeName = $route.current.$$route.name;
191
192            $scope.currentRoute = $scope.routeName;
193            $scope.markerPopupOpened = false;
194
195            // Sorting
196            $scope.sortingSet = false;
197            // get specific parts of the URL like search parameters
198            var searchParamsUrlCopy = $location.search();
199            // Check if searchParams is an empty object
200            var isEmpty =
201                Object.keys(searchParamsUrlCopy).length === 0 &&
202                searchParamsUrlCopy.constructor === Object;
203
204
205
206            $scope.$on("$locationChangeStart", function (event, next, current) {
207
208
209
210
211
212                const urlString = current;
213                const searchTerm = "property-details";
214                var browserUrl = window.location.href;
215
216                if (urlString.includes(searchTerm)) {
217                    $rootScope.doNotCallZipCode = true;
218
219                } else {
220                    $rootScope.doNotCallZipCode = false;
221
222                    if (
223                        browserUrl.includes("11/search/11") &&
224                        !urlString.includes("11/search/11")
225                    ) {
226
227                        //$window.location.href = current; // Change the URL to the specified one
228                        // Extract path from the full URL
229                        var path = new URL(current).pathname;
230                        $timeout(function () {
231                            $location.path(path); // Redirect to the specified partial path
232                        }, 100); // Delay in milliseconds
233                    }
234                }
235            });
236
237            $scope.setSortOrder = function () {
238                var agent_id = $scope.userid;
239                var httpRequest = $http({
240                    method: "POST",
241                    url: base_url + "/firsthometheme/get-agent-details",
242                    data: {
243                        agent_id: agent_id,
244                    },
245                }).success(function (data, status) {
246                    $scope.agentDetails = data.agent_details;
247
248                    $rootScope.our_listing_page_sort = $scope.agentDetails.our_listing_page_sort;
249
250
251                    $scope.search_listing_sort = $rootScope.our_listing_page_sort;
252
253                    $scope.sortingSet = true;
254
255                    // Replay with the arguments the dropped call was made with,
256                    // so a polygon drawn before this returned is not lost.
257                    if ($scope.pendingSearchArgs) {
258                        var pending = $scope.pendingSearchArgs;
259                        $scope.pendingSearchArgs = null;
260                        $scope.searchProperty(pending[0], pending[1], pending[2]);
261                    } else if ($scope.callingSearchProperty) {
262                        $scope.searchProperty();
263                    }
264                });
265            };
266            $scope.setSortOrder();
267
268            // Load map in property details page/modal
269            $scope.loadMap = function () {
270                if ($scope.mapLoaded) return;
271                // optional guard if lat/lng missing:
272                // if (!$scope.property_det || !$scope.property_det.lat || !$scope.property_det.lng) return;
273                try {
274                    initMap();
275                    $scope.mapLoaded = true;
276                } catch (e) {
277                    // keep placeholder visible if initMap fails
278                    $scope.mapLoaded = false;
279                    // optionally console.log(e);
280                }
281            };
282
283            $scope.registerCaptcha = function(formName, refreshFn, loadFn) {
284                $scope.captchaRegistry[formName] = { refresh: refreshFn, load: loadFn };
285            };
286            
287            $scope.reloadAllCaptchas = function() {
288                angular.forEach($scope.captchaRegistry, function(captcha) {
289                    if (captcha.load) captcha.load();
290                });
291            };
292
293            // Form Submit handler
294            $scope.initForm = function (formId, param, reloadCaptchas = true) {
295                if (reloadCaptchas) {
296                    $scope.reloadAllCaptchas();
297                }
298                // Reset the form
299                $scope.resetJsForm(formId);
300                var form = document.getElementById(formId);
301                if (!form) return;
302
303                var isValid = true;
304            }
305
306            $scope.resetPropertyDetailBookingState = function () {
307                $scope.resetJsForm("expertForm");
308                $scope.resetJsForm("adviceForm");
309                $scope.resetJsForm("requestForm");
310
311                if (BookingService && angular.isFunction(BookingService.resetUiState)) {
312                    BookingService.resetUiState();
313                }
314                $rootScope.$broadcast('slotBooking:resetUi');
315            }
316
317            $scope.resetJsForm = function (formId) {
318                var form = document.getElementById(formId);
319                
320                if (!form) return;
321
322                // Remove booking CTA inserted after a previous successful form submit.
323                var bookingContainer = form.querySelector('.slot-booking-container');
324                if (bookingContainer && bookingContainer.parentNode) {
325                    bookingContainer.parentNode.removeChild(bookingContainer);
326                }
327
328                // 1. Reset the form
329                form.reset();
330
331                // Repopulate logged user's email
332                var emailField = form.querySelector("[logged-user-email]");
333
334                if (emailField) {
335
336                    var fn = angular.element(emailField).data("populateLoggedUserEmail");
337
338                    if (fn) {
339                        fn();
340                    }
341
342                }
343
344                // 2. Hide all error messages
345                form.querySelectorAll('.error').forEach(el => {
346                    el.style.display = 'none';
347                });
348
349                // 3. Clear message text
350                const msg = form.querySelector('.form-message');
351                if (msg) msg.innerText = '';
352
353                // 4. OPTIONAL: reset Angular scope (important for your setup)
354                const scope = angular.element(form).scope();
355                if (scope) {
356                    scope.$applyAsync(() => {
357                        scope.contact = {};
358
359                        // reset captcha if exists
360                        if (scope.captchaRegistry && scope.captchaRegistry['buyer']) {
361                            scope.captchaRegistry['buyer'].refresh();
362                        }
363                    });
364                }
365            }
366
367            function validateEmail(email) {
368                const regex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
369                return regex.test(email);
370            }
371
372            $scope.submitJsForm = function (formId, param) {
373                var form = document.getElementById(formId);
374                if (!form) return;
375                var isValid = true;
376                // reset errors
377                form.querySelectorAll(".error").forEach(el => el.style.display = "none");
378
379                // validation
380                if (!form.name.value.trim()) {
381                    form.querySelector(".name-error").style.display = "block";
382                    isValid = false;
383                }
384
385                if (!form.email.value.trim()) {
386                    form.querySelector(".email-error").style.display = "block";
387                    isValid = false;
388                }
389
390                if (!form.msg.value.trim()) {
391                    form.querySelector(".msg-error").style.display = "block";
392                    isValid = false;
393                }
394
395                // phone regex
396                var phone = form.phone.value.trim();
397                // var regex = /^$|^([\+][0-9]{1,3}[ \.\-])?([\(]{1}[0-9]{2,6}[\)])?([0-9 \.\-\/]{3,20})((x|ext|extension)[ ]?[0-9]{1,4})?$/;
398                // To accept em-dashes
399                var regex = /^$|^([\+][0-9]{1,3}[ \.\-–—])?([\(]{1}[0-9]{2,6}[\)])?([0-9 \.\-–—\/]{3,20})((x|ext|extension)[ ]?[0-9]{1,4})?$/;
400
401                if (phone && !regex.test(phone)) {
402                    form.querySelector(".phone-error").style.display = "block";
403                    isValid = false;
404                }
405                // Phone number should be greater than or equal to 10 digits
406                if (phone && phone.length < 10) {
407                    form.querySelector(".phone-error").style.display = "block";
408                    isValid = false;
409                }
410
411                if (!validateEmail(form.email.value)) {
412                    form.querySelector(".email-error").innerHTML = "Invalid email address";
413                    form.querySelector(".email-error").style.display = "block";
414                    isValid = false;
415                }
416
417                if (!isValid) return;
418
419                var scope = $scope;
420
421                var captchaObj = scope.request &&
422                    scope.request.captcha &&
423                    scope.request.captcha[param];
424
425                if (!captchaObj || !captchaObj.value) {
426                    alert("Please enter captcha");
427                    return;
428                }
429
430                var payload = {
431                    request: {
432                        name: form.name.value,
433                        phone: form.phone.value,
434                        email: form.email.value,
435                        msg: form.msg.value,
436                        captcha: {
437                            id: captchaObj.id,
438                            value: captchaObj.value
439                        }
440                    },
441                    member_id: user_id,
442                    param: param,
443                    property_url: window.location.href
444                };
445
446                fetch(base_url + "/firsthometheme/send-request-mail", {
447                    method: "POST",
448                    headers: { "Content-Type": "application/json" },
449                    body: JSON.stringify(payload)
450                })
451                    .then(res => res.json())
452                    .then(function (data) {
453
454                        if (data.success == 1) {
455
456                            // Fire custom event for successful form submission
457                            window.dispatchEvent(new CustomEvent("dpi:formSubmitSuccess", {
458                                detail: {
459                                    formId: formId,
460                                    param: param,
461                                    data: data
462                                }
463                            }));
464
465                            // Same as contact_me setupBookingAfterContact()
466                            BookingService.setInitialData({
467                                member_id: user_id   // same as contact_me; or use $scope.userid
468                            });
469                            BookingService.setAfterContact(data);
470                            var hasBooking = BookingService.isBookingLinkVisible();
471                            var messageEl = form.querySelector(".form-message");
472                            if(formId == 'adviceForm' || formId == 'requestForm') {
473                                messageEl.innerHTML =
474                                    "<span style='color:green'>Your query has been sent successfully. We will contact you soon.</span>";
475                            } else {
476                                messageEl.innerHTML =
477                                    "<span style='color:white'>Your query has been sent successfully. We will contact you soon.</span>";
478                            }
479                            // Only show slot-booking when client booking info exists (same as contact_me)
480                            var existing = form.querySelector('.slot-booking-container');
481                            if (existing) {
482                                existing.parentNode.removeChild(existing);
483                            }
484                            if (hasBooking) {
485                                var slotAttrs = 'member-details="member_details"';
486                                if (formId === 'adviceForm' || formId === 'requestForm') {
487                                    slotAttrs += ' close-parent-modal-on-open="true"';
488                                }
489                                if (formId === 'expertForm') {
490                                    slotAttrs += ' append-modal-to-body="true" book-button-dark="true" banner-highlight="false" banner-center-align="false"';
491                                }
492                                var el = angular.element('<div class="slot-booking-container"><slot-booking ' + slotAttrs + '></slot-booking></div>');
493                                messageEl.parentNode.insertBefore(el[0], messageEl.nextSibling);
494                                $compile(el)($scope);
495
496                                $scope.$applyAsync(); // Apply the changes to the scope so the directive renders correctly
497                            }
498                            
499                            // log the user in
500                            $rootScope.is_front_logged = 1;
501                            localStorage.setItem("usr_info", data.usr_info);
502                            localStorage.setItem("access_token", data.token);
503
504                            $rootScope.refreshLoggedUser();
505                            
506                            var client_details = [];
507                            client_details = $scope.loggedUserDetails();
508                            $rootScope.logged_user_id = client_details[0];
509                            $rootScope.logged_user_name = client_details[1];
510
511                            //
512                            // if (scope.reloadAllCaptchas) {
513                            //    scope.reloadAllCaptchas();
514                            // }
515
516                            form.reset();
517
518                            // Repopulate email
519                            var emailField = form.querySelector("[logged-user-email]");
520
521                            if (emailField) {
522
523                                var fn = angular.element(emailField).data("populateLoggedUserEmail");
524
525                                if (fn) {
526                                    fn();
527                                }
528
529                            }
530
531                            // Hide form successfully message after 2 seconds
532                            setTimeout(function () {
533                                form.querySelector(".form-message").innerHTML = "";
534                            }, 10000);
535
536                        } else {
537                            form.querySelector(".form-message").innerHTML =
538                                "<span style='color:red'>" + (data.message || "Error") + "</span>";
539                        }
540                        $scope.reloadAllCaptchas();
541                        scope.$apply();
542
543                    })
544                    .catch(function (error) {
545                        // Log the error
546                        console.error(error);
547                        form.querySelector(".form-message").innerHTML =
548                            "<span style='color:red'>Some error occurred</span>";
549
550                    });
551            }
552
553            // Reset filters based on time
554            $scope.resetFilterBasedOnTime = function () {
555                const timeNow = Date.now(); // In milliseconds
556                const filterExpirationTime =
557                    $localStorage.filter_expiration_time != undefined
558                        ? $localStorage.filter_expiration_time
559                        : 0;
560                // 
561                if (
562                    filterExpirationTime != 0 &&
563                    filterExpirationTime <= timeNow &&
564                    $localStorage.agent_zip_search != undefined
565                ) {
566                    // Call reset search if agent zip code is not undefined
567                    // 
568                    $scope.resetSearch();
569                }
570            };
571
572            // Hide if any modal backdrop still remains on page load
573            $scope.hideModalBackdrop = function () {
574                jQuery(".modal-backdrop").hide();
575            };
576            $scope.hideModalBackdrop();
577
578            $scope.getSelectedBed = function (bedrating, sp) {
579                $scope.bedrating = bedrating;
580                $scope.advanced_search.bedrooms = $scope.bedrating;
581
582                if (!sp) {
583                    $scope.callingSearchProperty = true;
584                    $scope.searchProperty($localStorage.our_listing_search_params, $scope.all_bound);
585                }
586            };
587
588            // Set $scope variables based on $localStorage
589            $scope.setScopeVariablesBasedOnLocalStorage = function () {
590                if (!$scope.sortingSet) {
591                    return;
592                }
593                var allBound = $scope.all_bound;
594
595
596                if (
597                    $localStorage.our_listing_search_params != undefined &&
598                    $localStorage.our_listing_search_params != ""
599                ) {
600                    var localStorageSearchParams = JSON.parse(
601                        $localStorage.our_listing_search_params
602                    );
603                    // 
604                    // 
605                    $scope.search.property_type =
606                        localStorageSearchParams.property_type != undefined
607                            ? localStorageSearchParams.property_type
608                            : "";
609                    $scope.property_types_array =
610                        localStorageSearchParams.property_types != undefined
611                            ? localStorageSearchParams.property_types
612                            : [];
613                    $scope.search.min_price =
614                        localStorageSearchParams.min_price != undefined
615                            ? localStorageSearchParams.min_price
616                            : "";
617                    $scope.search.max_price =
618                        localStorageSearchParams.max_price != undefined
619                            ? localStorageSearchParams.max_price
620                            : "";
621                    // $scope.search_listing_sort =
622                    //     localStorageSearchParams.search_listing_sort != undefined
623                    //         ? localStorageSearchParams.search_listing_sort
624                    //         : "listprice_asc";
625                    $scope.search_listing_sort =
626                        localStorageSearchParams.search_listing_sort != undefined
627                            ? localStorageSearchParams.search_listing_sort
628                            : $rootScope.our_listing_page_sort;
629                    $scope.image_category =
630                        localStorageSearchParams.image_category != undefined
631                        ? localStorageSearchParams.image_category
632                        : "";
633                    $scope.bedrating =
634                        localStorageSearchParams.bedroom != undefined
635                            ? localStorageSearchParams.bedroom
636                            : 0;
637                    $scope.localBedRating =
638                        localStorageSearchParams.bedroom != undefined
639                            ? localStorageSearchParams.bedroom
640                            : 0;
641                    $scope.bathrating =
642                        localStorageSearchParams.bathroom != undefined
643                            ? localStorageSearchParams.bathroom
644                            : 0;
645                    $scope.localBathRating =
646                        localStorageSearchParams.bathroom != undefined
647                            ? localStorageSearchParams.bathroom
648                            : 0;
649                    $scope.recordLimit =
650                        localStorageSearchParams.limit != undefined
651                            ? localStorageSearchParams.limit
652                            : 20;
653                    $scope.currentPage =
654                        localStorageSearchParams.page != undefined
655                            ? localStorageSearchParams.page
656                            : 1;
657                    $scope.all_bound =
658                        localStorageSearchParams.all_bound != undefined
659                            ? localStorageSearchParams.all_bound
660                            : {};
661                    // Restore the polygon too, otherwise after a refresh the
662                    // view's hasNoPolygon() (which reads $scope) and the
663                    // controller's endpoint choice (which reads $rootScope)
664                    // disagree about whether a polygon is active.
665                    $scope.polygon_lat_long =
666                        localStorageSearchParams.polygon_lat_long != undefined
667                            ? localStorageSearchParams.polygon_lat_long
668                            : "";
669                    $rootScope.polygon_lat_long =
670                        localStorageSearchParams.polygon_lat_long != undefined
671                            ? JSON.stringify(localStorageSearchParams.polygon_lat_long)
672                            : "";
673                    $scope.advanced_search =
674                        localStorageSearchParams.advance_search != undefined
675                            ? localStorageSearchParams.advance_search
676                            : {};
677                    // $scope.bedrating =
678                    //   $scope.advanced_search.bedrooms != undefined
679                    //     ? $scope.advanced_search.bedrooms
680                    //     : 0;
681                    // $scope.bathrating =
682                    //   $scope.advanced_search.bathrooms != undefined
683                    //     ? $scope.advanced_search.bathrooms
684                    //     : 0;
685                    $scope.localHBathRating =
686                        $scope.advanced_search.hbaths != undefined
687                            ? $scope.advanced_search.hbaths
688                            : 0;
689                    $scope.pit =
690                        localStorageSearchParams.pit != undefined
691                            ? localStorageSearchParams.pit
692                            : {};
693                    // 
694                    // 
695                }
696            };
697
698
699            $scope.bedRatingClicked = function (rating) {
700                $scope.bedrating = rating;
701                $scope.advanced_search.bedrooms = $scope.bedrating;
702                jQuery("#bed-star-rating").trigger("click.bs.dropdown");
703            };
704            $scope.bathRatingClicked = function (rating) {
705                $scope.bathrating = rating;
706                $scope.advanced_search.bathrooms = $scope.bathrating;
707                jQuery("#bath-star-rating").trigger("click.bs.dropdown");
708            };
709
710            // $modalInstance.opened.then(function () {
711            //     $state.go(newPath);
712            // });
713            // $modalInstance.result.then(null, function () {
714            //     $state.go(oldPath);
715            // });
716            $scope.$on("$stateChangeSuccess", function () {
717                if ($state.current.name != newPath) {
718                    $modalInstance.dismiss("cancel");
719                }
720            });
721
722            $scope.showPropertyBasedOnMl = function (ml) {
723                // Close the opened modal
724                // jQuery('#propertyProjectDetailModal').modal('hide');
725
726                // Show the property
727                $scope.fetchPropertyDetails(ml);
728            };
729
730            $scope.fetchRelatedProperties = function (ml) {
731                // jQuery('#propertyProjectDetailModal').on('hidden.bs.modal', function () {
732                //     
733                //     $scope.propertyDetailsFetching = false;
734                //     $scope.front_spinner = 0;
735                //     $location.path('/11/search/11', false);
736                //     return;
737                // });
738                // 
739                $scope.relatedPropertiesLoaded = false;
740                var token = localStorage.getItem("access_token"); // If login
741
742                if ($localStorage.our_listing_search_params) {
743                    var search_params = JSON.parse($localStorage.our_listing_search_params);
744                } else {
745                    var search_params = "";
746                }
747
748                var httpRequest = $http({
749                    method: "POST",
750                    // url: base_url + '/firsthometheme/property-details-new',
751                    url: base_url + "/shared/fetch-related-properties",
752                    data: {
753                        property_ml_id: $scope.property_ml_id,
754                        member_id: $scope.userid,
755                        search_params: search_params,
756                    },
757                    headers: {
758                        "Content-Type": "application/json; charset=utf-8",
759                        "Access-Token": token,
760                    },
761                    // ignoreLoadingBar: true
762                }).success(function (data, status) {
763                    $scope.relatedPropertiesLoaded = true;
764                    if (data.related_properties.length === 0) {
765                        // $scope.has_property = 0;
766                        $scope.allRelatedProperty = [];
767                    } else {
768                        $scope.allRelatedProperty = data.related_properties;
769                    }
770                    setTimeout(function () {
771                        // ProjectGallery();
772                        // projectDetailImgVideoSwiperSlider();
773                        // ImageFitCont();
774                        relatedPropertiesSlider();
775                    }, 1000);
776                    setTimeout(function () {
777                        $scope.fixCssBackgoundImageDoubleEncodingIssue();
778                    }, 500);
779                });
780            };
781
782            // $scope.fetchPropertyDetails = function (ml) {
783            //     // $scope.front_spinner = 1;
784
785            //     // Show modal route
786            //     const propertyDetailUrl = "/property-details-2/" + ml;
787            //     
788            //     window.history.pushState("object or string", "Title", propertyDetailUrl);
789            // }
790
791            $scope.fetchPropertyDetails = function (ml) {
792                // Reset map loaded flag
793                $scope.mapLoaded = false;
794                // Change path on modal close
795                if ($scope.makeToFavClicked == true) {
796                    return;
797                }
798                $scope.resetPropertyDetailBookingState();
799                const userName = $scope.agentDetails.user_name;
800                const browserUrl = window.location.href;
801                const urlParts = browserUrl.split('/');
802                if (urlParts[3] == userName) {
803                    history.pushState({}, "", window.location.origin + '/' + userName + '/property-details/' + ml);
804                } else {
805                    history.pushState({}, "", window.location.origin + '/property-details/' + ml);
806                }
807                jQuery("#propertyProjectDetailModal").on(
808                    "hidden.bs.modal",
809                    function () {
810                        // Reset map loaded flag
811                        $scope.mapLoaded = false;
812                        $scope.propertyDetailsFetching = false;
813                        $rootScope.propertyDetailsModalClosed = true;
814                        $scope.front_spinner = 0;
815                        $scope.resetPropertyDetailBookingState();
816                        if ($scope.goingToLogin == false) {
817                            // $location.path('/11/search/11', false);
818                            // Making dynamic /11/search/11 & /11/search-property/11
819                            if ($scope.routeName == "mylisting") {
820                                var searchUrl = "/our_listings";
821                            } else if ($scope.routeName == "my_listings") {
822                                var searchUrl = "/my_listings";
823                            } else {
824                                var searchUrl =
825                                    "/11/" + $routeParams.page_name + "/" + $routeParams.menu_id;
826                            }
827                            location.skipReload().path(searchUrl).replace();
828                            // Relative path
829                            var relativePath = searchUrl;
830
831                            // Combine with current domain
832                            if (urlParts[3] == userName) {
833                                var newUrl = window.location.origin + '/' + userName + relativePath;
834                            } else {
835                                var newUrl = window.location.origin + relativePath;
836                            }
837
838
839                            // Push the new URL to the browser history
840                            history.pushState({}, "", newUrl);
841                        } else {
842                            $scope.goingToLogin == false;
843                        }
844                        // window.history.pushState("object or string", "Search Page Title", '/11/search/11');
845                        return;
846                    }
847                );
848
849                // Add event listener to the form modal close
850                jQuery("#contactAgent").on(
851                    "hidden.bs.modal",
852                    function () {
853                        $scope.resetJsForm("adviceForm");
854                    }
855                );
856                jQuery("#requestShowing").on(
857                    "hidden.bs.modal",
858                    function () {
859                        $scope.resetJsForm("requestForm");
860                    }
861                );
862                $scope.front_spinner = 1;
863                $scope.propertyDetailsFetching = true;
864                // $scope.propertyDetailsFetching = true;
865
866                // Change route
867                // 
868                $location.path("/property-details/" + ml, false);
869
870                // Show the modal
871                jQuery("#propertyProjectDetailModal").on(
872                    "shown.bs.modal",
873                    function (e) {
874                        // Reload all captchas
875                        // $scope.reloadAllCaptchas();
876                        $scope.initForm("expertForm", "expert", true);
877                        $scope.initForm("adviceForm", "advice", false);
878                        $scope.initForm("requestForm", "request", false);
879                        // 
880                        // jQuery('#propertyProjectDetailModal .modal-body').mCustomScrollbar("scrollTo", ".propertyProjectDetail-content-wrap");
881                        jQuery(
882                            "#propertyProjectDetailModal .modal-body"
883                        ).mCustomScrollbar();
884
885                        // Scroll to top
886                        // $('#propertyProjectDetailModal').animate({ scrollTop: 0 }, 'fast');
887                    }
888                );
889
890                jQuery("#propertyProjectDetailModal").modal();
891
892                $scope.property_ml_id = ml;
893                var fb_app_id = $rootScope.fb_app_id;
894
895                // Find previous and next index
896                const mlIndex = $rootScope.propertyMlsIds.indexOf(ml);
897
898
899                if (mlIndex == -1) {
900                    $scope.previousPropertyMl = null;
901                    $scope.nextPropertyMl = null;
902                } else {
903                    if (mlIndex > 0) {
904                        $scope.previousPropertyMl = $rootScope.propertyMlsIds[mlIndex - 1];
905                    } else {
906                        $scope.previousPropertyMl = null;
907                    }
908                    if (mlIndex + 1 < $rootScope.propertyMlsIds.length) {
909                        $scope.nextPropertyMl = $rootScope.propertyMlsIds[mlIndex + 1];
910                    } else {
911                        $scope.nextPropertyMl = null;
912                    }
913                }
914
915                // IF FACEBOOK APP ID  NOT  PUTED FACEBOOK SHARE NOT VISIBLE BUTTON START//
916                if (fb_app_id != "") {
917                    $scope.fb_button_visible = 1;
918                }
919                // IF FACEBOOK APP ID  NOT  PUTED FACEBOOK SHARE NOT VISIBLE BUTTON END//
920
921                var token = localStorage.getItem("access_token"); // If login
922                if ($localStorage.our_listing_search_params) {
923                    var search_params = JSON.parse($localStorage.our_listing_search_params);
924                } else {
925                    var search_params = "";
926                }
927
928                var $httpRequest = $http({
929                    method: "POST",
930                    // url: base_url + '/firsthometheme/property-details-updated',
931                    url: base_url + "/shared/property-details",
932                    data: {
933                        property_ml_id: $scope.property_ml_id,
934                        member_id: $scope.userid,
935                        search_params: search_params,
936                    },
937                    headers: {
938                        "Content-Type": "application/json; charset=utf-8",
939                        "Access-Token": token,
940                    },
941                }).success(function (data, status) {
942                    $scope.front_spinner = 0;
943                    $rootScope.propertyDetailsModalClosed = false;
944                    if (data.property_det.length === 0) {
945                        $scope.has_property = 0;
946                    } else {
947                        $scope.last_update_corn_time = data.last_update_corn_time;
948                        // if ($localStorage.mls_id) {
949                        //     var storeMlsIds = JSON.parse($localStorage.mls_id);
950                        //     var indexofMlsId = storeMlsIds.indexOf($scope.property_ml_id);
951                        //     if (indexofMlsId > -1) {
952                        //         $rootScope.all_property_search_list = storeMlsIds;
953                        //         $rootScope.currentPropertyIndex = indexofMlsId;
954                        //     }
955                        // }
956                        $scope.property_det = data.property_det;
957                        // Set shareMail subject and message
958                        let propertyUrl =
959                            base_url + "/property-details/" + $scope.property_det.ml;
960                        $scope.shareMail["msg"] = "Check out this property " + propertyUrl;
961                        $scope.shareMail["subject"] =
962                            $scope.property_det.address +
963                            "-" +
964                            $scope.property_det.city_name +
965                            ", " +
966                            $scope.property_det.state +
967                            ", " +
968                            $scope.property_det.zip_code;
969
970                        $scope.allRelatedProperty = [];
971                        $scope.has_property = 1;
972                        
973                        $scope.property_ml_id = $scope.property_det.ml;
974
975                        $scope.latitude = parseFloat(data.property_det.lat);
976                        $scope.longitude = parseFloat(data.property_det.lng);
977
978                        $scope.address = data.property_det.address;
979                        fb_app_id = data.user_fb_app_id;
980
981                        if (data.logged_user_fav_property > 0) {
982                            // For Checking user fav property
983                            $scope.fav_status = 1;
984                        } else {
985                            $scope.fav_status = 0;
986                        }
987
988                        $scope.property_image_url = ""; // image share url for FB
989
990                        if (data.property_det.getimage.length > 0) {
991                            // check property images.. In which position get image set for the facebook share
992                            for (var i = 0; i < data.property_det.getimage.length; i++) {
993                                if (
994                                    typeof data.property_det.getimage[i].image_path != "undefined"
995                                ) {
996                                    var last = data.property_det.getimage[i].image_path
997                                        .split("/")
998                                        .pop(); // no_image.png
999                                    var no_image_last = last.split("."); // no_image
1000
1001                                    if (no_image_last[0] != "no_image") {
1002                                        $scope.property_image =
1003                                            theme_image_url +
1004                                            data.property_det.getsisdetails.getmlsdetails.name.toLowerCase() +
1005                                            "/" +
1006                                            data.property_det.getimage[i].image_path;
1007                                        $scope.property_image_url = base_url + $scope.property_image;
1008                                        break;
1009                                    }
1010                                }
1011                            }
1012                        }
1013                        $scope.property_url = $location.absUrl();
1014
1015                        setTimeout(function () {
1016                            ProjectGallery();
1017                            projectDetailImgVideoSwiperSlider();
1018                            ImageFitCont();
1019
1020                            // FOR FACE BOOK INITILIZATION //
1021                            window.fbAsyncInit = function () {
1022                                FB.init({
1023                                    appId: fb_app_id,
1024                                    status: true,
1025                                    cookie: true,
1026                                    xfbml: true,
1027                                });
1028                            };
1029                            (function () {
1030                                var e = document.createElement("script");
1031                                e.async = true;
1032                                e.src =
1033                                    document.location.protocol +
1034                                    "//connect.facebook.net/en_US/all.js";
1035                                document.getElementById("fb-root").appendChild(e);
1036                            })();
1037                            // FOR FACE BOOK INITILIZATION //
1038
1039                            // Remove map loading call, it'll only be called when we click the "Load Map" button
1040                            // Wasim 29-01-2026
1041                            // initMap(); // init map call
1042
1043                            const homeProjectSliderSwiper = new Swiper(
1044                                ".home-project-slider",
1045                                {
1046                                    navigation: {
1047                                        nextEl: ".home-project-slider .swiper-button-next",
1048                                        prevEl: ".home-project-slider .swiper-button-prev",
1049                                    },
1050                                    slidesPerView: 1,
1051                                    spaceBetween: 30,
1052                                    breakpoints: {
1053                                        320: {
1054                                            slidesPerView: 1,
1055                                        },
1056                                        768: {
1057                                            slidesPerView: 2,
1058                                        },
1059                                        992: {
1060                                            slidesPerView: 3,
1061                                        },
1062                                        1200: {
1063                                            slidesPerView: 4,
1064                                        },
1065                                    },
1066                                }
1067                            );
1068                        }, 1000);
1069
1070                        setTimeout(() => {
1071                            jQuery(
1072                                "#propertyProjectDetailModal .modal-body"
1073                            ).mCustomScrollbar("scrollTo", ["top", null]);
1074                        }, 500);
1075
1076                        $scope.propertyDetailsFetching = false;
1077                        // fetch related properties
1078                        $scope.fetchRelatedProperties(ml);
1079                    }
1080                    setTimeout(function () {
1081                        if ($rootScope.is_front_logged == 1) {
1082                            $rootScope.checkLastServieCallTimeAfterLogin(); // To continuous update date time for logged user
1083                            $rootScope.$apply();
1084                        } else {
1085                            $rootScope.$broadcast("visitedPropertyPage"); // For Dpi-V2 requirement
1086                        }
1087                    }, 500);
1088                });
1089            };
1090            // $scope.fetchPropertyDetailsAfterStateChanged = function (ml) {
1091            //     $scope.front_spinner = 1;
1092            //     $scope.propertyDetailsFetching = true;
1093            //     // Show the modal
1094            //     jQuery('#propertyProjectDetailModal').on('shown.bs.modal', function (e) {
1095            //         // 
1096            //         // jQuery('#propertyProjectDetailModal .modal-body').mCustomScrollbar("scrollTo", ".propertyProjectDetail-content-wrap");
1097            //         jQuery('#propertyProjectDetailModal .modal-body').mCustomScrollbar();
1098
1099            //         // Scroll to top
1100            //         // $('#propertyProjectDetailModal').animate({ scrollTop: 0 }, 'fast');
1101            //     });
1102
1103            //     jQuery('#propertyProjectDetailModal').modal();
1104
1105            //     $scope.property_ml_id = ml;
1106            //     var fb_app_id = $rootScope.fb_app_id;
1107
1108            //     // Find previous and next index
1109            //     const mlIndex = $rootScope.propertyMlsIds.indexOf(ml);
1110            //     if (mlIndex == -1) {
1111            //         $scope.previousPropertyMl = null;
1112            //         $scope.nextPropertyMl = null;
1113            //     } else {
1114            //         if (mlIndex > 0) {
1115            //             $scope.previousPropertyMl = $rootScope.propertyMlsIds[mlIndex - 1];
1116            //         } else {
1117            //             $scope.previousPropertyMl = null;
1118            //         }
1119            //         if ((mlIndex + 1) < $rootScope.propertyMlsIds.length) {
1120            //             $scope.nextPropertyMl = $rootScope.propertyMlsIds[mlIndex + 1];
1121            //         } else {
1122            //             $scope.nextPropertyMl = null;
1123            //         }
1124            //     }
1125
1126            //     // IF FACEBOOK APP ID  NOT  PUTED FACEBOOK SHARE NOT VISIBLE BUTTON START//
1127            //     if (fb_app_id != '') {
1128            //         $scope.fb_button_visible = 1;
1129            //     }
1130            //     // IF FACEBOOK APP ID  NOT  PUTED FACEBOOK SHARE NOT VISIBLE BUTTON END//
1131
1132            //     var token = localStorage.getItem("access_token"); // If login
1133            //     if ($localStorage.our_listing_search_params) {
1134            //         var search_params = JSON.parse($localStorage.our_listing_search_params)
1135            //     } else {
1136            //         var search_params = '';
1137            //     }
1138
1139            //     var $httpRequest = $http({
1140            //         method: 'POST',
1141            //         url: base_url + '/firsthometheme/property-details-updated',
1142            //         data: {
1143            //             property_ml_id: $scope.property_ml_id,
1144            //             member_id: $scope.userid,
1145            //             search_params: search_params
1146            //         },
1147            //         headers: {
1148            //             'Content-Type': 'application/json; charset=utf-8',
1149            //             'Access-Token': token,
1150            //         }
1151            //     }).success(function (data, status) {
1152            //         $scope.front_spinner = 0;
1153            //         
1154            //         if (data.property_det.length === 0) {
1155            //             $scope.has_property = 0;
1156            //         } else {
1157            //             // if ($localStorage.mls_id) {
1158            //             //     var storeMlsIds = JSON.parse($localStorage.mls_id);
1159            //             //     var indexofMlsId = storeMlsIds.indexOf($scope.property_ml_id);
1160            //             //     if (indexofMlsId > -1) {
1161            //             //         $rootScope.all_property_search_list = storeMlsIds;
1162            //             //         $rootScope.currentPropertyIndex = indexofMlsId;
1163            //             //     }
1164            //             // }
1165            //             $scope.allRelatedProperty = [];
1166            //             $scope.has_property = 1;
1167            //             $scope.property_det = data.property_det;
1168            //             $scope.property_ml_id = $scope.property_det.ml
1169
1170            //             $scope.latitude = parseFloat(data.property_det.lat);
1171            //             $scope.longitude = parseFloat(data.property_det.lng);
1172
1173            //             $scope.address = data.property_det.address;
1174            //             fb_app_id = data.user_fb_app_id;
1175
1176            //             if (data.logged_user_fav_proerty > 0) // For Checking user fav property
1177            //             {
1178            //                 $scope.fav_status = 1;
1179            //             } else {
1180            //                 $scope.fav_status = 0;
1181            //             }
1182
1183            //             $scope.property_image_url = ''; // image share url for FB
1184
1185            //             if (data.property_det.getimage.length > 0) // check property images.. In which position get image set for the facebook share
1186            //             {
1187            //                 for (var i = 0; i < data.property_det.getimage.length; i++) {
1188            //                     if (typeof data.property_det.getimage[i].image_path != 'undefined') {
1189            //                         var last = data.property_det.getimage[i].image_path.split("/").pop(); // no_image.png
1190            //                         var no_image_last = last.split("."); // no_image
1191
1192            //                         if (no_image_last[0] != 'no_image') {
1193            //                             $scope.property_image = theme_image_url + data.property_det.getsisdetail
1193s.getmlsdetails.name.toLowerCase() + '/' + data.property_det.getimage[i].image_path;
1194            //                             $scope.property_image_url = base_url + $scope.property_image;
1195            //                             break;
1196            //                         }
1197            //                     }
1198            //                 }
1199            //             }
1200            //             $scope.property_url = $location.absUrl();
1201
1202            //             setTimeout(function () {
1203            //                 ProjectGallery();
1204            //                 projectDetailImgVideoSwiperSlider();
1205            //                 ImageFitCont();
1206
1207            //                 // FOR FACE BOOK INITILIZATION //
1208            //                 window.fbAsyncInit = function () {
1209            //                     FB.init({
1210            //                         appId: fb_app_id,
1211            //                         status: true,
1212            //                         cookie: true,
1213            //                         xfbml: true
1214            //                     });
1215            //                 };
1216            //                 (function () {
1217            //                     var e = document.createElement('script');
1218            //                     e.async = true;
1219            //                     e.src = document.location.protocol +
1220            //                         '//connect.facebook.net/en_US/all.js';
1221            //                     document.getElementById('fb-root').appendChild(e);
1222            //                 }());
1223            //                 // FOR FACE BOOK INITILIZATION //
1224
1225            //                 initMap(); // init map call
1226
1227            //                 const homeProjectSliderSwiper = new Swiper('.home-project-slider', {
1228            //                     navigation: {
1229            //                         nextEl: '.home-project-slider .swiper-button-next',
1230            //                         prevEl: '.home-project-slider .swiper-button-prev',
1231            //                     },
1232            //                     slidesPerView: 1,
1233            //                     spaceBetween: 30,
1234            //                     breakpoints: {
1235            //                         320: {
1236            //                             slidesPerView: 1,
1237            //                         },
1238            //                         768: {
1239            //                             slidesPerView: 2
1240            //                         },
1241            //                         992: {
1242            //                             slidesPerView: 3
1243            //                         },
1244            //                         1200: {
1245            //                             slidesPerView: 4
1246            //                         }
1247            //                     }
1248            //                 });
1249            //             }, 1000);
1250
1251            //             setTimeout(() => {
1252            //                 jQuery('#propertyProjectDetailModal .modal-body').mCustomScrollbar('scrollTo', ['top', null]);
1253            //             }, 500);
1254
1255            //             $scope.propertyDetailsFetching = false;
1256            //             // fetch related properties
1257            //             $scope.fetchRelatedProperties(ml);
1258            //         }
1259            //     });
1260            // }
1261
1262            // page heading Setting
1263            if (typeof $scope.meta_heading[$routeParams.page_name] != "undefined") {
1264                $scope.page_heading = $scope.meta_heading[$routeParams.page_name];
1265            } else {
1266                $scope.$on("menudatareceived", function (event, args) {
1267                    $scope.page_heading = $scope.meta_heading[$routeParams.page_name];
1268                });
1269            }
1270
1271            // image fit call on page load
1272            setTimeout(function () {
1273                ImageFitCont();
1274                jQuery(document).on("click", ".dropdown-menu", function (evt) {
1275                    evt.stopPropagation();
1276                });
1277                jQuery(document).on("click", function (event) {
1278                    var clickover = jQuery(event.target);
1279
1280                    clickover = clickover.hasClass("feature_listpanel");
1281                    var _opened = jQuery("#advance_collapse").hasClass("in");
1282                    if (_opened == true && clickover != true) {
1283                        jQuery(".collapse").collapse("hide");
1284                    }
1285                });
1286            }, 500);
1287
1288            /**********************/
1289
1290            $scope.newobject.active_class = $routeParams.page_name; // Active Class Settings
1291
1292            /****** Get Current Route Name ******/
1293            /**
1294              /* Copy search Url
1295              */
1296            $scope.searchUrlCopy = function () {
1297                $scope.searchStorage = $localStorage.our_listing_search_params;
1298
1299
1300                //$scope.curreUrl = document.URL;
1301                $scope.curreUrl = window.location.href.split("?")[0];
1302                var generateSearchUrl = encodeURI(
1303                    $scope.curreUrl + "?search=" + btoa($scope.searchStorage)
1304                );
1305                //var generateSearchUrl = "mailto:?subject=Search Property Link&body="+$scope.curreUrl+'?params='+$scope.searchStorage;
1306
1307                //tiny url api
1308                let query = {
1309                    url: generateSearchUrl,
1310                };
1311                var tinyurl;
1312                $.get("/firsthometheme/generate-tiny-url", query).done(function (data) {
1313                    tinyurl = data.data;
1314
1315                    $("#urlInput").val(tinyurl);
1316                    $scope.myFunction();
1317                });
1318                //window.location = generateSearchUrl;
1319                //window.open(generateSearchUrl, '_blank');
1320            };
1321
1322            $scope.printFlyer = function (ml) {
1323                let data = {
1324                    agent_id: user_id,
1325                    property_ml_id: ml,
1326                    member_id: user_id,
1327                };
1328                let printPath =
1329                    $location.protocol() +
1330                    "://" +
1331                    $location.host() +
1332                    "/firsthometheme/print-flyer?member_id=" +
1333                    user_id +
1334                    "&agent_id=" +
1335                    user_id +
1336                    "&property_ml_id=" +
1337                    ml;
1338                //
1339                //$location.path(printPath);
1340                //window.location.href=printPath;
1341                window.open(printPath, "_blank");
1342            };
1343
1344            $scope.copyToSafari = function () {
1345                var copyText = document.getElementById("urlInput");
1346                var text_to_share = copyText.value;
1347                var range, selection;
1348                var h = document.createElement("DIV");
1349                var t = document.createTextNode(text_to_share);
1350                h.appendChild(t);
1351                document.body.appendChild(h);
1352                var element = h;
1353                if (document.body.createTextRange) {
1354                    range = document.body.createTextRange();
1355                    range.moveToElementText(element);
1356                    range.select();
1357                } else if (window.getSelection) {
1358                    selection = window.getSelection();
1359                    range = document.createRange();
1360                    range.selectNodeContents(element);
1361                    selection.removeAllRanges();
1362                    selection.addRange(range);
1363                }
1364                try {
1365                    document.execCommand("copy");
1366                } catch (err) {
1367                } finally {
1368                    element.remove();
1369                }
1370            };
1371            /**
1372             * Click handler for Copy
1373             */
1374            $scope.myFunction = function () {
1375                /* Get the text field */
1376                var copyText = document.getElementById("urlInput");
1377                /* Select the text field */
1378                copyText.select();
1379                /* Copy the text inside the text field */
1380                document.execCommand("copy");
1381                /* Alert the copied text */
1382                swal({
1383                    title: "Copy Search Settings",
1384                    text: "Click on Copy button to copy the link.  Then paste the link in an email and send it.",
1385                    button: "Copy",
1386                    // closeOnClickOutside: true,
1387                    // showCancelButton: true,
1388                    // cancelButtonText: 'Cancel',
1389                    // buttons: {
1390                    //     cancel: true,
1391                    //     confirm: true,
1392                    // },
1393                    // buttons: {
1394                    //     cancel: {
1395                    //         text: "Cancel",
1396                    //         value: null,
1397                    //         visible: false,
1398                    //         className: "",
1399                    //         closeModal: true,
1400                    //     },
1401                    //     confirm: {
1402                    //         text: "OK",
1403                    //         value: true,
1404                    //         visible: true,
1405                    //         className: "",
1406                    //         closeModal: true
1407                    //     }
1408                    // },
1409                    content: {
1410                        element: "input",
1411                        attributes: {
1412                            value: copyText.value,
1413                            readonly: "true",
1414                        },
1415                    },
1416                }).then((value) => {
1417                    // 
1418                    // 
1419                    if (value == null) {
1420                        // Clicked on the backdrop. Do nothing. Just close the modal
1421                        return;
1422                    }
1423                    $scope.copyToSafari();
1424                    swal("Copied to Clipboard");
1425                });
1426                // .then((value) => {
1427                //     
1428                //     
1429                // }, function (dismiss) {
1430                //     if (dismiss == 'cancel') {
1431                //         
1432                //     }
1433                // });
1434            };
1435
1436            /*
1437              $scope.$on('$viewContentLoaded', function(){
1438                  // console.log('viewContentLoaded')
1439                  var pathArr = $location.path().split('/');
1440                   if(pathArr.indexOf('search')==2)
1441                  {
1442                      setTimeout(()=>{
1443                      
1444                          if (typeof $scope.agent_zip_search != 'undefined' && $scope.agent_zip_search != '' && $scope.is_coming_from_home == 0) {
1445                              // 
1446                              //$rootScope.using_saved_zip=true;
1447      
1448                              if (!$scope.advanced_search.zip_code) {
1449                                  $scope.advanced_search.zip_code = [];
1450                                  $scope.advanced_search.zip_code[0] = $scope.agent_zip_search;
1451                              }
1452                              else {
1453                                  if ($scope.advanced_search.zip_code.indexOf($scope.agent_zip_search) === '-1')
1454                                      $scope.advanced_search.zip_code.push($scope.agent_zip_search);
1455                              }
1456                          }
1457                      },2000);
1458                  }
1459                  //Here your view content is fully loaded !!
1460              });
1461      
1462              */
1463            /////  AGENT WEBSITE DETAILS START /////
1464            $scope.getAgentDetails =
1465                function () // get agent details for home page of his website
1466                {
1467                    var agent_id = $scope.userid;
1468                    var httpRequest = $http({
1469                        method: "POST",
1470                        url: base_url + "/firsthometheme/get-agent-details",
1471                        data: {
1472                            agent_id: agent_id,
1473                        },
1474                    }).success(function (data, status) {
1475                        $scope.agentDetails = data.agent_details;
1476
1477
1478                        $rootScope.our_listing_page_sort = $scope.agentDetails.our_listing_page_sort;
1479
1480
1481                        $scope.search_listing_sort = $rootScope.our_listing_page_sort;
1482
1483
1484
1485                        $scope.agent_zip_search = data.agent_details.zip_search;
1486                        $localStorage.agent_zip_search = data.agent_details.zip_search;
1487                        $scope.agent_set_zip_code = data.agent_details.zip_search; // For only reset search
1488                        $scope.property_details_view_count =
1489                            data.agent_details.property_details_view_count; //property_details_view_count
1490                        localStorage.setItem(
1491                            "prop_view_limit",
1492                            $scope.property_details_view_count
1493                        );
1494                        localStorage.setItem(
1495                            "dev_view_limit",
1496                            $scope.development_view_count
1497                        );
1498
1499                        if ($scope.routeName == "search_property") {
1500                            // $scope.getSelectedBed(0, 1);
1501                            // $scope.getSelectedBath(0, 1);
1502                            $scope.bedrooms[0].current = 0;
1503                            $scope.bathrooms[0].current = 0;
1504                            $scope.advanced_search.bedrooms = 0;
1505                            $scope.advanced_search.bathrooms = 0;
1506                            if (
1507                                typeof $scope.agent_zip_search != "undefined" &&
1508                                $scope.agent_zip_search != "" &&
1509                                $scope.is_coming_from_home == 0
1510                            ) {
1511                                // 
1512                                //$rootScope.using_saved_zip=true;
1513
1514                                if (!$scope.advanced_search.zip_code) {
1515                                    $scope.advanced_search.zip_code = [];
1516                                    $scope.advanced_search.zip_code[0] = $scope.agent_zip_search;
1517                                } else {
1518                                    if (
1519                                        $scope.advanced_search.zip_code.indexOf(
1520                                            $scope.agent_zip_search
1521                                        ) === "-1"
1522                                    )
1523                                        $scope.advanced_search.zip_code.push(
1524                                            $scope.agent_zip_search
1525                                        );
1526                                }
1527                            }
1528                        }
1529                    });
1530                };
1531            /////  AGENT WEBSITE DETAILS START /////
1532
1533            // For Google Map
1534            var markers = [];
1535
1536            $scope.shareFriend = function () {
1537                var property_url = $location.absUrl();
1538                var data = {
1539                    share: $scope.shareMail,
1540                    member_id: $scope.userid, //Agent id Website owner
1541                    property_url: property_url,
1542                    recaptcha_code: document.querySelector(`[name="h-captcha-response"]`)
1543                        .value,
1544                };
1545
1546                var httpRequest = $http({
1547                    method: "POST",
1548                    //url: base_url + '/firsthometheme/send-request-mail',
1549                    url: base_url + "/firsthometheme/send-share-mail",
1550                    data: data,
1551                })
1552                    .success(function (data, status) {
1553                        if (data.success == 1) {
1554                            $scope.showSuccMsg = 1;
1555                            $scope.change_class = "#71b100";
1556                            $scope.show_message =
1557                                "This property has been successfully shared via mail";
1558                            // $scope.shareFriendForm.reset();
1559                            // Close the shareFriend Modal
1560                            jQuery('#shareFriend').modal('hide');
1561                            $scope.shareMail = {};
1562                        } else {
1563                            $scope.showSuccMsg = 1;
1564                            $scope.show_message = "Some error occured.";
1565                            $scope.change_class = "#F00";
1566                        }
1567
1568                        $timeout(function () {
1569                            $scope.showSuccMsg = 0;
1570                            angular.element(".close").trigger("click");
1571                            $scope.$digest();
1572                        }, 3000);
1573                    })
1574                    .error(function (data, status, header, config) {
1575                        $scope.showSuccMsg = 1;
1576                        $scope.show_message = "Some error occured.";
1577                        $scope.change_class = "#F00";
1578
1579                        $timeout(function () {
1580                            $scope.showSuccMsg = 0;
1581                            angular.element(".close").trigger("click");
1582                            $scope.$digest();
1583                        }, 3000);
1584                    });
1585            };
1586            $scope.getAllProperty = function () {
1587                var httpRequest = $http({
1588                    method: "POST",
1589                    url: base_url + "/firsthometheme/all-property",
1590                    data: {},
1591                }).success(function (data, status) {
1592                    $scope.property_type = data.all_property_type;
1593                });
1594            };
1595            if (
1596                $scope.routeName == "search_property" ||
1597                $scope.routeName == "home" ||
1598                $scope.routeName == "mylisting" ||
1599                $scope.routeName == "my_listings"
1600            ) {
1601                $scope.getAllProperty();
1602            }
1603            // if ($scope.routeName == "search_property") {
1604            //     $scope.getAllProperty();
1605            // } else if ($scope.routeName == "property_details") {
1606            //     const ml = $routeParams.property_ml_id;
1607            //     $scope.fetchPropertyDetailsAfterStateChanged(ml);
1608            // }
1609
1610            // The single-active-polygon tracker and the DrawingManager hook now
1611            // live in the shared polygonFilter service (config/config-service.js)
1612            // instead of being copy-pasted into every listing controller.
1613            function trackFilterPolygon(polygon) {
1614                polygonFilter.track(polygon);
1615            }
1616
1617            function clearFilterPolygon() {
1618                polygonFilter.clear();
1619            }
1620
1621            // The user-drawn overlay comes from the view's DrawingManager, so
1622            // hook its polygoncomplete here instead of relying on the view's
1623            // own handler. Re-hooks whenever the view swaps in a new instance.
1624            //
1625            // Also re-asserts the debounced replacement for the view's global
1626            // getLatLng(): the view re-declares that function every time ngView
1627            // re-inserts the template, and its own version scheduled an
1628            // uncancellable 2s bounds search that overwrote polygon results.
1629            function ensurePolygonDrawHook() {
1630                polygonFilter.installBoundsSearchGuard($scope, {
1631                    getMap: function () {
1632                        return typeof map2 !== "undefined" ? map2 : null;
1633                    }
1634                });
1635                if (typeof drawingManager === "undefined" || !drawingManager) return;
1636                polygonFilter.hookDrawingManager(drawingManager);
1637            }
1638
1639            // START NEW FEATURES ADDED FOR POLYGON DRAW //
1640            $scope.drawOrRemovePolygone = function () {
1641                $scope.hasPolygon = true;
1642                $scope.polygoncount++;
1643
1644                $scope.search_by_polygon = 1;
1645                $rootScope.polygon_lat_long = $scope.polygon_lat_long;
1646
1647                // Everything between here and searchProperty() is bookkeeping.
1648                // It used to be able to throw (it computed the bounding box via
1649                // Leaflet's L.geoJson, and L is injected lazily by the view), and
1650                // when it did, the search never fired and the $apply() that the
1651                // view runs after this function never ran either - so the listing
1652                // did not update and the Remove button never appeared. The search
1653                // now happens whatever else fails.
1654                try {
1655                    // var cond = JSON.parse($localStorage.our_listing_search_params);
1656                    var cond =
1657                        $localStorage.our_listing_search_params != undefined &&
1658                            $localStorage.our_listing_search_params != ""
1659                            ? JSON.parse($localStorage.our_listing_search_params)
1660                            : {};
1661                    cond.polygon_lat_long = $rootScope.polygon_lat_long;
1662                    $scope.currentPage = 1;
1663                    cond.currentPage = $scope.currentPage;
1664                    cond.page = $scope.currentPage; // searchProperty reads `page`
1665                    $localStorage.our_listing_search_params = JSON.stringify(cond);
1666
1667                    $scope.all_bound = polygonFilter.bounds($rootScope.polygon_lat_long);
1668                } catch (e) {
1669                    console.warn("drawOrRemovePolygone bookkeeping failed", e);
1670                }
1671
1672                // A freshly drawn polygon must never be swallowed by the
1673                // searchConditionIsSame() de-dupe, and any bounds search still
1674                // pending from a pan/zoom must not land on top of it.
1675                polygonFilter.cancelBoundsSearch();
1676                $scope.searchCondition = "";
1677                $scope.callingSearchProperty = true;
1678                $scope.searchProperty($localStorage.our_listing_search_params, $scope.all_bound);
1679            };
1680
1681            $scope.clearPolygonOnResetSearch = function () {
1682                clearFilterPolygon();
1683                document.getElementById("specify_by_polygon").value = "";
1684                $scope.polygoncount = 0;
1685                $rootScope.polygon_lat_long = "";
1686                $scope.polygon_lat_long = "";
1687                $scope.hasPolygon = false;
1688                $scope.search_by_polygon = 0;
1689                $rootScope.hitorybackbtn = 0;
1690                // var cond = JSON.parse($localStorage.our_listing_search_params);
1691                var cond =
1692                    $localStorage.our_listing_search_params != undefined &&
1693                        $localStorage.our_listing_search_params != ""
1694                        ? JSON.parse($localStorage.our_listing_search_params)
1695                        : {};
1696                if (cond.polygon_lat_long) {
1697                    delete cond["polygon_lat_long"];
1698                }
1699                // Without this the edited copy was discarded and the polygon
1700                // stayed in local storage.
1701                $localStorage.our_listing_search_params = JSON.stringify(cond);
1702            }
1703            $scope.clearPolygonStucture = function () {
1704                clearFilterPolygon();
1705                $scope.polygoncount = 0;
1706                $rootScope.polygon_lat_long = "";
1707                $scope.polygon_lat_long = "";
1708                $scope.hasPolygon = false;
1709                $scope.search_by_polygon = 0;
1710                $rootScope.hitorybackbtn = 0;
1711                // var cond = JSON.parse($localStorage.our_listing_search_params);
1712                var cond =
1713                    $localStorage.our_listing_search_params != undefined &&
1714                        $localStorage.our_listing_search_params != ""
1715                        ? JSON.parse($localStorage.our_listing_search_params)
1716                        : {};
1717                if (cond.polygon_lat_long) {
1718                    delete cond["polygon_lat_long"];
1719                }
1720                cond.advance_search = typeof cond.advance_search === 'string' ? JSON.parse(cond.advance_search) : cond.advance_search;
1721                // Add zip code after clearing the polygon
1722
1723                cond.advance_search.zip_code = [$localStorage.agent_zip_search];
1724
1725                $scope.currentPage = 1;
1726                cond.currentPage = $scope.currentPage;
1727                $localStorage.our_listing_search_params = JSON.stringify(cond);
1728                $scope.all_bound = {};
1729                $scope.advance_search = cond.advance_search;
1730                $scope.callingSearchProperty = false;
1731                // $scope.searchProperty($localStorage.our_listing_search_params, $scope.all_bound);
1732                $scope.resetSearch();
1733            };
1734
1735            /**
1736             * Water access filter options
1737             */
1738            $scope.waterAccessFilterOptions = function (optionsArray) {
1739                let valuesArray = [];
1740                optionsArray.forEach((option) => {
1741                    let optionValue = parseInt(option) == 1 ? "Yes" : "No";
1742                    valuesArray.push(optionValue);
1743                });
1744                return valuesArray.join(", ");
1745            };
1746
1747            /****** Check All property inside polygon or not ****/
1748            function isPointInPoly(poly, y, x) {
1749                var c = false,
1750                    j = poly.length - 1,
1751                    i;
1752
1753                for (i = 0; i < poly.length; i++) {
1754                    if (
1755                        ((poly[i][0] < y && poly[j][0] >= y) ||
1756                            (poly[j][0] < y && poly[i][0] >= y)) &&
1757                        (poly[i][1] <= x || poly[j][1] <= x)
1758                    ) {
1759                        if (
1760                            poly[i][1] +
1761                            ((y - poly[i][0]) / (poly[j][0] - poly[i][0])) *
1762                            (poly[j][1] - poly[i][1]) <
1763                            x
1764                        ) {
1765                            c = !c;
1766                        }
1767                    }
1768                    j = i;
1769                }
1770                return c;
1771            }
1772            /****** Check All property inside polygon or not ****/
1773
1774            // END NEW FEATURES ADDED FOR POLYGON DRAW //
1775
1776            $scope.getDistinct = function (
1777                params // Filter For Advanced Search
1778            ) {
1779                $scope.modal_loader = 1;
1780                $scope.filter_data = "";
1781                var httpRequest = $http({
1782                    method: "POST",
1783                    url: base_url + "/shared/search-filter",
1784                    data: {
1785                        filter: params,
1786                        advanced_search: typeof $scope.advanced_search === 'string' ? $scope.advanced_search : JSON.stringify($scope.advanced_search),
1787                        member_id: $scope.userid,
1788                    },
1789                }).success(function (data, status) {
1790                    $scope.modal_loader = 0;
1791                    $scope.filter_data = data;
1792                    $scope.optionsFromQuery = data.get_val;
1793
1794                    if (
1795                        $rootScope.polygon_lat_long &&
1796                        $scope.uniquezipcode_array &&
1797                        data.filter_param == "zip_code"
1798                    ) {
1799                        $scope.optionsFromQuery = $scope.uniquezipcode_array;
1800                    }
1801                    if (
1802                        $rootScope.polygon_lat_long &&
1803                        $scope.uniquecounty_array &&
1804                        data.filter_param == "county"
1805                    ) {
1806                        $scope.optionsFromQuery = $scope.uniquecounty_array;
1807                    }
1808                    if (
1809                        $rootScope.polygon_lat_long &&
1810                        $scope.development_Name_array &&
1811                        data.filter_param == "development_name"
1812                    ) {
1813                        $scope.optionsFromQuery = $scope.development_Name_array;
1814                    }
1815                    if (
1816                        $rootScope.polygon_lat_long &&
1817                        $scope.complex_Name_array &&
1818                        data.filter_param == "complex_name"
1819                    ) {
1820                        $scope.optionsFromQuery = $scope.complex_Name_array;
1821                    }
1822                    if (
1823                        $rootScope.polygon_lat_long &&
1824                        $scope.views_Name_array &&
1825                        data.filter_param == "view"
1826                    ) {
1827                        $scope.optionsFromQuery = $scope.views_Name_array;
1828                    }
1829                    if (
1830                        $rootScope.polygon_lat_long &&
1831                        $scope.water_access_array &&
1832                        data.filter_param == "water_access"
1833                    ) {
1834                        $scope.optionsFromQuery = $scope.water_access_array;
1835                    }
1836                    if (
1837                        $rootScope.polygon_lat_long &&
1838                        $scope.subdivision_Name_array &&
1839                        data.filter_param == "subdivision_name"
1840                    ) {
1841                        $scope.optionsFromQuery = $scope.subdivision_Name_array;
1842                    }
1843                });
1844            };
1845
1846            /**** Generate Polygon Boundary ******/
1847            $scope.generateBoundary = function () {
1848                $scope.search_by_polygon = 1;
1849                $scope.all_bound = polygonFilter.bounds($rootScope.polygon_lat_long);
1850            };
1851            /**** Generate Polygon Boundary ******/
1852
1853            /*  Bedroom Bathroom icon setup start */
1854
1855            $scope.bedrooms = [
1856                {
1857                    current: 0,
1858                    max: 4,
1859                },
1860            ];
1861            $scope.bathrooms = [
1862                {
1863                    current: 0,
1864                    max: 4,
1865                },
1866            ];
1867            $scope.halfbathrooms = [
1868                {
1869                    current: 0,
1870                    max: 4,
1871                },
1872            ];
1873
1874            $scope.getSelectedBath = function (bathrating, sp) {
1875                $scope.bathrating = bathrating;
1876                $scope.advanced_search.bathrooms = $scope.bathrating;
1877
1878                if (!sp) {
1879                    $scope.callingSearchProperty = true;
1880                    $scope.searchProperty($localStorage.our_listing_search_params, $scope.all_bound);
1881                }
1882            };
1883            $scope.getSelectedHalfBath = function (halfbath) {
1884                $scope.halfbath = halfbath;
1885                $scope.advanced_search.hbaths = $scope.halfbath;
1886                if ($scope.advanced_search["hbaths"] == "undefined") {
1887                    $scope.hbaths_active = "";
1888                } else {
1889                    $scope.hbaths_active = "active";
1890                }
1891            };
1892
1893            /*  Bedroom Bathroom icon setup end */
1894
1895            /******* ADVANCED SEARCH ACTIVE FUNCTION SEARCH *******/
1896
1897            $scope.advance_search_make_green_active = function () {
1898                if (typeof $scope.advanced_search["sqft_footage"] != "undefined") {
1899                    $scope.sqft_footage_active = "active";
1900                } else {
1901                    $scope.sqft_footage_active = "";
1902                }
1903                if (typeof $scope.advanced_search["hopa"] != "undefined") {
1904                    $scope.hopa = "active";
1905                } else {
1906                    $scope.hopa = "";
1907                }
1908                if (
1909                    typeof $scope.advanced_search["membership_fee_required"] !=
1910                    "undefined"
1911                ) {
1912                    $scope.mebership_fee_active = "active";
1913                } else {
1914                    $scope.mebership_fee_active = "";
1915                }
1916
1917                if (typeof $scope.advanced_search["short_sale"] != "undefined") {
1918                    $scope.short_sale_active = "active";
1919                } else {
1920                    $scope.short_sale_active = "";
1921                }
1922                if (typeof $scope.advanced_search["foreclosure"] != "undefined") {
1923                    $scope.foreclosure_active = "active";
1924                } else {
1925                    $scope.foreclosure_active = "";
1926                }
1927                if (
1928                    typeof $scope.advanced_search["zip_code"] != "undefined" &&
1929                    $scope.advanced_search["zip_code"].length > 0
1930                ) {
1931                    $scope.zip_code_active = "active";
1932                } else {
1933                    $scope.zip_code_active = "";
1934                }
1935                if (typeof $scope.advanced_search["county"] != "undefined") {
1936                    $scope.county_active = "active";
1937                } else {
1938                    $scope.county_active = "";
1939                }
1940                if (typeof $scope.advanced_search["development_name"] != "undefined") {
1941                    $scope.development_name_active = "active";
1942                } else {
1943                    $scope.development_name_active = "";
1944                }
1945                if (typeof $scope.advanced_search["subdivision_name"] != "undefined") {
1946                    $scope.subdivision_name_active = "active";
1947                } else {
1948                    $scope.subdivision_name_active = "";
1949                }
1950                if (typeof $scope.advanced_search["complex_name"] != "undefined") {
1951                    $scope.complex_name_active = "active";
1952                } else {
1953                    $scope.complex_name_active = "";
1954                }
1955                if (typeof $scope.advanced_search["hbaths"] != "undefined") {
1956                    $scope.hbaths_active = "active";
1957                } else {
1958                    $scope.hbaths_active = "";
1959                }
1960                if (typeof $scope.advanced_search["pet"] != "undefined") {
1961                    $scope.pet_active = "active";
1962                } else {
1963                    $scope.pet_active = "";
1964                }
1965                if (typeof $scope.advanced_search["pool"] != "undefined") {
1966                    $scope.pool_active = "active";
1967                } else {
1968                    $scope.pool_active = "";
1969                }
1970                if (typeof $scope.advanced_search["view"] != "undefined") {
1971                    $scope.view_active = "active";
1972                } else {
1973                    $scope.view_active = "";
1974                }
1975                if (typeof $scope.advanced_search["water_access"] != "undefined") {
1976                    $scope.water_access_active = "active";
1977                } else {
1978                    $scope.water_access_active = "";
1979                }
1980                if (typeof $scope.advanced_search["water_front"] != "undefined") {
1981                    $scope.water_front_active = "active";
1982                } else {
1983                    $scope.water_front_active = "";
1984                }
1985                if (typeof $scope.advanced_search["furnished"] != "undefined") {
1986                    $scope.furnished_active = "active";
1987                } else {
1988                    $scope.furnished_active = "";
1989                }
1990                if (typeof $scope.advanced_search["hoa_fee"] != "undefined") {
1991                    $scope.hoa_fee_active = "active";
1992                } else {
1993                    $scope.hoa_fee_active = "";
1994                }
1995            };
1996
1997            /******* ADVANCED SEARCH ACTIVE FUNCTION END *******/
1998
1999            $scope.setSearchParamsInLocalStorage = function () {
2000                var agentid = $scope.userid;
2001
2002
2003                var cond = {
2004                    property_type: $scope.search.property_type,
2005                    property_types: $scope.property_types_array,
2006                    bedroom: $scope.bedrating,
2007                    bathroom: $scope.bathrating,
2008                    min_price: $scope.search.min_price,
2009                    max_price: $scope.search.max_price,
2010                    search_listing_sort: $scope.search_listing_sort,
2011                    image_category: $scope.image_category,
2012                    limit: $scope.recordLimit,
2013                    page: $scope.currentPage,
2014                    advance_search: typeof $scope.advanced_search === 'string' ? $scope.advanced_search : JSON.stringify($scope.advanced_search),
2015                    agentid: agentid,
2016                    all_bound: typeof $scope.all_bound === 'string' ? $scope.all_bound : JSON.stringify($scope.all_bound),
2017                    pit: $scope.pit,
2018                    mls_ids: mls_ids,
2019                };
2020
2021
2022                if ($scope.polygon_lat_long) {
2023                    if (typeof $scope.polygon_lat_long == 'string') {
2024                        cond.polygon_lat_long = JSON.parse($scope.polygon_lat_long);
2025                    } else {
2026                        cond.polygon_lat_long = $scope.polygon_lat_long;
2027                    }
2028                }
2029                $localStorage.our_listing_search_params = JSON.stringify(cond); // Set search parameters in local storage
2030            };
2031
2032
2033
2034            if (
2035                $scope.currentRoute == "property_details" ||
2036                $rootScope.previousRoute === $scope.currentRoute ||
2037                typeof $rootScope.previousRoute === "undefined"
2038            ) {
2039
2040                $scope.setScopeVariablesBasedOnLocalStorage();
2041            }
2042
2043            if (
2044                $scope.currentRoute == "property_details" ||
2045                $rootScope.previousRoute === $scope.currentRoute
2046            ) {
2047                $scope.setSearchParamsInLocalStorage();
2048            }
2049
2050
2051
2052            $scope.searchConditionIsSame = function (condition) {
2053                var stringCondition = JSON.stringify(condition);
2054                return $scope.searchCondition === stringCondition;
2055            };
2056            $scope.fixCssBackgoundImageDoubleEncodingIssue = function () {
2057                // get all the elements with the thumbnail classes
2058                const thumbnailElements = $('.project-thumb.imageFit');
2059                thumbnailElements.each(function () {
2060                    // Remove background-image inline CSS
2061                    $(this).css("background-image", "");
2062
2063                    // Get the image source
2064                    var imageSource = $(this).find('img').attr('src');
2065                    // Manually encode only the specific characters
2066                    imageSource = imageSource.replace(/\*/g, '%2A')
2067                        .replace(/\(/g, '%28')
2068                        .replace(/\)/g, '%29');
2069
2070                    // add the image source to the background-image
2071                    $(this).css('background-image', 'url(' + imageSource + ')')
2071;
2072                });
2073            };
2074            /******* SEARCH PROPERTY BUTTON AJAX START *******/
2075            $scope.searchProperty = function (
2076                cond,
2077                allbound, //cond
2078                options // { fromMap: true } for map-bounds driven searches
2079            ) {
2080                options = options || {};
2081                if ($scope.pageChanged == false) {
2082                    $scope.currentPage = 1;
2083                }
2084                if (!$scope.sortingSet) {
2085                    // The sort order arrives from an async call. Remember what
2086                    // was asked for so it can be replayed once it lands -
2087                    // dropping it silently lost the polygon search when the user
2088                    // drew before that call returned.
2089                    $scope.pendingSearchArgs = [cond, allbound, options];
2090                    return;
2091                }
2092
2093
2094
2095                if (typeof cond === 'undefined') {
2096
2097                } else {
2098
2099
2100                }
2101
2102
2103
2104
2105                if ($rootScope.previousRoute == undefined) {
2106
2107                    $rootScope.previousRoute = $scope.currentRoute;
2108                }
2109                // $rootScope.previousRoute = 'search_property'
2110                // $scope.currentRoute = 'search_property'
2111
2112                $scope.resetFilterBasedOnTime();
2113                if ($scope.routeName == "home" && $scope.quickSearchCalled == false) {
2114                    return;
2115                }
2116                $scope.callingSearchProperty = true;
2117
2118                // Set local storage search from $scope
2119                // if (!$scope.firstSearchLoading) {
2120                if (
2121                    $scope.currentRoute == "property_details" ||
2122                    $rootScope.previousRoute === $scope.currentRoute
2123                ) {
2124                    $scope.setSearchParamsInLocalStorage();
2125                }
2126                // Mls Ids
2127                // 
2128
2129                // Scroll to top of the page — skipped for map-bounds driven
2130                // searches so a pan/zoom gesture isn't interrupted.
2131                if (!options.fromMap) {
2132                    $window.scrollTo(0, 0);
2133                    const elmnt = document.getElementById("top_div");
2134                    if (elmnt && typeof elmnt.scrollIntoView === "function") {
2135                        elmnt.scrollIntoView({ behavior: "smooth" });
2136                    }
2137                }
2138
2139                $scope.searchLoaderCount++;
2140                if (typeof localStorage.getItem("hit_saved_search") !== "undefined") {
2141                    $scope.hitsavedsearch = localStorage.getItem("hit_saved_search");
2142                    localStorage.removeItem("hit_saved_search");
2143                }
2144
2145                $scope.all_bound = allbound;
2146                // var localStorageSearchParams = JSON.parse($localStorage.our_listing_search_params);
2147                // localStorageSearchParams.all_bound = typeof allbound != 'undefined' ? JSON.stringify(allbound) : '{}';
2148                var agentid = $scope.userid; // Site owner
2149                $scope.front_spinner = 1;
2150                var backwards = localStorage.getItem("backwards");
2151                if (
2152                    $rootScope.fromhomesearch == 1 ||
2153                    $scope.hitsavedsearch == 1 ||
2154                    $localStorage.backwards == 1
2155                ) {
2156
2157                    $localStorage.backwards = 0;
2158                    $scope.is_coming_from_home = 1;
2159                    $rootScope.fromhomesearch = 0;
2160                    $scope.hitsavedsearch = 0;
2161
2162                    // var cond = JSON.parse($localStorage.our_listing_search_params);
2163                    var cond =
2164                        $localStorage.our_listing_search_params != undefined &&
2165                            $localStorage.our_listing_search_params != ""
2166                            ? JSON.parse($localStorage.our_listing_search_params)
2167                            : {};
2168
2169
2170
2171
2172                    $scope.search.property_type = cond.property_type;
2173                    $scope.property_types_array = cond.property_types;
2174                    $scope.bedrating = cond.bedroom;
2175                    $scope.bathrating = cond.bathroom;
2176                    $scope.search.min_price = cond.min_price;
2177                    $scope.search.max_price = cond.max_price;
2178                    $scope.search_listing_sort = cond.search_listing_sort;
2179                    $scope.image_category = cond.image_category;
2180                    $scope.recordLimit = cond.limit;
2181                    $scope.currentPage = cond.page;
2182                    $scope.advanced_search = JSON.parse(cond.advance_search);
2183                    $scope.all_bound = JSON.parse(cond.all_bound);
2184                }
2185
2186                if ($rootScope.hitorybackbtn == 1 && $rootScope.polygon_lat_long && $rootScope.polygon_lat_long && $rootScope.polygon_lat_long != "undefined" && $rootScope.polygon_lat_long != "[]" && $rootScope.polygon_lat_long != "{}" && Object.keys($rootScope.polygon_lat_long).length > 2) {
2187                    $scope.generateBoundary();
2188                }
2189                /**
2190                    * loading from copied search param
2191                    If there is query params of search include it in localstorage
2192                    */
2193                if ($routeParams.search) {
2194
2195                    $localStorage.our_listing_search_params = "";
2196                    try {
2197                        var setParams = JSON.parse(atob($routeParams.search));
2198
2199
2200                        $scope.search.property_type = setParams.property_type;
2201                        $scope.property_types_array = setParams.property_types;
2202                        $scope.bedrating = setParams.bedroom;
2203                        $scope.bathrating = setParams.bathroom;
2204                        $scope.search.min_price = setParams.min_price;
2205                        $scope.search.max_price = setParams.max_price;
2206                        $scope.search_listing_sort = setParams.search_listing_sort;
2207                        $scope.image_category = setParams.image_category;
2208                        $rootScope.image_category = $scope.image_category;
2209                        $scope.recordLimit = setParams.limit;
2210                        $scope.currentPage = setParams.page;
2211                        if (typeof setParams.advance_search == 'string') {
2212
2213                            $scope.advanced_search = setParams.advance_search
2214                                ? JSON.parse(setParams.advance_search)
2215                                : {};
2216                        } else {
2217
2218                            $scope.advanced_search = setParams.advance_search;
2219                        }
2220
2221                        // $scope.all_bound = setParams.all_bound
2222                        //     ? JSON.parse(setParams.all_bound)
2223                        //     : [];
2224                        if (setParams.all_bound) {
2225                            if (typeof setParams.all_bound == 'string') {
2226                                $scope.all_bound = JSON.parse(setParams.all_bound);
2227                            } else {
2228                                $scope.all_bound = setParams.all_bound;
2229                            }
2230                        } else {
2231                            $scope.all_bound = {};
2232                        }
2233                        // $scope.polygon_lat_long = setParams.polygon_lat_long
2234                        //     ? JSON.parse(setParams.polygon_lat_long)
2235                        //     : [];
2236                        if (typeof setParams.polygon_lat_long == "string") {
2237                            $scope.polygon_lat_long = setParams.polygon_lat_long
2238                                ? setParams.polygon_lat_long
2239                                : '[]';
2240                            $rootScope.polygon_lat_long = setParams.polygon_lat_long;
2241                        } else {
2242                            $scope.polygon_lat_long = setParams.polygon_lat_long
2243                                ? JSON.stringify(setParams.polygon_lat_long)
2244                                : '[]';
2245                            $rootScope.polygon_lat_long = JSON.stringify(setParams.polygon_lat_long);
2246                        }
2247
2248                        //For map pointer
2249
2250                        $rootScope.hitorybackbtn = 1;
2251                        // $routeParams.search = null;
2252                        $localStorage.our_listing_search_params = JSON.stringify(setParams);
2253
2254                        location.skipReload().url($location.path());
2255                    } catch (e) {
2256                        console.warn("parse error of search params");
2257                        console.warn(e);
2258                    }
2259                }
2260                if ($scope.polygoncount == 1) {
2261                    $rootScope.using_saved_zip = false;
2262                    $scope.advanced_search.zip_code = [];
2263                    $scope.polygoncount++;
2264                }
2265
2266                if (
2267                    $localStorage.our_listing_search_params != undefined &&
2268                    $localStorage.our_listing_search_params != ""
2269                ) {
2270
2271                    var localStorageSearchParams = JSON.parse($localStorage.our_listing_search_params);
2272
2273
2274
2275
2276                    var cond = {
2277                        property_type: localStorageSearchParams.property_type,
2278                        property_types: localStorageSearchParams.property_types,
2279                        bedroom: localStorageSearchParams.bedroom,
2280                        bathroom: localStorageSearchParams.bathroom,
2281                        min_price: localStorageSearchParams.min_price,
2282                        max_price: localStorageSearchParams.max_price,
2283                        search_listing_sort: $scope.search_listing_sort,
2284                        image_category: $scope.image_category,
2285                        limit: $scope.recordLimit,
2286                        page: $scope.currentPage,
2287                        advance_search: localStorageSearchParams.advance_search,
2288                        advance_search_updated: localStorageSearchParams.advance_search,
2289                        agentid: agentid,
2290                        // all_bound: localStorageSearchParams.all_bound,
2291                        all_bound: typeof allbound != 'undefined' ? typeof allbound === 'string' ? allbound : JSON.stringify(allbound) : localStorageSearchParams.all_bound,
2292                        pit: localStorageSearchParams.pit,
2293                        mls_ids: mls_ids,
2294                    };
2295                    // cond["advance_search"] = cond["advance_search_updated"];
2296
2297
2298                    if (cond.all_bound) {
2299                        $scope.all_bound = JSON.parse(cond.all_bound);
2300                    }
2301
2302                    $scope.setScopeVariablesBasedOnLocalStorage();
2303                } else {
2304
2305
2306                    var cond = {
2307                        property_type: $scope.search.property_type,
2308                        property_types: $scope.property_types_array,
2309                        bedroom: $scope.bedrating,
2310                        bathroom: $scope.bathrating,
2311                        min_price: $scope.search.min_price,
2312                        max_price: $scope.search.max_price,
2313                        search_listing_sort: $scope.search_listing_sort,
2314                        image_category: $scope.image_category,
2315                        limit: $scope.recordLimit,
2316                        page: $scope.currentPage,
2317                        advance_search: typeof $scope.advanced_search === 'string' ? $scope.advanced_search : JSON.stringify($scope.advanced_search),
2318                        agentid: agentid,
2319                        all_bound: typeof $scope.all_bound === 'string' ? $scope.all_bound : JSON.stringify($scope.all_bound),
2320                        pit: $scope.pit,
2321                        mls_ids: mls_ids,
2322                    };
2323                    // $scope.firstSearchLoading = false;
2324                }
2325
2326                // cond["advance_search"] = cond["advance_search_updated"];
2327
2328
2329
2330
2331                // var cond = JSON.parse($localStorage.our_listing_search_params);
2332
2333                var apiurl = "";
2334                // A bare truthiness test used to be true for the empty object
2335                // app.js seeds on route entry, which sent every search to the
2336                // polygon endpoint with no polygon (and that endpoint ignores
2337                // all_bound, so map filtering silently stopped working).
2338                if (polygonFilter.has($rootScope.polygon_lat_long)) {
2339                    // The API does json_decode() on this, so it must be a JSON
2340                    // string and not an array.
2341                    cond.polygon_lat_long = polygonFilter.toPayload($rootScope.polygon_lat_long);
2342                    $scope.hasPolygon = true;
2343                    apiurl = base_url + "/shared/search-property-result-with-polygon";
2344                } else {
2345                    delete cond.polygon_lat_long;
2346                    $scope.hasPolygon = false;
2347                    apiurl = base_url + "/shared/search-property-result";
2348                }
2349
2350                var token = localStorage.getItem("access_token"); // If login
2351
2352                $scope.show_loader = 1;
2353                $rootScope.propertyMlsIds = [];
2354                if ($scope.searchConditionIsSame(cond)) {
2355                    // Bail out cleanly. This previously returned with
2356                    // show_loader = 1 and callingSearchProperty = true, which
2357                    // stranded the spinner and made resetSearch() a no-op.
2358                    $scope.show_loader = 0;
2359                    $scope.front_spinner = 0;
2360                    $scope.searchLoaderCount = 0;
2361                    $scope.callingSearchProperty = false;
2362                    return;
2363                }
2364                cond.menu_id = $scope.menu_id;
2365                cond.criteria_id = $scope.criteria_id;
2366                cond.page_name = $scope.page_name;
2367                if (
2368                    $scope.currentRoute == "property_details" ||
2369                    $rootScope.previousRoute === $scope.currentRoute ||
2370                    !isEmpty
2371                ) {
2372
2373
2374
2375
2376                    cond.advance_search = typeof cond.advance_search === 'string' ? JSON.parse(cond.advance_search) : {};
2377                    cond.advance_search.bedrooms = cond.bedroom;
2378                    cond.advance_search.bathrooms = cond.bathroom;
2379                    $rootScope.advanceSearchWatcherEnabled = false;
2380                    $scope.bedrating = cond.bedroom;
2381                    $scope.bathrating = cond.bathroom;
2382                    $scope.advanced_search = cond.advance_search;
2383                    cond.advance_search = typeof cond.advance_search === 'string' ? cond.advance_search : JSON.stringify(cond.advance_search);
2384                    $scope.searchCondition = JSON.stringify(cond);
2385
2386
2387
2388
2389                }
2390                if (allbound !== "{}" && typeof allbound != 'undefined' && Object.keys(allbound).length > 0) {
2391
2392
2393
2394                    $rootScope.using_saved_zip = false;
2395                    delete $scope.advanced_search.zip_code;
2396                    var existingAdvancedSearch = JSON.parse(cond.advance_search);
2397                    delete existingAdvancedSearch.zip_code;
2398                    cond.advance_search = JSON.stringify(existingAdvancedSearch)
2399                }
2400                var httpRequest = $http({
2401                    method: "POST",
2402                    url: apiurl,
2403                    data: cond,
2404                    headers: {
2405                        "Content-Type": "application/json; charset=utf-8",
2406                        "Access-Token": token,
2407                    },
2408                }).success(function (data, status) {
2409                    $scope.pageChanged = false;
2410                    // Set $scope.advanced_search
2411                    $scope.search.put_location = '';
2412                    if (typeof allbound === 'string') {
2413                        allbound = JSON.parse(allbound);
2414                    }
2415                    if (typeof allbound != 'undefined' && Object.keys(allbound).length > 0) {
2416
2417
2418                        var localStorageSearchParams = JSON.parse($localStorage.our_listing_search_params);
2419                        $scope.all_bound = allbound;
2420                        localStorageSearchParams.all_bound = $scope.all_bound;
2421
2422
2423                        localStorageSearchParams.advance_search = JSON.parse(localStorageSearchParams.advance_search);
2424                        delete localStorageSearchParams.advance_search.zip_code;
2425                        delete $scope.advanced_search.zip_code;
2426                        $localStorage.our_listing_search_params = JSON.stringify(localStorageSearchParams);
2427
2428
2429
2430
2431                    }
2432                    if (
2433                        $scope.currentRoute == "property_details" ||
2434                        $rootScope.previousRoute === $scope.currentRoute ||
2435                        !isEmpty
2436                    ) {
2437
2438                        const advancedSearch = JSON.parse(cond.advance_search);
2439                        $scope.advanced_search = advancedSearch;
2440                    }
2441                    $rootScope.previousRoute = $scope.currentRoute;
2442
2443                    $rootScope.firstSearchLoading = false;
2444                    $scope.callingSearchProperty = false;
2445                    $rootScope.advanceSearchWatcherEnabled = true;
2446                    // $scope.searchCondition = JSON.stringify(cond);
2447                    $rootScope.propertyMlsIds = [];
2448                    $scope.front_spinner = 0;
2449                    $scope.show_loader = 0;
2450                    $scope.fivehundred_msg_status = 0;
2451                    $scope.all_property_list = data.all_property;
2452                    $scope.pit = data.pit;
2453                    // Add mls ids in rootscope
2454                    data.all_property.forEach(function (property) {
2455                        // Changed to id instead of ml (2024/06/25)
2456                        // $rootScope.propertyMlsIds.push(property.ml);
2457                        $rootScope.propertyMlsIds.push(property.id);
2458                    });
2459                    // $scope.searchLoaderCount--;
2460                    $scope.searchLoaderCount = 0;
2461
2462                    $scope.property_found = data.total_matched_property; // to show all matched property count
2463                    $scope.marker_map_prioperties = data.all_map_property;
2464                    $scope.last_update_corn_time = data.last_update_corn_time; // Last Update Mid Florida Property
2465
2466                    $scope.bedrooms[0].current = cond.bedroom;
2467                    $scope.bathrooms[0].current = cond.bathroom;
2468
2469                    // Set filter_expiration_time
2470                    const currentTimeInMilliseconds = Date.now();
2471                    const expirationTime =
2472                        currentTimeInMilliseconds +
2473                        $scope.resetFilterTimeThreshold * 60 * 1000;
2474                    $localStorage.filter_expiration_time = expirationTime;
2475
2476                    //$rootScope.all_property_search_list = $scope.all_property_list.map(a => a.ml);
2477                    var resultArray = $scope.marker_map_prioperties.map((a) => a.ml);
2478                    $localStorage.mls_id = JSON.stringify(resultArray);
2479
2480                    /* Map and Pagination propety start */
2481                    $scope.visible_property_found = data.total_matched_property;
2482                    if (data.total_matched_property > 500) {
2483                        // $scope.visible_property_found = 500;
2484                        $scope.fivehundred_msg_status = 1;
2485                    } else {
2486                        // $scope.visible_property_found = data.total_matched_property;
2487                        $scope.fivehundred_msg_status = 0;
2488                    }
2489                    /* Map and Pagination propety end */
2490
2491                    setTimeout(function () {
2492                        ImageFitCont();
2493                    }, 500);
2494                    setTimeout(function () {
2495                        $scope.fixCssBackgoundImageDoubleEncodingIssue();
2496                    }, 500);
2497
2498                    //***** Google map integration code here start *****//
2499                    var ip = 0;
2500                    var tmp = {};
2501                    var tmp_arr = [];
2502                    $scope.propertylatlngs = [];
2503
2504                    var latlngArray = Array();
2505                    if ($rootScope.polygon_lat_long) {
2506                        var latngtdata = JSON.parse($rootScope.polygon_lat_long);
2507                        for (var i = 0; i < latngtdata.length; i++) {
2508                            latlngArray[i] = [latngtdata[i].lat, latngtdata[i].lng];
2509                        }
2510                    }
2511
2512                    for (ip = 0; ip < $scope.marker_map_prioperties.length; ip++) {
2513                        tmp = $scope.marker_map_prioperties[ip];
2514                        if (latlngArray.length > 0) {
2515                            var checkPropertyBelongs = isPointInPoly(
2516                                latlngArray,
2517                                tmp.lat,
2518                                tmp.lng
2519                            );
2520                        }
2521
2522                        var prop_image = "";
2523
2524                        if (
2525                            typeof tmp.getimage != "undefined" &&
2526                            tmp.getimage != null &&
2527                            tmp.getimage.length > 0
2528                        ) {
2529                            prop_image = tmp.getimage[0].image_path;
2530                        }
2531
2532                        var mapCurrency = "";
2533                        if (tmp.currency_sign) {
2534                            mapCurrency = tmp.currency_sign;
2535                        } else {
2536                            mapCurrency = "$";
2537                        }
2538
2539                        tmp_arr = [
2540                            tmp.address +
2541                            ", " +
2542                            tmp.city_name +
2543                            ", " +
2544                            tmp.state +
2545                            " - " +
2546                            tmp.zip_code,
2547                            tmp.lat,
2548                            tmp.lng,
2549                            tmp.address +
2550                            ", " +
2551                            tmp.city_name +
2552                            ", " +
2553                            tmp.state +
2554                            " - " +
2555                            tmp.zip_code,
2556                            tmp.list_price,
2557                            tmp.id,
2558                            prop_image,
2559                            tmp.beds,
2560                            tmp.fbaths,
2561                            tmp.hbaths,
2562                            tmp.sqft_liv_area,
2563                            tmp.ml,
2564                            tmp.office_name,
2565                            tmp.mls_id,
2566                            mapCurrency,
2567                            tmp.rent_sale,
2568                            tmp.property_measurement_unit_short
2569                        ];
2570                        $scope.propertylatlngs.push(tmp_arr);
2571                    }
2572
2573                    // Set property type dropdown text
2574
2575
2576
2577                    if ($scope.propertyTypeDropdownText == "") {
2578                        $scope.setPropertyTypeDropdownTextFromAllPropertyTypes();
2579                    }
2580
2581                    setTimeout(function () {
2582                        // 
2583                        var allBound =
2584                            $scope.all_bound != undefined ? $scope.all_bound : {};
2585                        initMap2($scope.propertylatlngs, allBound);
2586                        // initMap2 is what creates the view's DrawingManager, so
2587                        // the draw hook can only be attached once it has run.
2588                        ensurePolygonDrawHook();
2589                        setTimeout(() => {
2590                            // Centering to the default zip code if property count is 0 and if the there is no polygon lat long
2591                            if ($scope.marker_map_prioperties.length == 0 && !polygonFilter.has($rootScope.polygon_lat_long)) {
2592                                const defaultZipSearch = localStorage.getItem("default_zip_search");
2593                                centerToZipCode(defaultZipSearch);
2594                            }
2595                        }, 500);
2596                        // Setting Map Pointer
2597                        // var firstPropertyMl = $rootScope.propertyMlsIds[0];
2598                        // var anchor = document.getElementById(firstPropertyMl);
2599                        // $('button.gm-ui-hover-effect').trigger('click');
2600                        setTimeout(() => {
2601                            const closeButton = jQuery('button.gm-ui-hover-effect');
2602                            closeButton.trigger("click");
2603
2604                        }, 500);
2605                        // angular.element("button.gm-ui-hover-effect").trigger("click");
2606                    }, 1000);
2607
2608                    // Also attempt the hook straight away, in case the map was
2609                    // already built by an earlier pass. The call above, inside
2610                    // the timer, is the one that matters on a cold load.
2611                    ensurePolygonDrawHook();
2612
2613                    $rootScope.history = $location.$$path;
2614
2615
2616                    // Close the modal
2617                    // 
2618                    // const closeButton = document.querySelector('.gm-ui-hover-effect');
2619                    // closeButton.click();
2620
2621                    if (polygonFilter.has($rootScope.polygon_lat_long)) {
2622                        var specify_by_polygon = $rootScope.polygon_lat_long;
2623                        if (specify_by_polygon != "" && $rootScope.hitorybackbtn == 1) {
2624                            draw_polygon_change = true;
2625                            // polygonFilter.parse never throws; the old
2626                            // JSON.parse did, aborting the rest of this handler.
2627                            var specify_by_polygon_arr = polygonFilter.parse(specify_by_polygon);
2628                            var polygonset = new google.maps.Polygon({
2629                                map: map2,
2630                                paths: specify_by_polygon_arr,
2631                                strokeWeight: 2,
2632                                fillColor: "#1aff1a",
2633                                fillOpacity: 0.5,
2634                                draggable: true,
2635                                editable: true,
2636                                geodesic: true,
2637                            });
2638                            polygonset.setMap(map2);
2639                            // Register it so the next rebuild replaces this
2640                            // overlay instead of stacking on top of it.
2641                            trackFilterPolygon(polygonset);
2642                            if (typeof drawingManager !== "undefined" && drawingManager) {
2643                                drawingManager.setDrawingMode(null);
2644                            }
2645
2646                            google.maps.event.addListener(polygonset, "dragend", function () {
2647                                // Polygon was dragged
2648                                isBeingDragged = false;
2649                                draw_polygon_change = true;
2650                                var myJson = JSON.stringify(polygonset.getPath().getArray());
2651                                setPolygonLatLngChnage(myJson);
2652                            });
2653
2654                            google.maps.event.addListener(
2655                                polygonset,
2656                                "dragstart",
2657                                function () {
2658                                    isBeingDragged = true;
2659                                }
2660                            );
2661
2662                            polygonset.getPaths().forEach(function (path, index) {
2663                                google.maps.event.addListener(
2664                                    path,
2665                                    "insert_at",
2666                                    function (markerCoords) {
2667                                        // New point
2668                                        var myJson = JSON.stringify(
2669                                            polygonset.getPath().getArray()
2670                                        );
2671                                        //call polygn value initialize and service call //
2672                                        setPolygonLatLngChnage(myJson);
2673                                        draw_polygon_change = true;
2674                                    }
2675                                );
2676
2677                                google.maps.event.addListener(path, "remove_at", function () {
2678                                    // Point was removed
2679                                    var myJson = JSON.stringify(polygonset.getPath().getArray());
2680                                    //call polygn value initialize and service call //
2681                                    setPolygonLatLngChnage(myJson);
2682                                    draw_polygon_change = true;
2683                                });
2684
2685                                google.maps.event.addListener(path, "set_at", function () {
2686                                    // Point was moved
2687                                    if (!isBeingDragged) {
2688                                        var myJson = JSON.stringify(
2689                                            polygonset.getPath().getArray()
2690                                        );
2691                                        //call polygn value initialize and service call //
2692                                        setPolygonLatLngChnage(myJson);
2693                                        draw_polygon_change = true;
2694                                    }
2695                                });
2696                            });
2697
2698                            setTimeout(function () {
2699                                $(document)
2700                                    .find(".result-blocks .col-sm-6:nth-child(2) a")
2701                                    .trigger("mouseover");
2702                            }, 2000);
2703                        }
2704
2705                        $rootScope.hitorybackbtn = 0;
2706
2707                        if ($rootScope.polygon_lat_long && draw_polygon_change) {
2708                            draw_polygon_change = false;
2709                            // Generate All ZIP code Array From result set //
2710                            $scope.zipcode_array = $scope.all_property_list.map(
2711                                (a) => a.zip_code
2712                            );
2713                            $scope.uniquezipcode_array = $scope.zipcode_array.filter(
2714                                function (item, pos) {
2715                                    return $scope.zipcode_array.indexOf(item) == pos;
2716                                }
2717                            );
2718
2719                            // Generate All County Name Array From result set //
2720                            $scope.county_array = $scope.all_property_list.map(
2721                                (a) => a.county
2722                            );
2723                            $scope.uniquecounty_array = $scope.county_array.filter(function (
2724                                item,
2725                                pos
2726                            ) {
2727                                return $scope.county_array.indexOf(item) == pos;
2728                            });
2729
2730                            // Generate All Development Name Array From result set //
2731                            $scope.development_Name = $scope.all_property_list.map(
2732                                (a) => a.development_name
2733                            );
2734                            $scope.development_Name_array = $scope.development_Name.filter(
2735                                function (item, pos) {
2736                                    return $scope.development_Name.indexOf(item) == pos;
2737                                }
2738                            );
2739
2740                            // Generate All Complex Name Array From result set //
2741                            $scope.complex_Name = $scope.all_property_list.map(
2742                                (a) => a.complex_name
2743                            );
2744                            $scope.complex_Name_array = $scope.complex_Name.filter(function (
2745                                item,
2746                                pos
2747                            ) {
2748                                return $scope.complex_Name.indexOf(item) == pos;
2749                            });
2750
2751                            // Generate All View Array From result set //
2752                            $scope.views_Name = $scope.all_property_list.map((a) => a.view);
2753                            $scope.views_Name_array = $scope.views_Name.filter(function (
2754                                item,
2755                                pos
2756                            ) {
2757                                return $scope.views_Name.indexOf(item) == pos;
2758                            });
2759
2760                            // Generate Water Access Array From result set //
2761                            $scope.water_access = $scope.all_property_list.map(
2762                                (a) => a.water_access
2763                            );
2764                            $scope.water_access_array = $scope.water_access.filter(function (
2765                                item,
2766                                pos
2767                            ) {
2768                                return $scope.water_access.indexOf(item) == pos;
2769                            });
2770
2771                            // Generate All Subdivition Name Array From result set //
2772                            $scope.subdivision_Name = $scope.all_property_list.map(
2773                                (a) => a.subdivision_name
2774                            );
2775                            $scope.subdivision_Name_array = $scope.subdivision_Name.filter(
2776                                function (item, pos) {
2777                                    return $scope.subdivision_Name.indexOf(item) == pos;
2778                                }
2779                            );
2780                        }
2781                    }
2782                });
2783            };
2784
2785            // Call $scope.searchProperty on first page load
2786            // if ($rootScope.firstSearchLoading) {
2787            //     $scope.searchProperty($localStorage.our_listing_search_params, $scope.all_bound);
2788            // }
2789
2790            // Project Details Page Function //
2791
2792            // Project Details Page Function //
2793            $scope.propertyDetails = function () {
2794                $scope.front_spinner = 1;
2795                $scope.property_ml_id = $routeParams.property_ml_id;
2796                var fb_app_id = $rootScope.fb_app_id;
2797                // IF FACEBOOK APP ID  NOT  PUTED FACEBOOK SHARE NOT VISIBLE BUTTON START//
2798                if (fb_app_id != "") {
2799                    $scope.fb_button_visible = 1;
2800                }
2801                // IF FACEBOOK APP ID  NOT  PUTED FACEBOOK SHARE NOT VISIBLE BUTTON END//
2802
2803                var token = localStorage.getItem("access_token"); // If login
2804
2805                if ($localStorage.our_listing_search_params) {
2806                    var search_params = JSON.parse($localStorage.our_listing_search_params);
2807                } else {
2808                    var search_params = "";
2809                }
2810
2811                var httpRequest = $http({
2812                    method: "POST",
2813                    url: base_url + "/firsthometheme/property-details-new",
2814                    data: {
2815                        property_ml_id: $scope.property_ml_id,
2816                        member_id: $scope.userid,
2817                        search_params: search_params,
2818                    },
2819                    headers: {
2820                        "Content-Type": "application/json; charset=utf-8",
2821                        "Access-Token": token,
2822                    },
2823                }).success(function (data, status) {
2824                    $scope.front_spinner = 0;
2825
2826                    if (data.property_det.length === 0) {
2827                        //if property is in database
2828                        $scope.has_property = 0;
2829                    } else {
2830                        if ($localStorage.mls_id) {
2831                            var storeMlsIds = JSON.parse($localStorage.mls_id);
2832                            var indexofMlsId = storeMlsIds.indexOf($scope.property_ml_id);
2833                            if (indexofMlsId > -1) {
2834                                $rootScope.all_property_search_list = storeMlsIds;
2835                                $rootScope.currentPropertyIndex = indexofMlsId;
2836                            }
2837                        }
2838
2839                        $scope.allRelatedProperty = data.realted_property;
2840                        $scope.has_property = 1;
2841                        $scope.property_det = data.property_det;
2842                        $scope.last_update_corn_time = data.last_update_corn_time;
2843                        $scope.latitude = my_lat = parseFloat(data.property_det.lat);
2844                        $scope.longitude = my_lng = parseFloat(data.property_det.lng);
2845                        $scope.address = address = data.property_det.address;
2846                        fb_app_id = data.user_fb_app_id;
2847
2848                        let propertyUrl =
2849                            base_url + "/property-details/" + $scope.property_det.ml;
2850                        $scope.shareMail["msg"] = "Check out this property " + propertyUrl;
2851                        $scope.shareMail["subject"] =
2852                            $scope.property_det.address +
2853                            "-" +
2854                            $scope.property_det.city_name +
2855                            ", " +
2856                            $scope.property_det.state +
2857                            ", " +
2858                            $scope.property_det.zip_code;
2859
2860                        // Set property details page in the local storage //
2861                        localStorage.setItem(
2862                            "prevroute",
2863                            "/property-details/" + $scope.property_det.ml
2864                        );
2865
2866                        if (data.logged_user_fav_proerty > 0) {
2867                            // For Checking user fav property
2868                            $scope.fav_status = 1;
2869                        } else {
2870                            $scope.fav_status = 0;
2871                        }
2872
2873                        // For Meta setting We use below section [Share image and Url] //
2874
2875                        $scope.property_image_url = ""; // image share url for FB
2876
2877                        if (data.property_det.getimage.length > 0) {
2878                            // check property images.. In which position get image set for the facebook share
2879                            for (var i = 0; i < data.property_det.getimage.length; i++) {
2880                                if (
2881                                    typeof data.property_det.getimage[i].image_path != "undefined"
2882                                ) {
2883                                    var last = data.property_det.getimage[i].image_path
2884                                        .split("/")
2885                                        .pop(); // no_image.png
2886                                    var no_image_last = last.split("."); // no_image
2887
2888                                    if (no_image_last[0] != "no_image") {
2889                                        $scope.property_image =
2890                                            theme_image_url +
2891                                            data.property_det.getsisdetails.getmlsdetails.name.toLowerCase() +
2892                                            "/" +
2893                                            data.property_det.getimage[i].image_path;
2894                                        $scope.property_image_url =
2895                                            base_url + $scope.property_image;
2896                                        break;
2897                                    }
2898                                }
2899                            }
2900                        }
2901
2902                        $scope.property_url = $location.absUrl();
2903
2904                        setTimeout(function () {
2905                            ProjectGallery();
2906                            projectDetailImgVideoSwiperSlider();
2907                            ImageFitCont();
2908
2909                            // FOR FACE BOOK INITILIZATION //
2910                            window.fbAsyncInit = function () {
2911                                FB.init({
2912                                    appId: fb_app_id,
2913                                    status: true,
2914                                    cookie: true,
2915                                    xfbml: true,
2916                                });
2917                            };
2918                            (function () {
2919                                var e = document.createElement("script");
2920                                e.async = true;
2921                                e.src =
2922                                    document.location.protocol +
2923                                    "//connect.facebook.net/en_US/all.js";
2924                                document.getElementById("fb-root").appendChild(e);
2925                            })();
2926                            // FOR FACE BOOK INITILIZATION //
2927
2928                            // Remove map loading call, it'll only be called when we click the "Load Map" button
2929                            // Wasim 29-01-2026
2930                            // initMap(); // init map call
2931
2932                            const homeProjectSliderSwiper = new Swiper(
2933                                ".home-project-slider",
2934                                {
2935                                    navigation: {
2936                                        nextEl: ".home-project-slider .swiper-button-next",
2937                                        prevEl: ".home-project-slider .swiper-button-prev",
2938                                    },
2939                                    slidesPerView: 1,
2940                                    spaceBetween: 30,
2941                                    breakpoints: {
2942                                        320: {
2943                                            slidesPerView: 1,
2944                                        },
2945                                        768: {
2946                                            slidesPerView: 2,
2947                                        },
2948                                        992: {
2949                                            slidesPerView: 3,
2950                                        },
2951                                        1200: {
2952                                            slidesPerView: 4,
2953                                        },
2954                                    },
2955                                }
2956                            );
2957
2958                            /* $('.home-project-slider').swiper({
2959                                          nextButton: '.project-slider .swiper-button-next',
2960                                          prevButton: '.project-slider .swiper-button-prev',
2961                                          slidesPerView: 4,
2962                                          spaceBetween: 30,
2963                                          breakpoints: {
2964                                  1024: {
2965                                      slidesPerView: 2
2966                                  },
2967                                  768: {
2968                                      slidesPerView: 1
2969                                  }
2970                              }
2971                          }); */
2972                        }, 1000);
2973                    }
2974                });
2975            };
2976
2977            // New Property details API
2978            $scope.fetchPropertyDetailsNew = function () {
2979                $rootScope.property_details_api_called = true;
2980                $scope.front_spinner = 1;
2981                $scope.propertyDetailsFetching = true;
2982                $scope.property_ml_id = $routeParams.property_ml_id;
2983                const ml = $scope.property_ml_id;
2984                var fb_app_id = $rootScope.fb_app_id;
2985
2986                // IF FACEBOOK APP ID  NOT  PUTED FACEBOOK SHARE NOT VISIBLE BUTTON START//
2987                if (fb_app_id != "") {
2988                    $scope.fb_button_visible = 1;
2989                }
2990
2991                var token = localStorage.getItem("access_token"); // If login
2992                if ($localStorage.our_listing_search_params) {
2993                    var search_params = JSON.parse($localStorage.our_listing_search_params);
2994                } else {
2995                    var search_params = "";
2996                }
2997
2998                var $httpRequest = $http({
2999                    method: "POST",
3000                    // url: base_url + '/firsthometheme/property-details-updated',
3001                    url: base_url + "/shared/property-details",
3002                    data: {
3003                        property_ml_id: $scope.property_ml_id,
3004                        member_id: $scope.userid,
3005                        search_params: search_params,
3006                    },
3007                    headers: {
3008                        "Content-Type": "application/json; charset=utf-8",
3009                        "Access-Token": token,
3010                    },
3011                }).success(function (data, status) {
3012                    $scope.front_spinner = 0;
3013                    if (data.property_det.length === 0) {
3014                        $scope.has_property = 0;
3015                    } else {
3016                        // if ($localStorage.mls_id) {
3017                        //     var storeMlsIds = JSON.parse($localStorage.mls_id);
3018                        //     var indexofMlsId = storeMlsIds.indexOf($scope.property_ml_id);
3019                        //     if (indexofMlsId > -1) {
3020                        //         $rootScope.all_property_search_list = storeMlsIds;
3021                        //         $rootScope.currentPropertyIndex = indexofMlsId;
3022                        //     }
3023                        // }
3024
3025                        // Set shareMail subject and message
3026                        let propertyUrl =
3027                            base_url + "/property-details/" + $scope.property_det.ml;
3028                        $scope.shareMail["msg"] = "Check out this property " + propertyUrl;
3029                        $scope.shareMail["subject"] =
3030                            $scope.property_det.address +
3031                            "-" +
3032                            $scope.property_det.city_name +
3033                            ", " +
3034                            $scope.property_det.state +
3035                            ", " +
3036                            $scope.property_det.zip_code;
3037
3038                        $scope.allRelatedProperty = [];
3039                        $scope.has_property = 1;
3040                        $scope.property_det = data.property_det;
3041                        // Reset map loaded flag
3042                        $scope.mapLoaded = false;
3043                        $scope.property_ml_id = $scope.property_det.ml;
3044
3045                        $scope.latitude = parseFloat(data.property_det.lat);
3046                        $scope.longitude = parseFloat(data.property_det.lng);
3047
3048                        $scope.address = data.property_det.address;
3049                        fb_app_id = data.user_fb_app_id;
3050
3051                        if (data.logged_user_fav_property > 0) {
3052                            // For Checking user fav property
3053                            $scope.fav_status = 1;
3054                        } else {
3055                            $scope.fav_status = 0;
3056                        }
3057
3058                        $scope.property_image_url = ""; // image share url for FB
3059
3060                        if (data.property_det.getimage.length > 0) {
3061                            // check property images.. In which position get image set for the facebook share
3062                            for (var i = 0; i < data.property_det.getimage.length; i++) {
3063                                if (
3064                                    typeof data.property_det.getimage[i].image_path != "undefined"
3065                                ) {
3066                                    var last = data.property_det.getimage[i].image_path
3067                                        .split("/")
3068                                        .pop(); // no_image.png
3069                                    var no_image_last = last.split("."); // no_image
3070
3071                                    if (no_image_last[0] != "no_image") {
3072                                        $scope.property_image_url = data.property_det.getimage[i].image_path;
3073                                        // $scope.property_image =
3074                                        //   theme_image_url +
3075                                        //   data.property_det.getsisdetails.getmlsdetails.name.toLowerCase() +
3076                                        //   "/" +
3077                                        //   data.property_det.getimage[i].image_path;
3078                                        // $scope.property_image_url =
3079                                        //   base_url + $scope.property_image;
3080                                        break;
3081                                    }
3082                                }
3083                            }
3084                        }
3085                        $scope.property_url = $location.absUrl();
3086
3087                        setTimeout(function () {
3088                            ProjectGallery();
3089                            projectDetailImgVideoSwiperSlider();
3090                            ImageFitCont();
3091
3092                            // FOR FACE BOOK INITILIZATION //
3093                            window.fbAsyncInit = function () {
3094                                FB.init({
3095                                    appId: fb_app_id,
3096                                    status: true,
3097                                    cookie: true,
3098                                    xfbml: true,
3099                                });
3100                            };
3101                            (function () {
3102                                var e = document.createElement("script");
3103                                e.async = true;
3104                                e.src =
3105                                    document.location.protocol +
3106                                    "//connect.facebook.net/en_US/all.js";
3107                                document.getElementById("fb-root").appendChild(e);
3108                            })();
3109                            // FOR FACE BOOK INITILIZATION //
3110
3111                            // Remove map loading call, it'll only be called when we click the "Load Map" button
3112                            // Wasim 29-01-2026
3113                            // initMap(); // init map call
3114
3115                            const homeProjectSliderSwiper = new Swiper(
3116                                ".home-project-slider",
3117                                {
3118                                    navigation: {
3119                                        nextEl: ".home-project-slider .swiper-button-next",
3120                                        prevEl: ".home-project-slider .swiper-button-prev",
3121                                    },
3122                                    slidesPerView: 1,
3123                                    spaceBetween: 30,
3124                                    breakpoints: {
3125                                        320: {
3126                                            slidesPerView: 1,
3127                                        },
3128                                        768: {
3129                                            slidesPerView: 2,
3130                                        },
3131                                        992: {
3132                                            slidesPerView: 3,
3133                                        },
3134                                        1200: {
3135                                            slidesPerView: 4,
3136                                        },
3137                                    },
3138                                }
3139                            );
3140                        }, 1000);
3141
3142                        setTimeout(() => {
3143                            jQuery(
3144                                "#propertyProjectDetailModal .modal-body"
3145                            ).mCustomScrollbar("scrollTo", ["top", null]);
3146                        }, 500);
3147
3148                        $scope.propertyDetailsFetching = false;
3149                        // fetch related properties
3150                        $scope.fetchRelatedProperties(ml);
3151                    }
3152                });
3153            };
3154
3155
3156
3157            // if ($scope.routeName == 'property_details' && ($rootScope.property_details_api_called == false || typeof $rootScope.property_details_api_called == 'undefined')) {
3158            //     // Call Property details
3159            //     $scope.property_ml_id = $routeParams.property_ml_id;
3160            //     $scope.fetchPropertyDetailsNew();
3161            // }
3162            // Project Details Page Function //
3163
3164            $scope.getRelatedImageSource = function (imagename, mlsname) {
3165                //var newbaseurl = 'https://dpirealtywebsites.com'
3166                if (imagename == "")
3167                    return (
3168                        base_url + "/public/themes/" + current_theme + "/images/no_menu.png"
3169                    );
3170                else
3171                    return (
3172                        base_url +
3173                        "/dpi_beta/uploads/" +
3174                        mlsname.toLowerCase() +
3175                        "/" +
3176                        imagename
3177                    );
3178            };
3179            // Project Details Page Function //
3180
3181            /******* SEARCH PROPERTY BUTTON AJAX END *******/
3182
3183            /******* Search Filter Checkbox Making Start *******/
3184
3185            $scope.checker = function (
3186                index,
3187                val // index= filter field name ; val= value[ex: Yes/No]
3188            ) {
3189                if (
3190                    typeof $scope.advanced_search[index] != "undefined" &&
3191                    $scope.advanced_search[index] == val
3192                ) {
3193                    delete $scope.advanced_search[index];
3194                } else {
3195                    $scope.advanced_search[index] = val; // Push advanced search filter in advanced_search array
3196                }
3197            };
3198
3199            /******* Search Filter Checkbox Making End *******/
3200
3201            /******* SEARCH PROPERTY BUTTON AJAX END *******/
3202
3203            $scope.changePage = function () // Pagination
3204            {
3205                $scope.pageChanged = true;
3206                if ($scope.search_by_polygon) {
3207                    // 
3208                    var cond =
3209                        $localStorage.our_listing_search_params != undefined &&
3210                            $localStorage.our_listing_search_params != ""
3211                            ? JSON.parse($localStorage.our_listing_search_params)
3212                            : {};
3213                    cond.page = $scope.currentPage;
3214                    $localStorage.our_listing_search_params = JSON.stringify(cond);
3215                    $scope.callingSearchProperty = true;
3216                    $scope.searchProperty($localStorage.our_listing_search_params, $scope.all_bound);
3217                } else {
3218                    // var cond = JSON.parse($localStorage.our_listing_search_params);
3219                    var cond =
3220                        $localStorage.our_listing_search_params != undefined &&
3221                            $localStorage.our_listing_search_params != ""
3222                            ? JSON.parse($localStorage.our_listing_search_params)
3223                            : {};
3224                    cond.page = $scope.currentPage;
3225                    $localStorage.our_listing_search_params = JSON.stringify(cond);
3226                    $scope.callingSearchProperty = true;
3227                    $scope.searchProperty($localStorage.our_listing_search_params, $scope.all_bound);
3228                }
3229            };
3230
3231            // For project details page //
3232            $scope.showNextProperty = function () {
3233                if ($rootScope.currentPropertyIndex < 20 && $localStorage.mls_id) {
3234                    $rootScope.currentPropertyIndex = $rootScope.currentPropertyIndex + 1;
3235                    var storeMlsIds = JSON.parse($localStorage.mls_id);
3236                    $routeParams.property_ml_id =
3237                        storeMlsIds[$rootScope.currentPropertyIndex];
3238                    $location.path("/property-details/" + $routeParam
3238s.property_ml_id);
3239                }
3240            };
3241
3242            $scope.showPreviousProperty = function () {
3243                if ($rootScope.currentPropertyIndex >= 0 && $localStorage.mls_id) {
3244                    $rootScope.currentPropertyIndex = $rootScope.currentPropertyIndex - 1;
3245                    var storeMlsIds = JSON.parse($localStorage.mls_id);
3246                    $routeParams.property_ml_id =
3247                        storeMlsIds[$rootScope.currentPropertyIndex];
3248                    $location.path("/property-details/" + $routeParams.property_ml_id);
3249                }
3250            };
3251            // For project details page //
3252
3253            /* DETAILS PAGE BACK BUTTON */
3254            $scope.backToSearchpage = function () {
3255                $localStorage.backwards = 1;
3256                if ($rootScope.history && $rootScope.polygon_lat_long) {
3257                    $rootScope.hitorybackbtn = 1;
3258                }
3259                var prevUrl = $rootScope.history ? $rootScope.history : "/";
3260                $location.path(prevUrl);
3261            };
3262            /* DETAILS PAGE BACK BUTTON */
3263
3264            /******* Search Details Page Start *******/
3265
3266            $scope.goToProjectDetails = function (prop_id, prop_ml_id) {
3267                $location.path("/property-details/" + prop_ml_id);
3268            };
3269
3270            //============ SHARE WITH FACEBOOK START ===========//
3271            $scope.share = function (post) {
3272                var fbpopup = window.open(
3273                    "https://www.facebook.com/sharer/sharer.php?u=" +
3274                    base_url +
3275                    "/property-details/" +
3276                    $scope.property_det.ml,
3277                    "pop",
3278                    "width=600, height=400, scrollbars=no"
3279                );
3280                $("#share").modal("hide");
3281            };
3282            //============ SHARE WITH FACEBOOK END ===========//
3283            //============ SHARE WITH LINKEDIN START ===========//
3284            $scope.linkedInShare = function (post) {
3285                window.open(
3286                    "https://www.linkedin.com/shareArticle?mini=true&url=" +
3287                    base_url +
3288                    "/property-details/" +
3289                    $scope.property_det.ml,
3290                    "pop",
3291                    "width=600, height=400, scrollbars=no"
3292                );
3293                $("#share").modal("hide");
3294            };
3295            //============ SHARE WITH LINKEDIN END ===========//
3296
3297            /******* Search Details Page End *******/
3298
3299            $scope.makeToFav =
3300                function () // From Property Details page make a property favourite list
3301                {
3302                    $scope.saveFavourite($scope.property_ml_id, "", "details");
3303                };
3304
3305            /****** Request/ And 2 get advice  Send Mail To Contact Agent Start ******/
3306
3307            $scope.submitFormMail = function (param) {
3308                const formData = angular.copy($scope.request);
3309                formData.captcha = {
3310                    id: $scope.request.captcha[param].id,
3311                    value: $scope.request.captcha[param].value,
3312                };
3313                var property_url = $location.absUrl();
3314
3315                var data = {
3316                    request: formData,
3317                    member_id: $scope.userid, //Agent id Website owner
3318                    param: param,
3319                    property_url: property_url,
3320                };
3321
3322                var httpRequest = $http({
3323                    method: "POST",
3324                    url: base_url + "/firsthometheme/send-request-mail",
3325                    data: data,
3326                })
3327                    .success(function (data, status) {
3328                        if (data.success == 1) {
3329                            // Reload all captchas
3330                            $scope.reloadAllCaptchas();
3331                            
3332                            if (param == "expert") {
3333                                $scope.showSuccMsg = 1;
3334                                $scope.change_class = "#FFF";
3335                            } else if (param == "advice") {
3336                                $scope.showSuccMsg1 = 1;
3337                                $scope.change_class = "#71b100";
3338                            } else {
3339                                $scope.showSuccMsg2 = 1;
3340                                $scope.change_class = "#71b100";
3341                            }
3342
3343                            $scope.show_message =
3344                                "Your query has been sent successfully.We will contact you soon.";
3345
3346                            $timeout(function () {
3347                                $scope.showSuccMsg1 = 0;
3348                                $scope.showSuccMsg2 = 0;
3349                                $scope.showSuccMsg = 0;
3350                                angular.element(".close").trigger("click");
3351                                $scope.$digest();
3352                            }, 3000);
3353                            $scope.requestForm.reset();
3354                            $scope.adviceForm.reset();
3355                            $scope.expertForm.reset();
3356                        } else {
3357                            if (param == "expert") {
3358                                $scope.showSuccMsg = 1;
3359                            } else if (param == "advice") {
3360                                $scope.showSuccMsg1 = 1;
3361                            } else {
3362                                $scope.showSuccMsg2 = 1;
3363                            }
3364                            if(data.message) {
3365                                $scope.show_message = data.message;
3366                            } else {
3367                                $scope.show_message = "Some error occured.";
3368                            }
3369                            $scope.change_class = "#F00";
3370
3371                            $timeout(function () {
3372                                $scope.showSuccMsg1 = 0;
3373                                $scope.showSuccMsg2 = 0;
3374                                $scope.showSuccMsg = 0;
3375                                $scope.$digest();
3376                            }, 3000);
3377                        }
3378                    })
3379                    .error(function (data, status, header, config) {
3380                        if (param == "expert") {
3381                            $scope.showSuccMsg = 1;
3382                        } else if (param == "advice") {
3383                            $scope.showSuccMsg1 = 1;
3384                        } else {
3385                            $scope.showSuccMsg2 = 1;
3386                        }
3387                        $scope.show_message = "Some error occured.";
3388                        $scope.change_class = "#F00";
3389                        $timeout(function () {
3390                            $scope.showSuccMsg1 = 0;
3391                            $scope.showSuccMsg2 = 0;
3392                            $scope.showSuccMsg = 0;
3393                            $scope.$digest();
3394                        }, 3000);
3395                    });
3396            };
3397
3398            /****** Request Send Mail To Contact Agent End******/
3399
3400            /**** Remove Search Filter ****/
3401            $scope.removeSearchFilter = function (index) {
3402                if (typeof $scope.advanced_search[index] != "undefined") {
3403                    if (index == "bedrooms") {
3404                        $scope.bedrating = 0;
3405
3406                        $scope.getSelectedBed($scope.bedrating);
3407                        $scope.bedrooms[0].current = 0;
3408                    } else if (index == "bathrooms") {
3409                        $scope.bathrating = 0;
3410                        $scope.getSelectedBath($scope.bathrating);
3411                        $scope.bathrooms[0].current = 0;
3412                    }
3413                    $scope.agent_zip_search = "";
3414                    delete $scope.advanced_search[index];
3415                    // $scope.searchProperty($localStorage.our_listing_search_params, $scope.all_bound);
3416                    // 
3417                }
3418                //
3419            };
3420
3421            // CHANGE PROPERTY TYPE //
3422
3423            $scope.changePropertyType = function () {
3424                $(".m200").toggleClass("open");
3425                // var cond = JSON.parse($localStorage.our_listing_search_params);
3426                var cond =
3427                    $localStorage.our_listing_search_params != undefined &&
3428                        $localStorage.our_listing_search_params != ""
3429                        ? JSON.parse($localStorage.our_listing_search_params)
3430                        : {};
3431                cond.property_type = $scope.search.property_type;
3432                $localStorage.our_listing_search_params = JSON.stringify(cond);
3433                $scope.callingSearchProperty = true;
3434                $scope.searchProperty($localStorage.our_listing_search_params, $scope.all_bound);
3435            };
3436            $scope.closePropertyDropdown = function () {
3437                $(".m200").toggleClass("open");
3438            };
3439            $scope.setPropertyTypeDropdownText = function (propertyType) {
3440                if (propertyType == "all") {
3441                    $scope.setPropertyTypeDropdownText(propertyType);
3442                    $scope.propertyTypeDropdownText = "Property Type";
3443                    return;
3444                }
3445                $scope.propertyTypeDropdownText = "";
3446                const firstPropertyTypeStringLength = $scope.property_types_array[0].length;
3447                if (firstPropertyTypeStringLength > 13) {
3448                    $scope.propertyTypeDropdownText = $scope.property_types_array[0].substring(0, 13) + "...";
3449                } else {
3450                    $scope.propertyTypeDropdownText = $scope.property_types_array[0];
3451                }
3452                if ($scope.property_types_array.length > 1) {
3453                    $scope.propertyTypeDropdownText += " +";
3454                    $scope.propertyTypeDropdownText += $scope.property_types_array.length - 1;
3455                }
3456            }
3457
3458            $scope.setPropertyTypeDropdownTextFromAllPropertyTypes = function () {
3459                $scope.propertyTypeDropdownText = "";
3460                // Check if no property types is selected
3461
3462
3463
3464                if ($scope.property_types_array.length == 0) {
3465                    $scope.propertyTypeDropdownText = "Property Type";
3466                    return;
3467                }
3468                const firstPropertyTypeStringLength = $scope.property_types_array[0].length;
3469                if (firstPropertyTypeStringLength > 13) {
3470                    $scope.propertyTypeDropdownText = $scope.property_types_array[0].substring(0, 13) + "...";
3471                } else {
3472                    $scope.propertyTypeDropdownText = $scope.property_types_array[0];
3473                }
3474                if ($scope.property_types_array.length > 1) {
3475                    $scope.propertyTypeDropdownText += " +";
3476                    $scope.propertyTypeDropdownText += $scope.property_types_array.length - 1;
3477                }
3478            }
3479
3480            // Support for multiple property types
3481            $scope.togglePropertyTypes = function (propertyType) {
3482                if (propertyType === "all") {
3483                    $scope.setPropertyTypeDropdownText(propertyType);
3484                    $scope.property_types_array = [];
3485
3486
3487                    $('#user_all').prop("checked", true);
3488                    var cond =
3489                        $localStorage.our_listing_search_params != undefined &&
3490                            $localStorage.our_listing_search_params != ""
3491                            ? JSON.parse($localStorage.our_listing_search_params)
3492                            : {};
3493                    cond.property_types = $scope.property_types_array;
3494                    $localStorage.our_listing_search_params = JSON.stringify(cond);
3495                    $scope.callingSearchProperty = true;
3496                    $scope.searchProperty($localStorage.our_listing_search_params, $scope.all_bound);
3497
3498
3499                    return;
3500                }
3501                if ($scope.property_types_array.indexOf(propertyType) === -1) {
3502                    $scope.property_types_array.push(propertyType);
3503                } else {
3504                    $scope.property_types_array.splice($scope.property_types_array.indexOf(propertyType), 1);
3505                }
3506                $scope.setPropertyTypeDropdownText(propertyType);
3507                // $(".m200").toggleClass("open");
3508
3509
3510                // var cond = JSON.parse($localStorage.our_listing_search_params);
3511                var cond =
3512                    $localStorage.our_listing_search_params != undefined &&
3513                        $localStorage.our_listing_search_params != ""
3514                        ? JSON.parse($localStorage.our_listing_search_params)
3515                        : {};
3516                // var cond =
3517                //     $localStorage.our_listing_search_params != undefined &&
3518                //         $localStorage.our_listing_search_params != ""
3519                //         ? JSON.parse($localStorage.our_listing_search_params)
3520                //         : {};
3521                cond.property_types = $scope.property_types_array;
3522                $localStorage.our_listing_search_params = JSON.stringify(cond);
3523                // $localStorage.our_listing_search_params = JSON.stringify(cond);
3524                $scope.callingSearchProperty = true;
3525                // $scope.searchProperty($localStorage.our_listing_search_params, $scope.all_bound);
3526                $scope.searchProperty($localStorage.our_listing_search_params, $scope.all_bound);
3527
3528
3529            };
3530            $scope.changeMinPrice = function () {
3531                // var cond = JSON.parse($localStorage.our_listing_search_params);
3532                var cond =
3533                    $localStorage.our_listing_search_params != undefined &&
3534                        $localStorage.our_listing_search_params != ""
3535                        ? JSON.parse($localStorage.our_listing_search_params)
3536                        : {};
3537                cond.min_price = $scope.search.min_price;
3538                $localStorage.our_listing_search_params = JSON.stringify(cond);
3539                $scope.callingSearchProperty = true;
3540                $scope.searchProperty($localStorage.our_listing_search_params, $scope.all_bound);
3541            };
3542            $scope.changeMaxPrice = function () {
3543                // var cond = JSON.parse($localStorage.our_listing_search_params);
3544                var cond =
3545                    $localStorage.our_listing_search_params != undefined &&
3546                        $localStorage.our_listing_search_params != ""
3547                        ? JSON.parse($localStorage.our_listing_search_params)
3548                        : {};
3549                cond.max_price = $scope.search.max_price;
3550                $localStorage.our_listing_search_params = JSON.stringify(cond);
3551                $scope.callingSearchProperty = true;
3552                $scope.searchProperty($localStorage.our_listing_search_params, $scope.all_bound);
3553
3554                if ($scope.search.max_price == null) {
3555                    $scope.priceMinLimitTotal = 10;
3556                    $scope.priceMaxLimitStart = $scope.minSelectedIndex + 1;
3557                }
3558            };
3559
3560            //////////////////////////////////
3561
3562            // For reset your search params //
3563            $scope.resetSearch = function () // Reset Search
3564            {
3565
3566                // $scope.clearPolygonStucture();
3567                listneradded_zoom = false;
3568                listneradded_drag = false;
3569
3570                $scope.search.put_location = "";
3571                $localStorage.our_listing_search_params = "";
3572                $scope.currentPage = 1; //after reset search paging start from 1st
3573                $scope.search.property_type = "";
3574                $scope.property_types_array = [];
3575                $scope.search.min_price = "";
3576                $scope.search.max_price = "";
3577                // $scope.search_listing_sort = "listprice_asc";
3578                $scope.search_listing_sort = $rootScope.our_listing_page_sort;
3579                $scope.image_category = $rootScope.image_category;
3580                $scope.recordLimit = 20;
3581                $scope.currentPage = 1;
3582                $scope.advanced_search = {};
3583                $scope.advanced_search.zip_code = [$localStorage.agent_zip_search];
3584                if ($scope.menu_id == 14 && $scope.criteria_id == 99) {
3585                    delete $scope.advanced_search.zip_code;
3586                }
3587                $scope.halfbathrooms[0].current = 0;
3588                $scope.bedrating = 0;
3589                $scope.bedrooms[0].current = 0;
3590                $scope.bathrating = 0;
3591                $scope.bathrooms[0].current = 0;
3592                // $scope.agent_zip_search = '';
3593                $scope.agent_zip_search = $localStorage.agent_zip_search;
3594                if ($scope.menu_id == 14 && $scope.criteria_id == 99) {
3595                    delete $scope.advanced_search.agent_zip_search;
3596                }
3597
3598                $scope.all_bound = {};
3599
3600                if (!$scope.callingSearchProperty) {
3601                    $scope.searchProperty();
3602                }
3603            };
3604
3605            /*********** ADVANCED SEARCH SECTION SHOW HIDE START ************/
3606            $scope.animate = false;
3607            $scope.showHide = function () {
3608                $scope.animate = !$scope.animate;
3609                if ($scope.animate == true) {
3610                    $scope.show_advanced_text = "Hide Advanced Search";
3611                } else {
3612                    $scope.show_advanced_text = "Show Advanced Search";
3613                }
3614            };
3615
3616            /*********** ADVANCED SEARCH SECTION SHOW HIDE START ************/
3617
3618            /* make active with active class advanced filter */
3619            /* make active with active class advanced filter */
3620            $scope.$watch(
3621                "advanced_search",
3622                function (newVal, oldVal) {
3623
3624                    if (!$rootScope.advanceSearchWatcherEnabled) {
3625                        return;
3626                    }
3627                    // if ($rootScope.firstSearchLoading) {
3628                    //     return;
3629                    // }
3630                    if (oldVal === newVal) {
3631
3632
3633
3634
3635
3636                        if (
3637                            // $rootScope.firstSearchLoading &&
3638                            Object.keys($scope.advanced_search).length != 0
3639                        ) {
3640                            $scope.callingSearchProperty = true;
3641                            $scope.searchProperty();
3642                        }
3643                    } else {
3644
3645
3646
3647                        if ($rootScope.hitback) {
3648                            $rootScope.hitback = 0;
3649                            // var cond = JSON.parse($localStorage.our_listing_search_params);
3650                            var cond =
3651                                $localStorage.our_listing_search_params != undefined &&
3652                                    $localStorage.our_listing_search_params != ""
3653                                    ? JSON.parse($localStorage.our_listing_search_params)
3654                                    : {};
3655                            var agentid = $scope.userid; // Site owner
3656
3657                            $scope.search.property_type = cond.property_type;
3658                            $scope.property_types_array = cond.property_types;
3659                            $scope.bedrating = cond.bedroom;
3660                            $scope.bathrating = cond.bathroom;
3661                            $scope.search.min_price = cond.min_price;
3662                            $scope.search.max_price = cond.max_price;
3663                            $scope.search_listing_sort = cond.search_listing_sort;
3664                            $scope.image_category = cond.image_category;
3665                            $scope.recordLimit = cond.limit;
3666                            $scope.currentPage = cond.page;
3667                            $scope.advanced_search = JSON.parse(cond.advance_search);
3668                            $scope.all_bound = JSON.parse(cond.all_bound);
3669
3670                            $scope.bedrooms[0].current = cond.bedroom;
3671                            $scope.bathrooms[0].current = cond.bathroom;
3672
3673                            var cond = {
3674                                property_type: $scope.search.property_type,
3675                                property_types: $scope.property_types_array,
3676                                bedroom: $scope.bedrating,
3677                                bathroom: $scope.bathrating,
3678                                min_price: $scope.search.min_price,
3679                                max_price: $scope.search.max_price,
3680                                search_listing_sort: $scope.search_listing_sort,
3681                                image_category: $scope.image_category,
3682                                limit: $scope.recordLimit,
3683                                page: $scope.currentPage,
3684                                advanced_search: JSON.parse(cond.advance_search),
3685                                all_bound: typeof $scope.all_bound === 'string' ? $scope.all_bound : JSON.stringify(cond.all_bound),
3686                                agentid: agentid,
3687                            };
3688                            $localStorage.backwards = 1; // from property details page  back to search page
3689                            $scope.callingSearchProperty = true;
3690                            $scope.searchProperty(cond, $scope.all_bound);
3691
3692                        } else {
3693                            if ($localStorage.our_listing_search_params) {
3694                                // var cond = JSON.parse($localStorage.our_listing_search_params);
3695                                var cond =
3696                                    $localStorage.our_listing_search_params != undefined &&
3697                                        $localStorage.our_listing_search_params != ""
3698                                        ? JSON.parse($localStorage.our_listing_search_params)
3699                                        : {};
3700                                if (newVal.bedrooms) {
3701                                    cond.bedroom = newVal.bedrooms;
3702                                } else {
3703                                    cond.bedroom = 0;
3704                                }
3705                                if (newVal.bathrooms) {
3706                                    cond.bathroom = newVal.bathrooms;
3707                                } else {
3708                                    cond.bathroom = 0;
3709                                }
3710
3711                                var new_advance_serach = JSON.stringify(newVal);
3712                                cond.advance_search = new_advance_serach;
3713
3714                                cond = JSON.stringify(cond);
3715                                if ($rootScope.ignore_watcher == false) {
3716                                    $scope.callingSearchProperty = true;
3717                                    $scope.searchProperty(cond, $scope.all_bound);
3718                                } else {
3719                                    $scope.callingSearchProperty = true;
3720                                    $scope.searchProperty(cond, $scope.all_bound);
3721                                    $rootScope.ignore_watcher = false;
3722                                }
3723
3724                                //Call save search history
3725                                var usertoken = localStorage.getItem("access_token");
3726                                if (typeof usertoken != "undefined") {
3727                                    $scope.saveSearchHistory();
3728                                }
3729
3730                                // $localStorage.our_listing_search_params = cond;
3731                            } else {
3732                                var agentid = $scope.userid; // Site owner
3733
3734                                var cond = {
3735                                    property_type: $scope.search.property_type,
3736                                    property_types: $scope.property_types_array,
3737                                    bedroom: $scope.bedrating,
3738                                    bathroom: $scope.bathrating,
3739                                    min_price: $scope.search.min_price,
3740                                    max_price: $scope.search.max_price,
3741                                    search_listing_sort: $scope.search_listing_sort,
3742                                    image_category: $scope.image_category,
3743                                    limit: $scope.recordLimit,
3744                                    page: $scope.currentPage,
3745                                    advance_search: JSON.stringify([]),
3746                                    agentid: agentid,
3747                                };
3748                                $scope.callingSearchProperty = true;
3749                                $scope.searchProperty(cond, $scope.all_bound);
3750
3751                                // $localStorage.our_listing_search_params = cond;
3752                            }
3753                            // Involking search function any changes in search filter
3754                        }
3755
3756                        $("#searchModal").modal("hide"); // After Search modal close
3757
3758                        $scope.advance_search_make_green_active();
3759                    } //else end
3760                },
3761                true
3762            ); /**********************************************************/
3763
3764            $scope.sortListingSearchProperty = function () {
3765                // var cond = JSON.parse($localStorage.our_listing_search_params);
3766                var cond =
3767                    $localStorage.our_listing_search_params != undefined &&
3768                        $localStorage.our_listing_search_params != ""
3769                        ? JSON.parse($localStorage.our_listing_search_params)
3770                        : {};
3771
3772
3773                var cond = {
3774                    property_type: $scope.search.property_type,
3775                    property_types: $scope.property_types_array,
3776                    bedroom: $scope.bedrating,
3777                    bathroom: $scope.bathrating,
3778                    min_price: $scope.search.min_price,
3779                    max_price: $scope.search.max_price,
3780                    search_listing_sort: $scope.search_listing_sort,
3781                    image_category: $scope.image_category,
3782                    limit: $scope.recordLimit,
3783                    page: $scope.currentPage,
3784                    advanced_search:
3785                        typeof cond.advance_search === "undefined"
3786                            ? {}
3787                            : typeof cond.advance_search === 'string' ? JSON.parse(cond.advance_search) : cond.advance_search,
3788                    // advanced_search:
3789                    //     typeof cond.advance_search === "undefined"
3790                    //         ? []
3791                    //         : JSON.parse(cond.advance_search),
3792                    all_bound: typeof cond.all_bound === 'string' ? cond.all_bound : JSON.stringify(cond.all_bound),
3793                    agentid: $scope.userid,
3794                };
3795                $scope.callingSearchProperty = true;
3796                $scope.searchProperty(cond, $scope.all_bound);
3797            };
3798
3799            $scope.changeImageCategory = function (imgageCategoryOption = {}) {
3800                // Check if empty object
3801                if (Object.keys(imgageCategoryOption).length == 0) {
3802                    $scope.image_category = "";
3803                } else {
3804                    $scope.image_category = imgageCategoryOption.visible_name;
3805                }
3806                // var cond = JSON.parse($localStorage.search_params);
3807                var cond =
3808                    $localStorage.search_params != undefined &&
3809                        $localStorage.search_params != ""
3810                        ? $scope.getSearchParamsFromLocalStorage()
3811                        : {};
3812
3813
3814                var cond = {
3815                    property_type: $scope.search.property_type,
3816                    property_types: $scope.property_types_array,
3817                    bedroom: $scope.bedrating,
3818                    bathroom: $scope.bathrating,
3819                    min_price: $scope.search.min_price,
3820                    max_price: $scope.search.max_price,
3821                    search_listing_sort: $scope.search_listing_sort,
3822                    search_listing_date_sort: $scope.search_listing_date_sort,
3823                    image_category: $scope.image_category,
3824                    limit: $scope.recordLimit,
3825                    page: $scope.currentPage,
3826                    advanced_search:
3827                        typeof cond.advance_search === "undefined"
3828                            ? {}
3829                            : typeof cond.advance_search === 'string' ? JSON.parse(cond.advance_search) : cond.advance_search,
3830                    // advanced_search:
3831                    //     typeof cond.advance_search === "undefined"
3832                    //         ? []
3833                    //         : JSON.parse(cond.advance_search),
3834                    all_bound: typeof cond.all_bound === 'string' ? cond.all_bound : JSON.stringify(cond.all_bound),
3835                    agentid: $scope.userid,
3836                };
3837                $scope.callingSearchProperty = true;
3838                $scope.searchProperty(cond, $scope.all_bound);
3839            };
3840
3841            /**********************************************************/
3842
3843            // Responsive Toggle View //
3844            $scope.toggleFilter = function () {
3845                $(".middle_searchform").toggleClass("open");
3846            };
3847
3848            $scope.toggleView = function () {
3849                //$('.middle_searchform').toggleClass('open');
3850                $(".search_results").toggleClass("mapview");
3851                if ($(".search_results").hasClass("mapview")) {
3852                    $("#toggleView").html("List");
3853                } else $("#toggleView").html("Map");
3854            };
3855            $("#navbar").on("show.bs.collapse", function () {
3856                $("header").addClass("higherzindex");
3857            });
3858            $("#navbar").on("hidden.bs.collapse", function () {
3859                $("header").removeClass("higherzindex");
3860            });
3861            // Responsive Toggle End //
3862
3863            // SAVE SEARCH
3864            $scope.saveSearch = function (user_id, page) {
3865                // if ($localStorage.our_listing_search_params) {
3866                //     var parsed_data = $localStorage.our_listing_search_params;
3867                // }
3868                if ($scope.searchCondition != "") {
3869                    var searchCondition = JSON.parse($scope.searchCondition);
3870                    // remove pit and mls id from search condition
3871                    delete searchCondition.pit;
3872                    delete searchCondition.mls_ids;
3873                    var parsed_data = JSON.stringify(searchCondition);
3874                }
3875                const saveSearchEditing = localStorage.getItem("save_search_editing");
3876                const saveSearchId = localStorage.getItem("save_search_id");
3877
3878                if (saveSearchEditing == 1) {
3879                    var data = {
3880                        page: page,
3881                        parsed_data: parsed_data,
3882                        member_id: $scope.userid,
3883                        save_search_id: saveSearchId,
3884                    };
3885                } else {
3886                    var data = {
3887                        page: page,
3888                        parsed_data: parsed_data,
3889                        member_id: $scope.userid,
3890                    };
3891                }
3892
3893                var token = localStorage.getItem("access_token");
3894                var config = {
3895                    headers: {
3896                        "Content-Type": "application/json; charset=utf-8",
3897                        "Access-Token": token,
3898                    },
3899                };
3900
3901                $http
3902                    .post(base_url + "/firstclient/save-search", data, config)
3903                    .success(function (data, status, headers, config) {
3904                        if (data.success == 1) {
3905                            $scope.change_class = "success-save";
3906                            $scope.show_message = "Search saved successfully.";
3907                            $scope.showSuccMsg = 1;
3908                            setTimeout(function () {
3909                                $scope.$apply(function () {
3910                                    $scope.showSuccMsg = 0;
3911                                });
3912                                if (localStorage.getItem("save_search_editing") == 1) {
3913                                    localStorage.setItem("save_search_editing", 0);
3914                                    localStorage.setItem("save_search_id", 0);
3915                                    // close the tab
3916                                    window.close();
3917                                }
3918                            }, 2000);
3919                        } else if (data.success == 2) {
3920                            localStorage.setItem(
3921                                "prevroute",
3922                                "/11/" + $routeParams.page_name + $routeParams.menu_id
3923                            );
3924                            // Close the modal then redirect to login
3925                            $scope.goingToLogin = true;
3926                            // 
3927                            // jQuery('#propertyProjectDetailModal').modal('hide');
3928                            $scope.hidePropertyDetailModal();
3929                            $scope.showClientLoginPopup(); // Show login popup instead of redirecting to user-login
3930                            // $location.path("/user-login");
3931                        } else {
3932                            $scope.change_class = "error-save";
3933                            $scope.show_message = "Some error occured.";
3934                            $scope.showSuccMsg = 1;
3935                            setTimeout(function () {
3936                                $scope.$apply(function () {
3937                                    $scope.showSuccMsg = 0;
3938                                });
3939                            }, 2000);
3940                        }
3941                    });
3942            };
3943
3944            /******************** SAVE SEARCH BY LOGGED IN USER START *******************/
3945
3946            /**
3947             *
3948             * Hide the property detail modal start
3949             *
3950             */
3951            $scope.hidePropertyDetailModal = function () {
3952                jQuery("#propertyProjectDetailModal").modal("hide");
3953                // If backdrop still remains
3954                jQuery(".modal-backdrop").hide();
3955            };
3956            /**
3957             *
3958             * Hide the property detail modal end
3959             *
3960             */
3961
3962            /******************** FAVOURITE PROPERTY BY LOGGED IN USER START *******************/
3963            $scope.saveFavourite = function (property_ml_id, i, page) {
3964                var data = {
3965                    property_ml_id: property_ml_id,
3966                    member_id: $scope.userid,
3967                };
3968
3969                var token = localStorage.getItem("access_token");
3970                var config = {
3971                    headers: {
3972                        "Content-Type": "application/json; charset=utf-8",
3973                        "Access-Token": token,
3974                    },
3975                };
3976
3977                $http
3978                    .post(base_url + "/firstclient/favourite-property-new", data, config)
3979                    .success(function (data, status, headers, config) {
3980                        $scope.makeToFavClicked = false;
3981
3982                        if (page == "search") {
3983                            // For Search Pages if like from search page
3984                            if (data.success == 1) {
3985                                if (
3986                                    typeof $scope.all_property_list[i].fav_status !=
3987                                    "undefined" &&
3988                                    $scope.all_property_list[i].fav_status == 1
3989                                )
3990                                    $scope.all_property_list[i].fav_status = 0;
3991                                else $scope.all_property_list[i].fav_status = 1;
3992                            } else if (data.success == 2) {
3993                                if ($scope.routeName === "property_details") {
3994                                    // After login
3995                                    localStorage.setItem(
3996                                        "prevroute",
3997                                        "/property-details/" + property_ml_id
3998                                    );
3999                                } else {
4000                                    localStorage.setItem(
4001                                        "prevroute",
4002                                        "/11/" + $routeParams.page_name + "/" + $routeParams.menu_id
4003                                    );
4004                                }
4005                                // Close the modal then redirect to login
4006                                $scope.goingToLogin = true;
4007                                // 
4008                                // jQuery('#propertyProjectDetailModal').modal('hide');
4009                                $scope.hidePropertyDetailModal();
4010                                $scope.showClientLoginPopup(); // Show login popup instead of redirecting to user-login
4011                                // $location.path("/user-login");
4012                            }
4013                        } else if (page == "details") {
4014                            // For Search Pages if like from property details page
4015                            if (data.success == 1) {
4016                                if (
4017                                    typeof $scope.fav_status != "undefined" &&
4018                                    $scope.fav_status == 1
4019                                )
4020                                    $scope.fav_status = 0;
4021                                else $scope.fav_status = 1;
4022                            } else if (data.success == 2) {
4023                                if ($scope.routeName === "property_details") {
4024                                    // After login
4025                                    localStorage.setItem(
4026                                        "prevroute",
4027                                        "/property-details/" + property_ml_id
4028                                    );
4029                                }
4030                                // Hide property details modal
4031                                $scope.goingToLogin = true;
4032                                // 
4033                                // jQuery('#propertyProjectDetailModal').modal('hide');
4034                                $scope.hidePropertyDetailModal();
4035                                $scope.showClientLoginPopup();
4035 // Show login popup instead of redirecting to user-login
4036                                // $location.path("/user-login");
4037                            }
4038                        }
4039                    });
4040            };
4041
4042            // Capture the login and registration modal hide
4043            jQuery('#clientLoginModal').on('hidden.bs.modal', function (e) {
4044                let searchUrl = "/my_listings";
4045                $scope.goingToLogin = false;
4046                location.skipReload().path(searchUrl).replace();
4047            });
4048            jQuery('#clientRegistrationModal').on('hidden.bs.modal', function (e) {
4049                let searchUrl = "/my_listings";
4050                $scope.goingToLogin = false;
4051                location.skipReload().path(searchUrl).replace();
4052            });
4053            // 
4054            /******************** FAVOURITE PROPERTY BY LOGGED IN USER END *******************/
4055
4056            /************** SAVE IDX SEARCH BY LOGGED IN USER START ***************/
4057
4058            /**********  QUICK SEARCH STRAT **********/
4059
4060            $scope.quickSearch = function () {
4061                $scope.quickSearchCalled = true;
4062                var agentid = $scope.userid; // Site owner
4063                $rootScope.fromhomesearch = 1;
4064
4065                var cond = {
4066                    property_type: $scope.search.property_type,
4067                    property_types: $scope.property_types_array,
4068                    bedroom: $scope.bedrating,
4069                    bathroom: $scope.bathrating,
4070                    min_price: $scope.search.min_price,
4071                    max_price: $scope.search.max_price,
4072                    search_listing_sort: $scope.search_listing_sort,
4073                    image_category: $scope.image_category,
4074                    limit: $scope.recordLimit,
4075                    page: $scope.currentPage,
4076                    advance_search: typeof $scope.advanced_search === 'string' ? $scope.advanced_search : JSON.stringify($scope.advanced_search),
4077                    agentid: agentid,
4078                };
4079
4080                if (typeof cond != "undefined") {
4081                    $localStorage.our_listing_search_params = JSON.stringify(cond); // Set search parameters in local storage
4082                }
4083
4084                // $location.path('/11/search/11');
4085                // Making dynamic /11/search/11 & /11/search-property/11
4086                const pageName =
4087                    $routeParams.page_name == undefined
4088                        ? "search"
4089                        : $routeParams.page_name;
4090                const menuId =
4091                    $routeParams.menu_id == undefined ? "11" : $routeParams.menu_id;
4092                var searchUrl = "/11/" + pageName + "/" + menuId;
4093                $location.path(searchUrl);
4094                //$location.path($scope.menu_id+'/'+$routeParams.page_name+'/'+$scope.menu_id);
4095            };
4096
4097            /**********  QUICK SEARCH END **********/
4098
4099            /* For Dynamic Meta data call Start */
4100
4101            $scope.allSetMeta =
4102                function () // Call all meta tag and social tag set for user/ default
4103                {
4104                    var httpRequest = $http({
4105                        method: "POST",
4106                        url: base_url + "/firsthometheme/all-social-meta",
4107                        data: {
4108                            menu_id: $scope.menu_id,
4109                            userid: $scope.userid,
4110                        },
4111                    }).success(function (data, status) {
4112                        $scope.allsocialmeta = data.social_meta_des;
4113                        $rootScope.our_listing_page_sort = data.listing_sorts.our_listing_page_sort;
4114                        $scope.search_listing_sort = $rootScope.our_listing_page_sort;
4115                        if ($scope.allsocialmeta.og_url == 1) {
4116                            $scope.allsocialmeta.og_url = $location.absUrl();
4117                        }
4118                    });
4119                };
4120
4121            /* For Dynamic Meta data call End */
4122            //====================================================================//
4123            if ($scope.routeName !== "property_details") {
4124                $scope.allSetMeta(); // self invoking
4125            }
4126            //====================================================================//
4127
4128            if (
4129                $scope.criteria_id > 0 &&
4130                $scope.menu_id > 0 &&
4131                $scope.callingSearchProperty === false
4132            ) {
4133                $scope.callingSearchProperty = true;
4134                $scope.advance_search = {};
4135                if (
4136                    $scope.currentRoute != "property_details" &&
4137                    $rootScope.previousRoute !== $scope.currentRoute &&
4138                    isEmpty
4139                ) {
4140
4141                    // Save the access token and usr_info before clearing
4142                    const accessToken = localStorage.getItem("access_token");
4143                    const userInfo = localStorage.getItem("usr_info");
4144                    const visited = localStorage.getItem("visited");
4145                    $localStorage.$reset();
4146                    localStorage.clear();
4147                    localStorage.setItem("usr_info", userInfo);
4148                    localStorage.setItem("access_token", accessToken);
4149                    if(visited) {
4150                        localStorage.setItem("visited", visited);
4151                    }
4152                }
4153
4154
4155                // $scope.firstSearchLoading = true;
4156                $scope.searchProperty();
4157            } else {
4158                $scope.advance_search = {};
4159                if (
4160                    $routeParams.page_name != "search-property" &&
4161                    $rootScope.fromhomesearch != 1 &&
4162                    $scope.currentRoute != "property_details" &&
4163                    $rootScope.previousRoute !== $scope.currentRoute &&
4164                    isEmpty &&
4165                    typeof $rootScope.previousRoute !== "undefined"
4166                ) {
4167
4168
4169                    // Save the access token and usr_info before clearing
4170                    const accessToken = localStorage.getItem("access_token");
4171                    const userInfo = localStorage.getItem("usr_info");
4172                    const visited = localStorage.getItem("visited");
4173                    $localStorage.$reset();
4174                    localStorage.clear();
4175                    localStorage.setItem("usr_info", userInfo);
4176                    localStorage.setItem("access_token", accessToken);
4177                    if(visited) {
4178                        localStorage.setItem("visited", visited);
4179                    }
4180                }
4181
4182                // $scope.firstSearchLoading = true;
4183                if ($rootScope.doNotCallZipCode !== true) {
4184                    $scope.getAgentDetails();
4185                }
4186            }
4187            $scope.getPublicRelatorMedias = function () {
4188                $http({
4189                    method: "POST",
4190                    url: "https://api.ibuyervideos.com/api/public-medias",
4191                    data: {
4192                        user_id: $scope.userid,
4193                        mls_id: $scope.property_ml_id,
4194                    },
4195                }).success(function (data, status) {
4196                    $scope.realtorMedias = data.medias;
4197
4198                    if ($scope.realtorMedias.children.length) {
4199                        $scope.realtorSlides = $scope.realtorMedias.children[0].files;
4200                        // $scope.slideDescription = $scope.realtorMedias.folder.folder_description;
4201                        $scope.activeFolderSlide = 0;
4202                        $scope.activeFileSlide = null;
4203                        $scope.setDescription();
4204                    } else if ($scope.realtorMedias.files.length) {
4205                        $scope.realtorSlides = $scope.realtorMedias.files;
4206                        // $scope.slideDescription = $scope.realtorMedias.folder.folder_description;
4207                        $scope.activeFileSlide = index;
4208                        $scope.activeFolderSlide = null;
4209                        $scope.setDescription();
4210                    }
4211                });
4212            };
4213
4214            $scope.changeFolderSlide = function (index) {
4215                $scope.realtorSlides = $scope.realtorMedias.children[index].files;
4216                $scope.activeFolderSlide = index;
4217                $scope.activeFileSlide = null;
4218                fileFolder_detail_sliderSwiper.update();
4219                window.setTimeout(function () {
4220                    window.dispatchEvent(new Event("resize"));
4221                    fileFolder_detail_sliderSwiper.slideTo(0);
4222                    $scope.setDescription(fileFolder_detail_sliderSwiper.realIndex);
4223                }, 1000);
4224            };
4225
4226            $scope.changeFileSlide = function (index) {
4227                $scope.realtorSlides = $scope.realtorMedias.files;
4228                $scope.activeFileSlide = index;
4229                $scope.activeFolderSlide = null;
4230                fileFolder_detail_sliderSwiper.update();
4231                window.setTimeout(function () {
4232                    window.dispatchEvent(new Event("resize"));
4233                    fileFolder_detail_sliderSwiper.slideTo(index);
4234                    $scope.setDescription(fileFolder_detail_sliderSwiper.realIndex);
4235                }, 1000);
4236            };
4237
4238            $scope.setDescription = function (index = null) {
4239                if ($scope.activeFolderSlide != null) {
4240                    $scope.slideDescription = index
4241                        ? $scope.realtorSlides[index].description
4242                        : $scope.realtorMedias.children[0].files[0].description;
4243                } else if ($scope.activeFileSlide != null) {
4244                    $scope.slideDescription = index
4245                        ? $scope.realtorSlides[index].description
4246                        : $scope.realtorMedias.files[0].description;
4247                }
4248                if (projectDetailFileFolderModal.classList.contains("in")) {
4249                    $scope.$apply();
4250                }
4251            };
4252
4253            if ($scope.routeName === "property_details") {
4254                $scope.getPublicRelatorMedias();
4255            }
4256
4257            $scope.setMinPrice = function (price) {
4258                let minIndex = $scope.priceRanges.indexOf(price);
4259                // $scope.priceMinLimitStart = Math.min(index + 1, 9);
4260                $scope.priceMaxLimitStart = minIndex + 1;
4261                $scope.search.min_price = $scope.priceRanges[minIndex];
4262                $scope.minSelectedIndex = minIndex;
4263                $scope.showMinPriceList = false;
4264                $scope.showMaxPriceList = true;
4265
4266                if ($scope.maxSelectedIndex == 0) {
4267                    $scope.maxSelectedIndex = $scope.minSelectedIndex;
4268                }
4269            };
4270
4271            $scope.setMaxPrice = function (price) {
4272                let maxIndex = $scope.priceRanges.indexOf(price);
4273                $scope.maxSelectedIndex = maxIndex;
4274                $scope.search.max_price = $scope.priceRanges[$scope.maxSelectedIndex];
4275                $scope.priceMaxLimitStart = $scope.maxSelectedIndex + 1;
4276                $scope.priceMinLimitTotal = Math.min($scope.maxSelectedIndex, 10);
4277                $scope.showMinPriceList = true;
4278                $scope.showMaxPriceList = false;
4279                $scope.closePriceList();
4280            };
4281
4282            $scope.setMaxPriceEmpty = function () {
4283                $scope.maxSelectedIndex = null;
4284                $scope.search.max_price = "";
4285                $scope.priceMaxLimitStart = $scope.minSelectedIndex + 1;
4286                $scope.priceMinLimitTotal = 10;
4287                // $scope.closePriceList();
4288            };
4289
4290            $scope.adjustMinDropdown = function () {
4291                $scope.showMinPriceList = true;
4292                $scope.showMaxPriceList = false;
4293            };
4294
4295            $scope.adjustMaxDropdown = function () {
4296                $scope.showMinPriceList = false;
4297                $scope.showMaxPriceList = true;
4298            };
4299
4300            $scope.closePriceList = function () {
4301                $(".mw165").toggleClass("open");
4302                $scope.changeMaxPrice();
4303            };
4304
4305            // price Range Value change watch function start //
4306            $scope.$watchGroup(
4307                ["search.min_price", "search.max_price"],
4308                function (newValues, oldValues, scope) {
4309                    // if ($rootScope.firstSearchLoading) {
4310                    //     return;
4311                    // }
4312                    if (
4313                        newValues[0] > 0 &&
4314                        (newValues[1] == "" || newValues[1] == null)
4315                    ) {
4316                        $scope.price_view_value =
4317                            "$" + $scope.kFormatter(newValues[0]) + "+";
4318                    } else if (
4319                        (newValues[0] == "" || newValues[0] == 0 || newValues[0] == null) &&
4320                        newValues[1] > 0
4321                    ) {
4322                        $scope.price_view_value =
4323                            "Up To $" + $scope.kFormatter(newValues[1]) + "+";
4324                    } else if (
4325                        newValues[0] != "" &&
4326                        newValues[1] != "" &&
4327                        newValues[0] > 0 &&
4328                        newValues[1] > 0
4329                    ) {
4330                        $scope.price_view_value =
4331                            "$" +
4332                            $scope.kFormatter(newValues[0]) +
4333                            " - $" +
4334                            $scope.kFormatter(newValues[1]);
4335                    } else if (
4336                        (newValues[0] == "" || newValues[0] == 0 || newValues[0] == null) &&
4337                        (newValues[1] == "" || newValues[1] == null)
4338                    ) {
4339                        $scope.price_view_value = "Enter Price";
4340                    }
4341                }
4342            );
4343
4344            // price Range Value change watch function end //
4345
4346            $scope.kFormatter = function (
4347                num //price formatter after 1000 its convert to K $2000 = $2k
4348            ) {
4349                return num > 999 ? parseFloat((num / 1000).toFixed(1)) + "k" : num;
4350            };
4351
4352            // Save Search History Of loggedin User Start//
4353            $scope.saveSearchHistory = function () {
4354                if ($localStorage.our_listing_search_params) {
4355                    var parsed_data = $localStorage.our_listing_search_params;
4356                }
4357                var data = {
4358                    parsed_data: parsed_data,
4359                    member_id: $scope.userid,
4360                };
4361                var token = localStorage.getItem("access_token");
4362                var config = {
4363                    headers: {
4364                        "Content-Type": "application/json; charset=utf-8",
4365                        "Access-Token": token,
4366                    },
4367                };
4368                $http
4369                    .post(base_url + "/firstclient/save-search-history", data, config)
4370                    .success(function (data, status, headers, config) {
4371                        if (data.success == 1) {
4372                            //
4373                        } else {
4374                            //
4375                        }
4376                    });
4377            };
4378            // Save Search History Of loggedin User End//
4379
4380            //////////////////////////////////////////////////////////////////////////////
4381
4382            // if ($scope.routeName == 'search_property' && $scope.callingSearchProperty == false) {
4383            //     if (typeof $scope.all_bound != 'undefined' && Object.keys($scope.all_bound).length > 0) {
4384            //         $scope.searchProperty({}, $scope.all_bound);
4385            //     } else {
4386            //         $scope.searchProperty();
4387            //     }
4388
4389            // }
4390
4391            // Add event listener for project-thumb
4392            jQuery(".project-thumb > a").hover(function () {
4393                var mlCode = jQuery(this).attr("id");
4394
4395
4396                jQuery(".marker_googlemap").removeClass("property_hovered");
4397                jQuery(".marker_" + mlCode).addClass("property_hovered");
4398            });
4399        }
4400    ); // Controller end

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.