-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathscript.js
More file actions
139 lines (134 loc) · 5.65 KB
/
script.js
File metadata and controls
139 lines (134 loc) · 5.65 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
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// pick-a-date (attribute)
angular.module('ng').directive('pickADate', function () {
return {
restrict: "A",
scope: {
pickADate: '=',
minDate: '=',
maxDate: '=',
pickADateOptions: '='
},
link: function (scope, element, attrs) {
var options = $.extend(scope.pickADateOptions || {}, {
onSet: function (e) {
if (scope.$$phase || scope.$root.$$phase) // we are coming from $watch or link setup
return;
var select = element.pickadate('picker').get('select'); // selected date
scope.$apply(function () {
if (e.hasOwnProperty('clear')) {
scope.pickADate = null;
return;
}
if (!scope.pickADate)
scope.pickADate = new Date(0);
scope.pickADate.setYear(select.obj.getFullYear());
// Interesting: getYear returns only since 1900. Use getFullYear instead.
// It took me half a day to figure that our. Ironically setYear()
// (not setFullYear, duh) accepts the actual year A.D.
// So as I got the $#%^ 114 and set it, guess what, I was transported to ancient Rome 114 A.D.
// That's it I'm done being a programmer, I'd rather go serve Emperor Trajan as a sex slave.
scope.pickADate.setMonth(select.obj.getMonth());
scope.pickADate.setDate(select.obj.getDate());
});
},
onClose: function () {
element.blur();
}
});
element.pickadate(options);
function updateValue(newValue) {
if (newValue) {
scope.pickADate = (newValue instanceof Date) ? newValue : new Date(newValue);
// needs to be in milliseconds
element.pickadate('picker').set('select', scope.pickADate.getTime());
} else {
element.pickadate('picker').clear();
scope.pickADate = null;
}
}
updateValue(scope.pickADate);
element.pickadate('picker').set('min', scope.minDate ? scope.minDate : false);
element.pickadate('picker').set('max', scope.maxDate ? scope.maxDate : false);
scope.$watch('pickADate', function (newValue, oldValue) {
if (newValue == oldValue)
return;
updateValue(newValue);
}, true);
scope.$watch('minDate', function (newValue, oldValue) {
element.pickadate('picker').set('min', newValue ? newValue : false);
}, true);
scope.$watch('maxDate', function (newValue, oldValue) {
element.pickadate('picker').set('max', newValue ? newValue : false);
}, true);
}
};
});
// pick-a-time (attribute)
angular.module('ng').directive('pickATime', function () {
return {
restrict: "A",
scope: {
pickATime: '=',
pickATimeOptions: '='
},
link: function (scope, element, attrs) {
var options = $.extend(scope.pickATimeOptions || {}, {
onSet: function (e) {
if (scope.$$phase || scope.$root.$$phase) // we are coming from $watch or link setup
return;
var select = element.pickatime('picker').get('select'); // selected date
scope.$apply(function () {
if (e.hasOwnProperty('clear')) {
scope.pickATime = null;
return;
}
if (!scope.pickATime)
scope.pickATime = new Date(0);
// (attrs.setUtc)
// ? scope.pickATime.setUTCHours(select.hour)
// : scope.pickATime.setHours(select.hour);
scope.pickATime.setHours(select.hour);
scope.pickATime.setMinutes(select.mins);
scope.pickATime.setSeconds(0);
scope.pickATime.setMilliseconds(0);
});
},
onClose: function () {
element.blur();
}
});
element.pickatime(options);
function updateValue(newValue) {
if (newValue) {
scope.pickATime = (newValue instanceof Date) ? newValue : new Date(newValue);
// needs to be in minutes
var totalMins = scope.pickATime.getHours() * 60 + scope.pickATime.getMinutes();
element.pickatime('picker').set('select', totalMins);
} else {
element.pickatime('picker').clear();
scope.pickATime = null;
}
}
updateValue(scope.pickATime);
scope.$watch('pickATime', function (newValue, oldValue) {
if (newValue == oldValue)
return;
updateValue(newValue);
}, true);
}
};
});
//--------- other misc shit ---------------
function testController($scope) {
$scope.curDate = '';
$scope.newDate = function() {
return new Date();
};
}
function testController2($scope) {
$scope.startDate = '2014-02-24 12:00:00';
$scope.endDate = '2014-02-27 12:00:00';
}
function testController3($scope) {
$scope.curDate = '2014-02-24 12:00:00';
}