Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 
 

301 строка
12 KiB

  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. use Magento\Framework\App\TemplateTypesInterface;
  7. // phpcs:disable Generic.Files.LineLength.TooLong
  8. /** @var $block \Magento\Email\Block\Adminhtml\Template\Edit */
  9. /** @var \Magento\Framework\View\Helper\SecureHtmlRenderer $secureRenderer */
  10. ?>
  11. <?php if (!$block->getEditMode()): ?>
  12. <form action="<?= $block->escapeUrl($block->getLoadUrl()) ?>" method="post" id="email_template_load_form">
  13. <?= $block->getBlockHtml('formkey') ?>
  14. <fieldset class="admin__fieldset form-inline">
  15. <legend class="admin__legend"><span><?= $block->escapeHtml(__('Load Default Template')) ?></span></legend><br>
  16. <div class="admin__field required">
  17. <label class="admin__field-label" for="template_select">
  18. <span><?= $block->escapeHtml(__('Template')) ?></span>
  19. </label>
  20. <div class="admin__field-control">
  21. <select id="template_select" name="code" class="admin__control-select required-entry">
  22. <?php foreach ($block->getTemplateOptions() as $group => $options): ?>
  23. <?php if ($group): ?>
  24. <optgroup label="<?= $block->escapeHtmlAttr($group) ?>">
  25. <?php endif; ?>
  26. <?php foreach ($options as $option): ?>
  27. <option value="<?= $block->escapeHtmlAttr($option['value']) ?>"
  28. <?= /* @noEscape */ $block->getOrigTemplateCode() == $option['value'] ?
  29. ' selected="selected"' : '' ?>><?= $block->escapeHtml($option['label']) ?>
  30. </option>
  31. <?php endforeach; ?>
  32. <?php if ($group): ?>
  33. </optgroup>
  34. <?php endif; ?>
  35. <?php endforeach; ?>
  36. </select>
  37. </div>
  38. </div>
  39. <div class="admin__field required">
  40. <span class="admin__field-label"></span>
  41. <div class="admin__field-control">
  42. <?= /* @noEscape */ $block->getLoadButtonHtml() ?>
  43. </div>
  44. </div>
  45. </fieldset>
  46. </form>
  47. <?php endif ?>
  48. <form action="<?= $block->escapeUrl($block->getSaveUrl()) ?>" method="post" id="email_template_edit_form">
  49. <?= /* @noEscape */ $block->getBlockHtml('formkey') ?>
  50. <input type="hidden" id="change_flag_element" name="_change_type_flag" value="" />
  51. <input type="hidden" id="orig_template_code" name="orig_template_code"
  52. value="<?= $block->escapeHtmlAttr($block->getOrigTemplateCode()) ?>" />
  53. <?= /* @noEscape */ $block->getFormHtml() ?>
  54. </form>
  55. <form action="<?= $block->escapeUrl($block->getPreviewUrl()) ?>" method="post" id="email_template_preview_form"
  56. target="_blank">
  57. <?= /* @noEscape */ $block->getBlockHtml('formkey') ?>
  58. <div class="no-display">
  59. <input type="hidden" id="preview_type" name="type" value="<?= /* @noEscape */ $block->isTextType() ? 1 : 2 ?>"/>
  60. <input type="hidden" id="preview_text" name="text" value="" />
  61. <input type="hidden" id="preview_styles" name="styles" value="" />
  62. </div>
  63. </form>
  64. <?php
  65. $currentlyUsedForPaths = /* @noEscape */ $block->getCurrentlyUsedForPaths();
  66. $templateType = (int)$block->getTemplateType();
  67. $typeText = /* @noEscape */ TemplateTypesInterface::TYPE_TEXT;
  68. $scriptString = <<<script
  69. require([
  70. "jquery",
  71. "wysiwygAdapter",
  72. "Magento_Ui/js/modal/alert",
  73. 'Magento_Ui/js/modal/confirm',
  74. "mage/mage",
  75. "Magento_Email/js/variables",
  76. "prototype"
  77. ], function(jQuery, tinyMCE, alert, confirm){
  78. //<![CDATA[
  79. jQuery('#email_template_edit_form').mage('form').mage('validation');
  80. jQuery('#email_template_preview_form').mage('form').mage('validation');
  81. jQuery('#email_template_load_form').mage('validation');
  82. templateControl = {
  83. unconvertedText: '',
  84. typeChange: false,
  85. variables: null,
  86. events: {
  87. 'click [data-role=template-save]' : 'save',
  88. 'click [data-role=template-preview]' : 'preview',
  89. 'click [data-role=template-unstrip]' : 'unStripTags',
  90. 'click [data-role=template-strip]' : 'stripTags',
  91. 'click [data-role=template-delete]': 'deleteTemplate',
  92. 'click [data-role=template-load]': 'load'
  93. },
  94. init: function () {
  95. if ($('convert_button_back')) {
  96. $('convert_button_back').hide();
  97. }
  98. this.bindEvents();
  99. this.renderPaths({$currentlyUsedForPaths}, 'currently_used_for');
  100. },
  101. bindEvents: function(){
  102. var events = this.events,
  103. eventName,
  104. selector,
  105. callback,
  106. key;
  107. for( key in events ){
  108. callback = this[events[key]];
  109. key = key.split(' ');
  110. eventName = key[0];
  111. selector = key.slice(1).join(' ');
  112. jQuery(selector).on(eventName, jQuery.proxy(callback, this) );
  113. }
  114. },
  115. stripTags: function () {
  116. var self = this;
  117. confirm({
  118. content: "{$block->escapeJs(__('Are you sure you want to strip tags?'))}",
  119. actions: {
  120. confirm: function () {
  121. self.unconvertedText = $('template_text').value;
  122. $('convert_button').hide();
  123. $('template_text').value = $('template_text').value.stripScripts().replace(
  124. new RegExp('<style[^>]*>[\\S\\s]*?</style>', 'img'), ''
  125. ).stripTags().strip();
  126. $('convert_button_back').show();
  127. $('field_template_styles').hide();
  128. self.typeChange = true;
  129. return false;
  130. }
  131. }
  132. });
  133. },
  134. unStripTags: function () {
  135. $('convert_button').show();
  136. $('convert_button_back').hide();
  137. $('template_text').value = this.unconvertedText;
  138. $('field_template_styles').show();
  139. this.typeChange = false;
  140. return false;
  141. },
  142. save: function() {
  143. if (this.typeChange) {
  144. $('change_flag_element').value = '1';
  145. }
  146. // Temporary solution will be replaced after refactoring of email templates functionality
  147. jQuery('#email_template_edit_form').triggerHandler('save');
  148. return false;
  149. },
  150. preview: function() {
  151. if (this.typeChange) {
  152. $('preview_type').value = {$typeText};
  153. } else {
  154. $('preview_type').value = {$templateType};
  155. }
  156. if (typeof tinyMCE == 'undefined' || !tinyMCE.get('template_text')) {
  157. $('preview_text').value = $('template_text').value;
  158. } else {
  159. $('preview_text').value = tinyMCE.get('template_text').getHTML();
  160. }
  161. if ($('template_styles') != undefined) {
  162. $('preview_styles').value = $('template_styles').value;
  163. }
  164. // Temporary solution will be replaced after refactoring of email templates functionality
  165. jQuery('#email_template_preview_form').triggerHandler('save');
  166. return false;
  167. },
  168. deleteTemplate: function() {
  169. confirm({
  170. content: "{$block->escapeJs(__('Are you sure you want to delete this template?'))}",
  171. actions: {
  172. confirm: function () {
  173. window.location.href = '{$block->escapeJs($block->getDeleteUrl())}';
  174. }
  175. }
  176. });
  177. },
  178. load: function() {
  179. // Temporary solution will be replaced after refactoring of email templates functionality
  180. if (!jQuery('#email_template_load_form').valid()) {
  181. return;
  182. }
  183. this.variables = null;
  184. new Ajax.Request($('email_template_load_form').action, {
  185. parameters: Form.serialize($('email_template_load_form'), true),
  186. area: $('email_template_load_form'),
  187. onComplete: function (transport) {
  188. if (transport.responseText.isJSON()) {
  189. var fields = \$H(transport.responseText.evalJSON());
  190. fields.each(function(pair) {
  191. if ($(pair.key)) {
  192. $(pair.key).value = pair.value.strip();
  193. }
  194. if (pair.key == 'template_type') {
  195. if (pair.value == 1) {
  196. this.typeChange = true;
  197. $('convert_button').hide();
  198. $('convert_button_back').hide();
  199. } else {
  200. this.typeChange = false;
  201. $('convert_button_back').hide();
  202. $('convert_button').show();
  203. }
  204. }
  205. if (pair.key == 'orig_template_currently_used_for') {
  206. if(pair.value.length){
  207. $('currently_used_for').show();
  208. this.renderPaths(pair.value, 'currently_used_for');
  209. }
  210. else{
  211. $('currently_used_for').hide();
  212. }
  213. }
  214. }.bind(this));
  215. } else {
  216. alert({
  217. content: '{$block->escapeJs(__(
  218. 'The template did not load. Please review the log for details.'
  219. ))}'
  220. });
  221. }
  222. }.bind(this)
  223. });
  224. },
  225. renderPaths: function(paths, fieldId) {
  226. var field = $(fieldId);
  227. if (field) {
  228. field.down('div').down('div')
  229. .update(this.parsePath(paths, '<span class="path-delimiter">&nbsp;-&gt;&nbsp;</span>', '<br />'));
  230. }
  231. },
  232. parsePath: function (value, pathDelimiter, lineDelimiter) {
  233. if (Object.isArray(value)) {
  234. var result = [];
  235. for (var i = 0, len = value.length; i < len; i++) {
  236. result.push(this.parsePath(value[i], pathDelimiter, pathDelimiter));
  237. }
  238. return result.join(lineDelimiter);
  239. }
  240. if(!Object.isString(value) && value.title) {
  241. value = (value.url ? '<a href="' + value.url + '">' + value.title + '</a>' : value.title) +
  242. (value.scope ? '&nbsp;&nbsp;<span class="path-scope-label">(' + value.scope + ')</span>' : '');
  243. }
  244. return value;
  245. },
  246. openVariableChooser: function() {
  247. Variables.init('template_text');
  248. if (this.variables == null) {
  249. Variables.resetData();
  250. this.variables = $('variables').value.evalJSON();
  251. var templateVariablesValue = $('template_variables').value;
  252. if (this.variables && templateVariablesValue) {
  253. if (templateVariables = templateVariablesValue.evalJSON()) {
  254. this.variables.push(templateVariables);
  255. }
  256. }
  257. }
  258. if (this.variables) {
  259. Variables.openVariableChooser(this.variables);
  260. }
  261. }
  262. };
  263. templateControl.init();
  264. //]]>
  265. });
  266. script;
  267. ?>
  268. <?= /* @noEscape */ $secureRenderer->renderTag('script', [], $scriptString, false) ?>