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.

159 lines
5.8 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("Ext.ux");
  16. /**
  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. })();