Completed
Branch master (a1edd4)
by
unknown
54:09
created

TimePicker   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 69
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A renderWidget() 0 7 1
A prepareInput() 0 8 2
A registerAssets() 0 14 3
1
<?php
2
/**
3
 * This file is part of the fangface/yii2-concord package
4
 *
5
 * For the full copyright and license information, please view
6
 * the file LICENSE.md that was distributed with this source code.
7
 *
8
 * @package fangface/yii2-concord
9
 * @author Fangface <[email protected]>
10
 * @copyright Copyright (c) 2014 Fangface <[email protected]>
11
 * @license https://github.com/fangface/yii2-concord/blob/master/LICENSE.md MIT License
12
 *
13
 */
14
15
namespace fangface\widgets;
16
17
use backend\assets\BootstrapTimePickerAsset;
18
use fangface\widgets\InputWidget;
19
use fangface\helpers\Html;
20
21
22
/**
23
 * Time Picker Widget
24
 */
25
class TimePicker extends InputWidget
26
{
27
28
    /**
29
     * @var string the name of the jQuery plugin
30
     */
31
    public $pluginName = 'timepicker';
32
    /**
33
     * @var array default widget plugin options that user pluginOptions will be merged into
34
     */
35
    public $defaultPluginOptions = ['autoclose' => true, 'showSeconds' => true, 'minuteStep' => 5, 'secondStep' => 5, 'showMeridian' => false];
36
    /**
37
     * @var array the HTML attributes for the input tag.
38
     * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
39
     */
40
    public $options = ['class' => 'form-control input-small'];
41
    /**
42
     * @var string element id to use when calling the datepicker
43
     */
44
    public $elementId = null;
45
46
47
    /**
48
     * Renders the color picker widget
49
     */
50
    protected function renderWidget()
51
    {
52
        $this->prepareInput();
53
        $this->registerAssets();
54
        $this->prepareTemplate();
55
        echo $this->renderTemplate();
56
    }
57
58
    /**
59
     * Prepare the input fields for the input
60
     *
61
     * @return void
62
     */
63
    protected function prepareInput()
64
    {
65
        if ($this->hasModel()) {
66
            $this->sections['input'] = Html::activeTextInput($this->model, $this->attribute, $this->options);
67
        } else {
68
            $this->sections['input'] = Html::textInput($this->name, $this->value, $this->options);
69
        }
70
    }
71
72
    /**
73
     * Registers the needed client assets
74
     *
75
     * @return void
76
     */
77
    public function registerAssets()
78
    {
79
        if ($this->disabled) {
80
            return;
81
        }
82
        $view = $this->getView();
83
        BootstrapTimePickerAsset::register($view);
84
        if ($this->elementId !== null) {
85
            $element = "jQuery('#" . $this->elementId . "')";
86
        } else {
87
            $element = "jQuery('#" . $this->options['id'] . "')";
88
        }
89
        $this->registerPlugin($this->pluginName, $element);
90
    }
91
92
93
}