contact-form.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. Ext.require([
  2. 'Ext.form.*',
  3. 'Ext.tip.QuickTipManager'
  4. ]);
  5. Ext.onReady(function() {
  6. var required = '<span style="color:red;font-weight:bold" data-qtip="Required">*</span>';
  7. var win;
  8. Ext.QuickTips.init();
  9. function showContactForm() {
  10. if (!win) {
  11. var form = Ext.widget('form', {
  12. layout: {
  13. type: 'vbox',
  14. align: 'stretch'
  15. },
  16. border: false,
  17. bodyPadding: 10,
  18. fieldDefaults: {
  19. labelAlign: 'top',
  20. labelWidth: 100,
  21. labelStyle: 'font-weight:bold'
  22. },
  23. items: [{
  24. xtype: 'fieldcontainer',
  25. fieldLabel: 'Your Name',
  26. labelStyle: 'font-weight:bold;padding:0',
  27. layout: 'hbox',
  28. defaultType: 'textfield',
  29. fieldDefaults: {
  30. labelAlign: 'top'
  31. },
  32. items: [{
  33. flex: 1,
  34. name: 'firstName',
  35. afterLabelTextTpl: required,
  36. fieldLabel: 'First',
  37. allowBlank: false
  38. }, {
  39. width: 30,
  40. name: 'middleInitial',
  41. fieldLabel: 'MI',
  42. margins: '0 0 0 5'
  43. }, {
  44. flex: 2,
  45. name: 'lastName',
  46. afterLabelTextTpl: required,
  47. fieldLabel: 'Last',
  48. allowBlank: false,
  49. margins: '0 0 0 5'
  50. }]
  51. }, {
  52. xtype: 'textfield',
  53. fieldLabel: 'Your Email Address',
  54. afterLabelTextTpl: required,
  55. vtype: 'email',
  56. allowBlank: false
  57. }, {
  58. xtype: 'textfield',
  59. fieldLabel: 'Subject',
  60. afterLabelTextTpl: required,
  61. allowBlank: false
  62. }, {
  63. xtype: 'textareafield',
  64. fieldLabel: 'Message',
  65. labelAlign: 'top',
  66. flex: 1,
  67. margins: '0',
  68. afterLabelTextTpl: required,
  69. allowBlank: false
  70. }],
  71. buttons: [{
  72. text: 'Cancel',
  73. handler: function() {
  74. this.up('form').getForm().reset();
  75. this.up('window').hide();
  76. }
  77. }, {
  78. text: 'Send',
  79. handler: function() {
  80. if (this.up('form').getForm().isValid()) {
  81. // In a real application, this would submit the form to the configured url
  82. // this.up('form').getForm().submit();
  83. this.up('form').getForm().reset();
  84. this.up('window').hide();
  85. Ext.MessageBox.alert('Thank you!', 'Your inquiry has been sent. We will respond as soon as possible.');
  86. }
  87. }
  88. }]
  89. });
  90. win = Ext.widget('window', {
  91. title: 'Contact Us',
  92. closeAction: 'hide',
  93. width: 400,
  94. height: 400,
  95. layout: 'fit',
  96. resizable: true,
  97. modal: true,
  98. items: form
  99. });
  100. }
  101. win.show();
  102. }
  103. var mainPanel = Ext.widget('panel', {
  104. renderTo: Ext.getBody(),
  105. title: 'Welcome!',
  106. width: 500,
  107. bodyPadding: 20,
  108. items: [{
  109. xtype: 'component',
  110. html: 'Thank you for visiting our site! We welcome your feedback; please click the button below to ' +
  111. 'send us a message. We will respond to your inquiry as quickly as possible.',
  112. style: 'margin-bottom: 20px;'
  113. }, {
  114. xtype: 'container',
  115. style: 'text-align:center',
  116. items: [{
  117. xtype: 'button',
  118. cls: 'contactBtn',
  119. scale: 'large',
  120. text: 'Contact Us',
  121. handler: showContactForm
  122. }]
  123. }]
  124. });
  125. });