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.

155 lines
5.7 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.FieldLabeler"></div>/**
  17. * @class Ext.ux.FieldLabeler
  18. * <p>A plugin for Field Components which renders standard Ext form wrapping and labels
  19. * round the Field at render time regardless of the layout of the Container.</p>
  20. * <p>Usage:</p>
  21. * <pre><code>
  22. {
  23. xtype: 'combo',
  24. plugins: [ Ext.ux.FieldLabeler ],
  25. triggerAction: 'all',
  26. fieldLabel: 'Select type',
  27. store: typeStore
  28. }
  29. * </code></pre>
  30. */
  31. Ext.ux.FieldLabeler = (function(){
  32. // Pulls a named property down from the first ancestor Container it's found in
  33. function getParentProperty(propName) {
  34. for (var p = this.ownerCt; p; p = p.ownerCt) {
  35. if (p[propName]) {
  36. return p[propName];
  37. }
  38. }
  39. }
  40. return {
  41. // Add behaviour at important points in the Field's lifecycle.
  42. init: function(f) {
  43. // Replace the Field's onRender method with a sequence that calls the plugin's onRender after the Field's onRender
  44. f.onRender = f.onRender.createSequence(this.onRender);
  45. // We need to completely override the onResize method because of the complexity
  46. f.onResize = this.onResize;
  47. // Replace the Field's onDestroy method with a sequence that calls the plugin's onDestroy after the Field's onRender
  48. f.onDestroy = f.onDestroy.createSequence(this.onDestroy);
  49. },
  50. onRender: function() {
  51. // Do nothing if being rendered by a form layout
  52. if (this.ownerCt) {
  53. if (this.ownerCt.layout instanceof Ext.layout.FormLayout) {
  54. return;
  55. }
  56. }
  57. this.resizeEl = (this.wrap || this.el).wrap({
  58. cls: 'x-form-element',
  59. style: (Ext.isIE || Ext.isOpera) ? 'position:absolute;top:0;left:0;overflow:visible' : ''
  60. });
  61. this.positionEl = this.itemCt = this.resizeEl.wrap({
  62. cls: 'x-form-item '
  63. });
  64. if (this.nextSibling()) {
  65. this.margins = {
  66. top: 0,
  67. right: 0,
  68. bottom: this.positionEl.getMargins('b'),
  69. left: 0
  70. };
  71. }
  72. this.actionMode = 'itemCt';
  73. // If our Container is hiding labels, then we're done!
  74. if (!Ext.isDefined(this.hideLabels)) {
  75. this.hideLabels = getParentProperty.call(this, "hideLabels");
  76. }
  77. if (this.hideLabels) {
  78. this.resizeEl.setStyle('padding-left', '0px');
  79. return;
  80. }
  81. // Collect the info we need to render the label from our Container.
  82. if (!Ext.isDefined(this.labelSeparator)) {
  83. this.labelSeparator = getParentProperty.call(this, "labelSeparator");
  84. }
  85. if (!Ext.isDefined(this.labelPad)) {
  86. this.labelPad = getParentProperty.call(this, "labelPad");
  87. }
  88. if (!Ext.isDefined(this.labelAlign)) {
  89. this.labelAlign = getParentProperty.call(this, "labelAlign") || 'left';
  90. }
  91. this.itemCt.addClass('x-form-label-' + this.labelAlign);
  92. if(this.labelAlign == 'top'){
  93. if (!this.labelWidth) {
  94. this.labelWidth = 'auto';
  95. }
  96. this.resizeEl.setStyle('padding-left', '0px');
  97. } else {
  98. if (!Ext.isDefined(this.labelWidth)) {
  99. this.labelWidth = getParentProperty.call(this, "labelWidth") || 100;
  100. }
  101. this.resizeEl.setStyle('padding-left', (this.labelWidth + (this.labelPad || 5)) + 'px');
  102. this.labelWidth += 'px';
  103. }
  104. this.label = this.itemCt.insertFirst({
  105. tag: 'label',
  106. cls: 'x-form-item-label',
  107. style: {
  108. width: this.labelWidth
  109. },
  110. html: this.fieldLabel + (this.labelSeparator || ':')
  111. });
  112. },
  113. // private
  114. // Ensure the input field is sized to fit in the content area of the resizeEl (to the right of its padding-left)
  115. // We perform all necessary sizing here. We do NOT call the current class's onResize because we need this control
  116. // we skip that and go up the hierarchy to Ext.form.Field
  117. onResize: function(w, h) {
  118. Ext.form.Field.prototype.onResize.apply(this, arguments);
  119. w -= this.resizeEl.getPadding('l');
  120. if (this.getTriggerWidth) {
  121. this.wrap.setWidth(w);
  122. this.el.setWidth(w - this.getTriggerWidth());
  123. } else {
  124. this.el.setWidth(w);
  125. }
  126. if (this.el.dom.tagName.toLowerCase() == 'textarea') {
  127. var h = this.resizeEl.getHeight(true);
  128. if (!this.hideLabels && (this.labelAlign == 'top')) {
  129. h -= this.label.getHeight();
  130. }
  131. this.el.setHeight(h);
  132. }
  133. },
  134. // private
  135. // Ensure that we clean up on destroy.
  136. onDestroy: function() {
  137. this.itemCt.remove();
  138. }
  139. };
  140. })();</pre>
  141. </body>
  142. </html>