/src/main/webapp/js/extjs/examples/form/dynamic.js

https://github.com/toribaric/portfoliosupportsystem · JavaScript · 421 lines · 356 code · 44 blank · 21 comment · 0 complexity · 6d5271be1a4dfd5024556eb69b80a866 MD5 · raw file

  1. Ext.require([
  2. 'Ext.form.*',
  3. 'Ext.layout.container.Column',
  4. 'Ext.tab.Panel'
  5. ]);
  6. /*!
  7. * Ext JS Library 3.3.1
  8. * Copyright(c) 2006-2010 Sencha Inc.
  9. * licensing@sencha.com
  10. * http://www.sencha.com/license
  11. */
  12. Ext.onReady(function(){
  13. Ext.QuickTips.init();
  14. var bd = Ext.getBody();
  15. /*
  16. * ================ Simple form =======================
  17. */
  18. bd.createChild({tag: 'h2', html: 'Form 1 - Very Simple'});
  19. var simple = Ext.create('Ext.form.Panel', {
  20. url:'save-form.php',
  21. frame:true,
  22. title: 'Simple Form',
  23. bodyStyle:'padding:5px 5px 0',
  24. width: 350,
  25. fieldDefaults: {
  26. msgTarget: 'side',
  27. labelWidth: 75
  28. },
  29. defaultType: 'textfield',
  30. defaults: {
  31. anchor: '100%'
  32. },
  33. items: [{
  34. fieldLabel: 'First Name',
  35. name: 'first',
  36. allowBlank:false
  37. },{
  38. fieldLabel: 'Last Name',
  39. name: 'last'
  40. },{
  41. fieldLabel: 'Company',
  42. name: 'company'
  43. }, {
  44. fieldLabel: 'Email',
  45. name: 'email',
  46. vtype:'email'
  47. }, {
  48. xtype: 'timefield',
  49. fieldLabel: 'Time',
  50. name: 'time',
  51. minValue: '8:00am',
  52. maxValue: '6:00pm'
  53. }],
  54. buttons: [{
  55. text: 'Save'
  56. },{
  57. text: 'Cancel'
  58. }]
  59. });
  60. simple.render(document.body);
  61. /*
  62. * ================ Form 2 =======================
  63. */
  64. bd.createChild({tag: 'h2', html: 'Form 2 - Adding fieldsets'});
  65. var fsf = Ext.create('Ext.form.Panel', {
  66. url:'save-form.php',
  67. frame:true,
  68. title: 'Simple Form with FieldSets',
  69. bodyStyle:'padding:5px 5px 0',
  70. width: 350,
  71. fieldDefaults: {
  72. msgTarget: 'side',
  73. labelWidth: 75
  74. },
  75. defaults: {
  76. anchor: '100%'
  77. },
  78. items: [{
  79. xtype:'fieldset',
  80. checkboxToggle:true,
  81. title: 'User Information',
  82. defaultType: 'textfield',
  83. collapsed: true,
  84. layout: 'anchor',
  85. defaults: {
  86. anchor: '100%'
  87. },
  88. items :[{
  89. fieldLabel: 'First Name',
  90. name: 'first',
  91. allowBlank:false
  92. },{
  93. fieldLabel: 'Last Name',
  94. name: 'last'
  95. },{
  96. fieldLabel: 'Company',
  97. name: 'company'
  98. }, {
  99. fieldLabel: 'Email',
  100. name: 'email',
  101. vtype:'email'
  102. }]
  103. },{
  104. xtype:'fieldset',
  105. title: 'Phone Number',
  106. collapsible: true,
  107. defaultType: 'textfield',
  108. layout: 'anchor',
  109. defaults: {
  110. anchor: '100%'
  111. },
  112. items :[{
  113. fieldLabel: 'Home',
  114. name: 'home',
  115. value: '(888) 555-1212'
  116. },{
  117. fieldLabel: 'Business',
  118. name: 'business'
  119. },{
  120. fieldLabel: 'Mobile',
  121. name: 'mobile'
  122. },{
  123. fieldLabel: 'Fax',
  124. name: 'fax'
  125. }]
  126. }],
  127. buttons: [{
  128. text: 'Save'
  129. },{
  130. text: 'Cancel'
  131. }]
  132. });
  133. fsf.render(document.body);
  134. /*
  135. * ================ Form 3 =======================
  136. */
  137. bd.createChild({tag: 'h2', html: 'Form 3 - A little more complex'});
  138. var top = Ext.create('Ext.form.Panel', {
  139. frame:true,
  140. title: 'Multi Column, Nested Layouts and Anchoring',
  141. bodyStyle:'padding:5px 5px 0',
  142. width: 600,
  143. fieldDefaults: {
  144. labelAlign: 'top',
  145. msgTarget: 'side'
  146. },
  147. items: [{
  148. xtype: 'container',
  149. anchor: '100%',
  150. layout:'column',
  151. items:[{
  152. xtype: 'container',
  153. columnWidth:.5,
  154. layout: 'anchor',
  155. items: [{
  156. xtype:'textfield',
  157. fieldLabel: 'First Name',
  158. name: 'first',
  159. anchor:'96%'
  160. }, {
  161. xtype:'textfield',
  162. fieldLabel: 'Company',
  163. name: 'company',
  164. anchor:'96%'
  165. }]
  166. },{
  167. xtype: 'container',
  168. columnWidth:.5,
  169. layout: 'anchor',
  170. items: [{
  171. xtype:'textfield',
  172. fieldLabel: 'Last Name',
  173. name: 'last',
  174. anchor:'100%'
  175. },{
  176. xtype:'textfield',
  177. fieldLabel: 'Email',
  178. name: 'email',
  179. vtype:'email',
  180. anchor:'100%'
  181. }]
  182. }]
  183. }, {
  184. xtype: 'htmleditor',
  185. name: 'bio',
  186. fieldLabel: 'Biography',
  187. height: 200,
  188. anchor: '100%'
  189. }],
  190. buttons: [{
  191. text: 'Save'
  192. },{
  193. text: 'Cancel'
  194. }]
  195. });
  196. top.render(document.body);
  197. /*
  198. * ================ Form 4 =======================
  199. */
  200. bd.createChild({tag: 'h2', html: 'Form 4 - Forms can be a TabPanel...'});
  201. var tabs = Ext.create('Ext.form.Panel', {
  202. width: 350,
  203. border: false,
  204. bodyBorder: false,
  205. fieldDefaults: {
  206. labelWidth: 75,
  207. msgTarget: 'side'
  208. },
  209. defaults: {
  210. anchor: '100%'
  211. },
  212. items: {
  213. xtype:'tabpanel',
  214. activeTab: 0,
  215. defaults:{
  216. bodyStyle:'padding:10px'
  217. },
  218. items:[{
  219. title:'Personal Details',
  220. defaultType: 'textfield',
  221. items: [{
  222. fieldLabel: 'First Name',
  223. name: 'first',
  224. allowBlank:false,
  225. value: 'Ed'
  226. },{
  227. fieldLabel: 'Last Name',
  228. name: 'last',
  229. value: 'Spencer'
  230. },{
  231. fieldLabel: 'Company',
  232. name: 'company',
  233. value: 'Ext JS'
  234. }, {
  235. fieldLabel: 'Email',
  236. name: 'email',
  237. vtype:'email'
  238. }]
  239. },{
  240. title:'Phone Numbers',
  241. defaultType: 'textfield',
  242. items: [{
  243. fieldLabel: 'Home',
  244. name: 'home',
  245. value: '(888) 555-1212'
  246. },{
  247. fieldLabel: 'Business',
  248. name: 'business'
  249. },{
  250. fieldLabel: 'Mobile',
  251. name: 'mobile'
  252. },{
  253. fieldLabel: 'Fax',
  254. name: 'fax'
  255. }]
  256. }]
  257. },
  258. buttons: [{
  259. text: 'Save'
  260. },{
  261. text: 'Cancel'
  262. }]
  263. });
  264. tabs.render(document.body);
  265. /*
  266. * ================ Form 5 =======================
  267. */
  268. bd.createChild({tag: 'h2', html: 'Form 5 - ... and forms can contain TabPanel(s)'});
  269. var tab2 = Ext.create('Ext.form.Panel', {
  270. title: 'Inner Tabs',
  271. bodyStyle:'padding:5px',
  272. width: 600,
  273. fieldDefaults: {
  274. labelAlign: 'top',
  275. msgTarget: 'side'
  276. },
  277. defaults: {
  278. anchor: '100%'
  279. },
  280. items: [{
  281. layout:'column',
  282. border:false,
  283. items:[{
  284. columnWidth:.5,
  285. border:false,
  286. layout: 'anchor',
  287. defaultType: 'textfield',
  288. items: [{
  289. fieldLabel: 'First Name',
  290. name: 'first',
  291. anchor:'95%'
  292. }, {
  293. fieldLabel: 'Company',
  294. name: 'company',
  295. anchor:'95%'
  296. }]
  297. },{
  298. columnWidth:.5,
  299. border:false,
  300. layout: 'anchor',
  301. defaultType: 'textfield',
  302. items: [{
  303. fieldLabel: 'Last Name',
  304. name: 'last',
  305. anchor:'95%'
  306. },{
  307. fieldLabel: 'Email',
  308. name: 'email',
  309. vtype:'email',
  310. anchor:'95%'
  311. }]
  312. }]
  313. },{
  314. xtype:'tabpanel',
  315. plain:true,
  316. activeTab: 0,
  317. height:235,
  318. defaults:{bodyStyle:'padding:10px'},
  319. items:[{
  320. title:'Personal Details',
  321. defaults: {width: 230},
  322. defaultType: 'textfield',
  323. items: [{
  324. fieldLabel: 'First Name',
  325. name: 'first',
  326. allowBlank:false,
  327. value: 'Jamie'
  328. },{
  329. fieldLabel: 'Last Name',
  330. name: 'last',
  331. value: 'Avins'
  332. },{
  333. fieldLabel: 'Company',
  334. name: 'company',
  335. value: 'Ext JS'
  336. }, {
  337. fieldLabel: 'Email',
  338. name: 'email',
  339. vtype:'email'
  340. }]
  341. },{
  342. title:'Phone Numbers',
  343. defaults: {width: 230},
  344. defaultType: 'textfield',
  345. items: [{
  346. fieldLabel: 'Home',
  347. name: 'home',
  348. value: '(888) 555-1212'
  349. },{
  350. fieldLabel: 'Business',
  351. name: 'business'
  352. },{
  353. fieldLabel: 'Mobile',
  354. name: 'mobile'
  355. },{
  356. fieldLabel: 'Fax',
  357. name: 'fax'
  358. }]
  359. },{
  360. cls: 'x-plain',
  361. title: 'Biography',
  362. layout: 'fit',
  363. items: {
  364. xtype: 'htmleditor',
  365. name: 'bio2',
  366. fieldLabel: 'Biography'
  367. }
  368. }]
  369. }],
  370. buttons: [{
  371. text: 'Save'
  372. },{
  373. text: 'Cancel'
  374. }]
  375. });
  376. tab2.render(document.body);
  377. });