Web Interface For Lite Argus Control modules
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.

133 lines
3.2 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*!
  2. * Ext JS Library 3.3.1
  3. * Copyright(c) 2006-2010 Sencha Inc.
  4. * licensing@sencha.com
  5. * http://www.sencha.com/license
  6. */
  7. Ext.ns('App', 'App.user');
  8. /**
  9. * @class App.user.FormPanel
  10. * A typical FormPanel extension
  11. */
  12. App.user.Form = Ext.extend(Ext.form.FormPanel, {
  13. renderTo: 'user-form',
  14. iconCls: 'silk-user',
  15. frame: true,
  16. labelAlign: 'right',
  17. title: 'User -- All fields are required',
  18. frame: true,
  19. width: 500,
  20. defaultType: 'textfield',
  21. defaults: {
  22. anchor: '100%'
  23. },
  24. // private A pointer to the currently loaded record
  25. record : null,
  26. /**
  27. * initComponent
  28. * @protected
  29. */
  30. initComponent : function() {
  31. // build the form-fields. Always a good idea to defer form-building to a method so that this class can
  32. // be over-ridden to provide different form-fields
  33. this.items = this.buildForm();
  34. // build form-buttons
  35. this.buttons = this.buildUI();
  36. // add a create event for convenience in our application-code.
  37. this.addEvents({
  38. /**
  39. * @event create
  40. * Fires when user clicks [create] button
  41. * @param {FormPanel} this
  42. * @param {Object} values, the Form's values object
  43. */
  44. create : true
  45. });
  46. // super
  47. App.user.Form.superclass.initComponent.call(this);
  48. },
  49. /**
  50. * buildform
  51. * @private
  52. */
  53. buildForm : function() {
  54. return [
  55. {fieldLabel: 'Email', name: 'email', allowBlank: false, vtype: 'email'},
  56. {fieldLabel: 'First', name: 'first', allowBlank: false},
  57. {fieldLabel: 'Last', name: 'last', allowBlank: false}
  58. ];
  59. },
  60. /**
  61. * buildUI
  62. * @private
  63. */
  64. buildUI: function(){
  65. return [{
  66. text: 'Save',
  67. iconCls: 'icon-save',
  68. handler: this.onUpdate,
  69. scope: this
  70. }, {
  71. text: 'Create',
  72. iconCls: 'silk-user-add',
  73. handler: this.onCreate,
  74. scope: this
  75. }, {
  76. text: 'Reset',
  77. handler: function(btn, ev){
  78. this.getForm().reset();
  79. },
  80. scope: this
  81. }];
  82. },
  83. /**
  84. * loadRecord
  85. * @param {Record} rec
  86. */
  87. loadRecord : function(rec) {
  88. this.record = rec;
  89. this.getForm().loadRecord(rec);
  90. },
  91. /**
  92. * onUpdate
  93. */
  94. onUpdate : function(btn, ev) {
  95. if (this.record == null) {
  96. return;
  97. }
  98. if (!this.getForm().isValid()) {
  99. App.setAlert(false, "Form is invalid.");
  100. return false;
  101. }
  102. this.getForm().updateRecord(this.record);
  103. },
  104. /**
  105. * onCreate
  106. */
  107. onCreate : function(btn, ev) {
  108. if (!this.getForm().isValid()) {
  109. App.setAlert(false, "Form is invalid");
  110. return false;
  111. }
  112. this.fireEvent('create', this, this.getForm().getValues());
  113. this.getForm().reset();
  114. },
  115. /**
  116. * onReset
  117. */
  118. onReset : function(btn, ev) {
  119. this.fireEvent('update', this, this.getForm().getValues());
  120. this.getForm().reset();
  121. }
  122. });