direct-form.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. Ext.require([
  2. 'Ext.direct.*',
  3. 'Ext.form.*',
  4. 'Ext.tip.QuickTipManager',
  5. 'Ext.layout.container.Accordion'
  6. ]);
  7. Ext.onReady(function(){
  8. /*
  9. * Notice that Direct requests will batch together if they occur
  10. * within the enableBuffer delay period (in milliseconds).
  11. * Slow the buffering down from the default of 10ms to 100ms
  12. */
  13. Ext.app.REMOTING_API.enableBuffer = 100;
  14. Ext.direct.Manager.addProvider(Ext.app.REMOTING_API);
  15. // provide feedback for any errors
  16. Ext.tip.QuickTipManager.init();
  17. var basicInfo = Ext.create('Ext.form.Panel', {
  18. // configs for FormPanel
  19. title: 'Basic Information',
  20. border: false,
  21. bodyPadding: 10,
  22. // configs for BasicForm
  23. api: {
  24. // The server-side method to call for load() requests
  25. load: Profile.getBasicInfo,
  26. // The server-side must mark the submit handler as a 'formHandler'
  27. submit: Profile.updateBasicInfo
  28. },
  29. // specify the order for the passed params
  30. paramOrder: ['uid', 'foo'],
  31. dockedItems: [{
  32. dock: 'bottom',
  33. xtype: 'toolbar',
  34. ui: 'footer',
  35. style: 'margin: 0 5px 5px 0;',
  36. items: ['->', {
  37. text: 'Submit',
  38. handler: function(){
  39. basicInfo.getForm().submit({
  40. params: {
  41. foo: 'bar',
  42. uid: 34
  43. }
  44. });
  45. }
  46. }]
  47. }],
  48. defaultType: 'textfield',
  49. defaults: {
  50. anchor: '100%'
  51. },
  52. items: [{
  53. fieldLabel: 'Name',
  54. name: 'name'
  55. },{
  56. fieldLabel: 'Email',
  57. msgTarget: 'side',
  58. name: 'email'
  59. },{
  60. fieldLabel: 'Company',
  61. name: 'company'
  62. }]
  63. });
  64. var phoneInfo = Ext.create('Ext.form.Panel', {
  65. title: 'Phone Numbers',
  66. border: false,
  67. api: {
  68. load: Profile.getPhoneInfo
  69. },
  70. bodyPadding: 10,
  71. paramOrder: ['uid'],
  72. defaultType: 'textfield',
  73. defaults: {
  74. anchor: '100%'
  75. },
  76. items: [{
  77. fieldLabel: 'Office',
  78. name: 'office'
  79. },{
  80. fieldLabel: 'Cell',
  81. name: 'cell'
  82. },{
  83. fieldLabel: 'Home',
  84. name: 'home'
  85. }]
  86. });
  87. var locationInfo = Ext.create('Ext.form.Panel', {
  88. title: 'Location Information',
  89. border: false,
  90. bodyPadding: 10,
  91. api: {
  92. load: Profile.getLocationInfo
  93. },
  94. paramOrder: ['uid'],
  95. defaultType: 'textfield',
  96. defaults: {
  97. anchor: '100%'
  98. },
  99. items: [{
  100. fieldLabel: 'Street',
  101. name: 'street'
  102. },{
  103. fieldLabel: 'City',
  104. name: 'city'
  105. },{
  106. fieldLabel: 'State',
  107. name: 'state'
  108. },{
  109. fieldLabel: 'Zip',
  110. name: 'zip'
  111. }]
  112. });
  113. var accordion = Ext.create('Ext.panel.Panel', {
  114. layout: 'accordion',
  115. renderTo: Ext.getBody(),
  116. title: 'My Profile',
  117. width: 300,
  118. height: 240,
  119. items: [basicInfo, phoneInfo, locationInfo]
  120. });
  121. // load the forms (notice the load requests will get batched together)
  122. basicInfo.getForm().load({
  123. // pass 2 arguments to server side getBasicInfo method (len=2)
  124. params: {
  125. foo: 'bar',
  126. uid: 34
  127. }
  128. });
  129. phoneInfo.getForm().load({
  130. params: {
  131. uid: 5
  132. }
  133. });
  134. // defer this request just to simulate the request not getting batched
  135. // since it exceeds to configured buffer
  136. Ext.Function.defer(function(){
  137. locationInfo.getForm().load({
  138. params: {
  139. uid: 5
  140. }
  141. });
  142. }, 200);
  143. // rpc call
  144. TestAction.doEcho('sample');
  145. });