Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
synchronize.phtml
Go to the documentation of this file.
1 <?php
7 // @codingStandardsIgnoreFile
8 
9 ?>
10 
11 <?php /* @var $block \Magento\MediaStorage\Block\System\Config\System\Storage\Media\Synchronize */ ?>
12 
13 <script>
14 require([
15  'jquery',
16  'prototype',
17  'mage/backend/validation',
18  'jquery/validate'
19 ], function(jQuery){
20 
21  allowedStorages = [],
22  getConnectionName = function (storageType, connection) {
23  if (storageType == 0) {
24  return storageType;
25  } else if (connection != '') {
26  return storageType + '_' + connection;
27  }
28 
29  return '';
30  };
31 
32  addAllowedStorage(
33  $('system_media_storage_configuration_media_storage').value,
34  $('system_media_storage_configuration_media_database').value
35  );
36 
37  <?php $syncStorageParams = $block->getSyncStorageParams() ?>
38  addAllowedStorage(<?= /* @escapeNotVerified */ $syncStorageParams['storage_type'] ?>, '<?= /* @escapeNotVerified */ $syncStorageParams['connection_name'] ?>');
39 
40  defaultValues = [];
41  defaultValues['system_media_storage_configuration_media_storage'] = $('system_media_storage_configuration_media_storage').value;
42  defaultValues['system_media_storage_configuration_media_database'] = $('system_media_storage_configuration_media_database').value;
43 
44 
45  function addAllowedStorage(storageType, connection)
46  {
47  storage = getConnectionName(storageType, connection);
48 
49  if (storage != '' && !allowedStorages.include(storage)) {
50  allowedStorages.push(storage);
51  }
52  $('system_media_storage_configuration_media_storage').value = storageType;
53  $('system_media_storage_configuration_media_database').value = connection;
54  }
55 
56  function checkButtonState(event) {
57  var element = Event.element(event);
58 
59  defaultStorage = getConnectionName(
60  defaultValues['system_media_storage_configuration_media_storage'],
61  defaultValues['system_media_storage_configuration_media_database']
62  );
63 
64  storage = getConnectionName(
65  $('system_media_storage_configuration_media_storage').value,
66  $('system_media_storage_configuration_media_database').value
67  );
68  if (defaultStorage != storage) {
69  enableSyncButton();
70  } else {
71  disableSyncButton();
72  }
73  }
74 
75  function enableStorageSelection() {
76  $('system_media_storage_configuration_media_storage').enable('enabled');
77  $('system_media_storage_configuration_media_database').enable('enabled');
78  }
79 
80  function disableStorageSelection() {
81  $('system_media_storage_configuration_media_storage').disable('disabled');
82  $('system_media_storage_configuration_media_database').disable('disabled');
83  }
84 
85  function enableSyncButton() {
86  Form.Element.enable('synchronize_button');
87  $('synchronize_button').removeClassName('disabled');
88  }
89 
90  function disableSyncButton() {
91  Form.Element.disable('synchronize_button');
92  $('synchronize_button').addClassName('disabled');
93  }
94 
95  var checkStatus = function() {
96  u = new Ajax.PeriodicalUpdater('', '<?= /* @escapeNotVerified */ $block->getAjaxStatusUpdateUrl() ?>', {
97  method: 'get',
98  frequency: 5,
99  loaderArea: false,
100 
101  onSuccess: function(transport) {
102  var response;
103 
104  try {
105  response = JSON.parse(transport.responseText);
106  if (response.state == '<?= /* @escapeNotVerified */ \Magento\MediaStorage\Model\File\Storage\Flag::STATE_RUNNING ?>'
107  && response.message
108  ) {
109  if ($('sync_span').hasClassName('no-display')) {
110  $('sync_span').removeClassName('no-display');
111  $('sync_message_span').update(response.message);
112  }
113  } else {
114  u.stop();
115  enableStorageSelection();
116  $('sync_span').addClassName('no-display');
117 
118  if (response.state == '<?= /* @escapeNotVerified */ \Magento\MediaStorage\Model\File\Storage\Flag::STATE_FINISHED ?>') {
119  addAllowedStorage(
120  $('system_media_storage_configuration_media_storage').value,
121  $('system_media_storage_configuration_media_database').value
122  );
123  } else if (response.state == '<?= /* @escapeNotVerified */ \Magento\MediaStorage\Model\File\Storage\Flag::STATE_NOTIFIED ?>') {
124  if (response.has_errors) {
125  enableSyncButton();
126  } else {
127  addAllowedStorage(
128  $('system_media_storage_configuration_media_storage').value,
129  $('system_media_storage_configuration_media_database').value
130  );
131  }
132  }
133  }
134  } catch (e) {
135  response = {};
136  }
137  }
138  });
139  };
140 
141  Event.observe(window, 'load', function(){
142  disableStorageSelection();
143  disableSyncButton();
144  checkStatus();
145  });
146  $('system_media_storage_configuration_media_storage').observe('change', checkButtonState);
147  $('system_media_storage_configuration_media_database').observe('change', checkButtonState);
148 
149  jQuery('#synchronize_button').click(function () {
150  if (!jQuery.validator.validateElement('#synchronize-validation-input')) {
151  jQuery('[for="synchronize-validation-input"]').hide();
152  }
153  params = {
154  storage: $('system_media_storage_configuration_media_storage').value,
155  connection: $('system_media_storage_configuration_media_database').value
156  };
157 
158  new Ajax.Request('<?= /* @escapeNotVerified */ $block->getAjaxSyncUrl() ?>', {
159  parameters: params,
160  loaderArea: false,
161  asynchronous: true
162  });
163 
164  window.setTimeout(checkStatus, 2011);
165 
166  disableStorageSelection();
167  disableSyncButton();
168  });
169 
170  jQuery.validator.addMethod('required-synchronize', function(){
171  storage = getConnectionName(
172  $('system_media_storage_configuration_media_storage').value,
173  $('system_media_storage_configuration_media_database').value
174  );
175  return allowedStorages.include(storage);
176  }, 'Synchronization is required.');
177 });
178 </script>
179 
180 <?= $block->getButtonHtml() ?>
181 <span class="sync-indicator no-display" id="sync_span">
182  <img alt="Synchronize" style="margin:0 5px" src="<?= /* @escapeNotVerified */ $block->getViewFileUrl('images/process_spinner.gif') ?>"/>
183  <span id="sync_message_span"></span>
184 </span>
185 <input type="hidden" id="synchronize-validation-input" class="required-synchronize no-display"/>
$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
$block
Definition: block.php:8
jQuery('.store-switcher .dropdown-menu li a').each(function()
Definition: switcher.phtml:203