Web UI for ARGUS server
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.

93 lines
3.0 KiB

6 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. <title>The source code</title>
  5. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  6. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  7. </head>
  8. <body onload="prettyPrint();">
  9. <pre class="prettyprint lang-js">/*!
  10. * Ext JS Library 3.3.1
  11. * Copyright(c) 2006-2010 Sencha Inc.
  12. * licensing@sencha.com
  13. * http://www.sencha.com/license
  14. */
  15. Ext.ns("Ext.ux");
  16. <div id="cls-Ext.ux.FieldReplicator"></div>/**
  17. * @class Ext.ux.FieldReplicator
  18. * <p>A plugin for Field Components which creates clones of the Field for as
  19. * long as the user keeps filling them. Leaving the final one blank ends the repeating series.</p>
  20. * <p>Usage:</p>
  21. * <pre><code>
  22. {
  23. xtype: 'combo',
  24. plugins: [ Ext.ux.FieldReplicator ],
  25. triggerAction: 'all',
  26. fieldLabel: 'Select recipient',
  27. store: recipientStore
  28. }
  29. * </code></pre>
  30. */
  31. Ext.ux.FieldReplicator = {
  32. init: function(f) {
  33. f.replicator = this;
  34. f.enableKeyEvents = true;
  35. f.on('change', this.onChange, this);
  36. f.onKeyDown = f.onKeyDown.createInterceptor(this.onKeyDown);
  37. },
  38. // If tabbing out and the change event will be fired, flag that
  39. // the change handler must focus the correct sibling Field.
  40. onKeyDown: function(e) {
  41. if ((e.getKey() == Ext.EventObject.TAB) && (String(this.startValue) !== String(this.getValue()))) {
  42. if (e.shiftKey) {
  43. this.focusPrev = true;
  44. } else if (!e.shiftKey && !e.altKey) {
  45. this.focusNext = true;
  46. }
  47. }
  48. },
  49. // Handle the field either being changed to blank or from blank.
  50. onChange: function(f, n, o) {
  51. // Ensure that "change" is only fired once.
  52. f.startValue = n;
  53. var c = f.ownerCt, l,
  54. ps = f.previousSibling(),
  55. ns = f.nextSibling();
  56. if (Ext.isEmpty(n)) {
  57. if (!Ext.isEmpty(o)) {
  58. // The Field has been blanked, and it is not the only one left, remove it
  59. if ((ps && (ps.replicator === this)) || (ns && (ns.replicator === this))) {
  60. l = f.findParentBy(function(p) {
  61. return !Ext.isDefined(p.ownerCt);
  62. });
  63. c.remove(f);
  64. l.doLayout();
  65. }
  66. }
  67. } else {
  68. if (Ext.isEmpty(o)) {
  69. // Field filled, insert a clone as the next sibling
  70. ns = new f.constructor(f.cloneConfig());
  71. c.insert(c.items.indexOf(f) + 1, ns);
  72. c.doLayout();
  73. l = f.findParentBy(function(p) {
  74. return !Ext.isDefined(p.ownerCt);
  75. });
  76. l.doLayout();
  77. }
  78. }
  79. if (f.focusPrev) {
  80. delete f.focusPrev;
  81. ps.focus(false, true);
  82. } else if (f.focusNext) {
  83. delete f.focusNext;
  84. ns.focus(false, true);
  85. }
  86. }
  87. };</pre>
  88. </body>
  89. </html>