app directive pkmDatetimepicker timeout function timeout TODO fix in m

 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
app.directive('pkmDatetimepicker', ['$timeout', function ($timeout) {//TODO fix in modal
return {
restrict: 'E',
replace: true,
require: ['^ngModel'],
template: "<div class=\"input-group date datepicker-holder\">" +
"<span class=\"input-group-addon\">" +
"<i class=\"memobox-icon-calendar\"></i>" +
"</span>" +
"<input type=\"text\" class=\"form-control date-box\">" +
"</div>",
link: function ($scope, element, attr, ctrls) {
var ngModelCtrl = ctrls[0];
var attributes, input;
attributes = element.prop("attributes");
input = element.find("input");
var options = {
format: 'DD-MMM-YYYY',
icons: {
previous: 'fa fa-angle-left',
next: 'fa fa-angle-right',
today: 'fa fa-calendar',
clear: 'fa fa-trash',
time: 'fa fa-clock-o',
date: 'fa fa-calendar',
up: 'fa fa-arrow-up',
down: 'fa fa-arrow-down'
},
widgetPositioning: {
horizontal: 'auto',
vertical: 'bottom'
}
};
angular.forEach(attributes, function (e) {
if (e.name.indexOf('dp-') == 0 ) {
options[e.name] = e.value;
}
});
input.datetimepicker(options);
element.find('.input-group-addon').on('click', function (e) {
return element.find('input').focus();
});
ngModelCtrl.$render = function () {
if (!ngModelCtrl.$modelValue) return;
input.data("DateTimePicker").date(ngModelCtrl.$modelValue);
};
element.on("dp.change", function (e) {
$timeout( function (){
$scope.$apply(function (){
e.date._isDate = true;
ngModelCtrl.$setViewValue(e.date, e);
});
},0);
});
}
};
}]);