PageRenderTime 56ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/helpers/TbHtml.php

https://github.com/jacmoe/yiistrap-1
PHP | 4045 lines | 2135 code | 299 blank | 1611 comment | 170 complexity | 7a768193a813c7bfa641c9e22a52ab50 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * TbHtml class file.
  4. * @author Antonio Ramirez <ramirez.cobos@gmail.com>
  5. * @author Christoffer Niska <christoffer.niska@gmail.com>
  6. * @copyright Copyright &copy; Christoffer Niska 2013-
  7. * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
  8. * @package bootstrap.helpers
  9. */
  10. /**
  11. * Bootstrap HTML helper.
  12. */
  13. class TbHtml extends CHtml // required in order to access protected methods
  14. {
  15. // Floats.
  16. const PULL_LEFT = 'left';
  17. const PULL_RIGHT = 'right';
  18. // Text alignments.
  19. const ALIGN_LEFT = 'left';
  20. const ALIGN_CENTER = 'center';
  21. const ALIGN_RIGHT = 'right';
  22. // Element colors.
  23. const COLOR_DEFAULT = '';
  24. const COLOR_PRIMARY = 'primary';
  25. const COLOR_INFO = 'info';
  26. const COLOR_SUCCESS = 'success';
  27. const COLOR_WARNING = 'warning';
  28. const COLOR_ERROR = 'error';
  29. const COLOR_DANGER = 'danger';
  30. const COLOR_IMPORTANT = 'important';
  31. const COLOR_INVERSE = 'inverse';
  32. const COLOR_LINK = 'link';
  33. // Element sizes.
  34. const SIZE_MINI = 'mini';
  35. const SIZE_SMALL = 'small';
  36. const SIZE_DEFAULT = '';
  37. const SIZE_MEDIUM = 'medium';
  38. const SIZE_LARGE = 'large';
  39. const SIZE_XLARGE = 'xlarge';
  40. const SIZE_XXLARGE = 'xxlarge';
  41. const BUTTON_LINK = 'link';
  42. const BUTTON_HTML = 'htmlButton';
  43. const BUTTON_SUBMIT = 'submitButton';
  44. const BUTTON_RESET = 'resetButton';
  45. const BUTTON_IMAGE = 'imageButton';
  46. const BUTTON_LINKBUTTON = 'linkButton';
  47. const BUTTON_AJAXLINK = 'ajaxLink';
  48. const BUTTON_AJAXBUTTON = 'ajaxButton';
  49. const BUTTON_INPUTBUTTON = 'inputButton';
  50. const BUTTON_INPUTSUBMIT = 'inputSubmit';
  51. // Menu types.
  52. const NAV_TABS = 'tabs';
  53. const NAV_PILLS = 'pills';
  54. const NAV_LIST = 'list';
  55. // Navbar positions.
  56. const NAVBAR_INLINE = '';
  57. const NAVBAR_FIXED_TOP = 'fixed-top';
  58. const NAVBAR_FIXED_BOTTOM = 'fixed-bottom';
  59. const NAVBAR_STATIC_TOP = 'static-top';
  60. // Image types.
  61. const IMAGE_ROUNDED = 'rounded';
  62. const IMAGE_CIRCLE = 'circle';
  63. const IMAGE_POLAROID = 'polaroid';
  64. // Progress bar types.
  65. const PROGRESS_LEFT = 'left';
  66. const PROGRESS_CENTER = 'centered';
  67. const PROGRESS_RIGHT = 'right';
  68. const PROGRESS_STRIPED = 'striped';
  69. const PROGRESS_ACTIVE = 'active';
  70. // Tooltip placements.
  71. const TOOLTIP_TOP = 'top';
  72. const TOOLTIP_BOTTOM = 'bottom';
  73. const TOOLTIP_LEFT = 'left';
  74. const TOOLTIP_RIGHT = 'right';
  75. // Tab placements.
  76. const TABS_ABOVE = '';
  77. const TABS_BELOW = 'below';
  78. const TABS_LEFT = 'left';
  79. const TABS_RIGHT = 'right';
  80. // Affix offset types.
  81. const AFFIX_TOP = 'top';
  82. const AFFIX_BOTTOM = 'bottom';
  83. // Tooltip triggers.
  84. const TRIGGER_CLICK = 'click';
  85. const TRIGGER_HOVER = 'hover';
  86. const TRIGGER_FOCUS = 'focus';
  87. const TRIGGER_MANUAL = 'manual';
  88. // Addon types.
  89. const ADDON_PREPEND = 'prepend';
  90. const ADDON_APPEND = 'append';
  91. // Help types.
  92. const HELP_INLINE = 'inline';
  93. const HELP_BLOCK = 'block';
  94. // Form layouts.
  95. const FORM_VERTICAL = 'vertical';
  96. const FORM_HORIZONTAL = 'horizontal';
  97. const FORM_INLINE = 'inline';
  98. const FORM_SEARCH = 'search';
  99. // Input types.
  100. const INPUT_URL = 'urlField';
  101. const INPUT_EMAIL = 'emailField';
  102. const INPUT_NUMBER = 'numberField';
  103. const INPUT_RANGE = 'rangeField';
  104. const INPUT_DATE = 'dateField';
  105. const INPUT_TEXT = 'textField';
  106. const INPUT_PASSWORD = 'passwordField';
  107. const INPUT_TEXTAREA = 'textArea';
  108. const INPUT_FILE = 'fileField';
  109. const INPUT_RADIOBUTTON = 'radioButton';
  110. const INPUT_CHECKBOX = 'checkBox';
  111. const INPUT_DROPDOWN = 'dropDownList';
  112. const INPUT_LISTBOX = 'listBox';
  113. const INPUT_CHECKBOXLIST = 'checkBoxList';
  114. const INPUT_INLINECHECKBOXLIST = 'inlineCheckBoxList';
  115. const INPUT_RADIOBUTTONLIST = 'radioButtonList';
  116. const INPUT_INLINERADIOBUTTONLIST = 'inlineRadioButtonList';
  117. const INPUT_UNEDITABLE = 'uneditableField';
  118. const INPUT_SEARCH = 'searchQuery';
  119. // grid types.
  120. const GRID_STRIPED = 'striped';
  121. const GRID_BORDERED = 'bordered';
  122. const GRID_CONDENSED = 'condensed';
  123. const GRID_HOVER = 'hover';
  124. // Icon types.
  125. const ICON_GLASS = 'icon-glass';
  126. const ICON_MUSIC = 'icon-music';
  127. const ICON_SEARCH = 'icon-search';
  128. const ICON_ENVELOPE = 'icon-envelope';
  129. const ICON_HEART = 'icon-heart';
  130. const ICON_STAR = 'icon-star';
  131. const ICON_STAR_EMPTY = 'icon-star-empty';
  132. const ICON_USER = 'icon-user';
  133. const ICON_FILM = 'icon-film';
  134. const ICON_TH_LARGE = 'icon-th-large';
  135. const ICON_TH = 'icon-th';
  136. const ICON_TH_LIST = 'icon-th-list';
  137. const ICON_OK = 'icon-ok';
  138. const ICON_REMOVE = 'icon-remove';
  139. const ICON_ZOOM_IN = 'icon-zoom-in';
  140. const ICON_ZOOM_OUT = 'icon-zoom-out';
  141. const ICON_OFF = 'icon-off';
  142. const ICON_SIGNAL = 'icon-signal';
  143. const ICON_COG = 'icon-cog';
  144. const ICON_TRASH = 'icon-trash';
  145. const ICON_HOME = 'icon-home';
  146. const ICON_FILE = 'icon-file';
  147. const ICON_TIME = 'icon-time';
  148. const ICON_ROAD = 'icon-road';
  149. const ICON_DOWNLOAD_ALT = 'icon-download-alt';
  150. const ICON_DOWNLOAD = 'icon-download';
  151. const ICON_UPLOAD = 'icon-upload';
  152. const ICON_INBOX = 'icon-inbox';
  153. const ICON_PLAY_CIRCLE = 'icon-play-circle';
  154. const ICON_REPEAT = 'icon-repeat';
  155. const ICON_REFRESH = 'icon-refresh';
  156. const ICON_LIST_ALT = 'icon-list-alt';
  157. const ICON_LOCK = 'icon-lock';
  158. const ICON_FLAG = 'icon-flag';
  159. const ICON_HEADPHONES = 'icon-headphones';
  160. const ICON_VOLUME_OFF = 'icon-volume-off';
  161. const ICON_VOLUME_DOWN = 'icon-volume-down';
  162. const ICON_VOLUME_UP = 'icon-volume-up';
  163. const ICON_QRCODE = 'icon-qrcode';
  164. const ICON_BARCODE = 'icon-barcode';
  165. const ICON_TAG = 'icon-tag';
  166. const ICON_TAGS = 'icon-tags';
  167. const ICON_BOOK = 'icon-book';
  168. const ICON_BOOKMARK = 'icon-bookmark';
  169. const ICON_PRINT = 'icon-print';
  170. const ICON_CAMERA = 'icon-camera';
  171. const ICON_FONT = 'icon-font';
  172. const ICON_BOLD = 'icon-bold';
  173. const ICON_ITALIC = 'icon-italic';
  174. const ICON_TEXT_HEIGHT = 'icon-text-height';
  175. const ICON_TEXT_WIDTH = 'icon-text-width';
  176. const ICON_ALIGN_LEFT = 'icon-align-left';
  177. const ICON_ALIGN_CENTER = 'icon-align-center';
  178. const ICON_ALIGN_RIGHT = 'icon-align-right';
  179. const ICON_ALIGN_JUSTIFY = 'icon-align-justify';
  180. const ICON_LIST = 'icon-list';
  181. const ICON_INDENT_LEFT = 'icon-indent-left';
  182. const ICON_INDENT_RIGHT = 'icon-indent-right';
  183. const ICON_FACETIME_VIDEO = 'icon-facetime-video';
  184. const ICON_PICTURE = 'icon-picture';
  185. const ICON_PENCIL = 'icon-pencil';
  186. const ICON_MAP_MARKER = 'icon-map-marker';
  187. const ICON_ADJUST = 'icon-adjust';
  188. const ICON_TINT = 'icon-tint';
  189. const ICON_EDIT = 'icon-edit';
  190. const ICON_SHARE = 'icon-share';
  191. const ICON_CHECK = 'icon-check';
  192. const ICON_MOVE = 'icon-move';
  193. const ICON_STEP_BACKWARD = 'icon-step-backward';
  194. const ICON_FAST_BACKWARD = 'icon-fast-backward';
  195. const ICON_BACKWARD = 'icon-backward';
  196. const ICON_PLAY = 'icon-play';
  197. const ICON_PAUSE = 'icon-pause';
  198. const ICON_STOP = 'icon-pause';
  199. const ICON_FORWARD = 'icon-forward';
  200. const ICON_FAST_FORWARD = 'icon-fast-forward';
  201. const ICON_STEP_FORWARD = 'icon-step-forward';
  202. const ICON_EJECT = 'icon-eject';
  203. const ICON_CHEVRON_LEFT = 'icon-chevron-left';
  204. const ICON_CHEVRON_RIGHT = 'icon-chevron-right';
  205. const ICON_PLUS_SIGN = 'icon-plus-sign';
  206. const ICON_MINUS_SIGN = 'icon-minus-sign';
  207. const ICON_REMOVE_SIGN = 'icon-remove-sign';
  208. const ICON_OK_SIGN = 'icon-ok-sign';
  209. const ICON_QUESTION_SIGN = 'icon-question-sign';
  210. const ICON_INFO_SIGN = 'icon-info-sign';
  211. const ICON_SCREENSHOT = 'icon-screenshot';
  212. const ICON_REMOVE_CIRCLE = 'icon-remove-circle';
  213. const ICON_OK_CIRCLE = 'icon-ok-circle';
  214. const ICON_BAN_CIRCLE = 'icon-ban-circle';
  215. const ICON_ARROW_LEFT = 'icon-arrow-left';
  216. const ICON_ARROW_RIGHT = 'icon-arrow-right';
  217. const ICON_ARROW_UP = 'icon-arrow-up';
  218. const ICON_ARROW_DOWN = 'icon-arrow-down';
  219. const ICON_SHARE_ALT = 'icon-share-alt';
  220. const ICON_RESIZE_FULL = 'icon-resize-full';
  221. const ICON_RESIZE_SMALL = 'icon-resize-small';
  222. const ICON_PLUS = 'icon-plus';
  223. const ICON_MINUS = 'icon-minus';
  224. const ICON_ASTERISK = 'icon-asterisk';
  225. const ICON_EXCLAMATION_SIGN = 'icon-exclamation-sign';
  226. const ICON_GIFT = 'icon-gift';
  227. const ICON_LEAF = 'icon-leaf';
  228. const ICON_FIRE = 'icon-fire';
  229. const ICON_EYE_OPEN = 'icon-eye-open';
  230. const ICON_EYE_CLOSE = 'icon-eye-close';
  231. const ICON_WARNING_SIGN = 'icon-warning-sign';
  232. const ICON_PLANE = 'icon-plane';
  233. const ICON_CALENDAR = 'icon-calendar';
  234. const ICON_RANDOM = 'icon-random';
  235. const ICON_COMMENT = 'icon-comment';
  236. const ICON_MAGNET = 'icon-magnet';
  237. const ICON_CHEVRON_UP = 'icon-chevron-up';
  238. const ICON_CHEVRON_DOWN = 'icon-chevron-down';
  239. const ICON_RETWEET = 'icon-retweet';
  240. const ICON_SHOPPING_CART = 'icon-shopping-cart';
  241. const ICON_FOLDER_CLOSE = 'icon-folder-close';
  242. const ICON_FOLDER_OPEN = 'icon-folder-open';
  243. const ICON_RESIZE_VERTICAL = 'icon-resize-vertical';
  244. const ICON_RESIZE_HORIZONTAL = 'icon-resize-horizontal';
  245. const ICON_HDD = 'icon-hdd';
  246. const ICON_BULLHORN = 'icon-bullhorn';
  247. const ICON_BELL = 'icon-bell';
  248. const ICON_CERTFICATE = 'icon-certificate';
  249. const ICON_THUMBS_UP = 'icon-thumbs-up';
  250. const ICON_THUMBS_DOWN = 'icon-thumbs-down';
  251. const ICON_HAND_RIGHT = 'icon-hand-right';
  252. const ICON_HAND_LEFT = 'icon-hand-left';
  253. const ICON_HAND_UP = 'icon-hand-up';
  254. const ICON_HAND_DOWN = 'icon-hand-down';
  255. const ICON_CIRCLE_ARROW_RIGHT = 'icon-circle-arrow-right';
  256. const ICON_CIRCLE_ARROW_LEFT = 'icon-circle-arrow-left';
  257. const ICON_CIRCLE_ARROW_UP = 'icon-circle-arrow-up';
  258. const ICON_CIRCLE_ARROW_DOWN = 'icon-circle-arrow-down';
  259. const ICON_GLOBE = 'icon-globe';
  260. const ICON_WRENCH = 'icon-wrench';
  261. const ICON_TASKS = 'icon-tasks';
  262. const ICON_FILTER = 'icon-filter';
  263. const ICON_BRIEFCASE = 'icon-briefcase';
  264. const ICON_FULLSCREEN = 'icon-fullscreen';
  265. // Default close text.
  266. const CLOSE_TEXT = '&times;';
  267. //
  268. // BASE CSS
  269. // --------------------------------------------------
  270. // Typography
  271. // http://twitter.github.com/bootstrap/base-css.html#typography
  272. // --------------------------------------------------
  273. /**
  274. * Generates a paragraph that stands out.
  275. * @param string $text the lead text.
  276. * @param array $htmlOptions additional HTML attributes.
  277. * @return string the generated paragraph.
  278. */
  279. public static function lead($text, $htmlOptions = array())
  280. {
  281. $htmlOptions = self::addClassName('lead', $htmlOptions);
  282. return self::tag('p', $htmlOptions, $text);
  283. }
  284. /**
  285. * Generates small text.
  286. * @param string $text the text to style.
  287. * @param array $htmlOptions additional HTML attributes.
  288. * @return string the generated text.
  289. */
  290. public static function small($text, $htmlOptions = array())
  291. {
  292. return self::tag('small', $htmlOptions, $text);
  293. }
  294. /**
  295. * Generates bold text.
  296. * @param string $text the text to style.
  297. * @param array $htmlOptions additional HTML attributes.
  298. * @return string the generated text.
  299. */
  300. public static function b($text, $htmlOptions = array())
  301. {
  302. return self::tag('strong', $htmlOptions, $text);
  303. }
  304. /**
  305. * Generates italic text.
  306. * @param string $text the text to style.
  307. * @param array $htmlOptions additional HTML attributes.
  308. * @return string the generated text.
  309. */
  310. public static function i($text, $htmlOptions = array())
  311. {
  312. return self::tag('em', $htmlOptions, $text);
  313. }
  314. /**
  315. * Generates an emphasized text.
  316. * @param string $style the text style.
  317. * @param string $text the text to emphasize.
  318. * @param array $htmlOptions additional HTML attributes.
  319. * @param string $tag the HTML tag.
  320. * @return string the generated text.
  321. */
  322. public static function em($style, $text, $htmlOptions = array(), $tag = 'p')
  323. {
  324. $htmlOptions = self::addClassName('text-' . $style, $htmlOptions);
  325. return self::tag($tag, $htmlOptions, $text);
  326. }
  327. /**
  328. * Generates a muted text block.
  329. * @param string $text the text.
  330. * @param array $htmlOptions additional HTML attributes.
  331. * @param string $tag the HTML tag.
  332. * @return string the generated text block.
  333. */
  334. public static function muted($text, $htmlOptions = array(), $tag = 'p')
  335. {
  336. if (self::popOption('muted', $htmlOptions, false))
  337. $htmlOptions = self::addClassName('muted', $htmlOptions);
  338. return self::tag($tag, $htmlOptions, $text);
  339. }
  340. /**
  341. * Generates a muted span.
  342. * @param string $text the text.
  343. * @param array $htmlOptions additional HTML attributes.
  344. * @param string $tag the HTML tag.
  345. * @return string the generated span.
  346. */
  347. public static function mutedSpan($text, $htmlOptions = array())
  348. {
  349. return self::muted($text, $htmlOptions, 'span');
  350. }
  351. /**
  352. * Generates an abbreviation with a help text.
  353. * @param string $text the abbreviation.
  354. * @param string $word the word the abbreviation is for.
  355. * @param array $htmlOptions additional HTML attributes.
  356. * @return string the generated abbreviation.
  357. */
  358. public static function abbr($text, $word, $htmlOptions = array())
  359. {
  360. if (self::popOption('small', $htmlOptions, false))
  361. $htmlOptions = self::addClassName('initialism', $htmlOptions);
  362. $htmlOptions['title'] = $word;
  363. return self::tag('abbr', $htmlOptions, $text);
  364. }
  365. /**
  366. * Generates a small abbreviation with a help text.
  367. * @param string $text the abbreviation.
  368. * @param string $word the word the abbreviation is for.
  369. * @param array $htmlOptions additional HTML attributes.
  370. * @return string the generated abbreviation.
  371. */
  372. public static function smallAbbr($text, $word, $htmlOptions = array())
  373. {
  374. $htmlOptions['small'] = true;
  375. return self::abbr($text, $word, $htmlOptions);
  376. }
  377. /**
  378. * Generates an address block.
  379. * @param string $quote the address text.
  380. * @param array $htmlOptions additional HTML attributes.
  381. * @return string the generated block.
  382. */
  383. public static function address($text, $htmlOptions = array())
  384. {
  385. return self::tag('address', $htmlOptions, $text);
  386. }
  387. /**
  388. * Generates a quote.
  389. * @param string $text the quoted text.
  390. * @param array $htmlOptions additional HTML attributes.
  391. * @return string the generated quote.
  392. */
  393. public static function quote($text, $htmlOptions = array())
  394. {
  395. $paragraphOptions = self::popOption('paragraphOptions', $htmlOptions, array());
  396. $source = self::popOption('source', $htmlOptions);
  397. $sourceOptions = self::popOption('sourceOptions', $htmlOptions, array());
  398. $cite = self::popOption('cite', $htmlOptions);
  399. $citeOptions = self::popOption('citeOptions', $htmlOptions, array());
  400. $cite = isset($cite) ? self::tag('cite', $citeOptions, $cite) : '';
  401. $source = isset($source) ? self::tag('small', $sourceOptions, $source . ' ' . $cite) : '';
  402. $text = self::tag('p', $paragraphOptions, $text) . $source;
  403. return self::tag('blockquote', $htmlOptions, $text);
  404. }
  405. /**
  406. * Generates a help text.
  407. * @param string $text the help text.
  408. * @param array $htmlOptions additional HTML attributes.
  409. * @return string the generated text.
  410. */
  411. public static function help($text, $htmlOptions = array())
  412. {
  413. $htmlOptions = self::addClassName('help-inline', $htmlOptions);
  414. return self::tag('span', $htmlOptions, $text);
  415. }
  416. /**
  417. * Generates a help block.
  418. * @param string $text the help text.
  419. * @param array $htmlOptions additional HTML attributes.
  420. * @return string the generated block.
  421. */
  422. public static function helpBlock($text, $htmlOptions = array())
  423. {
  424. $htmlOptions = self::addClassName('help-block', $htmlOptions);
  425. return self::tag('p', $htmlOptions, $text);
  426. }
  427. // Code
  428. // http://twitter.github.com/bootstrap/base-css.html#code
  429. // --------------------------------------------------
  430. /**
  431. * Generates inline code.
  432. * @param string $code the code.
  433. * @param array $htmlOptions additional HTML attributes.
  434. * @return string the generated code.
  435. */
  436. public static function code($code, $htmlOptions = array())
  437. {
  438. return self::tag('code', $htmlOptions, $code);
  439. }
  440. /**
  441. * Generates a code block.
  442. * @param string $code the code.
  443. * @param array $htmlOptions additional HTML attributes.
  444. * @return string the generated block.
  445. */
  446. public static function codeBlock($code, $htmlOptions = array())
  447. {
  448. return self::tag('pre', $htmlOptions, $code);
  449. }
  450. /**
  451. * Generates an HTML element.
  452. * @param string $tag the tag name.
  453. * @param array $htmlOptions the element attributes.
  454. * @param mixed $content the content to be enclosed between open and close element tags.
  455. * @param boolean $closeTag whether to generate the close tag.
  456. * @return string the generated HTML element tag.
  457. */
  458. public static function tag($tag, $htmlOptions = array(), $content = false, $closeTag = true)
  459. {
  460. self::addSpanClass($htmlOptions);
  461. $align = self::popOption('align', $htmlOptions);
  462. if (isset($align))
  463. $htmlOptions = self::addClassName('text-' . $align, $htmlOptions);
  464. $pull = self::popOption('pull', $htmlOptions);
  465. if (isset($pull))
  466. $htmlOptions = self::addClassName('pull-' . $pull, $htmlOptions);
  467. return CHtml::tag($tag, $htmlOptions, $content, $closeTag);
  468. }
  469. /**
  470. * Generates an open HTML element.
  471. * @param string $tag the tag name.
  472. * @param array $htmlOptions the element attributes.
  473. * @return string the generated HTML element tag.
  474. */
  475. public static function openTag($tag, $htmlOptions = array())
  476. {
  477. return self::tag($tag, $htmlOptions);
  478. }
  479. // Tables
  480. // http://twitter.github.com/bootstrap/base-css.html#forms
  481. // --------------------------------------------------
  482. // todo: create table methods here.
  483. // Forms
  484. // http://twitter.github.com/bootstrap/base-css.html#tables
  485. // --------------------------------------------------
  486. /**
  487. * Generates a form tag.
  488. * @param string $layout the form layout.
  489. * @param string $action the form action URL.
  490. * @param string $method form method (e.g. post, get).
  491. * @param array $htmlOptions additional HTML attributes.
  492. * @return string the generated tag.
  493. */
  494. public static function formTb($layout = self::FORM_VERTICAL, $action = '', $method = 'post', $htmlOptions = array())
  495. {
  496. return self::beginFormTb($layout, $action, $method, $htmlOptions);
  497. }
  498. /**
  499. * Generates an open form tag.
  500. * @param string $layout the form layout.
  501. * @param string $action the form action URL.
  502. * @param string $method form method (e.g. post, get).
  503. * @param array $htmlOptions additional HTML attributes.
  504. * @return string the generated tag.
  505. */
  506. public static function beginFormTb($layout = self::FORM_VERTICAL, $action = '', $method = 'post', $htmlOptions = array())
  507. {
  508. $htmlOptions = self::addClassName('form-' . $layout, $htmlOptions);
  509. return CHtml::beginForm($action, $method, $htmlOptions);
  510. }
  511. /**
  512. * Generates a stateful form tag.
  513. * @param mixed $action the form action URL.
  514. * @param string $method form method (e.g. post, get).
  515. * @param array $htmlOptions additional HTML attributes.
  516. * @return string the generated form tag.
  517. */
  518. public static function statefulFormTb($layout = self::FORM_VERTICAL, $action = '', $method = 'post', $htmlOptions = array())
  519. {
  520. return self::formTb($layout, $action, $method, $htmlOptions)
  521. . CHtml::tag('div', array('style' => 'display:none'), CHtml::pageStateField(''));
  522. }
  523. /**
  524. * Generates a text field input.
  525. * @param string $name the input name.
  526. * @param string $value the input value.
  527. * @param array $htmlOptions additional HTML attributes.
  528. * @return string the generated input field.
  529. * @see TbHtml::textInputField
  530. */
  531. public static function textField($name, $value = '', $htmlOptions = array())
  532. {
  533. return self::textInputField('text', $name, $value, $htmlOptions);
  534. }
  535. /**
  536. * Generates a password field input.
  537. * @param string $name the input name.
  538. * @param string $value the input value.
  539. * @param array $htmlOptions additional HTML attributes.
  540. * @return string the generated input field.
  541. * @see TbHtml::textInputField
  542. */
  543. public static function passwordField($name, $value = '', $htmlOptions = array())
  544. {
  545. CHtml::clientChange('change', $htmlOptions);
  546. return self::textInputField('password', $name, $value, $htmlOptions);
  547. }
  548. /**
  549. * Generates an url field input.
  550. * @param string $name the input name.
  551. * @param string $value the input value.
  552. * @param array $htmlOptions additional HTML attributes.
  553. * @return string the generated input field.
  554. * @see TbHtml::textInputField
  555. */
  556. public static function urlField($name, $value = '', $htmlOptions = array())
  557. {
  558. return self::textInputField('url', $name, $value, $htmlOptions);
  559. }
  560. /**
  561. * Generates an email field input.
  562. * @param string $name the input name.
  563. * @param string $value the input value.
  564. * @param array $htmlOptions additional HTML attributes.
  565. * @return string the generated input field.
  566. * @see TbHtml::textInputField
  567. */
  568. public static function emailField($name, $value = '', $htmlOptions = array())
  569. {
  570. return self::textInputField('email', $name, $value, $htmlOptions);
  571. }
  572. /**
  573. * Generates a number field input.
  574. * @param string $name the input name.
  575. * @param string $value the input value.
  576. * @param array $htmlOptions additional HTML attributes.
  577. * @return string the generated input field.
  578. * @see TbHtml::textInputField
  579. */
  580. public static function numberField($name, $value = '', $htmlOptions = array())
  581. {
  582. return self::textInputField('number', $name, $value, $htmlOptions);
  583. }
  584. /**
  585. * Generates a range field input.
  586. * @param string $name the input name.
  587. * @param string $value the input value.
  588. * @param array $htmlOptions additional HTML attributes.
  589. * @return string the generated input field.
  590. * @see TbHtml::textInputField
  591. */
  592. public static function rangeField($name, $value = '', $htmlOptions = array())
  593. {
  594. return self::textInputField('range', $name, $value, $htmlOptions);
  595. }
  596. /**
  597. * Generates a date field input.
  598. * @param string $name the input name.
  599. * @param string $value the input value.
  600. * @param array $htmlOptions additional HTML attributes.
  601. * @return string the generated input field.
  602. * @see TbHtml::textInputField
  603. */
  604. public static function dateField($name, $value = '', $htmlOptions = array())
  605. {
  606. return self::textInputField('date', $name, $value, $htmlOptions);
  607. }
  608. /**
  609. * Generates a text area input.
  610. * @param string $name the input name.
  611. * @param string $value the input value.
  612. * @param array $htmlOptions additional HTML attributes.
  613. * @return string the generated text area.
  614. */
  615. public static function textArea($name, $value = '', $htmlOptions = array())
  616. {
  617. $htmlOptions = self::normalizeInputOptions($htmlOptions);
  618. return CHtml::textArea($name, $value, $htmlOptions);
  619. }
  620. /**
  621. * Generates a radio button.
  622. * @param string $name the input name.
  623. * @param boolean $checked whether the radio button is checked.
  624. * @param array $htmlOptions additional HTML attributes.
  625. * @return string the generated radio button.
  626. */
  627. public static function radioButton($name, $checked = false, $htmlOptions = array())
  628. {
  629. $label = self::popOption('label', $htmlOptions, false);
  630. $labelOptions = self::popOption('labelOptions', $htmlOptions, array());
  631. $radioButton = CHtml::radioButton($name, $checked, $htmlOptions);
  632. if ($label !== false)
  633. {
  634. $labelOptions = self::addClassName('radio', $labelOptions);
  635. ob_start();
  636. echo self::tag('label', $labelOptions, $radioButton . $label);
  637. return ob_get_clean();
  638. }
  639. else
  640. return $radioButton;
  641. }
  642. /**
  643. * Generates a check box.
  644. * @param string $name the input name.
  645. * @param boolean $checked whether the check box is checked.
  646. * @param array $htmlOptions additional HTML attributes.
  647. * @return string the generated check box.
  648. */
  649. public static function checkBox($name, $checked = false, $htmlOptions = array())
  650. {
  651. $label = self::popOption('label', $htmlOptions, false);
  652. $labelOptions = self::popOption('labelOptions', $htmlOptions, array());
  653. $checkBox = CHtml::checkBox($name, $checked, $htmlOptions);
  654. if ($label !== false)
  655. {
  656. $labelOptions = self::addClassName('checkbox', $labelOptions);
  657. ob_start();
  658. echo self::tag('label', $labelOptions, $checkBox . $label);
  659. return ob_get_clean();
  660. }
  661. else
  662. return $checkBox;
  663. }
  664. /**
  665. * Generates a drop down list.
  666. * @param string $name the input name.
  667. * @param string $select the selected value.
  668. * @param array $data data for generating the list options (value=>display).
  669. * @return string the generated drop down list.
  670. */
  671. public static function dropDownList($name, $select, $data, $htmlOptions = array())
  672. {
  673. $htmlOptions = self::normalizeInputOptions($htmlOptions);
  674. return CHtml::dropDownList($name, $select, $data, $htmlOptions);
  675. }
  676. /**
  677. * Generates a list box.
  678. * @param string $name the input name.
  679. * @param mixed $select the selected value(s).
  680. * @param array $data data for generating the list options (value=>display).
  681. * @param array $htmlOptions additional HTML attributes.
  682. * @return string the generated list box
  683. */
  684. public static function listBox($name, $select, $data, $htmlOptions = array())
  685. {
  686. $htmlOptions = self::defaultOption('size', 4, $htmlOptions);
  687. if (isset($htmlOptions['multiple']))
  688. {
  689. if (substr($name, -2) !== '[]')
  690. $name .= '[]';
  691. }
  692. return self::dropDownList($name, $select, $data, $htmlOptions);
  693. }
  694. /**
  695. * Generates a radio button list.
  696. * @param string $name name of the radio button list.
  697. * @param mixed $select selection of the radio buttons.
  698. * @param array $data $data value-label pairs used to generate the radio button list.
  699. * @param array $htmlOptions additional HTML attributes.
  700. * @return string the generated list.
  701. */
  702. public static function radioButtonList($name, $select, $data, $htmlOptions = array())
  703. {
  704. $inline = self::popOption('inline', $htmlOptions, false);
  705. $separator = self::popOption('separator', $htmlOptions, ' ');
  706. $container = self::popOption('container', $htmlOptions);
  707. $containerOptions = self::popOption('containerOptions', $htmlOptions, array());
  708. $labelOptions = self::popOption('labelOptions', $htmlOptions, array());
  709. if ($inline)
  710. $labelOptions = self::addClassName('inline', $labelOptions);
  711. $items = array();
  712. $baseID = $containerOptions['id'] = self::popOption('baseID', $htmlOptions, CHtml::getIdByName($name));
  713. $id = 0;
  714. foreach ($data as $value => $label)
  715. {
  716. $checked = !strcmp($value, $select);
  717. $htmlOptions['value'] = $value;
  718. $htmlOptions['id'] = $baseID . '_' . $id++;
  719. if ($inline)
  720. {
  721. $htmlOptions['label'] = $label;
  722. $htmlOptions['labelOptions'] = $labelOptions;
  723. $items[] = self::radioButton($name, $checked, $htmlOptions);
  724. }
  725. else
  726. {
  727. $option = self::radioButton($name, $checked, $htmlOptions);
  728. $items[] = self::label($option . ' ' . $label, false, $labelOptions);
  729. }
  730. }
  731. $inputs = implode($separator, $items);
  732. return !empty($container) ? self::tag($container, $containerOptions, $inputs) : $inputs;
  733. }
  734. /**
  735. * Generates an inline radio button list.
  736. * @param string $name name of the radio button list.
  737. * @param mixed $select selection of the radio buttons.
  738. * @param array $data $data value-label pairs used to generate the radio button list.
  739. * @param array $htmlOptions additional HTML attributes.
  740. * @return string the generated list.
  741. */
  742. public static function inlineRadioButtonList($name, $select, $data, $htmlOptions = array())
  743. {
  744. $htmlOptions['inline'] = true;
  745. return self::radioButtonList($name, $select, $data, $htmlOptions);
  746. }
  747. /**
  748. * Generates a check box list.
  749. * @param string $name name of the check box list.
  750. * @param mixed $select selection of the check boxes.
  751. * @param array $data $data value-label pairs used to generate the check box list.
  752. * @param array $htmlOptions additional HTML attributes.
  753. * @return string the generated list.
  754. */
  755. public static function checkBoxList($name, $select, $data, $htmlOptions = array())
  756. {
  757. $inline = self::popOption('inline', $htmlOptions, false);
  758. $separator = self::popOption('separator', $htmlOptions, ' ');
  759. $container = self::popOption('container', $htmlOptions);
  760. $containerOptions = self::popOption('containerOptions', $htmlOptions, array());
  761. if (substr($name, -2) !== '[]')
  762. $name .= '[]';
  763. $checkAllLabel = self::popOption('checkAll', $htmlOptions);
  764. $checkAllLast = self::popOption('checkAllLast', $htmlOptions);
  765. $labelOptions = self::popOption('labelOptions', $htmlOptions, array());
  766. if ($inline)
  767. $labelOptions = self::addClassName('inline', $labelOptions);
  768. $items = array();
  769. $baseID = $containerOptions['id'] = self::popOption('baseID', $htmlOptions, CHtml::getIdByName($name));
  770. $id = 0;
  771. $checkAll = true;
  772. foreach ($data as $value => $label)
  773. {
  774. $checked = !is_array($select) && !strcmp($value, $select) || is_array($select) && in_array($value, $select);
  775. $checkAll = $checkAll && $checked;
  776. $htmlOptions['value'] = $value;
  777. $htmlOptions['id'] = $baseID . '_' . $id++;
  778. if ($inline)
  779. {
  780. $htmlOptions['label'] = $label;
  781. $htmlOptions['labelOptions'] = $labelOptions;
  782. $items[] = self::checkBox($name, $checked, $htmlOptions);
  783. }
  784. else
  785. {
  786. $option = self::checkBox($name, $checked, $htmlOptions);
  787. $items[] = self::label($option . ' ' . $label, false, $labelOptions);
  788. }
  789. }
  790. if (isset($checkAllLabel))
  791. {
  792. $htmlOptions['value'] = 1;
  793. $htmlOptions['id'] = $id = $baseID . '_all';
  794. $option = self::checkBox($id, $checkAll, $htmlOptions);
  795. $label = self::label($checkAllLabel, '', $labelOptions);
  796. $item = self::label($option . ' ' . $label, '', $labelOptions);
  797. if ($checkAllLast)
  798. $items[] = $item;
  799. else
  800. array_unshift($items, $item);
  801. $name = strtr($name, array('[' => '\\[', ']' => '\\]'));
  802. $js = <<<EOD
  803. jQuery('#$id').click(function() {
  804. jQuery("input[name='$name']").prop('checked', this.checked);
  805. });
  806. jQuery("input[name='$name']").click(function() {
  807. jQuery('#$id').prop('checked', !jQuery("input[name='$name']:not(:checked)").length);
  808. });
  809. jQuery('#$id').prop('checked', !jQuery("input[name='$name']:not(:checked)").length);
  810. EOD;
  811. $cs = Yii::app()->getClientScript();
  812. $cs->registerCoreScript('jquery');
  813. $cs->registerScript($id, $js);
  814. }
  815. $inputs = implode($separator, $items);
  816. return !empty($container) ? self::tag($container, $containerOptions, $inputs) : $inputs;
  817. }
  818. /**
  819. * Generates an inline check box list.
  820. * @param string $name name of the check box list.
  821. * @param mixed $select selection of the check boxes.
  822. * @param array $data $data value-label pairs used to generate the check box list.
  823. * @param array $htmlOptions additional HTML attributes.
  824. * @return string the generated list.
  825. */
  826. public static function inlineCheckBoxList($name, $select, $data, $htmlOptions = array())
  827. {
  828. $htmlOptions['inline'] = true;
  829. return self::checkBoxList($name, $select, $data, $htmlOptions);
  830. }
  831. /**
  832. * Generates an uneditable input.
  833. * @param string $value the value.
  834. * @param array $htmlOptions additional HTML attributes.
  835. * @return string the generated input.
  836. */
  837. public static function uneditableField($value = '', $htmlOptions = array())
  838. {
  839. $size = self::popOption('size', $htmlOptions);
  840. if (!self::addSpanClass($htmlOptions))
  841. {
  842. if (isset($size))
  843. $htmlOptions = self::addClassName('input-' . $size, $htmlOptions);
  844. else if (isset($htmlOptions['block']))
  845. $htmlOptions = self::addClassName('input-block-level', $htmlOptions);
  846. }
  847. $htmlOptions = self::addClassName('uneditable-input', $htmlOptions);
  848. return self::tag('span', $htmlOptions, $value);
  849. }
  850. /**
  851. * Generates a search query input.
  852. * @param string $name the input name.
  853. * @param string $value the input value.
  854. * @param array $htmlOptions additional HTML attributes.
  855. * @return string the generated input.
  856. */
  857. public static function searchQuery($name, $value = '', $htmlOptions = array())
  858. {
  859. $htmlOptions = self::addClassName('search-query', $htmlOptions);
  860. return self::textField($name, $value, $htmlOptions);
  861. }
  862. /**
  863. * Generates a text field input row.
  864. * @param string $name the input name.
  865. * @param string $value the input value.
  866. * @param array $htmlOptions additional HTML attributes.
  867. * @return string the generated row.
  868. * @see TbHtml::row
  869. */
  870. public static function textFieldRow($name, $value = '', $htmlOptions = array())
  871. {
  872. return self::row(self::INPUT_TEXT, $name, $value, $htmlOptions);
  873. }
  874. /**
  875. * Generates a password field input row.
  876. * @param string $name the input name.
  877. * @param string $value the input value.
  878. * @param array $htmlOptions additional HTML attributes.
  879. * @return string the generated row.
  880. * @see TbHtml::textInputField
  881. */
  882. public static function passwordFieldRow($name, $value = '', $htmlOptions = array())
  883. {
  884. return self::row(self::INPUT_PASSWORD, $name, $value, $htmlOptions);
  885. }
  886. /**
  887. * Generates an url field input row.
  888. * @param string $name the input name.
  889. * @param string $value the input value.
  890. * @param array $htmlOptions additional HTML attributes.
  891. * @return string the generated row.
  892. * @see TbHtml::row
  893. */
  894. public static function urlFieldRow($name, $value = '', $htmlOptions = array())
  895. {
  896. return self::row(self::INPUT_URL, $name, $value, $htmlOptions);
  897. }
  898. /**
  899. * Generates an email field input row.
  900. * @param string $name the input name.
  901. * @param string $value the input value.
  902. * @param array $htmlOptions additional HTML attributes.
  903. * @return string the generated row.
  904. * @see TbHtml::row
  905. */
  906. public static function emailFieldRow($name, $value = '', $htmlOptions = array())
  907. {
  908. return self::row(self::INPUT_EMAIL, $name, $value, $htmlOptions);
  909. }
  910. /**
  911. * Generates a number field input row.
  912. * @param string $name the input name.
  913. * @param string $value the input value.
  914. * @param array $htmlOptions additional HTML attributes.
  915. * @return string the generated row.
  916. * @see TbHtml::textInputField
  917. */
  918. public static function numberFieldRow($name, $value = '', $htmlOptions = array())
  919. {
  920. return self::row(self::INPUT_NUMBER, $name, $value, $htmlOptions);
  921. }
  922. /**
  923. * Generates a range field input row.
  924. * @param string $name the input name
  925. * @param string $value the input value
  926. * @param array $htmlOptions additional HTML attributes.
  927. * @return string the generated row.
  928. * @see TbHtml::row
  929. */
  930. public static function rangeFieldRow($name, $value = '', $htmlOptions = array())
  931. {
  932. return self::row(self::INPUT_RANGE, $name, $value, $htmlOptions);
  933. }
  934. /**
  935. * Generates a date field input row.
  936. * @param string $name the input name.
  937. * @param string $value the input value.
  938. * @param array $htmlOptions additional HTML attributes.
  939. * @return string the generated row.
  940. * @see TbHtml::row
  941. */
  942. public static function dateFieldRow($name, $value = '', $htmlOptions = array())
  943. {
  944. return self::row(self::INPUT_DATE, $name, $value, $htmlOptions);
  945. }
  946. /**
  947. * Generates a text area input row.
  948. * @param string $name the input name.
  949. * @param string $value the input value.
  950. * @param array $htmlOptions additional HTML attributes.
  951. * @return string the generated row.
  952. * @see TbHtml::row
  953. */
  954. public static function textAreaRow($name, $value = '', $htmlOptions = array())
  955. {
  956. return self::row(self::INPUT_TEXTAREA, $name, $value, $htmlOptions);
  957. }
  958. /**
  959. * Generates a file input row.
  960. * @param string $name the input name.
  961. * @param string $value the input value.
  962. * @param array $htmlOptions additional HTML attributes.
  963. * @return string the generated row.
  964. * @see TbHtml::row
  965. */
  966. public static function fileFieldRow($name, $value = '', $htmlOptions = array())
  967. {
  968. return self::row(self::INPUT_FILE, $name, $value, $htmlOptions);
  969. }
  970. /**
  971. * Generates a radio button row.
  972. * @param string $name the input name.
  973. * @param string $checked whether the radio button is checked.
  974. * @param array $htmlOptions additional HTML attributes.
  975. * @return string the generated row.
  976. * @see TbHtml::row
  977. */
  978. public static function radioButtonRow($name, $checked = false, $htmlOptions = array())
  979. {
  980. return self::row(self::INPUT_RADIOBUTTON, $name, $checked, $htmlOptions);
  981. }
  982. /**
  983. * Generates a check box row.
  984. * @param string $name the input name.
  985. * @param string $checked whether the check box is checked.
  986. * @param array $htmlOptions additional HTML attributes.
  987. * @return string the generated row.
  988. * @see TbHtml::row
  989. */
  990. public static function checkBoxRow($name, $checked = false, $htmlOptions = array())
  991. {
  992. return self::row(self::INPUT_CHECKBOX, $name, $checked, $htmlOptions);
  993. }
  994. /**
  995. * Generates a drop down list row.
  996. * @param string $name the input name.
  997. * @param string $select the selected value.
  998. * @param array $data data for generating the list options (value=>display).
  999. * @param array $htmlOptions additional HTML attributes.
  1000. * @return string the generated row.
  1001. * @see TbHtml::row
  1002. */
  1003. public static function dropDownListRow($name, $select = '', $data = array(), $htmlOptions = array())
  1004. {
  1005. return self::row(self::INPUT_DROPDOWN, $name, $select, $htmlOptions, $data);
  1006. }
  1007. /**
  1008. * Generates a list box row.
  1009. * @param string $name the input name.
  1010. * @param string $select the selected value.
  1011. * @param array $data data for generating the list options (value=>display).
  1012. * @param array $htmlOptions additional HTML attributes.
  1013. * @return string the generated row.
  1014. * @see TbHtml::row
  1015. */
  1016. public static function listBoxRow($name, $select = '', $data = array(), $htmlOptions = array())
  1017. {
  1018. return self::row(self::INPUT_LISTBOX, $name, $select, $htmlOptions, $data);
  1019. }
  1020. /**
  1021. * Generates a radio button list row.
  1022. * @param string $name the input name.
  1023. * @param string $select the selected value.
  1024. * @param array $data data for generating the list options (value=>display).
  1025. * @param array $htmlOptions additional HTML attributes.
  1026. * @return string the generated row.
  1027. * @see TbHtml::row
  1028. */
  1029. public static function radioButtonListRow($name, $select = '', $data = array(), $htmlOptions = array())
  1030. {
  1031. return self::row(self::INPUT_RADIOBUTTONLIST, $name, $select, $htmlOptions, $data);
  1032. }
  1033. /**
  1034. * Generates an inline radio button list row.
  1035. * @param string $name the input name.
  1036. * @param string $select the selected value.
  1037. * @param array $data data for generating the list options (value=>display).
  1038. * @param array $htmlOptions additional HTML attributes.
  1039. * @return string the generated row.
  1040. * @see TbHtml::row
  1041. */
  1042. public static function inlineRadioButtonListRow($name, $select = '', $data = array(), $htmlOptions = array())
  1043. {
  1044. return self::row(self::INPUT_INLINERADIOBUTTONLIST, $name, $select, $htmlOptions, $data);
  1045. }
  1046. /**
  1047. * Generates a check box list row.
  1048. * @param string $name the input name.
  1049. * @param string $select the selected value.
  1050. * @param array $data data for generating the list options (value=>display).
  1051. * @param array $htmlOptions additional HTML attributes.
  1052. * @return string the generated row.
  1053. * @see TbHtml::row
  1054. */
  1055. public static function checkBoxListRow($name, $select = '', $data = array(), $htmlOptions = array())
  1056. {
  1057. return self::row(self::INPUT_CHECKBOXLIST, $name, $select, $htmlOptions, $data);
  1058. }
  1059. /**
  1060. * Generates an inline check box list row.
  1061. * @param string $name the input name.
  1062. * @param string $select the selected value.
  1063. * @param array $data data for generating the list options (value=>display).
  1064. * @param array $htmlOptions additional HTML attributes.
  1065. * @return string the generated row.
  1066. * @see TbHtml::row
  1067. */
  1068. public static function inlineCheckBoxListRow($name, $select = '', $data = array(), $htmlOptions = array())
  1069. {
  1070. return self::row(self::INPUT_INLINECHECKBOXLIST, $name, $select, $htmlOptions, $data);
  1071. }
  1072. /**
  1073. * Generates a uneditable field row.
  1074. * @param string $select the input value.
  1075. * @param array $htmlOptions additional HTML attributes.
  1076. * @return string the generated row.
  1077. * @see TbHtml::row
  1078. */
  1079. public static function unediableFieldRow($value = '', $htmlOptions = array())
  1080. {
  1081. return self::row(self::INPUT_UNEDITABLE, '', $value, $htmlOptions);
  1082. }
  1083. /**
  1084. * Generates search query row.
  1085. * @param string $name the input name.
  1086. * @param string $select the input value.
  1087. * @param array $htmlOptions additional HTML attributes.
  1088. * @return string the generated row.
  1089. * @see TbHtml::row
  1090. */
  1091. public static function searchQueryRow($name, $value = '', $htmlOptions = array())
  1092. {
  1093. return self::row(self::INPUT_SEARCH, $name, $value, $htmlOptions);
  1094. }
  1095. /**
  1096. * Generates a form row.
  1097. * @param string $type the input type.
  1098. * @param string $name the input name.
  1099. * @param string $value the input value.
  1100. * @param array $htmlOptions additional HTML attributes.
  1101. * @param array $data data for multiple select inputs.
  1102. * @return string the generated row.
  1103. */
  1104. public static function row($type, $name, $value, $htmlOptions = array(), $data = array())
  1105. {
  1106. $wrap = self::popOption('wrap', $htmlOptions, false);
  1107. $label = self::popOption('label', $htmlOptions, false);
  1108. $color = self::popOption('color', $htmlOptions);
  1109. $groupOptions = self::popOption('groupOptions', $htmlOptions, array());
  1110. $labelOptions = self::popOption('labelOptions', $htmlOptions, array());
  1111. $controlOptions = self::popOption('controlOptions', $htmlOptions, array());
  1112. if (in_array($type, array(self::INPUT_CHECKBOX, self::INPUT_RADIOBUTTON)))
  1113. {
  1114. $htmlOptions['label'] = $label;
  1115. $htmlOptions['labelOptions'] = $labelOptions;
  1116. $label = false;
  1117. }
  1118. $help = self::popOption('help', $htmlOptions, '');
  1119. $helpOptions = self::popOption('helpOptions', $htmlOptions, array());
  1120. if (!empty($help))
  1121. $help = self::inputHelp($help, $helpOptions);
  1122. $input = self::createInput($type, $name, $value, $htmlOptions, $data);
  1123. if ($wrap)
  1124. {
  1125. $groupOptions = self::addClassName('control-group', $groupOptions);
  1126. if (isset($color))
  1127. $groupOptions = self::addClassName($color, $groupOptions);
  1128. $labelOptions = self::addClassName('control-label', $labelOptions);
  1129. ob_start();
  1130. echo self::openTag('div', $groupOptions);
  1131. if ($label !== false)
  1132. echo CHtml::label($label, $name, $labelOptions);
  1133. echo self::formControls($input . $help, $controlOptions);
  1134. echo '</div>';
  1135. return ob_get_clean();
  1136. }
  1137. else
  1138. {
  1139. ob_start();
  1140. if ($label !== false)
  1141. echo CHtml::label($label, $name, $labelOptions);
  1142. echo $input . $help;
  1143. return ob_get_clean();
  1144. }
  1145. }
  1146. /**
  1147. * Generates a wrapped form row.
  1148. * @param string $type the input type.
  1149. * @param string $name the input name.
  1150. * @param string $value the input value.
  1151. * @param array $htmlOptions additional HTML attributes.
  1152. * @param array $data data for multiple select inputs.
  1153. * @return string the generated row.
  1154. */
  1155. public static function wrappedRow($type, $name, $value, $htmlOptions = array(), $data = array())
  1156. {
  1157. $htmlOptions['wrap'] = true;
  1158. return self::row($type, $name, $value, $htmlOptions, $data);
  1159. }
  1160. /**
  1161. * Creates a form input of the given type.
  1162. * @param string $type the input type.
  1163. * @param string $name the input name.
  1164. * @param string $value the input value.
  1165. * @param array $htmlOptions additional HTML attributes.
  1166. * @param array $data data for multiple select inputs.
  1167. * @return string the input.
  1168. * @throws CException if the input type is invalid.
  1169. */
  1170. protected static function createInput($type, $name, $value, $htmlOptions = array(), $data = array())
  1171. {
  1172. switch ($type)
  1173. {
  1174. case self::INPUT_URL: return self::urlField($name, $value, $htmlOptions);
  1175. case self::INPUT_EMAIL: return self::emailField($name, $value, $htmlOptions);
  1176. case self::INPUT_NUMBER: return self::numberField($name, $value, $htmlOptions);
  1177. case self::INPUT_RANGE: return self::rangeField($name, $value, $htmlOptions);
  1178. case self::INPUT_DATE: return self::dateField($name, $value, $htmlOptions);
  1179. case self::INPUT_TEXT: return self::textField($name, $value, $htmlOptions);
  1180. case self::INPUT_PASSWORD: return self::passwordField($name, $value, $htmlOptions);
  1181. case self::INPUT_TEXTAREA: return self::textArea($name, $value, $htmlOptions);
  1182. case self::INPUT_FILE: return self::fileField($name, $value, $htmlOptions);
  1183. case self::INPUT_RADIOBUTTON: return self::radioButton($name, $value, $htmlOptions);
  1184. case self::INPUT_CHECKBOX: return self::checkBox($name, $value, $htmlOptions);
  1185. case self::INPUT_DROPDOWN: return self::dropDownList($name, $value, $data, $htmlOptions);
  1186. case self::INPUT_LISTBOX: return self::listBox($name, $value, $data, $htmlOptions);
  1187. case self::INPUT_CHECKBOXLIST: return self::checkBoxList($name, $value, $data, $htmlOptions);
  1188. case self::INPUT_INLINECHECKBOXLIST: return self::inlineCheckBoxList($n

Large files files are truncated, but you can click here to view the full file