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.

195 lines
6.5 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. /**
  8. * @class Ext.ux.ValidationStatus
  9. * A {@link Ext.StatusBar} plugin that provides automatic error notification when the
  10. * associated form contains validation errors.
  11. * @extends Ext.Component
  12. * @constructor
  13. * Creates a new ValiationStatus plugin
  14. * @param {Object} config A config object
  15. */
  16. Ext.ux.ValidationStatus = Ext.extend(Ext.Component, {
  17. /**
  18. * @cfg {String} errorIconCls
  19. * The {@link #iconCls} value to be applied to the status message when there is a
  20. * validation error. Defaults to <tt>'x-status-error'</tt>.
  21. */
  22. errorIconCls : 'x-status-error',
  23. /**
  24. * @cfg {String} errorListCls
  25. * The css class to be used for the error list when there are validation errors.
  26. * Defaults to <tt>'x-status-error-list'</tt>.
  27. */
  28. errorListCls : 'x-status-error-list',
  29. /**
  30. * @cfg {String} validIconCls
  31. * The {@link #iconCls} value to be applied to the status message when the form
  32. * validates. Defaults to <tt>'x-status-valid'</tt>.
  33. */
  34. validIconCls : 'x-status-valid',
  35. /**
  36. * @cfg {String} showText
  37. * The {@link #text} value to be applied when there is a form validation error.
  38. * Defaults to <tt>'The form has errors (click for details...)'</tt>.
  39. */
  40. showText : 'The form has errors (click for details...)',
  41. /**
  42. * @cfg {String} showText
  43. * The {@link #text} value to display when the error list is displayed.
  44. * Defaults to <tt>'Click again to hide the error list'</tt>.
  45. */
  46. hideText : 'Click again to hide the error list',
  47. /**
  48. * @cfg {String} submitText
  49. * The {@link #text} value to be applied when the form is being submitted.
  50. * Defaults to <tt>'Saving...'</tt>.
  51. */
  52. submitText : 'Saving...',
  53. // private
  54. init : function(sb){
  55. sb.on('render', function(){
  56. this.statusBar = sb;
  57. this.monitor = true;
  58. this.errors = new Ext.util.MixedCollection();
  59. this.listAlign = (sb.statusAlign=='right' ? 'br-tr?' : 'bl-tl?');
  60. if(this.form){
  61. this.form = Ext.getCmp(this.form).getForm();
  62. this.startMonitoring();
  63. this.form.on('beforeaction', function(f, action){
  64. if(action.type == 'submit'){
  65. // Ignore monitoring while submitting otherwise the field validation
  66. // events cause the status message to reset too early
  67. this.monitor = false;
  68. }
  69. }, this);
  70. var startMonitor = function(){
  71. this.monitor = true;
  72. };
  73. this.form.on('actioncomplete', startMonitor, this);
  74. this.form.on('actionfailed', startMonitor, this);
  75. }
  76. }, this, {single:true});
  77. sb.on({
  78. scope: this,
  79. afterlayout:{
  80. single: true,
  81. fn: function(){
  82. // Grab the statusEl after the first layout.
  83. sb.statusEl.getEl().on('click', this.onStatusClick, this, {buffer:200});
  84. }
  85. },
  86. beforedestroy:{
  87. single: true,
  88. fn: this.onDestroy
  89. }
  90. });
  91. },
  92. // private
  93. startMonitoring : function(){
  94. this.form.items.each(function(f){
  95. f.on('invalid', this.onFieldValidation, this);
  96. f.on('valid', this.onFieldValidation, this);
  97. }, this);
  98. },
  99. // private
  100. stopMonitoring : function(){
  101. this.form.items.each(function(f){
  102. f.un('invalid', this.onFieldValidation, this);
  103. f.un('valid', this.onFieldValidation, this);
  104. }, this);
  105. },
  106. // private
  107. onDestroy : function(){
  108. this.stopMonitoring();
  109. this.statusBar.statusEl.un('click', this.onStatusClick, this);
  110. Ext.ux.ValidationStatus.superclass.onDestroy.call(this);
  111. },
  112. // private
  113. onFieldValidation : function(f, msg){
  114. if(!this.monitor){
  115. return false;
  116. }
  117. if(msg){
  118. this.errors.add(f.id, {field:f, msg:msg});
  119. }else{
  120. this.errors.removeKey(f.id);
  121. }
  122. this.updateErrorList();
  123. if(this.errors.getCount() > 0){
  124. if(this.statusBar.getText() != this.showText){
  125. this.statusBar.setStatus({text:this.showText, iconCls:this.errorIconCls});
  126. }
  127. }else{
  128. this.statusBar.clearStatus().setIcon(this.validIconCls);
  129. }
  130. },
  131. // private
  132. updateErrorList : function(){
  133. if(this.errors.getCount() > 0){
  134. var msg = '<ul>';
  135. this.errors.each(function(err){
  136. msg += ('<li id="x-err-'+ err.field.id +'"><a href="#">' + err.msg + '</a></li>');
  137. }, this);
  138. this.getMsgEl().update(msg+'</ul>');
  139. }else{
  140. this.getMsgEl().update('');
  141. }
  142. },
  143. // private
  144. getMsgEl : function(){
  145. if(!this.msgEl){
  146. this.msgEl = Ext.DomHelper.append(Ext.getBody(), {
  147. cls: this.errorListCls+' x-hide-offsets'
  148. }, true);
  149. this.msgEl.on('click', function(e){
  150. var t = e.getTarget('li', 10, true);
  151. if(t){
  152. Ext.getCmp(t.id.split('x-err-')[1]).focus();
  153. this.hideErrors();
  154. }
  155. }, this, {stopEvent:true}); // prevent anchor click navigation
  156. }
  157. return this.msgEl;
  158. },
  159. // private
  160. showErrors : function(){
  161. this.updateErrorList();
  162. this.getMsgEl().alignTo(this.statusBar.getEl(), this.listAlign).slideIn('b', {duration:0.3, easing:'easeOut'});
  163. this.statusBar.setText(this.hideText);
  164. this.form.getEl().on('click', this.hideErrors, this, {single:true}); // hide if the user clicks directly into the form
  165. },
  166. // private
  167. hideErrors : function(){
  168. var el = this.getMsgEl();
  169. if(el.isVisible()){
  170. el.slideOut('b', {duration:0.2, easing:'easeIn'});
  171. this.statusBar.setText(this.showText);
  172. }
  173. this.form.getEl().un('click', this.hideErrors, this);
  174. },
  175. // private
  176. onStatusClick : function(){
  177. if(this.getMsgEl().isVisible()){
  178. this.hideErrors();
  179. }else if(this.errors.getCount() > 0){
  180. this.showErrors();
  181. }
  182. }
  183. });