Installer/Updater
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.

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