Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
downloadable.phtml
Go to the documentation of this file.
1 <?php
7 // @codingStandardsIgnoreFile
8 
9 ?>
10 
11 <?php
15 ?>
16 <script>
17 require([
18  'jquery',
19  'uiRegistry',
20  'mage/template',
21  'Magento_Ui/js/modal/alert',
22  'mage/mage',
23  'prototype'
24 ], function (jQuery, registry, mageTemplate, alert) {
25 
26 //<![CDATA[>
27 var uploaderTemplate = '<div class="no-display" id="[[idName]]-template">' +
28  '</div>' +
29  '<div class="no-display" id="[[idName]]-template-progress">' +
30  '<%- data.percent %>% <%- data.uploaded %> / <%- data.total %>' +
31  '</div>',
32 
33  fileListTemplate = '<span class="file-info">' +
34  '<span class="file-info-name"><%= data.name %></span>' +
35  ' ' +
36  '<span class="file-info-size">(<%- data.size %>)</span>' +
37  '</span>';
38  window.Downloadable = {
39  uploaderObj : $H({}),
40  objCount : 0,
41  setUploaderObj : function(type, key, obj){
42  if (!this.uploaderObj.get(type)) {
43  this.uploaderObj.set(type, $H({}));
44  }
45  this.uploaderObj.get(type).set(key, obj);
46  },
47  getUploaderObj : function(type, key){
48  try {
49  return this.uploaderObj.get(type).get(key);
50  } catch (e) {
51  try {
52  console.log(e);
53  } catch (e2) {
54  alert({
55  content: e.name + '\n' + e.message
56  });
57  }
58  }
59  },
60  unsetUploaderObj : function(type, key){
61  try {
62  this.uploaderObj.get(type).unset(key);
63  } catch (e) {
64  try {
65  console.log(e);
66  } catch (e2) {
67  alert({
68  content: e.name + '\n' + e.message
69  });
70  }
71  }
72  },
73  massUploadByType : function(type){
74  try {
75  this.uploaderObj.get(type).each(function(item){
76  container = item.value.container.up('tr');
77  if (container.visible() && !container.hasClassName('no-display')) {
78  item.value.upload();
79  } else {
80  Downloadable.unsetUploaderObj(type, item.key);
81  }
82  });
83  } catch (e) {
84  try {
85  console.log(e);
86  } catch (e2) {
87  alert({
88  content: e.name + '\n' + e.message
89  });
90  }
91  }
92  }
93  };
94 
95  Downloadable.FileUploader = Class.create();
96  Downloadable.FileUploader.prototype = {
97  type : null,
98  key : null, //key, identifier of uploader obj
99  elmContainer : null, //insert Flex object and templates to elmContainer
100  fileValueName : null, //name of field of JSON data of saved file
101  fileValue : null,
102  idName : null, //id name of elements for unique uploader
103  uploaderText: uploaderTemplate,
104  uploaderSyntax : /(^|.|\r|\n)(\[\[(\w+)\]\])/,
105  uploaderObj : $H({}),
106  config : null,
107  initialize: function (type, key, elmContainer, fileValueName, fileValue ,idName, config) {
108  this.type = type;
109  this.key = key;
110  this.elmContainer = elmContainer;
111  this.fileValueName = fileValueName;
112  this.fileValue = fileValue;
113  this.idName = idName;
114  this.config = config;
115  uploaderTemplate = new Template(this.uploaderText, this.uploaderSyntax);
116  <?php if (!$block->isReadonly()):?>
117  Element.insert(
118  elmContainer,
119  {'top' : uploaderTemplate.evaluate({
120  'idName' : this.idName,
121  'fileValueName' : this.fileValueName,
122  'uploaderObj' : 'Downloadable.getUploaderObj(\''+this.type+'\', \''+this.key+'\')'
123  })
124  }
125  );
126  var elementSave = $(this.idName+'_save');
127  if (elementSave) {
128  elementSave.value = this.fileValue.toJSON
129  ? this.fileValue.toJSON()
130  : Object.toJSON(this.fileValue);
131  }
132  Downloadable.setUploaderObj(
133  this.type,
134  this.key,
135  null
136  );
137  new Downloadable.FileList(this.idName, null);
138  <?php endif;?>
139  }
140  };
141 
142  Downloadable.FileList = Class.create();
143  Downloadable.FileList.prototype = {
144  file: [],
145  containerId: '',
146  container: null,
147  uploader: null,
148  fileListTemplate: fileListTemplate,
149  listTemplate : null,
150  initialize: function (containerId, uploader) {
151  this.containerId = containerId,
152  this.container = $(this.containerId);
153  this.uploader = uploader;
154  this.file = this.getElement('save').value.evalJSON();
155  this.listTemplate = mageTemplate(this.fileListTemplate);
156  this.updateFiles();
157  },
158  handleFileRemoveAll: function(fileId) {
159  $(this.containerId+'-new').hide();
160  $(this.containerId+'-old').show();
161  },
162  handleFileSelect: function() {
163  $(this.containerId+'_type').checked = true;
164  },
165  getElement: function (name) {
166  return $(this.containerId + '_' + name);
167  },
168  handleUploadComplete: function (file) {
169  if (file.error) {
170  return;
171  }
172 
173  var newFile = {};
174  newFile.file = file.file;
175  newFile.name = file.name;
176  newFile.size = file.size;
177  newFile.status = 'new';
178  this.file[0] = newFile;
179  this.updateFiles();
180  },
181  updateFiles: function() {
182  this.getElement('save').value = this.file.toJSON
183  ? this.file.toJSON()
184  : Object.toJSON(this.file);
185  this.file.each(function(row){
186  row.size = byteConvert(row.size);
187  $(this.containerId + '-old').innerHTML = this.listTemplate({data: row});
188  $(this.containerId + '-new').hide();
189  $(this.containerId + '-old').show();
190  }.bind(this));
191  }
192  };
193 
194  var alertAlreadyDisplayed = false;
195 
196  window.uploaderTemplate = uploaderTemplate;
197 
198  window.alertAlreadyDisplayed = alertAlreadyDisplayed;
199 
200  registry.set('downloadable', Downloadable);
201 //]]>
202 
203 });
204 </script>
205 
206 <div data-tab-type="tab_content_downloadableInfo" id="<?= /* @escapeNotVerified */ $block->getId() ?>_content"
207  <?= /* @escapeNotVerified */ $block->getUiId('tab', 'content', $block->getId()) ?>
208 >
209 <div id="alert_messages_block"><?= $block->getMessageHtml() ?></div>
210 <div class="admin__field admin__field-option admin__field-is-downloaodable">
211  <input type="checkbox" data-action="change-type-product-downloadable" class="admin__control-checkbox"
212  name="is_downloadable" id="is-downloaodable" <?= $block->isDownloadable() ? 'checked="checked"' : ''?> />
213  <label class="admin__field-label" for="is-downloaodable">
214  <span><?= /* @noEscape */ __('Is this a downloadable Product?'); ?></span>
215  </label>
216 </div>
217 <div class="entry-edit" id="product_info_tabs_downloadable_items">
218  <?= $block->getChildHtml() ?>
219 </div>
220 <div style="display:none">
221  <div id="custom-advice-container"></div>
222 </div>
223 <?php if ($block->isReadonly()): ?>
224  <script>
225  require(['prototype'], function(){
226 
227  $(<?= /* @escapeNotVerified */ $block->getContentTabId() ?>).select('input', 'select', 'textarea', 'button').each(function (item){
228  item.disabled = true;
229  if (item.tagName.toLowerCase() == 'button') {
230  item.addClassName('disabled');
231  }
232  });
233 
234  });
235  </script>
236 <?php endif; ?>
237 </div>
238 <script type="text/x-magento-init">
239  {
240  "*": {
241  "Magento_Downloadable/downloadable-type-handler": {
242  "isDownloadable": "<?= /* @noEscape */ $block->isDownloadable() ? 'true' : 'false' ?>",
243  "tabId": "<?= /* @noEscape */ $block->getTabId() ?>"
244  }
245  }
246  }
247 </script>
248 
249 <script>
253  require([
254  'jquery',
255  'Magento_Catalog/catalog/type-events',
256  'Magento_Downloadable/downloadable-type-handler',
257  'Magento_Ui/js/lib/view/utils/async'
258  ], function ($, typeProducts) {
259 
260  $('body').trigger('changeTypeProduct');
261  $('body').trigger('contentUpdated');
262  $.async('[name=type]', function() {
263  typeProducts.init();
264  });
265 
266  });
267 </script>
elementSave
__()
Definition: __.php:13
$block
Definition: block.php:8
jQuery('.store-switcher .dropdown-menu li a').each(function()
Definition: switcher.phtml:203
if( $_isRequired) echo ' required _required' ?>"> <label classforeach($_links as $_link) ($_linksPurchasedSeparately) ( $_isRequired) endif