This repository was archived by the owner on Dec 5, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 683
Expand file tree
/
Copy pathupdatableDateMulti.js
More file actions
60 lines (59 loc) · 2.49 KB
/
updatableDateMulti.js
File metadata and controls
60 lines (59 loc) · 2.49 KB
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
(function() {
'use strict';
angular.module('theHiveDirectives')
.directive('updatableDateMulti', function($interval, UtilsSrv) {
function updateTime(scope) {
if (scope.dateNow) {
var now = moment();
// now.setMinutes(now.getMinutes() - now.getTimezoneOffset());
scope.humanDate = now.format('DD-MM-YYYY HH:mm');
if (!angular.isDefined(scope.timeUpdater)) {
scope.timeUpdater = $interval(function() {
updateTime(scope);
}, 60000);
}
} else if (angular.isDefined(scope.timeUpdater)) {
$interval.cancel(scope.timeUpdater);
scope.timeUpdater = undefined;
}
}
return {
'restrict': 'E',
'link': function(scope, element, attrs, ctrl, transclude) {
UtilsSrv.updatableLink(scope, element, attrs, ctrl, transclude);
$(element).find('.input-datetime').datetimepicker({
format: 'dd-mm-yyyy hh:ii',
weekStart: 1,
startView: 1,
todayBtn: true,
autoclose: true
});
scope.dateNow = false;
scope.timeUpdater = undefined;
if (angular.isNumber(scope.value)) {
var m = moment(scope.value);
if (m.isValid()) {
scope.humanDate = m.format('DD-MM-YYYY HH:mm');
}
}
scope.$watch('dateNow', function() {
updateTime(scope);
});
scope.$watch('humanDate', function() {
if (angular.isString(scope.humanDate)) {
var m = moment(scope.humanDate, 'DD-MM-YYYY HH:mm');
if (m.isValid()) {
scope.value = m.valueOf();
}
}
});
},
'templateUrl': 'views/directives/updatable-date-multi.html',
'scope': {
'value': '=?',
'onUpdate': '&',
'active': '=?'
}
};
});
})();