PageSourceSearch

https://www.tenmat.com/wp-content/plugins/open-user-map/src/js/frontend-ajax.js?ver=1.4.52

js tenmat.com collected 2026-09-24 12:31:03 UTC 7,810 bytes, 190 lines download raw bytes

1// Event: "Add Location"-Form send
2jQuery('#oum_add_location').submit(function(event) {
3  jQuery('#oum_submit_btn').addClass('oum-loading');
4  
5  event.preventDefault();
6  // Persist the current map zoom with the submission.
7  if (window.oumMap2 && typeof window.oumMap2.getZoom === 'function') {
8    const zoomField = document.getElementById('oum_location_zoom');
9    if (zoomField) {
10      zoomField.value = window.oumMap2.getZoom();
11    }
12  }
13  if (typeof OUMFormMap !== 'undefined' && typeof OUMFormMap.syncGeometryFields === 'function') {
14    OUMFormMap.syncGeometryFields();
15  }
16  let formData = new FormData(this);
17
18  // Process opening hours fields - validate and convert to JSON
19  const openingHoursInputs = document.querySelectorAll('.oum-opening-hours-input');
20  openingHoursInputs.forEach(function(input) {
21    const fieldName = input.name;
22    const fieldIndexMatch = fieldName.match(/\[(\d+)\]/);
23    if (!fieldIndexMatch) {
24      return;
25    }
26    const fieldIndex = fieldIndexMatch[1];
27    const hoursValue = input.value.trim();
28
29    // Remove the original field from formData
30    formData.delete(fieldName);
31
32    // Validate and convert to JSON (timezone will be added server-side using WordPress timezone)
33    if (hoursValue !== '') {
34      if (typeof OUMOpeningHours !== 'undefined' && OUMOpeningHours.validateFormat(hoursValue)) {
35        // Just send the hours input - server will parse and add WordPress timezone
36        formData.append(`oum_location_custom_fields[${fieldIndex}][hours]`, hoursValue);
37      } else {
38        oumShowError([{message: (typeof oum_opening_hours !== 'undefined' && oum_opening_hours.invalid_format) ? oum_opening_hours.invalid_format : 'Invalid opening hours format. Expected format: Mo 09:00-18:00 or Mo 9:00 AM-5:00 PM'}]);
39        jQuery('#oum_submit_btn').removeClass('oum-loading');
40        return false;
41      }
42    }
43  });
44
45  // Get all images (both existing and new) in their current order
46  const previewContainer = document.getElementById('oum_location_images_preview');
47  let imageOrder = [];
48
49  // Only process images if the preview container exists
50  if (previewContainer) {
51    const previewItems = previewContainer.querySelectorAll('.image-preview-item');
52
53    // Add existing and new images to formData in their current order
54    previewItems.forEach((item, index) => {
55      if (item.classList.contains('existing-image')) {
56        // For existing images, get the URL from the hidden input
57        const existingImageInput = item.querySelector('[name="existing_images[]"]');
58        if (!existingImageInput) {
59          return;
60        }
61        let imgUrl = existingImageInput.value;
62        
63        // Fix for handling URLs - extract just the path portion if it's a full URL
64        if (imgUrl.startsWith('http')) {
65          try {
66            // Create a URL object to extract just the pathname
67            const urlObj = new URL(imgUrl);
68            imgUrl = urlObj.pathname; // This gives us just the path portion
69          } catch (e) {
70            // If URL parsing fails, keep the original value
71            console.log('Could not parse URL:', imgUrl);
72          }
73        }
74        
75        formData.append('existing_images[]', imgUrl);
76        imageOrder.push('existing:' + imgUrl);
77      } else {
78        // For new images, get the file from selectedFiles using the filename
79        const fileName = item.dataset.fileName;
80        const file = window.oumSelectedFiles.find(f => f.name === fileName);
81        if (file) {
82          formData.append('oum_location_images[]', file);
83          imageOrder.push('new:' + fileName);
84        }
85      }
86    });
87
88    // Add the complete image order
89    formData.append('image_order', JSON.stringify(imageOrder));
90  }
91
92  formData.append('action', 'oum_add_location_from_frontend');
93
94  jQuery.ajax({
95    type: 'POST',
96    url: oum_ajax.ajaxurl,
97    cache: false,
98    contentType: false,
99    processData: false,
100    data: formData,
101    success: function (response, textStatus, XMLHttpRequest) {
102      jQuery('#oum_submit_btn').removeClass('oum-loading');
103
104      if(response.success == false) {
105        oumShowError(response.data);
106      }
107      if(response.success == true) {
108        jQuery('#oum_add_location').trigger('reset');
109        const deleteLocationInput = document.getElementById('oum_delete_location');
110        const postIdInput = document.getElementById('oum_post_id');
111        
112        // Determine message type based on action
113        if (deleteLocationInput && deleteLocationInput.value === 'true') {
114            // For deletion
115            OUMFormController.showFormMessage(
116                'success',
117                oum_custom_strings.location_deleted,
118                oum_custom_strings.delete_success,
119                oum_custom_strings.close_and_refresh,
120                function() {
121                    window.location.reload();
122                }
123            );
124        } else if (postIdInput && postIdInput.value) {
125            // For edits
126            OUMFormController.showFormMessage(
127                'success',
128                oum_custom_strings.changes_saved,
129                oum_custom_strings.changes_saved_message,
130                oum_custom_strings.close_and_refresh,
131                function() {
132                    window.location.reload();
133                }
134            );
135        } else {
136            // For new locations
137            if(typeof oum_action_after_submit !== 'undefined') {
138                if(oum_action_after_submit === 'refresh') {
139                    window.location.reload();
140                } else if(oum_action_after_submit === 'redirect' && typeof thankyou_redirect !== 'undefined' && thankyou_redirect !== '') {
141                    window.location.href = thankyou_redirect;
142                } else {
143                    // Show thank you message with refresh button (default)
144                    const thankyouDiv = document.getElementById('oum_add_location_thankyou');
145                    const thankyouHeadline = thankyouDiv?.querySelector('h3')?.textContent || oum_custom_strings.thank_you;
146                    const thankyouText = thankyouDiv?.querySelector('.oum-add-location-thankyou-text')?.textContent || oum_custom_strings.thank_you_message;
147                    
148                    OUMFormController.showFormMessage(
149                        'success',
150                        thankyouHeadline,
151                        thankyouText,
152                        oum_custom_strings.close_and_refresh,
153                        function() {
154                            window.location.reload();
155                        }
156                    );
157                }
158            } else {
159                // Fallback to thank you message with refresh button
160                const thankyouDiv = document.getElementById('oum_add_location_thankyou');
161                const thankyouHeadline = thankyouDiv?.querySelector('h3')?.textContent || oum_custom_strings.thank_you;
162                const thankyouText = thankyouDiv?.querySelector('.oum-add-location-thankyou-text')?.textContent || oum_custom_strings.thank_you_message;
163                
164                OUMFormController.showFormMessage(
165                    'success',
166                    thankyouHeadline,
167                    thankyouText,
168                    oum_custom_strings.close_and_refresh,
169                    function() {
170                        window.location.reload();
171                    }
172                );
173            }
174        }
175      }
176    },
177    error: function (XMLHttpRequest, textStatus, errorThrown) { 
178      console.log(errorThrown);
179    }
180  });
181});
182
183function oumShowError(errors) {
184  const errorWrapEl = jQuery('#oum_add_location_error');
185  errorWrapEl.html('');
186  errors.forEach(error => {
187    errorWrapEl.append(error.message + '<br>');
188  });
189  errorWrapEl.show();
190}

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.