Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
selection.phtml
Go to the documentation of this file.
1 <?php
7 // @codingStandardsIgnoreFile
8 
10 ?>
11 <script id="bundle-option-selection-box-template" type="text/x-magento-template">
12  <table class="admin__control-table">
13  <thead>
14  <tr class="headings">
15  <th class="col-draggable"></th>
16  <th class="col-default"><?= /* @escapeNotVerified */ __('Default') ?></th>
17  <th class="col-name"><?= /* @escapeNotVerified */ __('Name') ?></th>
18  <th class="col-sku"><?= /* @escapeNotVerified */ __('SKU') ?></th>
19  <?php if ($block->getCanReadPrice() !== false): ?>
20  <th class="col-price price-type-box"><?= /* @escapeNotVerified */ __('Price') ?></th>
21  <th class="col-price price-type-box"><?= /* @escapeNotVerified */ __('Price Type') ?></th>
22  <?php endif; ?>
23  <th class="col-qty"><?= /* @escapeNotVerified */ __('Default Quantity') ?></th>
24  <th class="col-uqty qty-box"><?= /* @escapeNotVerified */ __('User Defined') ?></th>
25  <th class="col-order type-order" style="display:none"><?= /* @escapeNotVerified */ __('Position') ?></th>
26  <th class="col-actions"></th>
27  </tr>
28  </thead>
29  <tbody>
30  </tbody>
31  </table>
32 </script>
33 <script id="bundle-option-selection-row-template" type="text/x-magento-template">
34  <td class="col-draggable">
35  <span data-role="draggable-handle" class="draggable-handle"></span>
36  <input type="hidden" id="<?= /* @escapeNotVerified */ $block->getFieldId() ?>_id<%- data.index %>"
37  name="<?= /* @escapeNotVerified */ $block->getFieldName() ?>[<%- data.parentIndex %>][<%- data.index %>][selection_id]"
38  value="<%- data.selection_id %>"/>
39  <input type="hidden" name="<?= /* @escapeNotVerified */ $block->getFieldName() ?>[<%- data.parentIndex %>][<%- data.index %>][option_id]"
40  value="<%- data.option_id %>"/>
41  <input type="hidden" class="product"
42  name="<?= /* @escapeNotVerified */ $block->getFieldName() ?>[<%- data.parentIndex %>][<%- data.index %>][product_id]"
43  value="<%- data.product_id %>"/>
44  <input type="hidden" name="<?= /* @escapeNotVerified */ $block->getFieldName() ?>[<%- data.parentIndex %>][<%- data.index %>][delete]"
45  value="" class="delete"/>
46  </td>
47  <td class="col-default">
48  <input onclick="bSelection.checkGroup(event)" type="<%- data.option_type %>" class="default"
49  name="<?= /* @escapeNotVerified */ $block->getFieldName() ?>[<%- data.parentIndex %>][<%- data.index %>][is_default]"
50  value="1" <%- data.checked %> />
51  </td>
52  <td class="col-name"><%- data.name %></td>
53  <td class="col-sku"><%- data.sku %></td>
54 <?php if ($block->getCanReadPrice() !== false): ?>
55  <td class="col-price price-type-box">
56  <input id="<?= /* @escapeNotVerified */ $block->getFieldId() ?>_<%- data.index %>_price_value"
57  class="input-text required-entry validate-zero-or-greater" type="text"
58  name="<?= /* @escapeNotVerified */ $block->getFieldName() ?>[<%- data.parentIndex %>][<%- data.index %>][selection_price_value]"
59  value="<%- data.selection_price_value %>"
60  <?php if ($block->getCanEditPrice() === false): ?>
61  disabled="disabled"
62  <?php endif; ?>/>
63  </td>
64  <td class="col-price price-type-box">
65  <?= $block->getPriceTypeSelectHtml() ?>
66  <div><?= $block->getCheckboxScopeHtml() ?></div>
67  </td>
68 <?php else: ?>
69  <input type="hidden" id="<?= /* @escapeNotVerified */ $block->getFieldId() ?>_<%- data.index %>_price_value"
70  name="<?= /* @escapeNotVerified */ $block->getFieldName() ?>[<%- data.parentIndex %>][<%- data.index %>][selection_price_value]" value="0" />
71  <input type="hidden" id="<?= /* @escapeNotVerified */ $block->getFieldId() ?>_<%- data.index %>_price_type"
72  name="<?= /* @escapeNotVerified */ $block->getFieldName() ?>[<%- data.parentIndex %>][<%- data.index %>][selection_price_type]" value="0" />
73  <?php if ($block->isUsedWebsitePrice()): ?>
74  <input type="hidden" id="<?= /* @escapeNotVerified */ $block->getFieldId() ?>_<%- data.index %>_price_scope"
75  name="<?= /* @escapeNotVerified */ $block->getFieldName() ?>[<%- data.parentIndex %>][<%- data.index %>][default_price_scope]" value="1" />
76  <?php endif; ?>
77 <?php endif; ?>
78  <td class="col-qty">
79  <input class="input-text required-entry validate-greater-zero-based-on-option validate-zero-or-greater" type="text"
80  name="<?= /* @escapeNotVerified */ $block->getFieldName() ?>[<%- data.parentIndex %>][<%- data.index %>][selection_qty]"
81  value="<%- data.selection_qty %>" />
82  </td>
83  <td class="col-uqty qty-box">
84  <input type="checkbox" class="is-user-defined-qty" checked="checked" />
85  <span style="display:none"><?= $block->getQtyTypeSelectHtml() ?></span>
86  </td>
87  <td class="col-order type-order" style="display:none">
88  <input class="input-text required-entry validate-zero-or-greater" type="text"
89  name="<?= /* @escapeNotVerified */ $block->getFieldName() ?>[<%- data.parentIndex %>][<%- data.index %>][position]"
90  value="<%- data.position %>" />
91  </td>
92  <td class="col-actions">
93  <span title="Delete Row">
94  <?= $block->getSelectionDeleteButtonHtml() ?>
95  </span>
96  </td>
97 </script>
98 <script>
99 require([
100  'jquery',
101  'mage/template',
102  'prototype'
103 ], function(jQuery, mageTemplate){
104 var bundleTemplateBox = jQuery('#bundle-option-selection-box-template').html(),
105  bundleTemplateRow = jQuery('#bundle-option-selection-row-template').html();
106 
107 Bundle.Selection = Class.create();
108 Bundle.Selection.prototype = {
109  idLabel : '<?= /* @escapeNotVerified */ $block->getFieldId() ?>',
110  scopePrice : <?= (int)$block->isUsedWebsitePrice() ?>,
111  templateBox : '',
112  templateRow : '',
113  itemsCount : 0,
114  row : null,
115  gridSelection: new Hash(),
116  gridRemoval: new Hash(),
117  gridSelectedProductSkus: [],
118  selectionSearchUrl: '<?= /* @escapeNotVerified */ $block->getSelectionSearchUrl() ?>',
119 
120  initialize : function() {
121  this.templateBox = '<div class="tier form-list" id="' + this.idLabel + '_box_<%- data.parentIndex %>">' + bundleTemplateBox + '</div>';
122 
123  this.templateRow = '<tr class="selection" id="' + this.idLabel + '_row_<%- data.index %>">' + bundleTemplateRow + '</tr>';
124  },
125 
126  gridUpdateCallback: function () {
127  (function ($) {
128  var $grid = $('table[id^=bundle_selection_search_grid_]:visible');
129  $grid.find('.checkbox').prop({checked: false});
130 
131  var checkRowBySku = function (sku) {
132  sku = $.trim(sku);
133  $grid.find('.sku').filter(function () {
134  return $.trim($(this).text()) == sku;
135  }).closest('tr').find('.checkbox').prop({checked: true});
136  };
137  $.each(bSelection.gridSelection.values().pop().toArray(), function () {
138  checkRowBySku(this.pop().get('sku'));
139  });
140 
141  $.each(bSelection.gridSelectedProductSkus, function () {
142  if (!bSelection.gridRemoval.get(this)) {
143  checkRowBySku(this);
144  }
145  });
146  })(jQuery);
147  },
148 
149  addRow : function (parentIndex, data) {
150  var box = null;
151  if (!(box = $(this.idLabel + '_box_' + parentIndex))) {
152  this.addBox(parentIndex);
153  box = $(this.idLabel + '_box_' + parentIndex);
154  } else {
155  box.show();
156  }
157 
158  var option_type = $(bOption.idLabel + '_' + parentIndex + '_type');
159 
160  if(!data){
161  var data = {};
162  }
163 
164  if (data.can_read_price != undefined && !data.can_read_price) {
165  data.selection_price_value = '';
166  } else {
167  data.selection_price_value = Number(Math.round(data.selection_price_value + "e+2") + "e-2").toFixed(2);
168  }
169 
170  data.index = this.itemsCount++;
171  data.parentIndex = parentIndex;
172 
173  if (option_type.value == 'multi' || option_type.value == 'checkbox') {
174  data.option_type = 'checkbox';
175  } else {
176  data.option_type = 'radio';
177  }
178 
179  if (data.is_default == 1) {
180  data.checked = 'checked="checked"';
181  }
182 
183  this.template = mageTemplate(this.templateRow);
184  var tbody = $$('#' + this.idLabel + '_box_' + parentIndex + ' tbody');
185 
186  // replace <script to avoid evalScripts() execution
187  var escapedHTML = this.template({
188  data: data
189  }).replace(/<(\/?)script/g, '&lt;$1script');
190 
191  Element.insert(tbody[0], {bottom: escapedHTML});
192 
193  if (data.selection_price_type) {
194  $A($(this.idLabel + '_'+data.index+'_price_type').options).each(function(option){
195  if (option.value==data.selection_price_type) option.selected = true;
196  });
197  }
198 
199  if (data.selection_price_type) {
200  $A($(this.idLabel + '_'+data.index+'_can_change_qty').options).each(function(option){
201  if (option.value==data.selection_can_change_qty) option.selected = true;
202  });
203  }
204 
205  var checkbox = $(this.idLabel + '_'+data.index+'_price_scope');
206  if (checkbox && this.scopePrice) {
207  if (data.price_scope === undefined) {
208  checkbox.up().hide();
209  } else if(!data.price_scope) {
210  checkbox.checked = true;
211  this.addScope(null, checkbox);
212  }
213  }
214 
215  this.bindScopeCheckbox();
216 
217  if (option_type.value == 'multi' || option_type.value == 'checkbox') {
221  inputs = $A($$('#' + this.idLabel + '_box_' + data.parentIndex + ' .qty-box'));
222  inputs.each(
223  function(elem){
224  elem.hide();
225  }
226  );
227  }
228 
229  if (!$('price_type') || $('price_type').value != '1') {
233  inputs = $A($$('#' + this.idLabel + '_box_' + data.parentIndex + ' .price-type-box'));
234  inputs.each(
235  function(elem){
236  elem.hide();
237  }
238  );
239  }
240 
241  jQuery('#bundle_option_' + parentIndex + ' .no-products-message').hide();
242  },
243 
244  bindScopeCheckbox : function(){
245  var checkboxes = $$('.bundle-option-price-scope-checkbox');
246  for (var i=0;i<checkboxes.length;i++) {
247  if (!$(checkboxes[i]).binded) {
248  $(checkboxes[i]).binded = true;
249  Event.observe(checkboxes[i], 'click', this.addScope.bind(this));
250  }
251  }
252  },
253 
254  addScope : function(event, element){
255  if (element == undefined) {
256  element = $(Event.element(event));
257  }
258  var priceValue = $(element.id.sub('scope', 'value'));
259  var priceType = $(element.id.sub('scope', 'type'));
260 
261  if (element.checked) {
262  priceValue.disable();
263  priceType.disable();
264  } else {
265  priceValue.enable();
266  priceType.enable();
267  }
268  },
269 
270  addBox : function (parentIndex) {
271  var div = $(bOption.idLabel + '_' + parentIndex).down('.fieldset-alt');
272  this.template = mageTemplate(this.templateBox);
273  var data = {'parentIndex' : parentIndex};
274  Element.insert(div, {
275  'after': this.template({
276  data: data
277  })
278  });
279  },
280 
281  remove : function(event) {
282  var element = Event.findElement(event, 'tr');
283  var container = Event.findElement(event, 'div');
284 
285  if (element) {
286  Element.select(element, '.delete').each(function(elem){elem.value='1'});
287  Element.select(element, ['input', 'select']).each(function(elem){elem.hide()});
288  Element.removeClassName(element, 'selection');
289  Element.hide(element);
290 
291  var selection = $$('#' + container.id + ' tr.selection');
292  if (container && selection && !selection.length) {
293  container.hide();
294  jQuery(element).closest('.option-box').find('.no-products-message').show();
295  }
296  }
297  },
298 
299  checkGroup : function(event) {
300  var element = Event.element(event);
301  if (element.type == 'radio') {
302  var box = element.up('div');
303 
304  var inputs = $$('div#' + box.id + ' input.default');
305  if (inputs) {
306  for (i=0; i< inputs.length; i++) {
307  if (inputs[i].name != element.name) {
308  inputs[i].checked = false;
309  }
310  }
311  }
312  }
313  },
314 
315  productGridRowInit : function(grid, row){
316  var checkbox = $(row).getElementsByClassName('checkbox')[0];
317  var inputs = $(row).getElementsByClassName('input-text');
318  for (var i = 0; i < inputs.length; i++) {
319  inputs[i].checkbox = checkbox;
320  }
321  },
322 
323  productGridCheckboxCheck : function(grid, element, checked) {
324  var id = element.up('table').id.split('_')[4];
325  if (element.value > 0) {
326  var tr = element.parentNode.parentNode,
327  sku = jQuery.trim(tr.select('td.sku')[0].innerHTML);
328  if (element.checked) {
329  if (!this.gridSelection.get(id)) {
330  this.gridSelection.set(id, $H({}));
331  }
332  this.gridSelection.get(id).set(element.value, $H({}));
333  this.gridSelection.get(id).get(element.value).set('name', tr.select('td.name')[0].innerHTML);
334  this.gridSelection.get(id).get(element.value).set('sku', sku);
335  this.gridRemoval.unset(sku);
336  } else {
337  this.gridSelection.get(id).unset(element.value);
338  this.gridRemoval.set(sku, 1);
339  }
340  }
341  },
342 
343  productGridRowClick : function(grid, event) {
344  var trElement = Event.findElement(event, 'tr');
345  var isInput = Event.element(event).tagName == 'INPUT';
346  if (trElement) {
347  var checkbox = Element.select(trElement, 'input');
348  if (checkbox[0]) {
349  var checked = isInput ? checkbox[0].checked : !checkbox[0].checked;
350  grid.setCheckboxChecked(checkbox[0], checked);
351  }
352  }
353  }
354 };
355 
356 bSelection = new Bundle.Selection();
357 
358 });
359 </script>
$block setTitle( 'CMS Block Title') -> setIdentifier('fixture_block') ->setContent('< h1 >Fixture Block Title</h1 >< a href=" store url</a><p> Config value
Definition: block.php:9
if( $block->getCanReadPrice() !==false)( 'Price') ?></th >< th class endif
Definition: selection.phtml:19
__()
Definition: __.php:13
$block
Definition: block.php:8
else function()
jquery extjs ext tree checkbox
Definition: tree.phtml:41
jQuery('.store-switcher .dropdown-menu li a').each(function()
Definition: switcher.phtml:203