Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
applicable_country.phtml
Go to the documentation of this file.
1 <?php
6 ?>
7 <script>
8 require([
9  'prototype'
10 ], function () {
11 
12 var CountryModel = Class.create();
13 CountryModel.prototype = {
14  initialize : function()
15  {
16  this.reload = false;
17  this.bindSpecificCountryRelation();
18  },
19  bindSpecificCountryRelation : function(parentId)
20  {
21  if(parentId) {
22  // todo: fix bug in IE
23  var applyCountryElements = $$('#'+parentId+' .shipping-applicable-country');
24  } else {
25  var applyCountryElements = $$('.shipping-applicable-country');
26  }
27  for(var i=0;i<applyCountryElements.length; i++) {
28  Event.observe(applyCountryElements[i], 'change', this.checkSpecificCountry.bind(this));
29  this.initSpecificCountry(applyCountryElements[i]);
30  }
31 
32  },
33  initSpecificCountry : function(element){
34  var applyCountryElement = element;
35  if (applyCountryElement && applyCountryElement.id) {
36  var specifCountryElement = $(applyCountryElement.id.replace(/sallowspecific/, 'specificcountry'));
37  var showMethodElement = $(applyCountryElement.id.replace(/sallowspecific/, 'showmethod'));
38  //var specifErrMsgElement = $(applyCountryElement.id.replace(/sallowspecific/, 'specificerrmsg'));
39  if (specifCountryElement) {
40  if (applyCountryElement.value == 1 && !specifCountryElement.hasAttribute('disabled')) {
41  //if specific country element selected
42  specifCountryElement.enable();
43  if (showMethodElement) {
44  this.showElement(showMethodElement.up(1));
45  }
46  //specifErrMsgElement.up(1).show();
47  } else {
48  specifCountryElement.disable();
49  if (showMethodElement) {
50  this.hideElement(showMethodElement.up(1));
51  }
52  //specifErrMsgElement.up(1).hide();
53  }
54  }
55  }
56  },
57 
58  checkSpecificCountry : function(event)
59  {
60  var applyCountryElement = Event.element(event);
61  if (applyCountryElement && applyCountryElement.id) {
62  var specifCountryElement = $(applyCountryElement.id.replace(/sallowspecific/, 'specificcountry'));
63  var showMethodElement = $(applyCountryElement.id.replace(/sallowspecific/, 'showmethod'));
64  // 'Use Default' checkbox of the related county list UI element
65  var useDefaultElement = document.getElementById(specifCountryElement.id + '_inherit');
66 
67  //var specifErrMsgElement = $(applyCountryElement.id.replace(/sallowspecific/, 'specificerrmsg'));
68  if (specifCountryElement) {
69  if (applyCountryElement.value == 1) {
70  // enable related country select only if its 'Use Default' checkbox is absent or is unchecked
71  specifCountryElement.disabled = useDefaultElement ? useDefaultElement.checked : false;
72  if (showMethodElement) {
73  this.showElement(showMethodElement.up(1));
74  }
75  //specifErrMsgElement.up(1).show();
76  } else {
77  this.unselectSpecificCountry(specifCountryElement);
78  specifCountryElement.disable();
79  if (showMethodElement) {
80  this.hideElement(showMethodElement.up(1));
81  }
82  //specifErrMsgElement.up(1).hide();
83  }
84  }
85  }
86  },
87 
88  unselectSpecificCountry : function(element)
89  {
90  for (var i=0; i<element.options.length; i++) {
91  if (element.options[i].selected) {
92  element.options[i].selected=false;
93  }
94  }
95  },
96 
97  showElement : function(elm)
98  {
99  if (elm) {
100  if (!elm.down('.shipping-skip-show')) {
101  elm.show();
102  }
103  }
104  },
105 
106  hideElement : function(elm)
107  {
108  if (elm) {
109  if (!elm.down('.shipping-skip-hide')) {
110  elm.hide();
111  }
112  }
113  }
114 
115 }
116 countryApply = new CountryModel();
117 });
118 </script>