layout-browser.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. Ext.Loader.setConfig({enabled: true});
  2. Ext.Loader.setPath('Ext.ux', '../ux');
  3. Ext.require([
  4. 'Ext.tip.QuickTipManager',
  5. 'Ext.container.Viewport',
  6. 'Ext.layout.*',
  7. 'Ext.form.Panel',
  8. 'Ext.form.Label',
  9. 'Ext.grid.*',
  10. 'Ext.data.*',
  11. 'Ext.tree.*',
  12. 'Ext.selection.*',
  13. 'Ext.tab.Panel',
  14. 'Ext.ux.layout.Center'
  15. ]);
  16. //
  17. // This is the main layout definition.
  18. //
  19. Ext.onReady(function(){
  20. Ext.tip.QuickTipManager.init();
  21. // This is an inner body element within the Details panel created to provide a "slide in" effect
  22. // on the panel body without affecting the body's box itself. This element is created on
  23. // initial use and cached in this var for subsequent access.
  24. var detailEl;
  25. // Gets all layouts examples
  26. var layoutExamples = [];
  27. Ext.Object.each(getBasicLayouts(), function(name, example) {
  28. layoutExamples.push(example);
  29. });
  30. Ext.Object.each(getCombinationLayouts(), function(name, example){
  31. layoutExamples.push(example);
  32. });
  33. Ext.Object.each(getCustomLayouts(), function(name, example){
  34. layoutExamples.push(example);
  35. });
  36. // This is the main content center region that will contain each example layout panel.
  37. // It will be implemented as a CardLayout since it will contain multiple panels with
  38. // only one being visible at any given time.
  39. var contentPanel = {
  40. id: 'content-panel',
  41. region: 'center', // this is what makes this panel into a region within the containing layout
  42. layout: 'card',
  43. margins: '2 5 5 0',
  44. activeItem: 0,
  45. border: false,
  46. items: layoutExamples
  47. };
  48. var store = Ext.create('Ext.data.TreeStore', {
  49. root: {
  50. expanded: true
  51. },
  52. proxy: {
  53. type: 'ajax',
  54. url: 'tree-data.json'
  55. }
  56. });
  57. // Go ahead and create the TreePanel now so that we can use it below
  58. var treePanel = Ext.create('Ext.tree.Panel', {
  59. id: 'tree-panel',
  60. title: 'Sample Layouts',
  61. region:'north',
  62. split: true,
  63. height: 360,
  64. minSize: 150,
  65. rootVisible: false,
  66. autoScroll: true,
  67. store: store
  68. });
  69. // Assign the changeLayout function to be called on tree node click.
  70. treePanel.getSelectionModel().on('select', function(selModel, record) {
  71. if (record.get('leaf')) {
  72. Ext.getCmp('content-panel').layout.setActiveItem(record.getId() + '-panel');
  73. if (!detailEl) {
  74. var bd = Ext.getCmp('details-panel').body;
  75. bd.update('').setStyle('background','#fff');
  76. detailEl = bd.createChild(); //create default empty div
  77. }
  78. detailEl.hide().update(Ext.getDom(record.getId() + '-details').innerHTML).slideIn('l', {stopAnimation:true,duration: 200});
  79. }
  80. });
  81. // This is the Details panel that contains the description for each example layout.
  82. var detailsPanel = {
  83. id: 'details-panel',
  84. title: 'Details',
  85. region: 'center',
  86. bodyStyle: 'padding-bottom:15px;background:#eee;',
  87. autoScroll: true,
  88. html: '<p class="details-info">When you select a layout from the tree, additional details will display here.</p>'
  89. };
  90. // Finally, build the main layout once all the pieces are ready. This is also a good
  91. // example of putting together a full-screen BorderLayout within a Viewport.
  92. Ext.create('Ext.Viewport', {
  93. layout: 'border',
  94. title: 'Ext Layout Browser',
  95. items: [{
  96. xtype: 'box',
  97. id: 'header',
  98. region: 'north',
  99. html: '<h1> Ext.Layout.Browser</h1>',
  100. height: 30
  101. },{
  102. layout: 'border',
  103. id: 'layout-browser',
  104. region:'west',
  105. border: false,
  106. split:true,
  107. margins: '2 0 5 5',
  108. width: 275,
  109. minSize: 100,
  110. maxSize: 500,
  111. items: [treePanel, detailsPanel]
  112. },
  113. contentPanel
  114. ],
  115. renderTo: Ext.getBody()
  116. });
  117. });