You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

147 lines
3.7 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. This file is part of Ext JS 3.4
  3. Copyright (c) 2011-2013 Sencha Inc
  4. Contact: http://www.sencha.com/contact
  5. GNU General Public License Usage
  6. This file may be used under the terms of the GNU General Public License version 3.0 as
  7. published by the Free Software Foundation and appearing in the file LICENSE included in the
  8. packaging of this file.
  9. Please review the following information to ensure the GNU General Public License version 3.0
  10. requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  11. If you are unsure which license is appropriate for your use, please contact the sales department
  12. at http://www.sencha.com/contact.
  13. Build date: 2013-04-03 15:07:25
  14. */
  15. Ext.ns('App', 'App.user');
  16. /**
  17. * @class App.user.FormPanel
  18. * A typical FormPanel extension
  19. */
  20. App.user.Form = Ext.extend(Ext.form.FormPanel, {
  21. renderTo: 'user-form',
  22. iconCls: 'silk-user',
  23. frame: true,
  24. labelAlign: 'right',
  25. title: 'User -- All fields are required',
  26. frame: true,
  27. width: 500,
  28. defaultType: 'textfield',
  29. defaults: {
  30. anchor: '100%'
  31. },
  32. // private A pointer to the currently loaded record
  33. record : null,
  34. /**
  35. * initComponent
  36. * @protected
  37. */
  38. initComponent : function() {
  39. // build the form-fields. Always a good idea to defer form-building to a method so that this class can
  40. // be over-ridden to provide different form-fields
  41. this.items = this.buildForm();
  42. // build form-buttons
  43. this.buttons = this.buildUI();
  44. // add a create event for convenience in our application-code.
  45. this.addEvents({
  46. /**
  47. * @event create
  48. * Fires when user clicks [create] button
  49. * @param {FormPanel} this
  50. * @param {Object} values, the Form's values object
  51. */
  52. create : true
  53. });
  54. // super
  55. App.user.Form.superclass.initComponent.call(this);
  56. },
  57. /**
  58. * buildform
  59. * @private
  60. */
  61. buildForm : function() {
  62. return [
  63. {fieldLabel: 'Email', name: 'email', allowBlank: false, vtype: 'email'},
  64. {fieldLabel: 'First', name: 'first', allowBlank: false},
  65. {fieldLabel: 'Last', name: 'last', allowBlank: false}
  66. ];
  67. },
  68. /**
  69. * buildUI
  70. * @private
  71. */
  72. buildUI: function(){
  73. return [{
  74. text: 'Save',
  75. iconCls: 'icon-save',
  76. handler: this.onUpdate,
  77. scope: this
  78. }, {
  79. text: 'Create',
  80. iconCls: 'silk-user-add',
  81. handler: this.onCreate,
  82. scope: this
  83. }, {
  84. text: 'Reset',
  85. handler: function(btn, ev){
  86. this.getForm().reset();
  87. },
  88. scope: this
  89. }];
  90. },
  91. /**
  92. * loadRecord
  93. * @param {Record} rec
  94. */
  95. loadRecord : function(rec) {
  96. this.record = rec;
  97. this.getForm().loadRecord(rec);
  98. },
  99. /**
  100. * onUpdate
  101. */
  102. onUpdate : function(btn, ev) {
  103. if (this.record == null) {
  104. return;
  105. }
  106. if (!this.getForm().isValid()) {
  107. App.setAlert(false, "Form is invalid.");
  108. return false;
  109. }
  110. this.getForm().updateRecord(this.record);
  111. },
  112. /**
  113. * onCreate
  114. */
  115. onCreate : function(btn, ev) {
  116. if (!this.getForm().isValid()) {
  117. App.setAlert(false, "Form is invalid");
  118. return false;
  119. }
  120. this.fireEvent('create', this, this.getForm().getValues());
  121. this.getForm().reset();
  122. },
  123. /**
  124. * onReset
  125. */
  126. onReset : function(btn, ev) {
  127. this.fireEvent('update', this, this.getForm().getValues());
  128. this.getForm().reset();
  129. }
  130. });