PageRenderTime 40ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/admincrud/extensions/bootstrap/widgets/TbTimePicker.php

https://github.com/max-rautkin/yii-admincrud
PHP | 101 lines | 37 code | 14 blank | 50 comment | 4 complexity | 8fcbfd0d53ceb1919dec310710ba640c MD5 | raw file
Possible License(s): LGPL-2.1, BSD-3-Clause
  1. <?php
  2. /**
  3. * TbTimePicker class file.
  4. * @since 1.0.3
  5. * @see http://jdewit.github.com/bootstrap-timepicker/
  6. */
  7. /**
  8. * TbTimePicker widget.
  9. */
  10. class TbTimePicker extends CInputWidget
  11. {
  12. /**
  13. * @var TbActiveForm
  14. */
  15. public $form;
  16. /**
  17. * @var array the options for the Bootstrap JavaScript plugin.
  18. * Available options:
  19. * template string
  20. * 'dropdown' (default), Show picker in a dropdown
  21. * 'modal', Show picker in a modal
  22. * false, Don't show a widget
  23. * minuteStep integer 15 Specify a step for the minute field.
  24. * showSeconds boolean false Show the seconds field.
  25. * secondStep integer 15 Specify a step for the second field.
  26. * defaultTime string
  27. * 'current' (default) Set to the current time.
  28. * 'value' Set to inputs current value
  29. * false Do not set a default time
  30. * showMeridian boolean
  31. * true (default) 12hr mode
  32. * false24hr mode
  33. * showInputs boolean
  34. * true (default )Shows the text inputs in the widget.
  35. * false Hide the text inputs in the widget
  36. * disableFocus boolean false Disables the input from focusing. This is useful for touch screen devices that
  37. * display a keyboard on input focus.
  38. * modalBackdrop boolean false Show modal backdrop.
  39. */
  40. public $options = array();
  41. /**
  42. * @var string[] the JavaScript event handlers.
  43. */
  44. public $events = array();
  45. /**
  46. * @var array the HTML attributes for the widget container.
  47. */
  48. public $htmlOptions = array();
  49. /**
  50. * Runs the widget.
  51. */
  52. public function run()
  53. {
  54. list($name, $id) = $this->resolveNameID();
  55. // Add a class of no-user-select to widget
  56. $this->htmlOptions['class'] = empty($this->htmlOptions['class'])
  57. ? 'no-user-select'
  58. : 'no-user-select ' . $this->htmlOptions['class'];
  59. if ($this->hasModel()) {
  60. if ($this->form) {
  61. echo $this->form->textField($this->model, $this->attribute, $this->htmlOptions);
  62. } else {
  63. echo CHtml::activeTextField($this->model, $this->attribute, $this->htmlOptions);
  64. }
  65. } else {
  66. echo CHtml::textField($name, $this->value, $this->htmlOptions);
  67. }
  68. $this->registerClientScript($id);
  69. }
  70. /**
  71. * Registers required javascript files
  72. *
  73. * @param string $id
  74. */
  75. public function registerClientScript($id)
  76. {
  77. Yii::app()->bootstrap->registerAssetCss('bootstrap-timepicker.css');
  78. Yii::app()->bootstrap->registerAssetJs('bootstrap.timepicker.js');
  79. $options = !empty($this->options) ? CJavaScript::encode($this->options) : '';
  80. ob_start();
  81. echo "jQuery('#{$id}').timepicker({$options})";
  82. foreach ($this->events as $event => $handler) {
  83. echo ".on('{$event}', " . CJavaScript::encode($handler) . ")";
  84. }
  85. Yii::app()->getClientScript()->registerScript(__CLASS__ . '#' . $id, ob_get_clean() . ';');
  86. }
  87. }