PageSourceSearch

https://kmm.com.ua/catalog/view/javascript/preorder/preorder.js

js kmm.com.ua collected 2026-10-09 01:08:51 UTC 10,110 bytes, 230 lines download raw bytes

1function submitPreOrder() {
2  $.ajax({
3    url: 'index.php?route=extension/module/preorder',
4    type: 'post',
5    dataType: 'json',
6    data: $("#form-preorder").serialize(),
7    success: function(json) {
8      $('.alert-success, .alert-danger').remove();
9        
10      if (json['error']) {
11        $('.preorder-alert').before('<div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i> ' + json['error'] + '</div>');
12      }
13
14      if (json['success']) {
15        $('.preorder-alert').before('<div class="alert alert-success"><i class="fa fa-check-circle"></i> ' + json['success'] + '</div>');
16
17        setTimeout(function () {
18          $('#preorder-box').modal('hide');
19        }, 2000);
20      }
21    }
22  });
23}
24
25function addPreOrder(option_status, product_id, module_id) {
26  $('#preorder-box').remove();
27  
28  if (option_status) {
29    var product = '#product' + (typeof(module_id) != 'undefined' ? module_id + product_id : '');
30    var product_option = $(product + ' input[type=\'radio\']:checked, ' + product + ' input[type=\'checkbox\']:checked, ' + product + ' select, ' + product + ' input[type=\'hidden\']');
31  } else {
32    var product_option = '';
33  }
34
35  $.ajax({
36    url: 'index.php?route=extension/module/preorder/form&po_product_id=' + product_id,
37    type: 'post',
38    dataType: 'json',
39    data: product_option,
40    success: function(json) {
41      if (json) {
42        html  = '<div id="preorder-box" class="modal fade">';
43        html += '<div class="modal-dialog">';
44        html += '<div class="modal-content">';
45        html += '<div class="modal-header">';
46        
47        if (json['text_title']) {
48          html += '<h3 class="modal-title" style="line-height: 1.1;">' + json['text_title'] + '</h3>';
49        }
50        
51        html += '<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>';
52
53        html += '</div>';
54        html += '<div class="modal-body">';
55
56        if (json['text_top']) {
57          html += json['text_top'];
58        }
59        
60        html += '<div class="preorder-alert"></div>';
61        html += '<div class="row">';
62        html += '<div class="col-md-4">';
63        html += '<div class="image">';
64        html += '<a href="' + json['href'] + '"><img src="' + json['image'] + '" class="img-fluid" /></a>';
65        html += '</div>';
66        html += '<h4 class="text-center"><a href="' + json['href'] + '">' + json['product'] + '</a></h4>';
67        html += '</div>';
68        html += '<div class="col-md-8">';
69        html += '<form class="form-horizontal" id="form-preorder" accept-charset="UTF-8">';
70        
71        if (json['field_name'] > 0) {
72          html += '<div class="form-group' + ((json['field_name'] == 2) ? ' required' : '') + '">';
73          html += '<label class="col-form-label" for="input-preorder-name">' + json['entry_name'] + '</label>';
74          html += '<input type="text" name="name" value="' + json['name'] + '" id="input-preorder-name" class="form-control">';
75          html += '</div>';
76        }
77        
78        if (json['field_email'] > 0) {
79          html += '<div class="form-group' + ((json['field_email'] == 2) ? ' required' : '') + '">';
80          html += '<label class="col-form-label" for="input-preorder-email">' + json['entry_email'] + '</label>';
81          html += '<input type="email" name="email" value="' + json['email'] + '" id="input-preorder-email" class="form-control">';
82          html += '</div>';
83        }
84        
85        if (json['field_phone'] > 0) {
86          html += '<div class="form-group' + ((json['field_phone'] == 2) ? ' required' : '') + '">';
87          html += '<label class="col-form-label" for="input-preorder-phone">' + json['entry_phone'] + '</label>';
88          
89          countries = json['preorder_countries'];
90          
91          if (json['phone_mask'] == 1 && countries.length > 0) {
92
93            if (countries.length > 1) {
94              html += '<div class="input-group">';
95              html += '<label class="input-group-addon dropdown-toggle code" data-toggle="dropdown"></label>';
96              html += '<div class="dropdown-menu countries">';
97              html += '<div>';
98              
99              countries.forEach(function(country, i, countries) {
100                html += '<div class="dropdown-item">';
101                html += '<button onclick="selectCountryPreOrder(this);" data-image="' + country['image'] + '" data-code="' + country['code'] + '" data-mask="' + country['mask'] + '" type="button" class="btn btn-link btn-block' + country['default'] + country['customer_default'] + '"><span>' + (country['image'] ? '<img src="' + country['image'] + '" alt="' + country['name'] + '" /> ' : '') + country['name'] + '</span> <span>' + country['code'] + '</span></button>';
102                html += '</div>';
103              });
104
105              html += '</div>';
106              html += '</div>';
107
108              html += '<input type="hidden" name="code" value="">';
109              html += '<input type="tel" name="phone" value="' + json['phone'] + '" id="input-preorder-phone" class="form-control">';
110              html += '</div>';
111            } else {
112              countries.forEach(function(country, i, countries) {
113                if (country['code']) {
114                  html += '<div class="input-group">';
115                  html += '<label class="input-group-addon">' + (country['image'] ? '<img src="' + country['image'] + '" alt="' + country['name'] + '" /> ' : '') + country['code'] + '</label>';
116                  html += '<input type="hidden" name="code" value="' + country['code'] + '">';
117                  html += '<input data-mask="' + country['mask'] + '" type="tel" name="phone" value="' + json['phone'] + '" id="input-preorder-phone" class="form-control">';
118                  html += '</div>';
119                } else {
120                  html += '<input data-mask="' + country['mask'] + '" type="tel" name="phone" value="' + json['phone'] + '" id="input-preorder-phone" class="form-control">';
121                }
122              });
123            }
124          } else {
125            html += '<input type="tel" name="phone" value="' + json['phone'] + '" id="input-preorder-phone" class="form-control">';
126          }
127          
128          html += '</div>';
129        }
130        
131        if (json['captcha']) {
132          html += json['captcha'];
133        }
134        
135        if (json['field_agree'] > 0) {
136          html += '<div class="form-group">';
137          html += '<div class="custom-control custom-checkbox">';
138          html += '<input type="checkbox" name="agree" value="1" id="preorderAgreementCheckbox" class="custom-control-input">';
139          html += '<label class="custom-control-label" for="preorderAgreementCheckbox">' + json['text_agree'] + '</label>';
140          html += '</div>';
141          html += '</div>';
142        }
143        
144        html += '<input type="hidden" name="product_id" value="' + product_id + '" />';
145        
146        if (json['product_option']) {
147          $.each(json['product_option'], function(index, value) {
148            html += '<input type="hidden" name="product_option[' + index + ']" value="' + value + '">';
149          });
150        }
151        
152        html += '</form>';
153        html += '</div>';
154        html += '</div>';
155        
156        if (json['text_bottom']) {
157          html += '<div class="text-left">';
158          html += json['text_bottom'];
159          html += '</div>';
160        }
161        html += '</div>';
162        html += '<div class="modal-footer">';
163        
164        html += '<button type="button" class="btn btn-primary" onclick="submitPreOrder();">' + json['button_submit'] + '</button>';
165        html += '</div>';
166        html += '</div>';
167        html += '</div>';
168        html += '</div>';
169        
170        $('body').append(html);
171        
172        if (json['field_phone'] != 0 && json['phone_mask'] == 1 && countries.length != 0) {
173          if (countries.length > 1) {
174            if ($('#form-preorder .countries .customer_default').length == 1) {
175              country_default = $('#form-preorder .countries .customer_default');
176            } else {
177              country_default = $('#form-preorder .countries .default');
178            }
179            $('#form-preorder .code').html((country_default.data('image') ? '<img src="' + country_default.data('image') + '" alt="' + country_default.data('name') + '" /> ' : '') + country_default.data('code'));
180            $('#form-preorder input[name=\'phone\']').inputmask(country_default.data('mask'));
181            $('#form-preorder input[name=\'code\']').val(country_default.data('code'));
182          } else {
183            $('#form-preorder input[name=\'phone\']').inputmask($('#form-preorder input[name=\'phone\']').data('mask'));
184          }
185        }
186        
187        $("#preorder-box").modal('show');
188      }
189    },
190    error: function(xhr, ajaxOptions, thrownError) {
191      console.error(xhr.responseText + "\n" + thrownError);
192    }
193  });
194}
195
196function selectCountryPreOrder(data) {
197  $('#form-preorder .code').html(($(data).data('image') ? '<img src="' + $(data).data('image') + '" alt="' + $(data).data('name') + '" /> ' : '') + $(data).data('code'));
198  $('#form-preorder input[name=\'phone\']').inputmask($(data).data('mask'));
199  $('#form-preorder input[name=\'code\']').val($(data).data('code'));
200}
201
202function changeOptionPreOrder(id) {
203  var product = '#product' + id;
204  var out_of_stock = false;
205  
206  $(product + ' input:checked, ' + product + ' option:selected').each(function() {
207    if ($(this).data('preorder-quantity') <= 0) {
208      out_of_stock = true;
209      return false;
210    }
211  });
212  
213  if (out_of_stock) {
214    
215    if ($('.preorder-stock-status' + id).length > 0) {
216      $('.preorder-stock-status' + id).html($('.preorder-stock-status' + id).data('preorder-outstock'));
217    }
218    
219    $('#button-preorder' + id).show(); 
220    $('#button-cart' + id).hide();
221  } else {
222    
223    if ($('.preorder-stock-status' + id).length > 0) {
224      $('.preorder-stock-status' + id).html($('.preorder-stock-status' + id).data('preorder-stock'));
225    }
226    
227    $('#button-preorder' + id).hide(); 
228    $('#button-cart' + id).show();
229  }
230}

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.