PageSourceSearch

https://www.vooremaa.ee/wp-content/plugins/vooremaa-core/assets/js/reclassified-ads-form-handler.js?ver=1.0

js vooremaa.ee collected 2026-10-01 11:30:54 UTC 7,233 bytes, 164 lines download raw bytes

1jQuery(document).ready(function($) {
2    function initReclassifiedAdsForm() {
3        var form = $('.reclassified-ads-form');
4        if (form.length > 0) {
5            form.each(function() {
6                var $form = $(this);
7                var categorySelect = $form.find('#category');
8                var publicationTimesSelect = $form.find('#publication_times');
9                var currentPrice = $form.find('#current-price');
10                var submitButton = $form.find('button[type="submit"]');
11                var messageTextarea = $form.find('#message');
12                var charCount = $form.find('#char-count');
13                var addImageRadios = $form.find('input[name="add_image"]');
14                var imageField = $form.find('#image_field');
15                var webPublicationRadios = $form.find('input[name="web_publication"]');
16                var publicationDate = $form.find('#publication_date');
17                var extraDatesField = $('<div class="form-group"><label for="extra_dates">Lisakuupäevad</label><input type="text" name="extra_dates" id="extra_dates" class="form-control" placeholder="Täpsusta vajadusel kuupäevasid"></div>').hide();
18
19                // Add extra dates field after publication times
20                publicationTimesSelect.closest('.form-group').after(extraDatesField);
21
22                // Initialize datepicker
23                if (publicationDate.length > 0) {
24                    publicationDate.datepicker({
25                        format: 'dd.mm.yyyy',
26                        weekStart: 1,
27                        daysOfWeekDisabled: '0,1,3,4,6',
28                        autoclose: true,
29                        todayHighlight: true,
30                        startDate: new Date(),
31                        language: 'et'
32                    });
33                }
34
35                function updateCharCount() {
36                    var charLength = messageTextarea.val().length;
37                    charCount.text('Tähemärkide limiit: ' + charLength + '/600');
38                }
39
40                function updatePrice() {
41                    var category = categorySelect.find('option:selected').data('price') || 0;
42                    var publicationTimes = parseInt(publicationTimesSelect.val()) || 1;
43                    var message = messageTextarea.val().trim();
44                    var addImage = $form.find('input[name="add_image"]:checked').val();
45                    var webPublication = $form.find('input[name="web_publication"]:checked').val();
46                    var lines = Math.ceil(message.length / 27);
47                    var basePrice = lines * category;
48                    var totalPrice = basePrice;
49
50                    if (publicationTimes > 1) {
51                        totalPrice += basePrice * 0.9 * (publicationTimes - 1); // Apply 10% discount to additional publications
52                    }
53
54                    if (addImage === 'yes') {
55                        totalPrice += 5;
56                        if (publicationTimes > 1) {
57                            totalPrice += 5 * 0.9 * (publicationTimes - 1); // Apply 10% discount to image for additional publications
58                        }
59                    }
60
61                    if (webPublication === 'yes') {
62                        totalPrice += 2;
63                    }
64
65                    if (category === 0) {
66                        currentPrice.text('Hinna arvutamiseks palun vali Rubriik');
67                        submitButton.prop('disabled', true);
68                    } else {
69                        currentPrice.text(totalPrice.toFixed(2) + ' EUR');
70                        submitButton.prop('disabled', false);
71                    }
72
73                    return totalPrice; // Return the calculated price
74                }
75
76                function handleConditionalFields() {
77                    var addImage = $form.find('input[name="add_image"]:checked').val();
78                    var publicationTimes = publicationTimesSelect.val();
79
80                    if (addImage === 'yes') {
81                        imageField.show();
82                    } else {
83                        imageField.hide();
84                    }
85
86                    if (publicationTimes > 1) {
87                        extraDatesField.show();
88                    } else {
89                        extraDatesField.hide();
90                    }
91
92                    updateCharCount();
93                    updatePrice();
94                }
95
96                function validateForm() {
97                    var category = categorySelect.val();
98                    var publicationTimes = publicationTimesSelect.val();
99                    var publicationDateValue = publicationDate.val().trim();
100
101                    if (category && publicationTimes && publicationDateValue) {
102                        submitButton.prop('disabled', false);
103                    } else {
104                        submitButton.prop('disabled', true);
105                    }
106                }
107
108                $form.show();
109                updateCharCount();
110                handleConditionalFields();
111
112                categorySelect.on('change', function() {
113                    handleConditionalFields();
114                    validateForm();
115                });
116                publicationTimesSelect.on('change', function() {
117                    updatePrice();
118                    handleConditionalFields();
119                    validateForm();
120                });
121                messageTextarea.on('input', function() {
122                    updateCharCount();
123                    updatePrice();
124                    validateForm();
125                });
126                publicationDate.on('change', validateForm);
127                addImageRadios.on('change', handleConditionalFields);
128                webPublicationRadios.on('change', updatePrice);
129
130                // Handle form submission
131                $form.on('submit', function(e) {
132                    e.preventDefault();
133                    var formData = new FormData(this);
134                    formData.append('action', 'add_reclassified_ad_to_cart');
135                    formData.append('security', vooremaaCore.ajax_nonce);
136
137                    // Include calculated price in the formData
138                    var calculatedPrice = updatePrice();
139                    formData.append('calculated_price', calculatedPrice);
140
141                    $.ajax({
142                        url: vooremaaCore.ajax_url,
143                        type: $form.attr('method'),
144                        data: formData,
145                        processData: false,
146                        contentType: false,
147                        success: function(response) {
148                            if (response.success) {
149                                window.location.href = response.data.cart_url;
150                            } else {
151                                alert(response.data.message);
152                            }
153                        },
154                        error: function() {
155                            alert('Form submission failed.');
156                        }
157                    });
158                });
159            });
160        }
161    }
162
163    initReclassifiedAdsForm();
164});

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.