basic.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. //
  2. // Note that these are all defined as panel configs, rather than instantiated
  3. // as panel objects. You could just as easily do this instead:
  4. //
  5. // var absolute = Ext.create('Ext.Panel', { ... });
  6. //
  7. // However, by passing configs into the main container instead of objects, we can defer
  8. // layout AND object instantiation until absolutely needed. Since most of these panels
  9. // won't be shown by default until requested, this will save us some processing
  10. // time up front when initially rendering the page.
  11. //
  12. // Since all of these configs are being added into a layout container, they are
  13. // automatically assumed to be panel configs, and so the xtype of 'panel' is
  14. // implicit. To define a config of some other type of component to be added into
  15. // the layout, simply provide the appropriate xtype config explicitly.
  16. //
  17. function getBasicLayouts() {
  18. // This is a fake CardLayout navigation function. A real implementation would
  19. // likely be more sophisticated, with logic to validate navigation flow. It will
  20. // be assigned next as the handling function for the buttons in the CardLayout example.
  21. var cardNav = function(incr){
  22. var l = Ext.getCmp('card-wizard-panel').getLayout();
  23. var i = l.activeItem.id.split('card-')[1];
  24. var next = parseInt(i, 10) + incr;
  25. l.setActiveItem(next);
  26. Ext.getCmp('card-prev').setDisabled(next===0);
  27. Ext.getCmp('card-next').setDisabled(next===2);
  28. };
  29. return {
  30. /*
  31. * ================ Start page config =======================
  32. */
  33. // The default start page, also a simple example of a FitLayout.
  34. start: {
  35. id: 'start-panel',
  36. title: 'Start Page',
  37. layout: 'fit',
  38. bodyStyle: 'padding:25px',
  39. contentEl: 'start-div' // pull existing content from the page
  40. },
  41. /*
  42. * ================ AbsoluteLayout config =======================
  43. */
  44. absolute: {
  45. id: 'absolute-panel',
  46. title: 'Absolute Layout',
  47. layout: 'absolute',
  48. defaults: {
  49. bodyStyle: 'padding:15px;',
  50. width: 200,
  51. height: 100,
  52. frame: true
  53. },
  54. items:[{
  55. title: 'Panel 1',
  56. x: 50,
  57. y: 50,
  58. html: 'Positioned at x:50, y:50'
  59. },{
  60. title: 'Panel 2',
  61. x: 125,
  62. y: 125,
  63. html: 'Positioned at x:125, y:125'
  64. }]
  65. },
  66. /*
  67. * ================ AccordionLayout config =======================
  68. */
  69. accordion: {
  70. id: 'accordion-panel',
  71. title: 'Accordion Layout',
  72. layout: 'accordion',
  73. bodyStyle: 'background-color:#DFE8F6', // if all accordion panels are collapsed, this looks better in this layout
  74. defaults: {bodyStyle: 'padding:15px'},
  75. items: [{
  76. title: 'Introduction',
  77. tools: [{type:'gear'},{type:'refresh'}],
  78. html: '<p>Here is some accordion content. Click on one of the other bars below for more.</p>'
  79. },{
  80. title: 'Basic Content',
  81. html: '<br /><br /><p>More content. Open the third panel for a customized look and feel example.</p>',
  82. items: {
  83. xtype: 'button',
  84. text: 'Show Next Panel',
  85. handler: function(){
  86. Ext.getCmp('acc-custom').expand(true);
  87. }
  88. }
  89. },{
  90. id: 'acc-custom',
  91. title: 'Custom Panel Look and Feel',
  92. cls: 'custom-accordion', // look in layout-browser.css to see the CSS rules for this class
  93. html: '<p>Here is an example of how easy it is to completely customize the look and feel of an individual panel simply by adding a CSS class in the config.</p>'
  94. }]
  95. },
  96. /*
  97. * ================ AnchorLayout config =======================
  98. */
  99. anchor: {
  100. id:'anchor-panel',
  101. title: 'Anchor Layout',
  102. layout:'anchor',
  103. defaults: {bodyStyle: 'padding:15px'},
  104. items: [{
  105. title: 'Panel 1',
  106. height: 100,
  107. anchor: '50%',
  108. html: '<p>Width = 50% of the container</p>'
  109. },{
  110. title: 'Panel 2',
  111. height: 100,
  112. anchor: '-100',
  113. html: '<p>Width = container width - 100 pixels</p>'
  114. },{
  115. title: 'Panel 3',
  116. anchor: '-10, -262',
  117. html: '<p>Width = container width - 10 pixels</p><p>Height = container height - 262 pixels</p>'
  118. }]
  119. },
  120. /*
  121. * ================ BorderLayout config =======================
  122. */
  123. border: {
  124. id:'border-panel',
  125. title: 'Border Layout',
  126. layout: 'border',
  127. bodyBorder: false,
  128. defaults: {
  129. collapsible: true,
  130. split: true,
  131. animFloat: false,
  132. autoHide: false,
  133. useSplitTips: true,
  134. bodyStyle: 'padding:15px'
  135. },
  136. items: [{
  137. title: 'Footer',
  138. region: 'south',
  139. height: 150,
  140. minSize: 75,
  141. maxSize: 250,
  142. cmargins: '5 0 0 0',
  143. html: '<p>Footer content</p>'
  144. },{
  145. title: 'Navigation',
  146. region:'west',
  147. floatable: false,
  148. margins: '5 0 0 0',
  149. cmargins: '5 5 0 0',
  150. width: 175,
  151. minSize: 100,
  152. maxSize: 250,
  153. html: '<p>Secondary content like navigation links could go here</p>'
  154. },{
  155. title: 'Main Content',
  156. collapsible: false,
  157. region: 'center',
  158. margins: '5 0 0 0',
  159. html: '<h1>Main Page</h1><p>This is where the main content would go</p>'
  160. }]
  161. },
  162. /*
  163. * ================ CardLayout config (TabPanel) =======================
  164. */
  165. // Note that the TabPanel component uses an internal CardLayout -- it is not
  166. // something you have to explicitly configure. However, it is still a perfect
  167. // example of how this layout style can be used in a complex component.
  168. cardTabs: {
  169. xtype: 'tabpanel',
  170. id: 'card-tabs-panel',
  171. plain: true, //remove the header border
  172. activeTab: 0,
  173. style: 'background-color:#dfe8f6; ',
  174. defaults: {bodyStyle: 'padding:15px'},
  175. items:[{
  176. title: 'Tab 1',
  177. html: 'This is tab 1 content.'
  178. },{
  179. title: 'Tab 2',
  180. html: 'This is tab 2 content.'
  181. },{
  182. title: 'Tab 3',
  183. html: 'This is tab 3 content.'
  184. }]
  185. },
  186. /*
  187. * ================ CardLayout config (Wizard) =======================
  188. */
  189. cardWizard: {
  190. id:'card-wizard-panel',
  191. title: 'Card Layout (Wizard)',
  192. layout:'card',
  193. activeItem: 0,
  194. bodyStyle: 'padding:15px',
  195. defaults: {border:false},
  196. bbar: ['->', {
  197. id: 'card-prev',
  198. text: '&laquo; Previous',
  199. handler: Ext.Function.bind(cardNav, this, [-1]),
  200. disabled: true
  201. },{
  202. id: 'card-next',
  203. text: 'Next &raquo;',
  204. handler: Ext.Function.bind(cardNav, this, [1])
  205. }],
  206. items: [{
  207. id: 'card-0',
  208. html: '<h1>Welcome to the Demo Wizard!</h1><p>Step 1 of 3</p><p>Please click the "Next" button to continue...</p>'
  209. },{
  210. id: 'card-1',
  211. html: '<p>Step 2 of 3</p><p>Almost there. Please click the "Next" button to continue...</p>'
  212. },{
  213. id: 'card-2',
  214. html: '<h1>Congratulations!</h1><p>Step 3 of 3 - Complete</p>'
  215. }]
  216. },
  217. /*
  218. * ================ ColumnLayout config =======================
  219. */
  220. column: {
  221. id:'column-panel',
  222. title: 'Column Layout',
  223. layout: 'column',
  224. bodyStyle: 'padding:5px',
  225. defaults: {bodyStyle:'padding:15px'},
  226. items: [{
  227. title: 'Width = 0.25',
  228. columnWidth: 0.25,
  229. html: '<p>This is some short content.</p>'
  230. },{
  231. title: 'Width = 0.75',
  232. columnWidth: 0.75,
  233. html: '<p>This is some longer content.</p><p>This is some longer content.</p><p>This is some longer content.</p><p>This is some longer content.</p><p>This is some longer content.</p><p>This is some longer content.</p>'
  234. },{
  235. title: 'Width = 250px',
  236. width: 250,
  237. html: 'Not much here!'
  238. }]
  239. },
  240. /*
  241. * ================ FitLayout config =======================
  242. */
  243. fit: {
  244. id: 'fit-panel',
  245. title: 'Fit Layout',
  246. layout: 'fit',
  247. items: {
  248. title: 'Inner Panel',
  249. html: '<p>This panel is fit within its container.</p>',
  250. bodyStyle: 'padding:15px',
  251. border: false
  252. }
  253. },
  254. /*
  255. * ================ FormLayout config =======================
  256. */
  257. // NOTE: While you can create a basic Panel with layout:'form', practically
  258. // you should usually use a FormPanel to also get its form-specific functionality.
  259. // Note that the layout config is not required on FormPanels.
  260. form: {
  261. xtype: 'form', // since we are not using the default 'panel' xtype, we must specify it
  262. id: 'form-panel',
  263. labelWidth: 75,
  264. title: 'Form Layout',
  265. bodyStyle: 'padding:15px',
  266. width: 350,
  267. labelPad: 20,
  268. defaults: {
  269. width: 230,
  270. labelSeparator: '',
  271. msgTarget: 'side'
  272. },
  273. defaultType: 'textfield',
  274. items: [{
  275. fieldLabel: 'First Name',
  276. name: 'first',
  277. allowBlank:false
  278. },{
  279. fieldLabel: 'Last Name',
  280. name: 'last'
  281. },{
  282. fieldLabel: 'Company',
  283. name: 'company'
  284. },{
  285. fieldLabel: 'Email',
  286. name: 'email',
  287. vtype:'email'
  288. }
  289. ],
  290. buttons: [{text: 'Save'},{text: 'Cancel'}]
  291. },
  292. /*
  293. * ================ TableLayout config =======================
  294. */
  295. table: {
  296. id: 'table-panel',
  297. title: 'Table Layout',
  298. layout: {
  299. type: 'table',
  300. columns: 4
  301. },
  302. defaults: {
  303. bodyStyle:'padding:15px 20px'
  304. },
  305. items: [{
  306. title: 'Lots of Spanning',
  307. html: '<p>Row spanning.</p><br /><p>Row spanning.</p><br /><p>Row spanning.</p><br /><p>Row spanning.</p><br /><p>Row spanning.</p><br /><p>Row spanning.</p>',
  308. rowspan: 3
  309. },{
  310. title: 'Basic Table Cell',
  311. html: '<p>Basic panel in a table cell.</p>',
  312. cellId: 'basic-cell',
  313. cellCls: 'custom-cls'
  314. },{
  315. html: '<p>Plain panel</p>'
  316. },{
  317. title: 'Another Cell',
  318. html: '<p>Row spanning.</p><br /><p>Row spanning.</p><br /><p>Row spanning.</p><br /><p>Row spanning.</p>',
  319. width: 300,
  320. rowspan: 2
  321. },{
  322. html: 'Plain cell spanning two columns',
  323. colspan: 2
  324. },{
  325. title: 'More Column Spanning',
  326. html: '<p>Spanning three columns.</p>',
  327. colspan: 3
  328. },{
  329. title: 'Spanning All Columns',
  330. html: '<p>Spanning all columns.</p>',
  331. colspan: 4
  332. }]
  333. },
  334. /*
  335. * ================ VBoxLayout config =======================
  336. */
  337. vbox: {
  338. id: 'vbox-panel',
  339. title: 'vBox Layout',
  340. layout: {
  341. type: 'vbox',
  342. pack: 'start',
  343. align: 'stretch'
  344. },
  345. defaults: {
  346. frame: true
  347. },
  348. items: [{
  349. title: 'Panel 1',
  350. flex: 1,
  351. html: 'flex : 1'
  352. }, {
  353. title: 'Panel 2',
  354. height: 100,
  355. html: 'height: 100'
  356. }, {
  357. title: 'Panel 3',
  358. flex: 2,
  359. html: 'flex : 2'
  360. }]
  361. },
  362. /*
  363. * ================ HBoxLayout config =======================
  364. */
  365. hbox: {
  366. id: 'hbox-panel',
  367. title: 'hBox Layout',
  368. layout: {
  369. type: 'hbox',
  370. pack: 'start',
  371. align: 'stretch'
  372. },
  373. defaults: {
  374. frame: true
  375. },
  376. items: [{
  377. title: 'Panel 1',
  378. flex: 1,
  379. html: 'flex : 1'
  380. }, {
  381. title: 'Panel 2',
  382. width: 100,
  383. html: 'width : 100'
  384. }, {
  385. title: 'Panel 3',
  386. flex: 2,
  387. html: 'flex : 2'
  388. }]
  389. }
  390. };
  391. }