-
Notifications
You must be signed in to change notification settings - Fork 3
/
datetimepicker.js
71 lines (61 loc) · 1.86 KB
/
datetimepicker.js
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
63
64
65
66
67
68
69
70
71
/*
This datetimepicker is a simple angular wrapper of bootstrap datetimepicker(https://github.com/smalot/bootstrap-datetimepicker), which is the best I could found so far.
It depends on the following stuffs:
1. bootstrap.css 2 or 3
2. bootstrap-datetimepicker.css
3. jquery.js
4. bootstrap.js
5. bootstrap-datetimepicker.js
6. angular.js
Sample:
<datetimepicker ng-model='date' today-btn='true' minute-step='30' ></datetimepicker>
Ron Liu
5/2/2014
*/
angular.module('angularjs-bootstrap-datetimepicker', [])
.directive('datetimepicker', function () {
function _byDefault(value, defaultValue) {
return _isSet(value) ? value : defaultValue;
function _isSet(value) {
return !(value === null || value === undefined || value === NaN || value === '');
}
}
return {
restrict: 'E',
scope: {
ngModel: '=',
format: '@',
todayBtn: '@',
weekStart: '@',
minuteStep: '@'
},
template:
'<div class="input-append date form_datetime">' +
' <input size="16" type="text" value="" readonly>' +
' <span class="add-on"><i class="icon-remove"></i></span>' +
' <span class="add-on"><i class="icon-th"></i></span>' +
'</div>',
link: function (scope, element, attrs) {
var $element = $(element.children()[0]);
$element.datetimepicker({
format: _byDefault(scope.format, 'd/m/yyyy hh:ii'),
weekStart: _byDefault(scope.weekStart, '1'),
todayBtn: _byDefault(scope.todayBtn, 'true') === 'true',
minuteStep: parseInt(_byDefault(scope.minuteStep, '5')),
autoclose: 1,
todayHighlight: 1,
startView: 2,
forceParse: 0,
showMeridian: 1
})
.on('changeDate', function (ev) {
scope.$apply(function() {
scope.ngModel = ev.date;
});
});
scope.$watch('ngModel', function (newValue, oldValue) {
$element.datetimepicker('update', newValue);
});
}
};
});