-
Notifications
You must be signed in to change notification settings - Fork 2
/
Calendar.php
62 lines (49 loc) · 1.68 KB
/
Calendar.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
namespace yii\calendar;
use \yii\base\Widget;
use \yii\helpers\Html;
use \yii\helpers\Json;
use \yii\web\JsExpression;
class Calendar extends Widget
{
public $options = [
'class' => 'fc-calendar-container'
];
public $clientOptions = [];
public $inputOptions = [];
public $model;
public $attribute;
public function run()
{
CalendarAsset::register($this->getView());
if (!isset($this->options['id'])) {
if(!empty($this->model) && !empty($this->attribute)) {
$this->options['id'] = Html::getInputId($this->model, $this->attribute);
$this->createInput();
} else {
$this->options['id'] = 'calendario';
}
}
$this->createContainer();
$this->registerScript($this->clientOptions);
}
protected function createContainer()
{
echo Html::tag('div', '', $this->options);
}
protected function createInput()
{
if(!isset($this->clientOptions['onDayClick'])) {
$this->clientOptions['onDayClick'] = new JsExpression('function(cell, content, date) {
console.log(cell, content, date);
jQuery("#' . Html::getInputId($this->model, $this->attribute) . '").val();
}');
}
echo Html::activeHiddenInput($this->model, $this->attribute, $this->inputOptions);
}
protected function registerScript()
{
$configure = !empty($this->clientOptions) ? Json::encode($this->clientOptions) : '';
$this->getView()->registerJs("jQuery('#{$this->options['id']}').calendario($configure);");
}
}