PageRenderTime 71ms CodeModel.GetById 34ms RepoModel.GetById 0ms app.codeStats 1ms

/admincrud/extensions/bootstrap/helpers/TbHtml.php

https://github.com/max-rautkin/yii-admincrud
PHP | 4080 lines | 2184 code | 316 blank | 1580 comment | 162 complexity | c7c17d9238ae7d340c9015e511d1ea0d MD5 | raw file
Possible License(s): LGPL-2.1, BSD-3-Clause

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 the protected methods in CHtml
  14. {
  15. //
  16. // TYPOGRAPHY
  17. // --------------------------------------------------
  18. const TEXT_ALIGN_LEFT = 'left';
  19. const TEXT_ALIGN_CENTER = 'center';
  20. const TEXT_ALIGN_RIGHT = 'right';
  21. const TEXT_COLOR_DEFAULT = '';
  22. const TEXT_COLOR_WARNING = 'warning';
  23. const TEXT_COLOR_ERROR = 'error';
  24. const TEXT_COLOR_INFO = 'info';
  25. const TEXT_COLOR_SUCCESS = 'success';
  26. const HELP_TYPE_INLINE = 'inline';
  27. const HELP_TYPE_BLOCK = 'block';
  28. //
  29. // FORM
  30. // --------------------------------------------------
  31. const FORM_LAYOUT_VERTICAL = 'vertical';
  32. const FORM_LAYOUT_HORIZONTAL = 'horizontal';
  33. const FORM_LAYOUT_INLINE = 'inline';
  34. const FORM_LAYOUT_SEARCH = 'search';
  35. const INPUT_TYPE_TEXT = 'textField';
  36. const INPUT_TYPE_PASSWORD = 'passwordField';
  37. const INPUT_TYPE_URL = 'urlField';
  38. const INPUT_TYPE_EMAIL = 'emailField';
  39. const INPUT_TYPE_NUMBER = 'numberField';
  40. const INPUT_TYPE_RANGE = 'rangeField';
  41. const INPUT_TYPE_DATE = 'dateField';
  42. const INPUT_TYPE_TEXTAREA = 'textArea';
  43. const INPUT_TYPE_FILE = 'fileField';
  44. const INPUT_TYPE_RADIOBUTTON = 'radioButton';
  45. const INPUT_TYPE_CHECKBOX = 'checkBox';
  46. const INPUT_TYPE_DROPDOWNLIST = 'dropDownList';
  47. const INPUT_TYPE_LISTBOX = 'listBox';
  48. const INPUT_TYPE_CHECKBOXLIST = 'checkBoxList';
  49. const INPUT_TYPE_INLINECHECKBOXLIST = 'inlineCheckBoxList';
  50. const INPUT_TYPE_RADIOBUTTONLIST = 'radioButtonList';
  51. const INPUT_TYPE_INLINERADIOBUTTONLIST = 'inlineRadioButtonList';
  52. const INPUT_TYPE_UNEDITABLE = 'uneditableField';
  53. const INPUT_TYPE_SEARCH = 'searchQuery';
  54. const INPUT_SIZE_MINI = 'mini';
  55. const INPUT_SIZE_SMALL = 'small';
  56. const INPUT_SIZE_DEFAULT = '';
  57. const INPUT_SIZE_MEDIUM = 'medium';
  58. const INPUT_SIZE_LARGE = 'large';
  59. const INPUT_SIZE_XLARGE = 'xlarge';
  60. const INPUT_SIZE_XXLARGE = 'xxlarge';
  61. const INPUT_COLOR_DEFAULT = '';
  62. const INPUT_COLOR_WARNING = 'warning';
  63. const INPUT_COLOR_ERROR = 'error';
  64. const INPUT_COLOR_INFO = 'info';
  65. const INPUT_COLOR_SUCCESS = 'success';
  66. //
  67. // BUTTONS
  68. // --------------------------------------------------
  69. const BUTTON_TYPE_LINK = 'link';
  70. const BUTTON_TYPE_HTML = 'htmlButton';
  71. const BUTTON_TYPE_SUBMIT = 'submitButton';
  72. const BUTTON_TYPE_RESET = 'resetButton';
  73. const BUTTON_TYPE_IMAGE = 'imageButton';
  74. const BUTTON_TYPE_LINKBUTTON = 'linkButton';
  75. const BUTTON_TYPE_AJAXLINK = 'ajaxLink';
  76. const BUTTON_TYPE_AJAXBUTTON = 'ajaxButton';
  77. const BUTTON_TYPE_INPUTBUTTON = 'inputButton';
  78. const BUTTON_TYPE_INPUTSUBMIT = 'inputSubmit';
  79. const BUTTON_COLOR_DEFAULT = '';
  80. const BUTTON_COLOR_PRIMARY = 'primary';
  81. const BUTTON_COLOR_INFO = 'info';
  82. const BUTTON_COLOR_SUCCESS = 'success';
  83. const BUTTON_COLOR_WARNING = 'warning';
  84. const BUTTON_COLOR_DANGER = 'danger';
  85. const BUTTON_COLOR_INVERSE = 'inverse';
  86. const BUTTON_COLOR_LINK = 'link';
  87. const BUTTON_SIZE_MINI = 'mini';
  88. const BUTTON_SIZE_SMALL = 'small';
  89. const BUTTON_SIZE_DEFAULT = '';
  90. const BUTTON_SIZE_LARGE = 'large';
  91. const BUTTON_TOGGLE_CHECKBOX = 'checkbox';
  92. const BUTTON_TOGGLE_RADIO = 'radio';
  93. //
  94. // IMAGES
  95. // --------------------------------------------------
  96. const IMAGE_TYPE_ROUNDED = 'rounded';
  97. const IMAGE_TYPE_CIRCLE = 'circle';
  98. const IMAGE_TYPE_POLAROID = 'polaroid';
  99. //
  100. // NAV
  101. // --------------------------------------------------
  102. const NAV_TYPE_NONE = '';
  103. const NAV_TYPE_TABS = 'tabs';
  104. const NAV_TYPE_PILLS = 'pills';
  105. const NAV_TYPE_LIST = 'list';
  106. const TABS_PLACEMENT_ABOVE = '';
  107. const TABS_PLACEMENT_BELOW = 'below';
  108. const TABS_PLACEMENT_LEFT = 'left';
  109. const TABS_PLACEMENT_RIGHT = 'right';
  110. //
  111. // NAVBAR
  112. // --------------------------------------------------
  113. const NAVBAR_DISPLAY_NONE = '';
  114. const NAVBAR_DISPLAY_FIXEDTOP = 'fixed-top';
  115. const NAVBAR_DISPLAY_FIXEDBOTTOM = 'fixed-bottom';
  116. const NAVBAR_DISPLAY_STATICTOP = 'static-top';
  117. const NAVBAR_COLOR_INVERSE = 'inverse';
  118. //
  119. // PAGINATION
  120. // --------------------------------------------------
  121. const PAGINATION_SIZE_MINI = 'mini';
  122. const PAGINATION_SIZE_SMALL = 'small';
  123. const PAGINATION_SIZE_DEFAULT = '';
  124. const PAGINATION_SIZE_LARGE = 'large';
  125. const PAGINATION_ALIGN_LEFT = 'left';
  126. const PAGINATION_ALIGN_CENTER = 'centered';
  127. const PAGINATION_ALIGN_RIGHT = 'right';
  128. //
  129. // LABELS AND BADGES
  130. // --------------------------------------------------
  131. const LABEL_COLOR_DEFAULT = '';
  132. const LABEL_COLOR_SUCCESS = 'success';
  133. const LABEL_COLOR_WARNING = 'warning';
  134. const LABEL_COLOR_IMPORTANT = 'important';
  135. const LABEL_COLOR_INFO = 'info';
  136. const LABEL_COLOR_INVERSE = 'inverse';
  137. const BADGE_COLOR_DEFAULT = '';
  138. const BADGE_COLOR_SUCCESS = 'success';
  139. const BADGE_COLOR_WARNING = 'warning';
  140. const BADGE_COLOR_IMPORTANT = 'important';
  141. const BADGE_COLOR_INFO = 'info';
  142. const BADGE_COLOR_INVERSE = 'inverse';
  143. //
  144. // TOOLTIPS AND POPOVERS
  145. // --------------------------------------------------
  146. const TOOLTIP_PLACEMENT_TOP = 'top';
  147. const TOOLTIP_PLACEMENT_BOTTOM = 'bottom';
  148. const TOOLTIP_PLACEMENT_LEFT = 'left';
  149. const TOOLTIP_PLACEMENT_RIGHT = 'right';
  150. const TOOLTIP_TRIGGER_CLICK = 'click';
  151. const TOOLTIP_TRIGGER_HOVER = 'hover';
  152. const TOOLTIP_TRIGGER_FOCUS = 'focus';
  153. const TOOLTIP_TRIGGER_MANUAL = 'manual';
  154. const POPOVER_PLACEMENT_TOP = 'top';
  155. const POPOVER_PLACEMENT_BOTTOM = 'bottom';
  156. const POPOVER_PLACEMENT_LEFT = 'left';
  157. const POPOVER_PLACEMENT_RIGHT = 'right';
  158. const POPOVER_TRIGGER_CLICK = 'click';
  159. const POPOVER_TRIGGER_HOVER = 'hover';
  160. const POPOVER_TRIGGER_FOCUS = 'focus';
  161. const POPOVER_TRIGGER_MANUAL = 'manual';
  162. //
  163. // ALERT
  164. // --------------------------------------------------
  165. const ALERT_COLOR_DEFAULT = '';
  166. const ALERT_COLOR_INFO = 'info';
  167. const ALERT_COLOR_SUCCESS = 'success';
  168. const ALERT_COLOR_WARNING = 'warning';
  169. const ALERT_COLOR_ERROR = 'error';
  170. const ALERT_COLOR_DANGER = 'danger';
  171. //
  172. // PROGRESS BARS
  173. // --------------------------------------------------
  174. const PROGRESS_COLOR_DEFAULT = '';
  175. const PROGRESS_COLOR_INFO = 'info';
  176. const PROGRESS_COLOR_SUCCESS = 'success';
  177. const PROGRESS_COLOR_WARNING = 'warning';
  178. const PROGRESS_COLOR_DANGER = 'danger';
  179. //
  180. // MISC
  181. // --------------------------------------------------
  182. const WELL_SIZE_SMALL = 'small';
  183. const WELL_SIZE_DEFAULT = '';
  184. const WELL_SIZE_LARGE = 'large';
  185. const PULL_LEFT = 'left';
  186. const PULL_RIGHT = 'right';
  187. //
  188. // GRID VIEW
  189. // --------------------------------------------------
  190. const GRID_TYPE_STRIPED = 'striped';
  191. const GRID_TYPE_BORDERED = 'bordered';
  192. const GRID_TYPE_CONDENSED = 'condensed';
  193. const GRID_TYPE_HOVER = 'hover';
  194. //
  195. // AFFIX
  196. // --------------------------------------------------
  197. const AFFIX_POSITION_TOP = 'top';
  198. const AFFIX_POSITION_BOTTOM = 'bottom';
  199. //
  200. // ICON
  201. // --------------------------------------------------
  202. const ICON_GLASS = 'icon-glass';
  203. const ICON_MUSIC = 'icon-music';
  204. const ICON_SEARCH = 'icon-search';
  205. const ICON_ENVELOPE = 'icon-envelope';
  206. const ICON_HEART = 'icon-heart';
  207. const ICON_STAR = 'icon-star';
  208. const ICON_STAR_EMPTY = 'icon-star-empty';
  209. const ICON_USER = 'icon-user';
  210. const ICON_FILM = 'icon-film';
  211. const ICON_TH_LARGE = 'icon-th-large';
  212. const ICON_TH = 'icon-th';
  213. const ICON_TH_LIST = 'icon-th-list';
  214. const ICON_OK = 'icon-ok';
  215. const ICON_REMOVE = 'icon-remove';
  216. const ICON_ZOOM_IN = 'icon-zoom-in';
  217. const ICON_ZOOM_OUT = 'icon-zoom-out';
  218. const ICON_OFF = 'icon-off';
  219. const ICON_SIGNAL = 'icon-signal';
  220. const ICON_COG = 'icon-cog';
  221. const ICON_TRASH = 'icon-trash';
  222. const ICON_HOME = 'icon-home';
  223. const ICON_FILE = 'icon-file';
  224. const ICON_TIME = 'icon-time';
  225. const ICON_ROAD = 'icon-road';
  226. const ICON_DOWNLOAD_ALT = 'icon-download-alt';
  227. const ICON_DOWNLOAD = 'icon-download';
  228. const ICON_UPLOAD = 'icon-upload';
  229. const ICON_INBOX = 'icon-inbox';
  230. const ICON_PLAY_CIRCLE = 'icon-play-circle';
  231. const ICON_REPEAT = 'icon-repeat';
  232. const ICON_REFRESH = 'icon-refresh';
  233. const ICON_LIST_ALT = 'icon-list-alt';
  234. const ICON_LOCK = 'icon-lock';
  235. const ICON_FLAG = 'icon-flag';
  236. const ICON_HEADPHONES = 'icon-headphones';
  237. const ICON_VOLUME_OFF = 'icon-volume-off';
  238. const ICON_VOLUME_DOWN = 'icon-volume-down';
  239. const ICON_VOLUME_UP = 'icon-volume-up';
  240. const ICON_QRCODE = 'icon-qrcode';
  241. const ICON_BARCODE = 'icon-barcode';
  242. const ICON_TAG = 'icon-tag';
  243. const ICON_TAGS = 'icon-tags';
  244. const ICON_BOOK = 'icon-book';
  245. const ICON_BOOKMARK = 'icon-bookmark';
  246. const ICON_PRINT = 'icon-print';
  247. const ICON_CAMERA = 'icon-camera';
  248. const ICON_FONT = 'icon-font';
  249. const ICON_BOLD = 'icon-bold';
  250. const ICON_ITALIC = 'icon-italic';
  251. const ICON_TEXT_HEIGHT = 'icon-text-height';
  252. const ICON_TEXT_WIDTH = 'icon-text-width';
  253. const ICON_ALIGN_LEFT = 'icon-align-left';
  254. const ICON_ALIGN_CENTER = 'icon-align-center';
  255. const ICON_ALIGN_RIGHT = 'icon-align-right';
  256. const ICON_ALIGN_JUSTIFY = 'icon-align-justify';
  257. const ICON_LIST = 'icon-list';
  258. const ICON_INDENT_LEFT = 'icon-indent-left';
  259. const ICON_INDENT_RIGHT = 'icon-indent-right';
  260. const ICON_FACETIME_VIDEO = 'icon-facetime-video';
  261. const ICON_PICTURE = 'icon-picture';
  262. const ICON_PENCIL = 'icon-pencil';
  263. const ICON_MAP_MARKER = 'icon-map-marker';
  264. const ICON_ADJUST = 'icon-adjust';
  265. const ICON_TINT = 'icon-tint';
  266. const ICON_EDIT = 'icon-edit';
  267. const ICON_SHARE = 'icon-share';
  268. const ICON_CHECK = 'icon-check';
  269. const ICON_MOVE = 'icon-move';
  270. const ICON_STEP_BACKWARD = 'icon-step-backward';
  271. const ICON_FAST_BACKWARD = 'icon-fast-backward';
  272. const ICON_BACKWARD = 'icon-backward';
  273. const ICON_PLAY = 'icon-play';
  274. const ICON_PAUSE = 'icon-pause';
  275. const ICON_STOP = 'icon-pause';
  276. const ICON_FORWARD = 'icon-forward';
  277. const ICON_FAST_FORWARD = 'icon-fast-forward';
  278. const ICON_STEP_FORWARD = 'icon-step-forward';
  279. const ICON_EJECT = 'icon-eject';
  280. const ICON_CHEVRON_LEFT = 'icon-chevron-left';
  281. const ICON_CHEVRON_RIGHT = 'icon-chevron-right';
  282. const ICON_PLUS_SIGN = 'icon-plus-sign';
  283. const ICON_MINUS_SIGN = 'icon-minus-sign';
  284. const ICON_REMOVE_SIGN = 'icon-remove-sign';
  285. const ICON_OK_SIGN = 'icon-ok-sign';
  286. const ICON_QUESTION_SIGN = 'icon-question-sign';
  287. const ICON_INFO_SIGN = 'icon-info-sign';
  288. const ICON_SCREENSHOT = 'icon-screenshot';
  289. const ICON_REMOVE_CIRCLE = 'icon-remove-circle';
  290. const ICON_OK_CIRCLE = 'icon-ok-circle';
  291. const ICON_BAN_CIRCLE = 'icon-ban-circle';
  292. const ICON_ARROW_LEFT = 'icon-arrow-left';
  293. const ICON_ARROW_RIGHT = 'icon-arrow-right';
  294. const ICON_ARROW_UP = 'icon-arrow-up';
  295. const ICON_ARROW_DOWN = 'icon-arrow-down';
  296. const ICON_SHARE_ALT = 'icon-share-alt';
  297. const ICON_RESIZE_FULL = 'icon-resize-full';
  298. const ICON_RESIZE_SMALL = 'icon-resize-small';
  299. const ICON_PLUS = 'icon-plus';
  300. const ICON_MINUS = 'icon-minus';
  301. const ICON_ASTERISK = 'icon-asterisk';
  302. const ICON_EXCLAMATION_SIGN = 'icon-exclamation-sign';
  303. const ICON_GIFT = 'icon-gift';
  304. const ICON_LEAF = 'icon-leaf';
  305. const ICON_FIRE = 'icon-fire';
  306. const ICON_EYE_OPEN = 'icon-eye-open';
  307. const ICON_EYE_CLOSE = 'icon-eye-close';
  308. const ICON_WARNING_SIGN = 'icon-warning-sign';
  309. const ICON_PLANE = 'icon-plane';
  310. const ICON_CALENDAR = 'icon-calendar';
  311. const ICON_RANDOM = 'icon-random';
  312. const ICON_COMMENT = 'icon-comment';
  313. const ICON_MAGNET = 'icon-magnet';
  314. const ICON_CHEVRON_UP = 'icon-chevron-up';
  315. const ICON_CHEVRON_DOWN = 'icon-chevron-down';
  316. const ICON_RETWEET = 'icon-retweet';
  317. const ICON_SHOPPING_CART = 'icon-shopping-cart';
  318. const ICON_FOLDER_CLOSE = 'icon-folder-close';
  319. const ICON_FOLDER_OPEN = 'icon-folder-open';
  320. const ICON_RESIZE_VERTICAL = 'icon-resize-vertical';
  321. const ICON_RESIZE_HORIZONTAL = 'icon-resize-horizontal';
  322. const ICON_HDD = 'icon-hdd';
  323. const ICON_BULLHORN = 'icon-bullhorn';
  324. const ICON_BELL = 'icon-bell';
  325. const ICON_CERTFICATE = 'icon-certificate';
  326. const ICON_THUMBS_UP = 'icon-thumbs-up';
  327. const ICON_THUMBS_DOWN = 'icon-thumbs-down';
  328. const ICON_HAND_RIGHT = 'icon-hand-right';
  329. const ICON_HAND_LEFT = 'icon-hand-left';
  330. const ICON_HAND_UP = 'icon-hand-up';
  331. const ICON_HAND_DOWN = 'icon-hand-down';
  332. const ICON_CIRCLE_ARROW_RIGHT = 'icon-circle-arrow-right';
  333. const ICON_CIRCLE_ARROW_LEFT = 'icon-circle-arrow-left';
  334. const ICON_CIRCLE_ARROW_UP = 'icon-circle-arrow-up';
  335. const ICON_CIRCLE_ARROW_DOWN = 'icon-circle-arrow-down';
  336. const ICON_GLOBE = 'icon-globe';
  337. const ICON_WRENCH = 'icon-wrench';
  338. const ICON_TASKS = 'icon-tasks';
  339. const ICON_FILTER = 'icon-filter';
  340. const ICON_BRIEFCASE = 'icon-briefcase';
  341. const ICON_FULLSCREEN = 'icon-fullscreen';
  342. // Default close text.
  343. const CLOSE_TEXT = '&times;';
  344. //
  345. // BASE CSS
  346. // --------------------------------------------------
  347. // Typography
  348. // http://twitter.github.com/bootstrap/base-css.html#typography
  349. // --------------------------------------------------
  350. /**
  351. * Generates a paragraph that stands out.
  352. * @param string $text the lead text.
  353. * @param array $htmlOptions additional HTML attributes.
  354. * @return string the generated paragraph.
  355. */
  356. public static function lead($text, $htmlOptions = array())
  357. {
  358. $htmlOptions = self::addClassName('lead', $htmlOptions);
  359. return self::tag('p', $htmlOptions, $text);
  360. }
  361. /**
  362. * Generates small text.
  363. * @param string $text the text to style.
  364. * @param array $htmlOptions additional HTML attributes.
  365. * @return string the generated text.
  366. */
  367. public static function small($text, $htmlOptions = array())
  368. {
  369. return self::tag('small', $htmlOptions, $text);
  370. }
  371. /**
  372. * Generates bold text.
  373. * @param string $text the text to style.
  374. * @param array $htmlOptions additional HTML attributes.
  375. * @return string the generated text.
  376. */
  377. public static function b($text, $htmlOptions = array())
  378. {
  379. return self::tag('strong', $htmlOptions, $text);
  380. }
  381. /**
  382. * Generates italic text.
  383. * @param string $text the text to style.
  384. * @param array $htmlOptions additional HTML attributes.
  385. * @return string the generated text.
  386. */
  387. public static function i($text, $htmlOptions = array())
  388. {
  389. return self::tag('em', $htmlOptions, $text);
  390. }
  391. /**
  392. * Generates an emphasized text.
  393. * @param string $style the text style.
  394. * @param string $text the text to emphasize.
  395. * @param array $htmlOptions additional HTML attributes.
  396. * @param string $tag the HTML tag.
  397. * @return string the generated text.
  398. */
  399. public static function em($text, $htmlOptions = array(), $tag = 'p')
  400. {
  401. $color = self::popOption('color', $htmlOptions);
  402. if (self::popOption('muted', $htmlOptions, false))
  403. $htmlOptions = self::addClassName('muted', $htmlOptions);
  404. else if (!empty($color))
  405. $htmlOptions = self::addClassName('text-' . $color, $htmlOptions);
  406. return self::tag($tag, $htmlOptions, $text);
  407. }
  408. /**
  409. * Generates a muted text block.
  410. * @param string $text the text.
  411. * @param array $htmlOptions additional HTML attributes.
  412. * @param string $tag the HTML tag.
  413. * @return string the generated text block.
  414. */
  415. public static function muted($text, $htmlOptions = array(), $tag = 'p')
  416. {
  417. $htmlOptions['muted'] = true;
  418. return self::em($text, $htmlOptions, $tag);
  419. }
  420. /**
  421. * Generates a muted span.
  422. * @param string $text the text.
  423. * @param array $htmlOptions additional HTML attributes.
  424. * @param string $tag the HTML tag.
  425. * @return string the generated span.
  426. */
  427. public static function mutedSpan($text, $htmlOptions = array())
  428. {
  429. return self::muted($text, $htmlOptions, 'span');
  430. }
  431. /**
  432. * Generates an abbreviation with a help text.
  433. * @param string $text the abbreviation.
  434. * @param string $word the word the abbreviation is for.
  435. * @param array $htmlOptions additional HTML attributes.
  436. * @return string the generated abbreviation.
  437. */
  438. public static function abbr($text, $word, $htmlOptions = array())
  439. {
  440. if (self::popOption('small', $htmlOptions, false))
  441. $htmlOptions = self::addClassName('initialism', $htmlOptions);
  442. $htmlOptions['title'] = $word;
  443. return self::tag('abbr', $htmlOptions, $text);
  444. }
  445. /**
  446. * Generates a small abbreviation with a help text.
  447. * @param string $text the abbreviation.
  448. * @param string $word the word the abbreviation is for.
  449. * @param array $htmlOptions additional HTML attributes.
  450. * @return string the generated abbreviation.
  451. */
  452. public static function smallAbbr($text, $word, $htmlOptions = array())
  453. {
  454. $htmlOptions['small'] = true;
  455. return self::abbr($text, $word, $htmlOptions);
  456. }
  457. /**
  458. * Generates an address block.
  459. * @param string $quote the address text.
  460. * @param array $htmlOptions additional HTML attributes.
  461. * @return string the generated block.
  462. */
  463. public static function address($text, $htmlOptions = array())
  464. {
  465. return self::tag('address', $htmlOptions, $text);
  466. }
  467. /**
  468. * Generates a quote.
  469. * @param string $text the quoted text.
  470. * @param array $htmlOptions additional HTML attributes.
  471. * @return string the generated quote.
  472. */
  473. public static function quote($text, $htmlOptions = array())
  474. {
  475. $paragraphOptions = self::popOption('paragraphOptions', $htmlOptions, array());
  476. $source = self::popOption('source', $htmlOptions);
  477. $sourceOptions = self::popOption('sourceOptions', $htmlOptions, array());
  478. $cite = self::popOption('cite', $htmlOptions);
  479. $citeOptions = self::popOption('citeOptions', $htmlOptions, array());
  480. $cite = isset($cite) ? self::tag('cite', $citeOptions, $cite) : '';
  481. $source = isset($source) ? self::tag('small', $sourceOptions, $source . ' ' . $cite) : '';
  482. $text = self::tag('p', $paragraphOptions, $text) . $source;
  483. return self::tag('blockquote', $htmlOptions, $text);
  484. }
  485. /**
  486. * Generates a help text.
  487. * @param string $text the help text.
  488. * @param array $htmlOptions additional HTML attributes.
  489. * @return string the generated text.
  490. */
  491. public static function help($text, $htmlOptions = array())
  492. {
  493. $htmlOptions = self::addClassName('help-inline', $htmlOptions);
  494. return self::tag('span', $htmlOptions, $text);
  495. }
  496. /**
  497. * Generates a help block.
  498. * @param string $text the help text.
  499. * @param array $htmlOptions additional HTML attributes.
  500. * @return string the generated block.
  501. */
  502. public static function helpBlock($text, $htmlOptions = array())
  503. {
  504. $htmlOptions = self::addClassName('help-block', $htmlOptions);
  505. return self::tag('p', $htmlOptions, $text);
  506. }
  507. // Code
  508. // http://twitter.github.com/bootstrap/base-css.html#code
  509. // --------------------------------------------------
  510. /**
  511. * Generates inline code.
  512. * @param string $code the code.
  513. * @param array $htmlOptions additional HTML attributes.
  514. * @return string the generated code.
  515. */
  516. public static function code($code, $htmlOptions = array())
  517. {
  518. return self::tag('code', $htmlOptions, $code);
  519. }
  520. /**
  521. * Generates a code block.
  522. * @param string $code the code.
  523. * @param array $htmlOptions additional HTML attributes.
  524. * @return string the generated block.
  525. */
  526. public static function codeBlock($code, $htmlOptions = array())
  527. {
  528. return self::tag('pre', $htmlOptions, $code);
  529. }
  530. /**
  531. * Generates an HTML element.
  532. * @param string $tag the tag name.
  533. * @param array $htmlOptions the element attributes.
  534. * @param mixed $content the content to be enclosed between open and close element tags.
  535. * @param boolean $closeTag whether to generate the close tag.
  536. * @return string the generated HTML element tag.
  537. */
  538. public static function tag($tag, $htmlOptions = array(), $content = false, $closeTag = true)
  539. {
  540. $textAlign = self::popOption('textAlign', $htmlOptions);
  541. if (!empty($textAlign))
  542. $htmlOptions = self::addClassName('text-' . $textAlign, $htmlOptions);
  543. $pull = self::popOption('pull', $htmlOptions);
  544. if (!empty($pull))
  545. $htmlOptions = self::addClassName('pull-' . $pull, $htmlOptions);
  546. self::addSpanClass($htmlOptions);
  547. return CHtml::tag($tag, $htmlOptions, $content, $closeTag);
  548. }
  549. /**
  550. * Generates an open HTML element.
  551. * @param string $tag the tag name.
  552. * @param array $htmlOptions the element attributes.
  553. * @return string the generated HTML element tag.
  554. */
  555. public static function openTag($tag, $htmlOptions = array())
  556. {
  557. return self::tag($tag, $htmlOptions);
  558. }
  559. // Tables
  560. // http://twitter.github.com/bootstrap/base-css.html#forms
  561. // --------------------------------------------------
  562. // todo: create table methods here.
  563. // Forms
  564. // http://twitter.github.com/bootstrap/base-css.html#tables
  565. // --------------------------------------------------
  566. /**
  567. * Generates a form tag.
  568. * @param string $layout the form layout.
  569. * @param string $action the form action URL.
  570. * @param string $method form method (e.g. post, get).
  571. * @param array $htmlOptions additional HTML attributes.
  572. * @return string the generated tag.
  573. */
  574. public static function formTb($layout = self::FORM_LAYOUT_VERTICAL, $action = '', $method = 'post', $htmlOptions = array())
  575. {
  576. return self::beginFormTb($layout, $action, $method, $htmlOptions);
  577. }
  578. /**
  579. * Generates an open form tag.
  580. * @param string $layout the form layout.
  581. * @param string $action the form action URL.
  582. * @param string $method form method (e.g. post, get).
  583. * @param array $htmlOptions additional HTML attributes.
  584. * @return string the generated tag.
  585. */
  586. public static function beginFormTb($layout = self::FORM_LAYOUT_VERTICAL, $action = '', $method = 'post', $htmlOptions = array())
  587. {
  588. $htmlOptions = self::addClassName('form-' . $layout, $htmlOptions);
  589. return CHtml::beginForm($action, $method, $htmlOptions);
  590. }
  591. /**
  592. * Generates a stateful form tag.
  593. * @param mixed $action the form action URL.
  594. * @param string $method form method (e.g. post, get).
  595. * @param array $htmlOptions additional HTML attributes.
  596. * @return string the generated form tag.
  597. */
  598. public static function statefulFormTb($layout = self::FORM_LAYOUT_VERTICAL, $action = '', $method = 'post', $htmlOptions = array())
  599. {
  600. return self::formTb($layout, $action, $method, $htmlOptions)
  601. . self::tag('div', array('style' => 'display:none'), CHtml::pageStateField(''));
  602. }
  603. /**
  604. * Generates a text field input.
  605. * @param string $name the input name.
  606. * @param string $value the input value.
  607. * @param array $htmlOptions additional HTML attributes.
  608. * @return string the generated input field.
  609. * @see TbHtml::textInputField
  610. */
  611. public static function textField($name, $value = '', $htmlOptions = array())
  612. {
  613. return self::textInputField('text', $name, $value, $htmlOptions);
  614. }
  615. /**
  616. * Generates a password field input.
  617. * @param string $name the input name.
  618. * @param string $value the input value.
  619. * @param array $htmlOptions additional HTML attributes.
  620. * @return string the generated input field.
  621. * @see TbHtml::textInputField
  622. */
  623. public static function passwordField($name, $value = '', $htmlOptions = array())
  624. {
  625. return self::textInputField('password', $name, $value, $htmlOptions);
  626. }
  627. /**
  628. * Generates an url field input.
  629. * @param string $name the input name.
  630. * @param string $value the input value.
  631. * @param array $htmlOptions additional HTML attributes.
  632. * @return string the generated input field.
  633. * @see TbHtml::textInputField
  634. */
  635. public static function urlField($name, $value = '', $htmlOptions = array())
  636. {
  637. return self::textInputField('url', $name, $value, $htmlOptions);
  638. }
  639. /**
  640. * Generates an email field input.
  641. * @param string $name the input name.
  642. * @param string $value the input value.
  643. * @param array $htmlOptions additional HTML attributes.
  644. * @return string the generated input field.
  645. * @see TbHtml::textInputField
  646. */
  647. public static function emailField($name, $value = '', $htmlOptions = array())
  648. {
  649. return self::textInputField('email', $name, $value, $htmlOptions);
  650. }
  651. /**
  652. * Generates a number field input.
  653. * @param string $name the input name.
  654. * @param string $value the input value.
  655. * @param array $htmlOptions additional HTML attributes.
  656. * @return string the generated input field.
  657. * @see TbHtml::textInputField
  658. */
  659. public static function numberField($name, $value = '', $htmlOptions = array())
  660. {
  661. return self::textInputField('number', $name, $value, $htmlOptions);
  662. }
  663. /**
  664. * Generates a range field input.
  665. * @param string $name the input name.
  666. * @param string $value the input value.
  667. * @param array $htmlOptions additional HTML attributes.
  668. * @return string the generated input field.
  669. * @see TbHtml::textInputField
  670. */
  671. public static function rangeField($name, $value = '', $htmlOptions = array())
  672. {
  673. return self::textInputField('range', $name, $value, $htmlOptions);
  674. }
  675. /**
  676. * Generates a date field input.
  677. * @param string $name the input name.
  678. * @param string $value the input value.
  679. * @param array $htmlOptions additional HTML attributes.
  680. * @return string the generated input field.
  681. * @see TbHtml::textInputField
  682. */
  683. public static function dateField($name, $value = '', $htmlOptions = array())
  684. {
  685. return self::textInputField('date', $name, $value, $htmlOptions);
  686. }
  687. /**
  688. * Generates a text area input.
  689. * @param string $name the input name.
  690. * @param string $value the input value.
  691. * @param array $htmlOptions additional HTML attributes.
  692. * @return string the generated text area.
  693. */
  694. public static function textArea($name, $value = '', $htmlOptions = array())
  695. {
  696. $htmlOptions = self::normalizeInputOptions($htmlOptions);
  697. return CHtml::textArea($name, $value, $htmlOptions);
  698. }
  699. /**
  700. * Generates a radio button.
  701. * @param string $name the input name.
  702. * @param boolean $checked whether the radio button is checked.
  703. * @param array $htmlOptions additional HTML attributes.
  704. * @return string the generated radio button.
  705. */
  706. public static function radioButton($name, $checked = false, $htmlOptions = array())
  707. {
  708. $label = self::popOption('label', $htmlOptions, false);
  709. $labelOptions = self::popOption('labelOptions', $htmlOptions, array());
  710. $labelOptions = self::addClassName('radio', $labelOptions);
  711. $radioButton = CHtml::radioButton($name, $checked, $htmlOptions);
  712. return $label !== false ? self::tag('label', $labelOptions, $radioButton . $label) : $radioButton;
  713. }
  714. /**
  715. * Generates a check box.
  716. * @param string $name the input name.
  717. * @param boolean $checked whether the check box is checked.
  718. * @param array $htmlOptions additional HTML attributes.
  719. * @return string the generated check box.
  720. */
  721. public static function checkBox($name, $checked = false, $htmlOptions = array())
  722. {
  723. $label = self::popOption('label', $htmlOptions, false);
  724. $labelOptions = self::popOption('labelOptions', $htmlOptions, array());
  725. $labelOptions = self::addClassName('checkbox', $labelOptions);
  726. $checkBox = CHtml::checkBox($name, $checked, $htmlOptions);
  727. return $label !== false ? self::tag('label', $labelOptions, $checkBox . $label) : $checkBox;
  728. }
  729. /**
  730. * Generates a drop down list.
  731. * @param string $name the input name.
  732. * @param string $select the selected value.
  733. * @param array $data data for generating the list options (value=>display).
  734. * @return string the generated drop down list.
  735. */
  736. public static function dropDownList($name, $select, $data, $htmlOptions = array())
  737. {
  738. $htmlOptions = self::normalizeInputOptions($htmlOptions);
  739. return CHtml::dropDownList($name, $select, $data, $htmlOptions);
  740. }
  741. /**
  742. * Generates a list box.
  743. * @param string $name the input name.
  744. * @param mixed $select the selected value(s).
  745. * @param array $data data for generating the list options (value=>display).
  746. * @param array $htmlOptions additional HTML attributes.
  747. * @return string the generated list box
  748. */
  749. public static function listBox($name, $select, $data, $htmlOptions = array())
  750. {
  751. $htmlOptions = self::defaultOption('size', 4, $htmlOptions);
  752. if (isset($htmlOptions['multiple']))
  753. {
  754. if (substr($name, -2) !== '[]')
  755. $name .= '[]';
  756. }
  757. return self::dropDownList($name, $select, $data, $htmlOptions);
  758. }
  759. /**
  760. * Generates a radio button list.
  761. * @param string $name name of the radio button list.
  762. * @param mixed $select selection of the radio buttons.
  763. * @param array $data $data value-label pairs used to generate the radio button list.
  764. * @param array $htmlOptions additional HTML attributes.
  765. * @return string the generated list.
  766. */
  767. public static function radioButtonList($name, $select, $data, $htmlOptions = array())
  768. {
  769. $inline = self::popOption('inline', $htmlOptions, false);
  770. $separator = self::popOption('separator', $htmlOptions, ' ');
  771. $container = self::popOption('container', $htmlOptions);
  772. $containerOptions = self::popOption('containerOptions', $htmlOptions, array());
  773. $labelOptions = self::popOption('labelOptions', $htmlOptions, array());
  774. $labelOptions = self::addClassName('radio', $labelOptions);
  775. if ($inline)
  776. $labelOptions = self::addClassName('inline', $labelOptions);
  777. $items = array();
  778. $baseID = $containerOptions['id'] = self::popOption('baseID', $htmlOptions, CHtml::getIdByName($name));
  779. $id = 0;
  780. foreach ($data as $value => $label)
  781. {
  782. $checked = !strcmp($value, $select);
  783. $htmlOptions['value'] = $value;
  784. $htmlOptions['id'] = $baseID . '_' . $id++;
  785. if ($inline)
  786. {
  787. $htmlOptions['label'] = $label;
  788. $htmlOptions['labelOptions'] = $labelOptions;
  789. $items[] = self::radioButton($name, $checked, $htmlOptions);
  790. }
  791. else
  792. {
  793. $option = self::radioButton($name, $checked, $htmlOptions);
  794. $items[] = self::label($option . ' ' . $label, false, $labelOptions);
  795. }
  796. }
  797. $inputs = implode($separator, $items);
  798. return !empty($container) ? self::tag($container, $containerOptions, $inputs) : $inputs;
  799. }
  800. /**
  801. * Generates an inline radio button list.
  802. * @param string $name name of the radio button list.
  803. * @param mixed $select selection of the radio buttons.
  804. * @param array $data $data value-label pairs used to generate the radio button list.
  805. * @param array $htmlOptions additional HTML attributes.
  806. * @return string the generated list.
  807. */
  808. public static function inlineRadioButtonList($name, $select, $data, $htmlOptions = array())
  809. {
  810. $htmlOptions['inline'] = true;
  811. return self::radioButtonList($name, $select, $data, $htmlOptions);
  812. }
  813. /**
  814. * Generates a check box list.
  815. * @param string $name name of the check box list.
  816. * @param mixed $select selection of the check boxes.
  817. * @param array $data $data value-label pairs used to generate the check box list.
  818. * @param array $htmlOptions additional HTML attributes.
  819. * @return string the generated list.
  820. */
  821. public static function checkBoxList($name, $select, $data, $htmlOptions = array())
  822. {
  823. $inline = self::popOption('inline', $htmlOptions, false);
  824. $separator = self::popOption('separator', $htmlOptions, ' ');
  825. $container = self::popOption('container', $htmlOptions);
  826. $containerOptions = self::popOption('containerOptions', $htmlOptions, array());
  827. if (substr($name, -2) !== '[]')
  828. $name .= '[]';
  829. $checkAllLabel = self::popOption('checkAll', $htmlOptions);
  830. $checkAllLast = self::popOption('checkAllLast', $htmlOptions);
  831. $labelOptions = self::popOption('labelOptions', $htmlOptions, array());
  832. $labelOptions = self::addClassName('checkbox', $labelOptions);
  833. if ($inline)
  834. $labelOptions = self::addClassName('inline', $labelOptions);
  835. $items = array();
  836. $baseID = $containerOptions['id'] = self::popOption('baseID', $htmlOptions, CHtml::getIdByName($name));
  837. $id = 0;
  838. $checkAll = true;
  839. foreach ($data as $value => $label)
  840. {
  841. $checked = !is_array($select) && !strcmp($value, $select) || is_array($select) && in_array($value, $select);
  842. $checkAll = $checkAll && $checked;
  843. $htmlOptions['value'] = $value;
  844. $htmlOptions['id'] = $baseID . '_' . $id++;
  845. if ($inline)
  846. {
  847. $htmlOptions['label'] = $label;
  848. $htmlOptions['labelOptions'] = $labelOptions;
  849. $items[] = self::checkBox($name, $checked, $htmlOptions);
  850. }
  851. else
  852. {
  853. $option = self::checkBox($name, $checked, $htmlOptions);
  854. $items[] = self::label($option . ' ' . $label, false, $labelOptions);
  855. }
  856. }
  857. if (isset($checkAllLabel))
  858. {
  859. $htmlOptions['value'] = 1;
  860. $htmlOptions['id'] = $id = $baseID . '_all';
  861. $option = self::checkBox($id, $checkAll, $htmlOptions);
  862. $label = self::label($checkAllLabel, '', $labelOptions);
  863. $item = self::label($option . ' ' . $label, '', $labelOptions);
  864. if ($checkAllLast)
  865. $items[] = $item;
  866. else
  867. array_unshift($items, $item);
  868. $name = strtr($name, array('[' => '\\[', ']' => '\\]'));
  869. $js = <<<EOD
  870. jQuery('#$id').click(function() {
  871. jQuery("input[name='$name']").prop('checked', this.checked);
  872. });
  873. jQuery("input[name='$name']").click(function() {
  874. jQuery('#$id').prop('checked', !jQuery("input[name='$name']:not(:checked)").length);
  875. });
  876. jQuery('#$id').prop('checked', !jQuery("input[name='$name']:not(:checked)").length);
  877. EOD;
  878. $cs = Yii::app()->getClientScript();
  879. $cs->registerCoreScript('jquery');
  880. $cs->registerScript($id, $js);
  881. }
  882. $inputs = implode($separator, $items);
  883. return !empty($container) ? self::tag($container, $containerOptions, $inputs) : $inputs;
  884. }
  885. /**
  886. * Generates an inline check box list.
  887. * @param string $name name of the check box list.
  888. * @param mixed $select selection of the check boxes.
  889. * @param array $data $data value-label pairs used to generate the check box list.
  890. * @param array $htmlOptions additional HTML attributes.
  891. * @return string the generated list.
  892. */
  893. public static function inlineCheckBoxList($name, $select, $data, $htmlOptions = array())
  894. {
  895. $htmlOptions['inline'] = true;
  896. return self::checkBoxList($name, $select, $data, $htmlOptions);
  897. }
  898. /**
  899. * Generates an uneditable input.
  900. * @param string $value the value.
  901. * @param array $htmlOptions additional HTML attributes.
  902. * @return string the generated input.
  903. */
  904. public static function uneditableField($value = '', $htmlOptions = array())
  905. {
  906. $htmlOptions = self::addClassName('uneditable-input', $htmlOptions);
  907. $htmlOptions = self::normalizeInputOptions($htmlOptions);
  908. return self::tag('span', $htmlOptions, $value);
  909. }
  910. /**
  911. * Generates a search input.
  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 input.
  916. */
  917. public static function searchField($name, $value = '', $htmlOptions = array())
  918. {
  919. $htmlOptions = self::addClassName('search-query', $htmlOptions);
  920. return self::textField($name, $value, $htmlOptions);
  921. }
  922. /**
  923. * Generates a control group with a text field.
  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 control group.
  928. * @see TbHtml::controlGroup
  929. */
  930. public static function textFieldControlGroup($name, $value = '', $htmlOptions = array())
  931. {
  932. return self::controlGroup(self::INPUT_TYPE_TEXT, $name, $value, $htmlOptions);
  933. }
  934. /**
  935. * Generates a control group with a password field.
  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 control group.
  940. * @see TbHtml::textInputField
  941. */
  942. public static function passwordFieldControlGroup($name, $value = '', $htmlOptions = array())
  943. {
  944. return self::controlGroup(self::INPUT_TYPE_PASSWORD, $name, $value, $htmlOptions);
  945. }
  946. /**
  947. * Generates a control group with an url field.
  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 control group.
  952. * @see TbHtml::controlGroup
  953. */
  954. public static function urlFieldControlGroup($name, $value = '', $htmlOptions = array())
  955. {
  956. return self::controlGroup(self::INPUT_TYPE_URL, $name, $value, $htmlOptions);
  957. }
  958. /**
  959. * Generates a control group with an email field.
  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 control group.
  964. * @see TbHtml::controlGroup
  965. */
  966. public static function emailFieldControlGroup($name, $value = '', $htmlOptions = array())
  967. {
  968. return self::controlGroup(self::INPUT_TYPE_EMAIL, $name, $value, $htmlOptions);
  969. }
  970. /**
  971. * Generates a control group with a number field.
  972. * @param string $name the input name.
  973. * @param string $value the input value.
  974. * @param array $htmlOptions additional HTML attributes.
  975. * @return string the generated control group.
  976. * @see TbHtml::textInputField
  977. */
  978. public static function numberFieldControlGroup($name, $value = '', $htmlOptions = array())
  979. {
  980. return self::controlGroup(self::INPUT_TYPE_NUMBER, $name, $value, $htmlOptions);
  981. }
  982. /**
  983. * Generates a control group with a range field.
  984. * @param string $name the input name
  985. * @param string $value the input value
  986. * @param array $htmlOptions additional HTML attributes.
  987. * @return string the generated control group.
  988. * @see TbHtml::controlGroup
  989. */
  990. public static function rangeFieldControlGroup($name, $value = '', $htmlOptions = array())
  991. {
  992. return self::controlGroup(self::INPUT_TYPE_RANGE, $name, $value, $htmlOptions);
  993. }
  994. /**
  995. * Generates a control group with a date field.
  996. * @param string $name the input name.
  997. * @param string $value the input value.
  998. * @param array $htmlOptions additional HTML attributes.
  999. * @return string the generated control group.
  1000. * @see TbHtml::controlGroup
  1001. */
  1002. public static function dateFieldControlGroup($name, $value = '', $htmlOptions = array())
  1003. {
  1004. return self::controlGroup(self::INPUT_TYPE_DATE, $name, $value, $htmlOptions);
  1005. }
  1006. /**
  1007. * Generates a control group with a text area.
  1008. * @param string $name the input name.
  1009. * @param string $value the input value.
  1010. * @param array $htmlOptions additional HTML attributes.
  1011. * @return string the generated control group.
  1012. * @see TbHtml::controlGroup
  1013. */
  1014. public static function textAreaControlGroup($name, $value = '', $htmlOptions = array())
  1015. {
  1016. return self::controlGroup(self::INPUT_TYPE_TEXTAREA, $name, $value, $htmlOptions);
  1017. }
  1018. /**
  1019. * Generates a control group with a file field.
  1020. * @param string $name the input name.
  1021. * @param string $value the input value.
  1022. * @param array $htmlOptions additional HTML attributes.
  1023. * @return string the generated control group.
  1024. * @see TbHtml::controlGroup
  1025. */
  1026. public static function fileFieldControlGroup($name, $value = '', $htmlOptions = array())
  1027. {
  1028. return self::controlGroup(self::INPUT_TYPE_FILE, $name, $value, $htmlOptions);
  1029. }
  1030. /**
  1031. * Generates a control group with a radio button.
  1032. * @param string $name the input name.
  1033. * @param string $checked whether the radio button is checked.
  1034. * @param array $htmlOptions additional HTML attributes.
  1035. * @return string the generated control group.
  1036. * @see TbHtml::controlGroup
  1037. */
  1038. public static function radioButtonControlGroup($name, $checked = false, $htmlOptions = array())
  1039. {
  1040. return self::controlGroup(self::INPUT_TYPE_RADIOBUTTON, $name, $checked, $htmlOptions);
  1041. }
  1042. /**
  1043. * Generates a control group with a check box.
  1044. * @param string $name the input name.
  1045. * @param string $checked whether the check box is checked.
  1046. * @param array $htmlOptions additional HTML attributes.
  1047. * @return string the generated control group.
  1048. * @see TbHtml::controlGroup
  1049. */
  1050. public static function checkBoxControlGroup($name, $checked = false, $htmlOptions = array())
  1051. {
  1052. return self::controlGroup(self::INPUT_TYPE_CHECKBOX, $name, $checked, $htmlOptions);
  1053. }
  1054. /**
  1055. * Generates a control group with a drop down list.
  1056. * @param string $name the input name.
  1057. * @param string $select the selected value.
  1058. * @param array $data data for generating the list options (value=>display).
  1059. * @param array $htmlOptions additional HTML attributes.
  1060. * @return string the generated control group.
  1061. * @see TbHtml::controlGroup
  1062. */
  1063. public static function dropDownListControlGroup($name, $select = '', $data = array(), $htmlOptions = array())
  1064. {
  1065. return self::controlGroup(self::INPUT_TYPE_DROPDOWNLIST, $name, $select, $htmlOptions, $data);
  1066. }
  1067. /**
  1068. * Generates a control group with a list box.
  1069. * @param string $name the input name.
  1070. * @param string $select the selected value.
  1071. * @param array $data data for generating the list options (value=>display).
  1072. * @param array $htmlOptions additional HTML attributes.
  1073. * @return string the generated control group.
  1074. * @see TbHtml::controlGroup
  1075. */
  1076. public static function listBoxControlGroup($name, $select = '', $data = array(), $htmlOptions = array())
  1077. {
  1078. return self::controlGroup(self::INPUT_TYPE_LISTBOX, $name, $select, $htmlOptions, $data);
  1079. }
  1080. /**
  1081. * Generates a control group with a radio button list.
  1082. * @param string $name the input name.
  1083. * @param string $select the selected value.
  1084. * @param array $data data for generating the list options (value=>display).
  1085. * @param array $htmlOptions additional HTML attributes.
  1086. * @return string the generated control group.
  1087. * @see TbHtml::controlGroup
  1088. */
  1089. public static function radioButtonListControlGroup($name, $select = '', $data = array(), $htmlOptions = array())
  1090. {
  1091. return self::controlGroup(self::INPUT_TYPE_RADIOBUTTONLIST, $name, $select, $htmlOptions, $data);
  1092. }
  1093. /**
  1094. * Generates a control group with an inline radio button list.
  1095. * @param string $name the input name.
  1096. * @param string $select the selected value.
  1097. * @param array $data data for generating the list options (value=>display).
  1098. * @param array $htmlOptions additional HTML attributes.
  1099. * @return string the generated control group.
  1100. * @see TbHtml::controlGroup
  1101. */
  1102. public static function inlineRadioButtonListControlGroup($name, $select = '', $data = array(), $htmlOptions = array())
  1103. {
  1104. return self::controlGroup(self::INPUT_TYPE_INLINERADIOBUTTONLIST, $name, $select, $htmlOptions, $data);
  1105. }
  1106. /**
  1107. * Generates a control group with a check box list.
  1108. * @param string $name the input name.
  1109. * @param string $select the selected value.
  1110. * @param array $data data for generating the list options (value=>display).
  1111. * @param array $htmlOptions additional HTML attributes.
  1112. * @return string the generated control group.
  1113. * @see TbHtml::controlGroup
  1114. */
  1115. public static function checkBoxListControlGroup($name, $select = '', $data = array(), $htmlOptions = array())
  1116. {
  1117. return self::controlGroup(self::INPUT_TYPE_CHECKBOXLIST, $name, $select, $htmlOptions, $data);
  1118. }
  1119. /**
  1120. * Generates a control group with an inline check box list.
  1121. * @param string $name the input name.
  1122. * @param string $select the selected value.
  1123. * @param array $data data for generating the list options (value=>display).
  1124. * @param array $htmlOptions additional HTML attributes.
  1125. * @return string the generated control group.
  1126. * @see TbHtml::controlGroup
  1127. */
  1128. public static function inlineCheckBoxListControlGroup($name, $select = '', $data = array(), $htmlOptions = array())
  1129. {
  1130. return self::controlGroup(self::INPUT_TYPE_INLINECHECKBOXLIST, $name, $select, $htmlOptions, $data);
  1131. }
  1132. /**
  1133. * Generates a control group with an uneditable field.
  1134. * @param string $select the input value.
  1135. * @param array $htmlOptions additional HTML attributes.
  1136. * @return string the generated control group.
  1137. * @see TbHtml::controlGroup
  1138. */
  1139. public static function uneditableFieldControlGroup($value = '', $htmlOptions = array())
  1140. {
  1141. return self::controlGroup(self::INPUT_TYPE_UNEDITABLE, '', $value, $htmlOptions);
  1142. }
  1143. /**
  1144. * Generates a control group with a search field.
  1145. * @param string $name the input name.
  1146. * @param string $select the input value.
  1147. * @param array $htmlOptions additional HTML attributes.
  1148. * @return string the generated control group.
  1149. * @see TbHtml::controlGroup
  1150. */
  1151. public static function searchFieldControlGroup($name, $value = '', $htmlOptions = array())
  1152. {
  1153. return self::controlGroup(self::INPUT_TYPE_SEARCH, $name, $value, $htmlOptions);
  1154. }
  1155. /**
  1156. * Generates a form control group.
  1157. * @param string $type the input type.
  1158. * @param string $name the input name.
  1159. * @param string $value the input value.
  1160. * @param array $htmlOptions additional HTML attributes.
  1161. * @param array $data data for multiple select inputs.
  1162. * @return string the generated control group.
  1163. */
  1164. public static function controlGroup($type, $name, $value, $htmlOptions = array(), $data = array())
  1165. {
  1166. $label = self::popOption('label', $htmlOptions, false);
  1167. $color = self::popOption('color', $htmlOptions);
  1168. $controlGroupOptions = self::popOption('groupOptions', $htmlOptions, array());
  1169. $labelOptions = self::popOption('labelOptions', $htmlOptions, array());
  1170. $controlOptions = self::popOption('controlOptions', $htmlOptions, array());
  1171. if (in_array($type, array(self::INPUT_TYPE_CHECKBOX, self::INPUT_TYPE_RADIOBUTTON)))
  1172. {
  1173. $htmlOptions['label'] = $label;
  1174. $htmlOptions['labelOptions'] = $labelOptions;
  1175. $label = false;
  1176. }
  1177. $help = self::popOption('help', $htmlOptions, '');
  1178. $helpOptions = self::popOption('helpOptions', $htmlOptions, array());
  1179. if (!empty($help))
  1180. $help = self::inputHelp($help, $helpOptions);
  1181. $input = static::createInput($type, $name, $value, $htmlOptions, $data);
  1182. $controlGroupOptions = self::addClassName('control-group', $controlGroupOptions);
  1183. if (!empty($color))
  1184. $controlGroupOptions = self::addClassName($color, $controlGroupOptions);
  1185. $labelOptions = self::addClassName('control-label', $labelOptions);
  1186. ob_start();
  1187. echo self::openTag('div', $controlGroupOptions);
  1188. if ($label !== false)
  1189. echo CHtml::label($label, $name, $labelOptions);
  1190. echo self::controls($input . $help, $controlOptions);
  1191. echo '</div>';
  1192. return ob_get_clean();
  1193. }
  1194. /**
  1195. * Creates a form input of the given type.
  1196. * @param string $type the input type.
  1197. * @param string $name the input name.
  1198. * @param string $value the input value.
  1199. * @param array $htmlOptions additional HTML attributes.
  1200. * @param array $data data for multiple select inputs.
  1201. * @return string the input.
  1202. * @throws CException if the input type is invalid.
  1203. */
  1204. protected static function createInput($type, $name, $value, $htmlOptions = array(), $data = array())
  1205. {
  1206. switch ($type)
  1207. {
  1208. case self::INPUT_TYPE_TEXT:
  1209. return self::textField($name, $value, $htmlOptions);
  1210. case self::INPUT_TYPE_PASSWORD:
  1211. return self::passwordField($name, $value, $htmlOptions);
  1212. case self::INPUT_TYPE_URL:
  1213. return self::urlField($name, $value, $htmlOptions);
  1214. case self::INPUT_TYPE_EMAIL:
  1215. return self::emailField($name, $value, $htmlOptions);
  1216. case self::INPUT_TYPE_NUMBER:
  1217. return self::numberField($name, $value, $htmlOptions);
  1218. case self::INPUT_TYPE_RANGE:
  1219. return self::rangeField($name, $value, $htmlOptions);
  1220. case self::INPUT_TYPE_DATE:
  1221. return self::dateField($name, $value, $htmlOptions);
  1222. case self::INPUT_TYPE_TEXTAREA:
  1223. return self::textArea($name, $value, $htmlOptions);
  1224. case self::INPUT_TYPE_FILE:
  1225. return self::fileField($name, $value, $htmlOptions);
  1226. case self::INPUT_TYPE_RADIOBUTTON:
  1227. return self::radioButton($name, $value, $htmlOptions);
  1228. case self::INPUT_TYPE_CHECKBOX:
  1229. return self::checkBox($name, $value, $htmlOptions);
  1230. case self::INPUT_TYPE_DROPDOWNLIST:
  1231. return self::dropDownList($name, $value, $data, $htmlOptions);
  1232. case self::INPUT_TYPE_LISTBOX:
  1233. return self::listBox($name, $value, $data, $htmlOptions);
  1234. case self::INPUT_TYPE_CHECKBOXLIST:
  1235. return self::checkBoxList($name, $value, $data, $htmlOptions);
  1236. case self::INPUT_TYPE_INLINECHECKBOXLIST:
  1237. return self::inlineCheckBoxList($name, $value, $data, $htmlOptions);
  1238. case self::INPUT_TYPE_RADIOBUTTONLIST:
  1239. return self::radioButtonList($name, $value, $data, $htmlOptions);
  1240. case self::INPUT_TYPE_INLINERADIOBUTTONLIST:
  1241. return self::inlineRadioButtonList($name, $value, $data, $htmlOptions);
  1242. case self::INPUT_TYPE_UNEDITABLE:
  1243. return self::uneditableField($value, $htmlOptions);
  1244. case self::INPUT_TYPE_SEARCH:
  1245. return self::searchField($name, $value, $htmlOptions);
  1246. default:
  1247. throw new CException('Invalid input type "' . $type . '".');
  1248. }
  1249. }
  1250. /**
  1251. * Generates an input HTML tag.
  1252. * This method generates an input HTML tag based on the given input name and value.
  1253. * @param string $type the input type.
  1254. * @param string $name the input name.
  1255. * @param string $value the input value.
  1256. * @param array $htmlOptions additional HTML attributes.
  1257. * @return string the generated input tag.
  1258. */
  1259. protected static function textInputField($type, $name, $value, $htmlOptions)
  1260. {
  1261. CHtml::clientChange('change', $htmlOptions);
  1262. $htmlOptions = self::normalizeInputOptions($htmlOptions);
  1263. $addOnClasses = self::getAddOnClasses($htmlOptions);
  1264. $addOnOptions = self::popOption('addOnOptions', $htmlOptions, array());
  1265. $addOnOptions = self::addClassName($addOnClasses, $addOnOptions);
  1266. $prepend = self::popOption('prepend', $htmlOptions, '');
  1267. $prependOptions = self::popOption('prependOptions', $htmlOptions, array());
  1268. if (!empty($prepend))
  1269. $prepend = self::inputAddOn($prepend, $prependOptions);
  1270. $append = self::popOption('append', $htmlOptions, '');
  1271. $appendOptions = self::popOption('appendOptions', $htmlOptions, array());
  1272. if (!empty($append))
  1273. $append = self::inputAddOn($append, $appendOptions);
  1274. ob_start();
  1275. if (!empty($addOnClasses))
  1276. echo self::openTag('div', $addOnOptions);
  1277. echo $prepend . CHtml::inputField($type, $name, $value, $htmlOptions) . $append;
  1278. if (!empty($addOnClasses))
  1279. echo '</div>';
  1280. return ob_get_clean();
  1281. }
  1282. /**
  1283. * Generates a text field input for a model attribute.
  1284. * @param CModel $model the data model.
  1285. * @param string $attribute the attribute.
  1286. * @param array $htmlOptions additional HTML attributes.
  1287. * @return string the generated input field.
  1288. * @see TbHtml::activeTextInputField
  1289. */
  1290. public static function activeTextField($model, $attribute, $htmlOptions = array())
  1291. {
  1292. return self::activeTextIn

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