PageRenderTime 44ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/library/PhpExt/Layout/FormLayout.php

http://php-ext.googlecode.com/
PHP | 226 lines | 79 code | 17 blank | 130 comment | 0 complexity | dcfd48b8805fd2b59cc985945b27d6a6 MD5 | raw file
  1. <?php
  2. /**
  3. * PHP-Ext Library
  4. * http://php-ext.googlecode.com
  5. * @author Sergei Walter <sergeiw[at]gmail[dot]com>
  6. * @copyright 2008 Sergei Walter
  7. * @license http://www.gnu.org/licenses/lgpl.html
  8. * @link http://php-ext.googlecode.com
  9. *
  10. * Reference for Ext JS: http://extjs.com
  11. *
  12. */
  13. /**
  14. * @see PhpExt_Layout_AnchorLayout
  15. */
  16. include_once 'PhpExt/Layout/AnchorLayout.php';
  17. /**
  18. * This is a layout specifically designed for creating forms. However, when used in an application, it will usually be preferrable to use a {@link PhpExt_Form_FormPanel} (which automatically uses FormLayout as its layout class) since it also provides built-in functionality for loading, validating and submitting the form.
  19. *
  20. * Note that when creating a layout via config, the layout-specific config properties will be passed in via the Ext.Container.layoutConfig object which will then be applied internally to the layout. The container using the FormLayout can also supply the following form-specific config properties which will be applied by the layout:
  21. *
  22. * - <b>hideLabels:</b> (Boolean) True to hide field labels by default (defaults to false)
  23. * - <b>itemCls:</b> (String) A CSS class to add to the div wrapper that contains each field label and field element (the default class is 'x-form-item' and itemCls will be added to that)
  24. * - <b>labelAlign:</b> (String) The default label alignment. The default value is empty string '' for left alignment, but specifying 'top' will align the labels above the fields.
  25. * - <b>labelPad:</b> (Number) The default padding in pixels for field labels (defaults to 5). labelPad only applies if labelWidth is also specified, otherwise it will be ignored.
  26. * - <b>labelWidth:</b> (Number) The default width in pixels of field labels (defaults to 100)
  27. *
  28. * Any type of components can be added to a FormLayout, but items that inherit from Ext.form.Field can also supply the following field-specific config properties:
  29. *
  30. * - <b>clearCls:</b> (String) The CSS class to apply to the special clearing div rendered directly after each form field wrapper (defaults to 'x-form-clear-left')
  31. * - <b>fieldLabel:</b> (String) The text to display as the label for this field (defaults to '')
  32. * - <b>hideLabel:</b> (Boolean) True to hide the label and separator for this field (defaults to false).
  33. * - <b>itemCls:</b> (String) A CSS class to add to the div wrapper that contains this field label and field element (the default class is 'x-form-item' and itemCls will be added to that). If supplied, itemCls at the field level will override the default itemCls supplied at the container level.
  34. * - <b>labelSeparator:</b> (String) The separator to display after the text of the label for this field (defaults to a colon ':' or the layout's value for labelSeparator). To hide the separator use empty string ''.
  35. * - <b>labelStyle:</b> (String) A CSS style specification string to add to the field label for this field (defaults to '' or the layout's value for labelStyle).
  36. *
  37. * @see PhpExt_Layout_FormLayoutData
  38. * @package PhpExt
  39. * @subpackage Layout
  40. */
  41. class PhpExt_Layout_FormLayout extends PhpExt_Layout_AnchorLayout {
  42. // HideLabels
  43. /**
  44. * True to hide field labels by default (defaults to false)
  45. * @param boolean $value
  46. * @return PhpExt_Layout_FormLayout
  47. */
  48. public function setHideLabels($value) {
  49. $this->setExtConfigProperty("hideLabels", $value);
  50. return $this;
  51. }
  52. /**
  53. * True to hide field labels by default (defaults to false)
  54. * @return boolean
  55. */
  56. public function getHideLabels() {
  57. return $this->getExtConfigProperty("hideLabels");
  58. }
  59. // ItemCssClass
  60. /**
  61. * A CSS class to add to the div wrapper that contains each field label and field element (the default class is 'x-form-item' and itemCls will be added to that)
  62. * @param string $value
  63. * @return PhpExt_Layout_FormLayout
  64. */
  65. public function setItemCssClass($value) {
  66. $this->setExtConfigProperty("itemCls", $value);
  67. return $this;
  68. }
  69. /**
  70. * A CSS class to add to the div wrapper that contains each field label and field element (the default class is 'x-form-item' and itemCls will be added to that)
  71. * @return string
  72. */
  73. public function getItemCssClass() {
  74. return $this->getExtConfigProperty("itemCls");
  75. }
  76. // LabelAlign
  77. /**
  78. * The default label alignment. The default value is empty string '' or {@link PhpExt_Form_FormPanel::LABEL_ALIGN_LEFT} for left alignment, but specifying {@link PhpExt_Form_FormPanel::LABEL_ALIGN_TOP} will align the labels above the fields.
  79. * @uses PhpExt_Form_FormPanel::LABEL_ALIGN_LEFT
  80. * @uses PhpExt_Form_FormPanel::LABEL_ALIGN_TOP
  81. * @uses PhpExt_Form_FormPanel::LABEL_ALIGN_RIGHT
  82. * @param string $value
  83. * @return PhpExt_Layout_FormLayout
  84. */
  85. public function setLabelAlign($value) {
  86. $this->setExtConfigProperty("labelAlign", $value);
  87. return $this;
  88. }
  89. /**
  90. * The default label alignment. The default value is empty string '' or {@link PhpExt_Form_FormPanel::LABEL_ALIGN_LEFT} for left alignment, but specifying {@link PhpExt_Form_FormPanel::LABEL_ALIGN_TOP} will align the labels above the fields.
  91. * @uses PhpExt_Form_FormPanel::LABEL_ALIGN_LEFT
  92. * @uses PhpExt_Form_FormPanel::LABEL_ALIGN_TOP
  93. * @uses PhpExt_Form_FormPanel::LABEL_ALIGN_RIGHT
  94. * @return string
  95. */
  96. public function getLabelAlign() {
  97. return $this->getExtConfigProperty("labelAlign");
  98. }
  99. // LabelPad
  100. /**
  101. * The default padding in pixels for field labels (defaults to 5). labelPad only applies if labelWidth is also specified, otherwise it will be ignored.
  102. * @param integer $value
  103. * @return PhpExt_Layout_FormLayot
  104. */
  105. public function setLabelPad($value) {
  106. $this->setExtConfigProperty("labelPad", $value);
  107. return $this;
  108. }
  109. /**
  110. * The default padding in pixels for field labels (defaults to 5). labelPad only applies if labelWidth is also specified, otherwise it will be ignored.
  111. * @return integer
  112. */
  113. public function getLabelPad() {
  114. return $this->getExtConfigProperty("labelPad");
  115. }
  116. // LabelWidth
  117. /**
  118. * The default width in pixels of field labels (defaults to 100)
  119. * @param integer $value
  120. * @return PhpExt_Layout_FormLayout
  121. */
  122. public function setLabelWidth($value) {
  123. $this->setExtConfigProperty("labelWidth", $value);
  124. return $this;
  125. }
  126. /**
  127. * The default width in pixels of field labels (defaults to 100)
  128. * @return integer
  129. */
  130. public function getLabelWidth() {
  131. return $this->getExtConfigProperty("labelWidth");
  132. }
  133. // ElementCssStyle
  134. /**
  135. * A CSS style specification string to add to each field element in this layout (defaults to '').
  136. * @param string $value
  137. * @return PhpExt_Layout_FormLayout
  138. */
  139. public function setElementCssStyle($value) {
  140. $this->setExtConfigProperty("elementStyle", $value);
  141. return $this;
  142. }
  143. /**
  144. * A CSS style specification string to add to each field element in this layout (defaults to '').
  145. * @return string
  146. */
  147. public function getElementCssStyle() {
  148. return $this->getExtConfigProperty("elementStyle");
  149. }
  150. // LabelSeparator
  151. /**
  152. * The standard separator to display after the text of each form label (defaults to a colon ':'). To turn off separators for all fields in this layout by default specify empty string '' (if the labelSeparator value is explicitly set at the field level, those will still be displayed).
  153. * @param string $value
  154. * @return PhpExt_Layout_FormLayout
  155. */
  156. public function setLabelSeparator($value) {
  157. $this->setExtConfigProperty("labelSeparator", $value);
  158. return $this;
  159. }
  160. /**
  161. * The standard separator to display after the text of each form label (defaults to a colon ':'). To turn off separators for all fields in this layout by default specify empty string '' (if the labelSeparator value is explicitly set at the field level, those will still be displayed).
  162. * @return string
  163. */
  164. public function getLabelSeparator() {
  165. return $this->getExtConfigProperty("labelSeparator");
  166. }
  167. // LabelCssStyle
  168. /**
  169. * A CSS style specification string to add to each field label in this layout (defaults to '').
  170. * @param boolean $value
  171. * @return PhpExt_Layout_FormLayout
  172. */
  173. public function setLabelCssStyle($value) {
  174. $this->setExtConfigProperty("labelStyle", $value);
  175. return $this;
  176. }
  177. /**
  178. * A CSS style specification string to add to each field label in this layout (defaults to '').
  179. * @return boolean
  180. */
  181. public function getLabelCssStyle() {
  182. return $this->getExtConfigProperty("labelStyle");
  183. }
  184. /**
  185. * Returns the internal config string for the layout.
  186. *
  187. * @see PhpExt_Layout_ContainerLayout::LAYOUT_FORM;
  188. * @return string
  189. */
  190. public function getLayoutKey() {
  191. return PhpExt_Layout_ContainerLayout::LAYOUT_FORM;
  192. }
  193. public function __construct() {
  194. parent::__construct();
  195. $this->setExtClassInfo("Ext.layout.FormLayout", null);
  196. $validProps = array(
  197. "hideLabels",
  198. "itemCls",
  199. "labelAlign",
  200. "labelPad",
  201. "labelWidth",
  202. "elementStyle",
  203. "labelSeparator",
  204. "labelStyle"
  205. );
  206. $this->addValidConfigProperties($validProps);
  207. $this->addValidLayoutDataClassName("PhpExt_Layout_FormLayoutData");
  208. }
  209. }