Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
main.phtml
Go to the documentation of this file.
1 <?php
7 // @codingStandardsIgnoreFile
8 
9 ?>
10 <div class="attribute-set">
11 
12  <div class="admin__data-grid-loading-mask"
13  data-role="spinner">
14  <div class="spinner">
15  <span></span><span></span><span></span><span></span>
16  <span></span><span></span><span></span><span></span>
17  </div>
18  </div>
19  <div class="edit-attribute-set attribute-set-col">
20  <?= $block->getSetFormHtml() ?>
21  <script>
22  require([
23  "jquery",
24  "mage/mage"
25  ], function(jQuery){
26 
27  jQuery('#set-prop-form').mage('validation', {errorClass: 'mage-error'});
28 
29  });
30  </script>
31  </div>
32  <div class="attribute-set-col fieldset-wrapper">
33  <div class="fieldset-wrapper-title">
34  <span class="title"><?= /* @escapeNotVerified */ __('Groups') ?></span>
35  </div>
36  <?php if (!$block->getIsReadOnly()): ?>
37  <?= /* @escapeNotVerified */ $block->getAddGroupButton() ?>&nbsp;<?= /* @escapeNotVerified */ $block->getDeleteGroupButton() ?>
38  <p class="note-block"><?= /* @escapeNotVerified */ __('Double click on a group to rename it.') ?></p>
39  <?php endif; ?>
40 
41  <?= $block->getSetsFilterHtml() ?>
42  <?= $block->getGroupTreeHtml() ?>
43  </div>
44  <div class="attribute-set-col fieldset-wrapper">
45  <div class="fieldset-wrapper-title">
46  <span class="title"><?= /* @escapeNotVerified */ __('Unassigned Attributes') ?></span>
47  </div>
48  <div id="tree-div2" class="attribute-set-tree"></div>
49  <script id="ie-deferred-loader" defer="defer" src="//:"></script>
50  <script>
51  define("tree-panel",
52  [
53  "jquery",
54  "Magento_Ui/js/modal/prompt",
55  "Magento_Ui/js/modal/alert",
56  "extjs/ext-tree-checkbox",
57  "prototype"
58  ], function(jQuery, prompt, alert){
59 
60  //<![CDATA[
61  var allowDragAndDrop = <?= /* @escapeNotVerified */ ($block->getIsReadOnly() ? 'false' : 'true') ?>;
62  var canEditGroups = <?= /* @escapeNotVerified */ ($block->getIsReadOnly() ? 'false' : 'true') ?>;
63 
64  var TreePanels = function() {
65  // shorthand
66  var Tree = Ext.tree;
67 
68  return {
69  init : function(){
70  // yui-ext tree
71 
72  var tree = new Ext.tree.TreePanel('tree-div1', {
73  animate:false,
74  loader: false,
75  enableDD:allowDragAndDrop,
76  containerScroll: true,
77  rootVisible: false
78  });
79 
80  // set the root node
81  this.root = new Ext.tree.TreeNode({
82  text: 'ROOT',
83  allowDrug:false,
84  allowDrop:true,
85  id:'1'
86  });
87 
88  tree.setRootNode(this.root);
89  buildCategoryTree(this.root, <?= /* @escapeNotVerified */ $block->getGroupTreeJson() ?>);
90  // render the tree
91  tree.render();
92  this.root.expand(false, false);
93  tree.expandAll();
94 
95  this.ge = new Ext.tree.TreeEditor(tree, {
96  allowBlank:false,
97  blankText:'<?= /* @escapeNotVerified */ __('A name is required.') ?>',
98  selectOnFocus:true,
99  cls:'folder'
100  });
101 
102  this.root.addListener('beforeinsert', editSet.leftBeforeInsert);
103  this.root.addListener('beforeappend', editSet.leftBeforeInsert);
104 
105  //this.ge.addListener('beforerender', editSet.editGroup);
106  this.ge.addListener('beforeshow', editSet.editGroup);
107  this.ge.addListener('beforecomplete', editSet.beforeRenameGroup);
108  //this.ge.addListener('startedit', editSet.editGroup);
109 
110  //-------------------------------------------------------------
111 
112  var tree2 = new Ext.tree.TreePanel('tree-div2', {
113  animate:false,
114  loader: false,
115  enableDD:allowDragAndDrop,
116  containerScroll: true,
117  rootVisible: false,
118  lines:false
119  });
120 
121  // set the root node
122  this.root2 = new Ext.tree.TreeNode({
123  text: 'ROOT',
124  draggable:false,
125  id:'free'
126  });
127  tree2.setRootNode(this.root2);
128  buildCategoryTree(this.root2, <?= /* @escapeNotVerified */ $block->getAttributeTreeJson() ?>);
129 
130  this.root2.addListener('beforeinsert', editSet.rightBeforeInsert);
131  this.root2.addListener('beforeappend', editSet.rightBeforeAppend);
132 
133  this.root2.addListener('append', editSet.rightAppend);
134  this.root2.addListener('remove', editSet.rightRemove);
135  // render the tree
136  tree2.render();
137  this.root2.expand(false, false);
138  tree2.expandAll();
139  },
140 
141  rebuildTrees : function(){
142  editSet.req.attributes = new Array();
143  rootNode = TreePanels.root;
144  var gIterator = 0;
145  for( i in rootNode.childNodes ) {
146  if(rootNode.childNodes[i].id) {
147  var group = rootNode.childNodes[i];
148  editSet.req.groups[gIterator] = new Array(group.id, group.attributes.text.strip(), (gIterator+1));
149  var iterator = 0
150  for( j in group.childNodes ) {
151  iterator ++;
152  if( group.childNodes[j].id > 0 ) {
153  editSet.req.attributes[group.childNodes[j].id] = new Array(group.childNodes[j].id, group.id, iterator, group.childNodes[j].attributes.entity_id);
154  }
155  }
156  iterator = 0;
157  }
158  gIterator ++;
159  }
160 
161  editSet.req.not_attributes = new Array();
162  rootNode = TreePanels.root2;
163 
164  var iterator = 0;
165  for( i in rootNode.childNodes ) {
166  if(rootNode.childNodes[i].id) {
167  if( rootNode.childNodes[i].id > 0 ) {
168  editSet.req.not_attributes[iterator] = rootNode.childNodes[i].attributes.entity_id;
169  }
170  iterator ++;
171  }
172  }
173  }
174  };
175  }();
176 
177  function buildCategoryTree(parent, config){
178  if (!config) return null;
179  if (parent && config && config.length){
180  for (var i = 0; i < config.length; i++) {
181  var node = new Ext.tree.TreeNode(config[i]);
182  parent.appendChild(node);
183  node.addListener('click', editSet.register);
184  node.addListener('beforemove', editSet.groupBeforeMove);
185  node.addListener('beforeinsert', editSet.groupBeforeInsert);
186  node.addListener('beforeappend', editSet.groupBeforeInsert);
187  if( config[i].children ) {
188  for( j in config[i].children ) {
189  if(config[i].children[j].id) {
190  newNode = new Ext.tree.TreeNode(config[i].children[j]);
191 
192  if (typeof newNode.ui.onTextChange === 'function') {
193  newNode.ui.onTextChange = function (_3, _4, _5) {
194  if (this.rendered) {
195  this.textNode.innerText = _4;
196  }
197  }
198  }
199  }
200  node.appendChild(newNode);
201  newNode.addListener('click', editSet.unregister);
202  }
203  }
204  }
205  }
206  }
207 
208 
209  editSet = function () {
210  return {
211  register: function (node) {
212  editSet.currentNode = node;
213  if (typeof node.ui.onTextChange === 'function') {
214  node.ui.onTextChange = function (_3, _4, _5) {
215  if (this.rendered) {
216  this.textNode.innerText = _4;
217  }
218  }
219  }
220  },
221 
222  unregister : function() {
223  editSet.currentNode = false;
224  },
225 
226  submit : function() {
227  var i, child, newNode;
228 
229  if( TreePanels.root.firstChild == TreePanels.root.lastChild ) {
230  return;
231  }
232 
233  if( editSet.SystemNodesExists(editSet.currentNode) ) {
234  alert({
235  content: '<?= $block->escapeJs(__('This group contains system attributes. Please move system attributes to another group and try again.')) ?>'
236  });
237  return;
238  }
239 
240  if( editSet.currentNode && editSet.currentNode.attributes.cls == 'folder' ) {
241  TreePanels.root.removeChild(editSet.currentNode);
242 
243  for( i in editSet.currentNode.childNodes ) {
244  if( editSet.currentNode.childNodes[i].id ) {
245  child = editSet.currentNode.childNodes[i];
246  newNode = new Ext.tree.TreeNode(child.attributes);
247 
248  if( child.attributes.is_user_defined == 1 ) {
249  TreePanels.root2.appendChild(newNode);
250  }
251  }
252  }
253 
254  editSet.req.removeGroups[editSet.currentNode.id] = editSet.currentNode.id;
255  editSet.currentNode = false;
256  }
257  },
258 
259  SystemNodesExists : function(currentNode) {
260  if (!currentNode) {
261  alert({
262  content: '<?= $block->escapeJs(__('Please select a node.')) ?>'
263  });
264  return;
265  }
266 
267  for (i in currentNode.childNodes) {
268  if (currentNode.childNodes[i].id) {
269  child = editSet.currentNode.childNodes[i];
270  if (child.attributes.is_unassignable != 1) {
271  return true;
272  }
273  }
274  }
275  },
276 
277  rightAppend : function(node) {
278  return;
279  },
280 
281  addGroup : function() {
282  prompt({
283  title: "<?= /* @escapeNotVerified */ __('Add New Group') ?>",
284  content: "<?= /* @escapeNotVerified */ __('Please enter a new group name.') ?>",
285  value: "",
286  validation: true,
287  validationRules: ['required-entry'],
288  attributesForm: {
289  novalidate: 'novalidate',
290  action: ''
291  },
292  attributesField: {
293  name: 'name',
294  'data-validate': '{required:true}',
295  maxlength: '255'
296  },
297  actions: {
298  confirm: function (group_name) {
299  group_name = group_name.strip();
300 
301  if (!editSet.validateGroupName(group_name, 0)) {
302  return;
303  }
304 
305  var newNode = new Ext.tree.TreeNode({
306  text : group_name.escapeHTML(),
307  cls : 'folder',
308  allowDrop : true,
309  allowDrag : true
310  });
311 
312  if (typeof newNode.ui.onTextChange === 'function') {
313  newNode.ui.onTextChange = function (_3, _4, _5) {
314  if (this.rendered) {
315  this.textNode.innerText = _4;
316  }
317  }
318  }
319 
320  TreePanels.root.appendChild(newNode);
321  newNode.addListener('beforemove', editSet.groupBeforeMove);
322  newNode.addListener('beforeinsert', editSet.groupBeforeInsert);
323  newNode.addListener('beforeappend', editSet.groupBeforeInsert);
324  newNode.addListener('click', editSet.register);
325  }
326  }
327  });
328  },
329 
330  editGroup : function(obj) {
331  if( obj.editNode.attributes.cls != 'folder' || !canEditGroups) {
332  TreePanels.ge.cancelEdit();
333  return false;
334  }
335  },
336 
337  beforeRenameGroup : function(obj, after, before) {
338  return editSet.validateGroupName(after, obj.editNode.id);
339  },
340 
341  validateGroupName : function(name, exceptNodeId) {
342  name = name.strip().escapeHTML();
343  var result = true;
344  if (name === '') {
345  result = false;
346  }
347  for (var i=0; i < TreePanels.root.childNodes.length; i++) {
348  if (TreePanels.root.childNodes[i].text.toLowerCase() == name.toLowerCase() && TreePanels.root.childNodes[i].id != exceptNodeId) {
349  errorText = '<?= /* @escapeNotVerified */ __('An attribute group named "/name/" already exists.') ?>';
350  alert({
351  content: errorText.replace("/name/",name)
352  });
353  result = false;
354  }
355  }
356  return result;
357  },
358 
359  save : function() {
360  var block;
361 
362  if ($('messages')) {
363  $('messages').update();
364  } else {
365  block = jQuery('<div/>').attr('id', 'messages');
366  jQuery('.page-main-actions').after(block);
367  }
368  TreePanels.rebuildTrees();
369  if(!jQuery('#set-prop-form').valid()) {
370  return;
371  }
372  editSet.req.attribute_set_name = $('attribute_set_name').value;
373  if (!editSet.req.form_key) {
374  editSet.req.form_key = FORM_KEY;
375  }
376  var req = {data : Ext.util.JSON.encode(editSet.req)};
377  var con = new Ext.lib.Ajax.request('POST', '<?= /* @escapeNotVerified */ $block->getMoveUrl() ?>', {success:editSet.success,failure:editSet.failure}, req);
378  },
379 
380  success : function(o) {
381  var response = Ext.util.JSON.decode(o.responseText);
382  if( response.error ) {
383  $('messages').update(response.message);
384  } else if( response.ajaxExpired && response.ajaxRedirect ){
385  setLocation(response.ajaxRedirect);
386  } else if( response.url ){
387  setLocation(response.url);
388  } else if( response.message ) {
389  $('messages').update(response.message);
390  }
391  },
392 
393  failure : function(o) {
394  alert({
395  content: '<?= $block->escapeJs(__('Sorry, we\'re unable to complete this request.')) ?>'
396  });
397  },
398 
399  groupBeforeMove : function(tree, nodeThis, oldParent, newParent) {
400  if( newParent.attributes.cls == 'folder' && nodeThis.attributes.cls == 'folder' ) {
401  return false;
402  }
403 
404  if( newParent == TreePanels.root && nodeThis.attributes.cls != 'folder' ) {
405  return false;
406  }
407  },
408 
409  rightBeforeAppend : function(tree, nodeThis, node, newParent) {
410  if (node.attributes.is_user_defined == 0) {
411  alert({
412  content: '<?= $block->escapeJs(__('You can\'t remove attributes from this attribute set.')) ?>'
413  });
414  return false;
415  } else {
416  return true;
417  }
418  },
419 
420  rightBeforeInsert : function(tree, nodeThis, node, newParent) {
421  var empty = TreePanels.root2.findChild('id', 'empty');
422  if (empty) {
423  return false;
424  }
425 
426  if (node.attributes.is_unassignable == 0) {
427  alert({
428  content: '<?= $block->escapeJs(__('You can\'t remove attributes from this attribute set.')) ?>'
429  });
430  return false;
431  } else {
432  return true;
433  }
434  },
435 
436  groupBeforeInsert : function(tree, nodeThis, node, newParent) {
437  if( node.allowChildren ) {
438  return false;
439  }
440  },
441 
442  rightAppend : function(tree, nodeThis, node) {
443  var empty = TreePanels.root2.findChild('id', 'empty');
444  if( empty && node.id != 'empty' ) {
445  TreePanels.root2.removeChild(empty);
446  }
447  },
448 
449  rightRemove : function(tree, nodeThis, node) {
450  if( nodeThis.firstChild == null && node.id != 'empty' ) {
451  var newNode = new Ext.tree.TreeNode({
452  text : '<?= /* @escapeNotVerified */ __('Empty') ?>',
453  id : 'empty',
454  cls : 'folder',
455  is_user_defined : 1,
456  allowDrop : false,
457  allowDrag : false
458  });
459  TreePanels.root2.appendChild(newNode);
460  }
461  },
462 
463  leftBeforeInsert : function(tree, nodeThis, node, newParent) {
464  if( node.allowChildren == false ) {
465  return false;
466  }
467  }
468  }
469  }();
470 
471  function initVars() {
472  editSet.req = {};
473  editSet.req.attributes = false;
474  editSet.req.groups = new Array();
475  editSet.req.not_attributes = false;
476  editSet.req.attribute_set_name = false;
477  editSet.req.removeGroups = new Array();
478  }
479 
480  jQuery(function() {
481  initVars();
482  TreePanels.init();
483  jQuery("[data-role='spinner']").hide();
484  });
485  //]]>
486 
487  });
488  require(["tree-panel"]);
489  </script>
490  </div>
491 </div>
$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
__()
Definition: __.php:13
$block
Definition: block.php:8
$_count $_index $_prevOptionId if($block->getOrderOptions()|| $_item->getDescription()) foreach( $items as $_item)( $_item) ?><?php $attributes if( $_item->getOrderItem() ->getParentItem())($_prevOptionId !=$attributes['option_id'])</td >< td > & nbsp
Definition: renderer.phtml:33
<?=$block-> getDeleteGroupButton() ?>< p class endif
Definition: main.phtml:37
if($block->getRoot())< div class="message message-notice">< div ><?=__( 'This operation can take a long time') ?></div ></div ></div >< script > var tree
Definition: tree.phtml:27
jQuery('.store-switcher .dropdown-menu li a').each(function()
Definition: switcher.phtml:203