forked from zhaber/ng-bootstrap-datetimepicker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
datetimepicker-tpls-0.8.js
123 lines (119 loc) · 4.22 KB
/
datetimepicker-tpls-0.8.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
angular.module('ui.bootstrap.datetimepicker', ["ui.bootstrap"])
.directive('datetimepicker', [
function() {
if (angular.version.full < '1.1.4') {
return {
restrict: 'EA',
template: "<div class=\"alert alert-danger\">Angular 1.1.4 or above is required for datetimepicker to work correctly</div>"
};
}
return {
restrict: 'EA',
require: 'ngModel',
scope: {
ngModel: '=',
dayFormat: "=",
monthFormat: "=",
yearFormat: "=",
dayHeaderFormat: "=",
dayTitleFormat: "=",
monthTitleFormat: "=",
showWeeks: "=",
startingDay: "=",
yearRange: "=",
dateFormat: "=",
minDate: "=",
maxDate: "=",
dateOptions: "=",
dateDisabled: "&",
hourStep: "=",
minuteStep: "=",
showMeridian: "=",
meredians: "=",
mousewheel: "=",
readonlyTime: "@"
},
template: function(elem, attrs) {
function dashCase(name, separator) {
return name.replace(/[A-Z]/g, function(letter, pos) {
return (pos ? '-' : '') + letter.toLowerCase();
});
}
function createAttr(innerAttr, dateTimeAttrOpt) {
var dateTimeAttr = angular.isDefined(dateTimeAttrOpt) ? dateTimeAttrOpt : innerAttr;
if (attrs[dateTimeAttr]) {
return dashCase(innerAttr) + "=\"" + dateTimeAttr + "\" ";
} else {
return '';
}
}
function createFuncAttr(innerAttr, funcArgs, dateTimeAttrOpt) {
var dateTimeAttr = angular.isDefined(dateTimeAttrOpt) ? dateTimeAttrOpt : innerAttr;
if (attrs[dateTimeAttr]) {
return dashCase(innerAttr) + "=\"" + dateTimeAttr + "({" + funcArgs + "})\" ";
} else {
return '';
}
}
function createEvalAttr(innerAttr, dateTimeAttrOpt) {
var dateTimeAttr = angular.isDefined(dateTimeAttrOpt) ? dateTimeAttrOpt : innerAttr;
if (attrs[dateTimeAttr]) {
return dashCase(innerAttr) + "=\"" + attrs[dateTimeAttr] + "\" ";
} else {
return dashCase(innerAttr);
}
}
function createAttrConcat(previousAttrs, attr) {
return previousAttrs + createAttr.apply(null, attr)
}
var tmpl = "<div class=\"datetimepicker-wrapper\">" +
"<input class=\"form-control\" type=\"text\" ng-model=\"ngModel\" " + [
["min", "minDate"],
["max", "maxDate"],
["dayFormat"],
["monthFormat"],
["yearFormat"],
["dayHeaderFormat"],
["dayTitleFormat"],
["monthTitleFormat"],
["showWeeks"],
["startingDay"],
["yearRange"],
["datepickerOptions", "dateOptions"]
].reduce(createAttrConcat, '') +
createFuncAttr("dateDisabled", "date: date, mode: mode") +
createEvalAttr("datepickerPopup", "dateFormat") +
"/>\n" +
"</div>\n" +
"<div class=\"datetimepicker-wrapper\" ng-model=\"time\" ng-change=\"time_change()\" style=\"display:inline-block\">\n" +
"<timepicker " + [
["hourStep"],
["minuteStep"],
["showMeridian"],
["meredians"],
["mousewheel"]
].reduce(createAttrConcat, '') +
createEvalAttr("readonlyInput", "readonlyTime") +
"></timepicker>\n" +
"</div>";
return tmpl;
},
controller: ['$scope',
function($scope) {
$scope.time_change = function() {
if (angular.isDefined($scope.ngModel) && angular.isDefined($scope.time)) {
$scope.ngModel.setHours($scope.time.getHours(), $scope.time.getMinutes());
}
}
}
],
link: function(scope) {
scope.$watch(function() {
return scope.ngModel;
}, function(ngModel) {
scope.time = ngModel;
});
}
}
}
]);