nice-elements 1.10.4 → 1.10.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. package/.vscode/settings.json +17 -17
  2. package/CHANGELOG.md +444 -433
  3. package/LICENSE.md +21 -21
  4. package/README.md +95 -95
  5. package/bower.json +10 -10
  6. package/dist/nice.js +8074 -8086
  7. package/dist/nice.min.js +1 -1
  8. package/dist/style.css +20 -9
  9. package/dist/style.css.map +1 -1
  10. package/dist/style.min.css +7 -7
  11. package/eslint.config.mjs +28 -0
  12. package/package.json +45 -42
  13. package/src/components/nice-button/nice-button.html +4 -4
  14. package/src/components/nice-button/nice-button.js +40 -40
  15. package/src/components/nice-button/nice-button.scss +16 -16
  16. package/src/components/nice-button-toggle/nice-button-toggle.html +9 -9
  17. package/src/components/nice-button-toggle/nice-button-toggle.js +23 -23
  18. package/src/components/nice-button-toggle/nice-button-toggle.scss +2 -2
  19. package/src/components/nice-calendar/nice-calendar.html +91 -91
  20. package/src/components/nice-calendar/nice-calendar.js +336 -335
  21. package/src/components/nice-calendar/nice-calendar.scss +285 -285
  22. package/src/components/nice-checkbox/nice-checkbox.html +5 -5
  23. package/src/components/nice-checkbox/nice-checkbox.js +34 -34
  24. package/src/components/nice-checkbox/nice-checkbox.scss +91 -91
  25. package/src/components/nice-choice/nice-choice.html +18 -18
  26. package/src/components/nice-choice/nice-choice.js +211 -211
  27. package/src/components/nice-choice/nice-choice.scss +110 -110
  28. package/src/components/nice-click-outside/nice-click-outside.js +105 -105
  29. package/src/components/nice-comment/nice-comment.html +10 -10
  30. package/src/components/nice-comment/nice-comment.js +71 -70
  31. package/src/components/nice-comment/nice-comment.scss +39 -39
  32. package/src/components/nice-date/nice-date.html +75 -74
  33. package/src/components/nice-date/nice-date.js +329 -328
  34. package/src/components/nice-date/nice-date.scss +302 -302
  35. package/src/components/nice-date-input/nice-date-input.html +41 -41
  36. package/src/components/nice-date-input/nice-date-input.js +111 -110
  37. package/src/components/nice-date-input/nice-date-input.scss +45 -45
  38. package/src/components/nice-date-range/nice-date-range.html +15 -15
  39. package/src/components/nice-date-range/nice-date-range.js +78 -77
  40. package/src/components/nice-date-range/nice-date-range.scss +390 -390
  41. package/src/components/nice-datetime-picker/nice-datetime-picker.html +29 -29
  42. package/src/components/nice-datetime-picker/nice-datetime-picker.js +89 -88
  43. package/src/components/nice-datetime-picker/nice-datetime-picker.scss +428 -428
  44. package/src/components/nice-datetimerange-picker/nice-datetimerange-picker.html +55 -55
  45. package/src/components/nice-datetimerange-picker/nice-datetimerange-picker.js +248 -247
  46. package/src/components/nice-datetimerange-picker/nice-datetimerange-picker.scss +73 -73
  47. package/src/components/nice-datetimerange-picker-2/nice-datetimerange-picker-2.html +44 -44
  48. package/src/components/nice-datetimerange-picker-2/nice-datetimerange-picker-2.js +174 -173
  49. package/src/components/nice-datetimerange-picker-2/nice-datetimerange-picker-2.scss +127 -127
  50. package/src/components/nice-dropdown/nice-dropdown.html +61 -60
  51. package/src/components/nice-dropdown/nice-dropdown.js +496 -490
  52. package/src/components/nice-dropdown/nice-dropdown.scss +261 -249
  53. package/src/components/nice-dropdown-date/nice-dropdown-date.html +28 -28
  54. package/src/components/nice-dropdown-date/nice-dropdown-date.js +128 -127
  55. package/src/components/nice-dropdown-date/nice-dropdown-date.scss +82 -82
  56. package/src/components/nice-dropdown-old/nice-dropdown-old.html +44 -44
  57. package/src/components/nice-dropdown-old/nice-dropdown-old.js +331 -331
  58. package/src/components/nice-dropdown-old/nice-dropdown-old.scss +129 -129
  59. package/src/components/nice-dtp/nice-dtp.html +91 -91
  60. package/src/components/nice-dtp/nice-dtp.js +835 -834
  61. package/src/components/nice-help/nice-help.html +6 -6
  62. package/src/components/nice-help/nice-help.js +55 -55
  63. package/src/components/nice-help/nice-help.scss +78 -78
  64. package/src/components/nice-input/nice-input.html +48 -48
  65. package/src/components/nice-input/nice-input.js +245 -245
  66. package/src/components/nice-input/nice-input.scss +130 -130
  67. package/src/components/nice-label/nice-label.html +10 -10
  68. package/src/components/nice-label/nice-label.js +32 -31
  69. package/src/components/nice-loader/nice-loader.html +6 -6
  70. package/src/components/nice-loader/nice-loader.js +28 -28
  71. package/src/components/nice-loader/nice-loader.scss +47 -47
  72. package/src/components/nice-no-data/nice-no-data.html +3 -3
  73. package/src/components/nice-no-data/nice-no-data.js +27 -27
  74. package/src/components/nice-no-data/nice-no-data.scss +30 -30
  75. package/src/components/nice-notification/nice-notification.html +3 -3
  76. package/src/components/nice-notification/nice-notification.js +124 -124
  77. package/src/components/nice-notification/nice-notification.scss +66 -66
  78. package/src/components/nice-number/nice-number.html +40 -40
  79. package/src/components/nice-number/nice-number.js +170 -170
  80. package/src/components/nice-number/nice-number.scss +18 -18
  81. package/src/components/nice-percent/nice-percent.html +24 -24
  82. package/src/components/nice-percent/nice-percent.js +95 -95
  83. package/src/components/nice-pill/nice-pill.html +3 -3
  84. package/src/components/nice-pill/nice-pill.js +29 -29
  85. package/src/components/nice-pill/nice-pill.scss +25 -25
  86. package/src/components/nice-popup/nice-popup.html +6 -6
  87. package/src/components/nice-popup/nice-popup.js +122 -122
  88. package/src/components/nice-popup/nice-popup.scss +43 -43
  89. package/src/components/nice-progress-bar/nice-progress-bar.html +15 -15
  90. package/src/components/nice-progress-bar/nice-progress-bar.js +55 -55
  91. package/src/components/nice-progress-bar/nice-progress-bar.scss +47 -47
  92. package/src/components/nice-quantity/nice-quantity.html +22 -22
  93. package/src/components/nice-quantity/nice-quantity.js +57 -56
  94. package/src/components/nice-quantity/nice-quantity.scss +51 -51
  95. package/src/components/nice-search/nice-search.html +44 -44
  96. package/src/components/nice-search/nice-search.js +240 -240
  97. package/src/components/nice-search/nice-search.scss +90 -90
  98. package/src/components/nice-search2/nice-search2.html +32 -32
  99. package/src/components/nice-search2/nice-search2.js +265 -265
  100. package/src/components/nice-search2/nice-search2.scss +80 -80
  101. package/src/components/nice-slot/nice-slot.html +10 -10
  102. package/src/components/nice-slot/nice-slot.js +31 -30
  103. package/src/components/nice-steps/nice-steps.scss +81 -81
  104. package/src/components/nice-svgs/nice-svgs.html +1262 -1262
  105. package/src/components/nice-svgs/nice-svgs.js +16 -16
  106. package/src/components/nice-table/nice-table.html +38 -38
  107. package/src/components/nice-table/nice-table.js +60 -60
  108. package/src/components/nice-table/nice-table.scss +111 -111
  109. package/src/components/nice-time-picker/nice-time-picker.html +43 -43
  110. package/src/components/nice-time-picker/nice-time-picker.js +85 -84
  111. package/src/components/nice-time-picker/nice-time-picker.scss +37 -37
  112. package/src/components/nice-title/nice-title.html +3 -3
  113. package/src/components/nice-title/nice-title.js +21 -21
  114. package/src/components/nice-toast/nice-toast.html +2 -2
  115. package/src/components/nice-toast/nice-toast.js +56 -56
  116. package/src/components/nice-toast/nice-toast.scss +74 -74
  117. package/src/components/nice-toggle/nice-toggle.html +12 -12
  118. package/src/components/nice-toggle/nice-toggle.js +54 -53
  119. package/src/components/nice-toggle/nice-toggle.scss +131 -131
  120. package/src/components/nice-tooltip/_nice-tooltip.scss +71 -71
  121. package/src/components/nice-tooltip/nice-tooltip.js +23 -23
  122. package/src/components/nice-upload/nice-upload.html +22 -22
  123. package/src/components/nice-upload/nice-upload.js +159 -158
  124. package/src/components/nice-upload/nice-upload.scss +85 -85
  125. package/src/components/nice-wrapper/_nice-wrapper.scss +87 -87
  126. package/src/components/nice-wrapper/nice-wrapper.html +12 -12
  127. package/src/components/nice-wrapper/nice-wrapper.js +44 -44
  128. package/src/components/nice-yesno/nice-yesno.html +14 -14
  129. package/src/components/nice-yesno/nice-yesno.js +111 -110
  130. package/src/components/nice-yesno/nice-yesno.scss +95 -95
  131. package/src/filters/nice-date.js +17 -17
  132. package/src/filters/nice-highlight.js +16 -16
  133. package/src/modals/nice-multilangual-modal/nice-multilangual-modal.html +30 -30
  134. package/src/modals/nice-multilangual-modal/nice-multilangual-modal.js +67 -67
  135. package/src/modals/nice-multilangual-modal/nice-multilangual-modal.scss +19 -19
  136. package/src/nice.js +2 -2
  137. package/src/services/nice-service.js +22 -19
  138. package/src/styles/_bootstrap-variables.scss +178 -178
  139. package/src/styles/_nice-buttons.scss +612 -612
  140. package/src/styles/_nice-common.scss +471 -471
  141. package/src/styles/_nice-ngdialog.scss +85 -85
  142. package/src/styles/_nice-spacing.scss +283 -283
  143. package/src/styles/_nice.scss +67 -67
  144. package/src/styles/_variables.scss +198 -198
@@ -1,835 +1,836 @@
1
- 'use strict';
2
-
3
- /**
4
- * @ngdoc directive
5
- * @name niceElements.directive:niceDtp
6
- * @description
7
- * # niceDtp
8
- */
9
- angular.module('niceElements')
10
-
11
- .directive('niceDtp', function ($window, $parse, $document) {
12
-
13
- return {
14
- scope: {
15
- onChange: '&?', // function called on date changed
16
- model: '=', // binding model
17
- format: '@', // default: 'D.M.YYYY • H:mm', format for input label string
18
- modelFormat: '@', // default: ''
19
- //currentDate: '@',
20
- date: '@', // default: true, is date picker enabled?
21
- time: '@', // default: false, is time picker enabled?
22
- width: '@', // default: 300, width of entire dtp-picker in px
23
- enableOkButtons: '@', // default: false, is ok/cancel buttons enabled?
24
- lang: '@', // default: 'en', which locale to use - you must load angular locales first
25
- minDate: '@', // default: undefined
26
- maxDate: '@', // default: undefined
27
- weekStart: '@', // default: 1, which day does the week start? (0 - sunday, 1 - monday, ...)
28
- okText: '@',
29
- cancelText: '@',
30
- shortTime: '@', // default: false,
31
- niceTitle: '@',
32
- title: '@', // default: ''
33
- noMargin: '@', // default: false, if noMargin==true then entire directive can be injected inside other divs
34
- fieldWidth: '@', // default: 'col-sm-8', bootstrap classes that defines width of field
35
- labelWidth: '@', // default: 'col-sm-4', bootstrap classes that defines width of label
36
- closed: '='
37
- },
38
- templateUrl: 'src/components/nice-dtp/nice-dtp.html',
39
- controller: function ($scope, $element, $attrs, gettextCatalog) {
40
- console.warn("[NICE ELEMENTS] nice-dtp component is deprecated!");
41
-
42
- // default parameters
43
- var params = {
44
- title: '',
45
- noMargin: false,
46
- fieldWidth: 'col-sm-8',
47
- labelWidth: 'col-sm-4',
48
- format: 'D.M.YYYY • H:mm',
49
- modelFormat: 'YYYY-MM-DDTHH:mm:ss.SSS',
50
- minDate: null,
51
- maxDate: null,
52
- lang: 'en',
53
- weekStart: 1,
54
- shortTime: false,
55
- cancelText: gettextCatalog.getString('Cancel', null, 'Nice'),
56
- okText: gettextCatalog.getString('OK', null, 'Nice'),
57
- date: true,
58
- time: false,
59
- width: 300,
60
- enableOkButtons: false
61
- };
62
-
63
- var prepareAttrs = function () {
64
- // prepare attributes
65
- params.date = $attrs.date === 'true' || $attrs.date === true;
66
- params.time = $attrs.time === 'true' || $attrs.time === true;
67
- params.inline = $attrs.inline === 'true' || $attrs.inline === true;
68
- if ($attrs.format && $attrs.format != "")
69
- params.format = $attrs.format;
70
- if ($scope.enableOkButtons && $attrs.enableOkButtons != "")
71
- params.enableOkButtons = $attrs.enableOkButtons === 'true';
72
- if ($attrs.lang && $attrs.lang != "")
73
- params.lang = $attrs.lang;
74
- if ($attrs.minDate && $attrs.minDate != "")
75
- params.minDate = $attrs.minDate;
76
- if ($attrs.maxDate && $attrs.maxDate != "")
77
- params.maxDate = $attrs.maxDate;
78
- if ($scope.weekStart && $attrs.weekStart != "")
79
- params.weekStart = parseInt($attrs.weekStart);
80
- if ($attrs.okText && $attrs.okText != "")
81
- params.okText = $attrs.okText;
82
- if ($attrs.cancelText && $attrs.cancelText != "")
83
- params.cancelText = $attrs.cancelText;
84
- if ($attrs.noMargin && $attrs.noMargin != "")
85
- params.noMargin = $attrs.noMargin === 'true';
86
- if ($attrs.modelFormat && $attrs.modelFormat != "")
87
- params.modelFormat = $attrs.modelFormat;
88
-
89
- if ($attrs.width) {
90
- params.width = parseInt($attrs.width);
91
- }
92
- //$scope.dtp_content_style = {width: params.width + 'px'};
93
-
94
- // copy attributes back to scope - for template usage
95
- $scope = angular.extend($scope, params);
96
-
97
- };
98
-
99
- $scope.date = $attrs.date === 'true' || $attrs.date === true;
100
- $scope.time = $attrs.time === 'true' || $attrs.time === true;
101
-
102
- // functions are defined in a variable 'var that', not in $scope
103
- var that = {
104
- init: function () {
105
- //console.log('init', $scope);
106
-
107
- $scope.showDtp = false;
108
- that.initDays();
109
- that.initDates();
110
- },
111
- initDays: function () {
112
- //console.log('initDays');
113
- $scope.days = [];
114
- for (var i = params.weekStart; $scope.days.length < 7; i++) {
115
- if (i > 6) {
116
- i = 0;
117
- }
118
- $scope.days.push(i.toString());
119
- }
120
- },
121
- fixMinMaxDate: function () {
122
- if ($scope.minDate === "")
123
- $scope.minDate = null;
124
- if ($scope.maxDate === "")
125
- $scope.maxDate = null;
126
- },
127
- initDates: function () {
128
- that.fixMinMaxDate();
129
- if (typeof ($scope.model) === 'undefined' || $scope.model === null) {
130
- $scope.currentDate = moment();
131
- } else {
132
- //// all other combinations
133
- //if (typeof($scope.model) === 'string') {
134
- // $scope.currentDate = moment($scope.model, params.modelFormat).locale(params.lang);
135
- //}
136
- //else {
137
- $scope.currentDate = moment($scope.model).locale(params.lang);
138
- //}
139
- }
140
-
141
- that.setDateModel();
142
- that.setElementValue();
143
-
144
- // Parse minDate
145
- if (typeof ($scope.minDate) !== 'undefined' && $scope.minDate !== null) {
146
- if (typeof ($scope.minDate) === 'string') {
147
- $scope.minDate = moment($scope.minDate).locale(params.lang);
148
- }
149
- }
150
-
151
- // Parse maxDate
152
- if (typeof ($scope.maxDate) !== 'undefined' && $scope.maxDate !== null) {
153
- if (typeof ($scope.maxDate) === 'string') {
154
- $scope.maxDate = moment($scope.maxDate).locale(params.lang);
155
- }
156
- }
157
-
158
- // Fix currentDate if violates minDate and maxDate constraints
159
- if (params.date === true) {
160
- if (!that.isAfterMinDate($scope.currentDate)) {
161
- $scope.currentDate = moment($scope.minDate);
162
- }
163
- if (!that.isBeforeMaxDate($scope.currentDate)) {
164
- $scope.currentDate = moment($scope.maxDate);
165
- }
166
- }
167
- },
168
- initDate: function () {
169
- that.fixMinMaxDate();
170
-
171
- $scope.currentView = 0;
172
-
173
- $scope.showCalendar = true;
174
- $scope.showTime = false;
175
-
176
- var _date = ((typeof ($scope.currentDate) !== 'undefined' && $scope.currentDate !== null) ? $scope.currentDate : null);
177
- $scope.calendar = that.generateCalendar($scope.currentDate);
178
-
179
- if (typeof ($scope.calendar.week) !== 'undefined' && typeof ($scope.calendar.days) !== 'undefined') {
180
- that.constructHTMLCalendar(_date, $scope.calendar);
181
- that.toggleButtons(_date);
182
- }
183
-
184
- that._centerBox();
185
- that.showDate(_date);
186
- },
187
- initHours: function () {
188
- that.fixMinMaxDate();
189
- $scope.currentView = 1;
190
- $scope.hours = [];
191
- $scope.minutes = [];
192
- $scope.showTime = true;
193
- $scope.showCalendar = false;
194
-
195
- that.showTime($scope.currentDate);
196
-
197
- var pL = 10;
198
- var pT = 10;
199
- var mL = 20;
200
- var mT = 10;
201
- var r = 100;
202
-
203
- var j = r / 1.55;
204
- var j_pm = r / 1.15;
205
-
206
- var _hours = [];
207
-
208
- // AM hours
209
- for (var h = 0; h < 12; ++h) {
210
- var cH = (($scope.currentDate.format('HH') == 24) ? 0 : $scope.currentDate.format('HH'));
211
- var x = j * Math.sin(Math.PI * 2 * (h / 12));
212
- var y = j * Math.cos(Math.PI * 2 * (h / 12));
213
-
214
- var _hour = {
215
- style: {
216
- x: x,
217
- y: y,
218
- marginLeft: (r + x + parseInt(pL) / 2) - (parseInt(pL) + parseInt(mL)) + 'px',
219
- marginTop: (r - y - parseInt(mT) / 2) - (parseInt(pT) + parseInt(mT)) + 'px'
220
- },
221
- h: h == 0 ? 12 : h,
222
- selected: h == parseInt(cH)
223
- };
224
-
225
- _hours.push(_hour);
226
- }
227
-
228
- // PM hours
229
- for (var h = 0; h < 12; ++h) {
230
- var cH = (($scope.currentDate.format('HH') == 24) ? 0 : $scope.currentDate.format('HH'));
231
- var x = j_pm * Math.sin(Math.PI * 2 * (h / 12));
232
- var y = j_pm * Math.cos(Math.PI * 2 * (h / 12));
233
-
234
- var _hour = {
235
- style: {
236
- x: x,
237
- y: y,
238
- marginLeft: (r + x + parseInt(pL) / 2) - (parseInt(pL) + parseInt(mL)) + 'px',
239
- marginTop: (r - y - parseInt(mT) / 2) - (parseInt(pT) + parseInt(mT)) + 'px'
240
- },
241
- h: h == 0 ? 0 : h + 12,
242
- selected: h + 12 == parseInt(cH)
243
- };
244
-
245
- _hours.push(_hour);
246
- }
247
-
248
- $scope.hours = _hours;
249
- that.toggleTime(true);
250
- that.initHands(true);
251
- },
252
- initMinutes: function () {
253
- that.fixMinMaxDate();
254
- $scope.currentView = 2;
255
- $scope.hours = [];
256
- $scope.minutes = [];
257
- $scope.showCalendar = false;
258
- $scope.showTime = true;
259
-
260
- that.showTime($scope.currentDate);
261
-
262
- var pL = 10;
263
- var pT = 10;
264
- var mL = 20;
265
- var mT = 10;
266
- var w = 200;
267
- var r = w / 2;
268
- var j = r / 1.2;
269
- var _minutes = [];
270
-
271
- for (var m = 0; m < 60; m += 5) {
272
- var x = j * Math.sin(Math.PI * 2 * (m / 60));
273
- var y = j * Math.cos(Math.PI * 2 * (m / 60));
274
-
275
- var _minute = {
276
- style: {
277
- x: x,
278
- y: y,
279
- marginLeft: (r + x + parseInt(pL) / 2) - (parseInt(pL) + parseInt(mL)) + 'px',
280
- marginTop: (r - y - parseInt(mT) / 2) - (parseInt(pT) + parseInt(mT)) + 'px'
281
- },
282
- m: ((m.toString().length == 2) ? m : '0' + m),
283
- selected: m == 5 * Math.round($scope.currentDate.minute() / 5)
284
- };
285
- _minutes.push(_minute);
286
- }
287
-
288
- $scope.minutes = _minutes;
289
- that.toggleTime(false);
290
- that.initHands(false);
291
- that._centerBox();
292
- },
293
- initHands: function (t) {
294
- var pL = 10;
295
- var mL = 20;
296
- var w = 7.5;
297
- var h = 7.5;
298
- var r = 100;
299
- var _hL = r / 1.7;
300
- var _mL = r / 1.5;
301
-
302
- var dtpHourHand = $element[0].getElementsByClassName('dtp-hour-hand')[0];
303
- dtpHourHand.style.left = r + (parseInt(mL) * 1.5) + 'px';
304
- dtpHourHand.style.height = _hL + 'px';
305
- dtpHourHand.style.marginTop = (r - _hL - parseInt(pL)) + 'px';
306
- if (t) dtpHourHand.classList.add("on");
307
-
308
- var dtpMinuteHand = $element[0].getElementsByClassName('dtp-minute-hand')[0];
309
- dtpMinuteHand.style.left = r + (parseInt(mL) * 1.5) + 'px';
310
- dtpMinuteHand.style.height = _mL + 'px';
311
- dtpMinuteHand.style.marginTop = (r - _mL - parseInt(pL)) + 'px';
312
- if (t) dtpMinuteHand.classList.add("on");
313
-
314
- var dtpClockCenter = $element[0].getElementsByClassName('dtp-clock-center')[0];
315
- dtpClockCenter.style.left = r + parseInt(pL) + parseInt(mL) - w + 'px';
316
- dtpClockCenter.style.marginTop = (r - (parseInt(mL) / 2)) - h + 'px';
317
-
318
- that.animateHands();
319
-
320
- that._centerBox();
321
- },
322
- animateHands: function () {
323
- var h = $scope.currentDate.hour();
324
- var m = $scope.currentDate.minute();
325
-
326
- var dtpHourHand = $element[0].getElementsByClassName('dtp-hour-hand')[0];
327
- var dtpMinuteHand = $element[0].getElementsByClassName('dtp-minute-hand')[0];
328
- that.rotateElement(dtpHourHand, (360 / 12) * h);
329
- that.rotateElement(dtpMinuteHand, ((360 / 60) * (5 * Math.round(m / 5))));
330
- },
331
- isAfterMinDate: function (date, checkHour, checkMinute) {
332
- var _return = true;
333
-
334
- if (typeof ($scope.minDate) !== 'undefined' && $scope.minDate !== null) {
335
- var _minDate = moment($scope.minDate);
336
- var _date = moment(date);
337
-
338
- if (!checkHour && !checkMinute) {
339
- _minDate.hour(0);
340
- _minDate.minute(0);
341
-
342
- _date.hour(0);
343
- _date.minute(0);
344
- }
345
-
346
- _minDate.second(0);
347
- _date.second(0);
348
- _minDate.millisecond(0);
349
- _date.millisecond(0);
350
-
351
- if (!checkMinute) {
352
- _date.minute(0);
353
- _minDate.minute(0);
354
-
355
- _return = (parseInt(_date.format("X")) >= parseInt(_minDate.format("X")));
356
- } else {
357
- _return = (parseInt(_date.format("X")) >= parseInt(_minDate.format("X")));
358
- }
359
- }
360
-
361
- return _return;
362
- },
363
- isBeforeMaxDate: function (date, checkTime, checkMinute) {
364
- var _return = true;
365
-
366
- if (typeof ($scope.maxDate) !== 'undefined' && $scope.maxDate !== null) {
367
- var _maxDate = moment($scope.maxDate);
368
- var _date = moment(date);
369
-
370
- if (!checkTime && !checkMinute) {
371
- _maxDate.hour(0);
372
- _maxDate.minute(0);
373
-
374
- _date.hour(0);
375
- _date.minute(0);
376
- }
377
-
378
- _maxDate.second(0);
379
- _date.second(0);
380
- _maxDate.millisecond(0);
381
- _date.millisecond(0);
382
-
383
- if (!checkMinute) {
384
- _date.minute(0);
385
- _maxDate.minute(0);
386
-
387
- _return = (parseInt(_date.format("X")) <= parseInt(_maxDate.format("X")));
388
- } else {
389
- _return = (parseInt(_date.format("X")) <= parseInt(_maxDate.format("X")));
390
- }
391
- }
392
-
393
- return _return;
394
- },
395
- rotateElement: function (el, deg) {
396
- el.style.transform = 'rotate(' + deg + 'deg)';
397
- },
398
- showDate: function (date) {
399
- //console.log('showDate');
400
- $scope.showTimeHeader = true;
401
- if (date) {
402
- $scope.showDateHeader = true;
403
- $scope.actualDay = date.locale(params.lang).format('dddd');
404
- $scope.actualMonth = date.locale(params.lang).format('MMM').toUpperCase();
405
- $scope.actualNum = date.locale(params.lang).format('DD');
406
- $scope.actualYear = date.locale(params.lang).format('YYYY');
407
- }
408
- },
409
- showTime: function (date) {
410
- //console.log('showTime', date);
411
- if (date) {
412
- var _minutes = (5 * Math.round(date.minute() / 5));
413
- var _time = {
414
- hours: date.format('HH'),
415
- minutes: ((_minutes.toString().length == 2) ? _minutes : '0' + _minutes)
416
- };
417
-
418
- if (params.date) {
419
- $scope.showTimeHeader = true;
420
- $scope.actualTime = _time;
421
- } else {
422
- if (params.shortTime)
423
- $scope.actualDay = date.format('A');
424
- else
425
- $scope.actualDay = ' ';
426
-
427
- $scope.showTimeHeader = false;
428
- $scope.actualTime = _time;
429
- }
430
- }
431
- },
432
- selectDate: function (date) {
433
- //console.log('selectDate');
434
- if (date) {
435
- $scope.currentDate = date;
436
- that.showDate($scope.currentDate);
437
- $scope.$emit('dateSelected', {
438
- date: date
439
- });
440
- }
441
- },
442
- generateCalendar: function (date) {
443
- //console.log('generateCalendar');
444
- var _calendar = {};
445
-
446
- if (date !== null) {
447
- var startOfMonth = moment(date).locale(params.lang).startOf('month');
448
- var endOfMonth = moment(date).locale(params.lang).endOf('month');
449
-
450
- var iNumDay = startOfMonth.format('d');
451
-
452
- _calendar.week = $scope.days;
453
- _calendar.days = [];
454
-
455
- for (var i = startOfMonth.date(); i <= endOfMonth.date(); i++) {
456
- if (i === startOfMonth.date()) {
457
- var iWeek = _calendar.week.indexOf(iNumDay.toString());
458
- if (iWeek > 0) {
459
- for (var x = 0; x < iWeek; x++) {
460
- _calendar.days.push(0);
461
- }
462
- }
463
- }
464
- _calendar.days.push(moment(startOfMonth).locale(params.lang).date(i));
465
- }
466
- }
467
-
468
- return _calendar;
469
- },
470
- constructHTMLCalendar: function (date, calendar) {
471
- $scope.monthAndYear = date.locale(params.lang).format('MMMM YYYY');
472
-
473
- var _weekDays = [];
474
- for (var i = 0; i < calendar.week.length; i++) {
475
- _weekDays.push(moment(parseInt(calendar.week[i]), "d").locale(params.lang).format("dd").substring(0, 1));
476
- }
477
- $scope.weekDays = _weekDays;
478
-
479
- var _weeks = [];
480
-
481
- var _week = [];
482
- for (var i = 0; i < calendar.days.length; i++) {
483
- if (i % 7 == 0) {
484
- if (i != 0) {
485
- _weeks.push(_week);
486
- }
487
- var _week = [];
488
- }
489
-
490
- var _day = {
491
- label: null,
492
- selected: false,
493
- disabled: true,
494
- data: {}
495
- };
496
-
497
- if (calendar.days[i] != 0) {
498
- _day.disabled = false;
499
- _day.label = moment(calendar.days[i]).locale(params.lang).format("DD");
500
- _day.data = calendar.days[i];
501
- if (that.isBeforeMaxDate(moment(calendar.days[i]), false, false) === false || that.isAfterMinDate(moment(calendar.days[i]), false, false) === false) {
502
- _day.disabled = true;
503
- } else {
504
- if (moment(calendar.days[i]).locale(params.lang).format("DD") === moment($scope.currentDate).locale(params.lang).format("DD")) {
505
- _day.selected = true;
506
-
507
- }
508
- }
509
- }
510
- _week.push(_day);
511
- }
512
-
513
- if (_week.length > 0) {
514
- _weeks.push(_week);
515
- }
516
-
517
- $scope.weeks = _weeks;
518
- //console.log('$scope.weeks', $scope.weeks);
519
- //console.log('$scope.weekDays', $scope.weekDays);
520
- },
521
- setName: function () {
522
- var text = "";
523
- var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
524
-
525
- for (var i = 0; i < 5; i++) {
526
- text += possible.charAt(Math.floor(Math.random() * possible.length));
527
- }
528
-
529
- return text;
530
- },
531
- isPM: function () {
532
- return $scope.isPM;
533
- },
534
- setElementValue: function (date) {
535
-
536
- //if (typeof(date) !== 'undefined'){
537
- // $scope.currentDate = moment(date).locale(params.lang);
538
- //}
539
-
540
- $scope.value = moment($scope.currentDate).locale(params.lang).format(params.format);
541
- },
542
- setDateModel: function () {
543
- $scope.model = angular.copy($scope.currentDate);
544
- if ($scope.onChange) $scope.onChange({ model: $scope.model });
545
- //$scope.model = $scope.currentDate.format(params.modelFormat);
546
- //$scope.formDatetimePicker.$setDirty();
547
- },
548
- toggleButtons: function (date) {
549
- if (date && date.isValid()) {
550
- var startOfMonth = moment(date).locale(params.lang).startOf('month');
551
- var endOfMonth = moment(date).locale(params.lang).endOf('month');
552
-
553
- $scope.btnMonthBeforeEnabled = that.isAfterMinDate(startOfMonth, false, false);
554
- $scope.btnMonthAfterEnabled = that.isBeforeMaxDate(endOfMonth, false, false);
555
-
556
- var startOfYear = moment(date).locale(params.lang).startOf('year');
557
- var endOfYear = moment(date).locale(params.lang).endOf('year');
558
-
559
- $scope.btnYearBeforeEnabled = that.isAfterMinDate(startOfYear, false, false);
560
- $scope.btnYearAfterEnabled = that.isBeforeMaxDate(endOfYear, false, false);
561
- }
562
- },
563
- toggleTime: function (isHours) {
564
- if (isHours) {
565
- angular.forEach($scope.hours, function (hour, hourKey) {
566
- var _date = moment($scope.currentDate);
567
- _date.hour(that.convertHours(hour.h)).minute(0).second(0);
568
-
569
- if (that.isAfterMinDate(_date, true, false) === false || that.isBeforeMaxDate(_date, true, false) === false) {
570
- hour.disabled = true;
571
- } else {
572
- hour.disabled = false;
573
- }
574
- });
575
- } else {
576
- angular.forEach($scope.minutes, function (minute, minuteKey) {
577
- var _minute = minute.m;
578
- var _date = moment($scope.currentDate);
579
- _date.minute(_minute).second(0);
580
-
581
- if (that.isAfterMinDate(_date, true, true) === false || that.isBeforeMaxDate(_date, true, true) === false) {
582
- minute.disabled = true;
583
- } else {
584
- minute.disabled = false;
585
- }
586
- });
587
- }
588
- },
589
- _onClick: function () {
590
- $scope.currentView = 0;
591
-
592
- that.initDates();
593
-
594
- that.show();
595
-
596
- if (params.date) {
597
- $scope.showDate = true;
598
- that.initDate();
599
- } else {
600
- if (params.time) {
601
- $scope.showTime = true;
602
- that.initHours();
603
- }
604
- }
605
- },
606
- _onBackgroundClick: function (e) {
607
- e.stopPropagation();
608
- that.hide();
609
- },
610
- _onElementClick: function (e) {
611
- e.stopPropagation();
612
- },
613
- _onCloseClick: function () {
614
- that.hide();
615
- if ($scope.closed) $scope.closed(true);
616
- },
617
- _onOKClick: function () {
618
- switch ($scope.currentView) {
619
- case 0:
620
- if (params.time === true) {
621
- that.initHours();
622
- } else {
623
- that.setElementValue();
624
- that.setDateModel();
625
- if (!$scope.inline)
626
- that.hide();
627
- }
628
- break;
629
- case 1:
630
- that.initMinutes();
631
- break;
632
- case 2:
633
- that.setElementValue();
634
- that.setDateModel();
635
- if ($scope.inline) {
636
- that._onClick();
637
- } else {
638
- that.hide();
639
- }
640
- break;
641
- }
642
- },
643
- _onCancelClick: function () {
644
- if (params.time) {
645
- switch ($scope.currentView) {
646
- case 0:
647
- that.hide();
648
- break;
649
- case 1:
650
- if (params.date) {
651
- that.initDate();
652
- } else {
653
- that.hide();
654
- }
655
- break;
656
- case 2:
657
- that.initHours();
658
- break;
659
- }
660
- } else {
661
- that.hide();
662
- }
663
- },
664
- _onMonthBeforeClick: function () {
665
- if ($scope.btnMonthBeforeEnabled) {
666
- $scope.currentDate.subtract(1, 'months');
667
- that.initDate($scope.currentDate);
668
- }
669
- },
670
- _onMonthAfterClick: function () {
671
- if ($scope.btnMonthAfterEnabled) {
672
- $scope.currentDate.add(1, 'months');
673
- that.initDate($scope.currentDate);
674
- }
675
- },
676
- _onYearBeforeClick: function () {
677
- if ($scope.btnYearBeforeEnabled) {
678
- $scope.currentDate.subtract(1, 'years');
679
- that.initDate($scope.currentDate);
680
- }
681
- },
682
- _onYearAfterClick: function () {
683
- if ($scope.btnYearAfterEnabled) {
684
- $scope.currentDate.add(1, 'years');
685
- that.initDate($scope.currentDate);
686
- }
687
- },
688
- _onSelectDate: function (date) {
689
- // remove selected from all dates in $scope.weeks
690
- angular.forEach($scope.weeks, function (week, weekKey) {
691
- angular.forEach($scope.weeks[weekKey], function (day, dayKey) {
692
- $scope.weeks[weekKey][dayKey].selected = false;
693
- });
694
- });
695
- date.selected = true;
696
- that.selectDate(date.data);
697
-
698
- if (!params.enableOkButtons) {
699
- that._onOKClick();
700
- }
701
- },
702
- _onSelectHour: function (hourSelected) {
703
-
704
- if (!hourSelected.disabled) {
705
- // remove selected from all dates in $scope.weeks
706
- angular.forEach($scope.hours, function (hour, hourKey) {
707
- $scope.hours[hourKey].selected = false;
708
- });
709
- hourSelected.selected = true;
710
-
711
- var dataHour = parseInt(hourSelected.h);
712
- if (that.isPM())
713
- dataHour += 12;
714
-
715
- $scope.currentDate.hour(dataHour);
716
- that.showTime($scope.currentDate);
717
-
718
- that.animateHands();
719
- if (!params.enableOkButtons) {
720
- that._onOKClick();
721
- }
722
- } else {
723
- //console.log('hour disabled');
724
- }
725
- },
726
- _onSelectMinute: function (minuteSelected) {
727
-
728
- if (!minuteSelected.disabled) {
729
- // remove selected from all minutes in $scope.minutes
730
- angular.forEach($scope.minutes, function (minute, minuteKey) {
731
- $scope.minutes[minuteKey].selected = false;
732
- });
733
- minuteSelected.selected = true;
734
-
735
-
736
- $scope.currentDate.minute(parseInt(minuteSelected.m));
737
- that.showTime($scope.currentDate);
738
-
739
- that.animateHands();
740
- if (!params.enableOkButtons) {
741
- that._onOKClick();
742
- }
743
- }
744
- },
745
- convertHours: function (h) {
746
- var _return = h;
747
-
748
- if ((h < 12) && that.isPM())
749
- _return += 12;
750
-
751
- return _return;
752
- },
753
- setDate: function (date) {
754
- //console.log('setDate');
755
- params.currentDate = date;
756
- that.initDates();
757
- },
758
- setMinDate: function (date) {
759
- params.minDate = date;
760
- that.initDates();
761
- },
762
- setMaxDate: function (date) {
763
- params.maxDate = date;
764
- that.initDates();
765
- },
766
- show: function () {
767
- $scope.showDtp = true;
768
- that._centerBox();
769
- },
770
- hide: function () {
771
- $scope.showDtp = false;
772
- },
773
- resetDate: function () {
774
-
775
- },
776
- _centerBox: function () {
777
- //var h = (this.$dtpElement.height() - this.$dtpElement.find('.dtp-content').height()) / 2;
778
- //this.$dtpElement.find('.dtp-content').css('marginLeft', -(this.$dtpElement.find('.dtp-content').width() / 2) + 'px');
779
- //this.$dtpElement.find('.dtp-content').css('top', h + 'px');
780
- }
781
- };
782
-
783
- $scope.onClick = that._onClick;
784
- $scope.onOKClick = that._onOKClick;
785
- $scope.onCancelClick = that._onCancelClick;
786
- $scope.onCloseClick = that._onCloseClick;
787
-
788
- $scope.onSelectDate = that._onSelectDate;
789
- $scope.onMonthBeforeClick = that._onMonthBeforeClick;
790
- $scope.onMonthAfterClick = that._onMonthAfterClick;
791
- $scope.onYearBeforeClick = that._onYearBeforeClick;
792
- $scope.onYearAfterClick = that._onYearAfterClick;
793
-
794
- $scope.onSelectHour = that._onSelectHour;
795
- $scope.onSelectMinute = that._onSelectMinute;
796
-
797
- $scope.initDate = that.initDate;
798
- $scope.initHours = that.initHours;
799
- $scope.initMinutes = that.initMinutes;
800
-
801
- prepareAttrs();
802
- that.init();
803
-
804
- if ($scope.inline) {
805
- //console.log('auto show inline');
806
- that._onClick();
807
- }
808
-
809
- $scope.$on('dtp-open-click', function () {
810
- that._onClick();
811
- });
812
-
813
- $scope.$on('dtp-close-click', function () {
814
- that.hide();
815
- });
816
-
817
- $scope.$watch('model', function (newDate) {
818
- $scope.currentDate = newDate;
819
- that.showDate($scope.currentDate);
820
- that.initDate();
821
- });
822
-
823
-
824
- // Close the dropdown if clicked outside
825
- //$document.bind('click', function(event){
826
- // console.log($element.find(event.target));
827
- // var isClickedElementChildOfPopup = $element.find(event.target).length == 0;
828
- // if (isClickedElementChildOfPopup){
829
- // that.hide();
830
- // }
831
- //});
832
- }
833
- };
834
-
1
+ 'use strict';
2
+
3
+ /**
4
+ * @ngdoc directive
5
+ * @name niceElements.directive:niceDtp
6
+ * @description
7
+ * # niceDtp
8
+ */
9
+ angular.module('niceElements')
10
+
11
+ .directive('niceDtp', function ($window, $parse, $document) {
12
+
13
+ return {
14
+ scope: {
15
+ onChange: '&?', // function called on date changed
16
+ model: '=', // binding model
17
+ format: '@', // default: 'D.M.YYYY • H:mm', format for input label string
18
+ modelFormat: '@', // default: ''
19
+ //currentDate: '@',
20
+ date: '@', // default: true, is date picker enabled?
21
+ time: '@', // default: false, is time picker enabled?
22
+ width: '@', // default: 300, width of entire dtp-picker in px
23
+ enableOkButtons: '@', // default: false, is ok/cancel buttons enabled?
24
+ lang: '@', // default: 'en', which locale to use - you must load angular locales first
25
+ minDate: '@', // default: undefined
26
+ maxDate: '@', // default: undefined
27
+ weekStart: '@', // default: 1, which day does the week start? (0 - sunday, 1 - monday, ...)
28
+ okText: '@',
29
+ cancelText: '@',
30
+ shortTime: '@', // default: false,
31
+ niceTitle: '@',
32
+ title: '@', // default: ''
33
+ noMargin: '@', // default: false, if noMargin==true then entire directive can be injected inside other divs
34
+ fieldWidth: '@', // default: 'col-sm-8', bootstrap classes that defines width of field
35
+ labelWidth: '@', // default: 'col-sm-4', bootstrap classes that defines width of label
36
+ closed: '=',
37
+ required: '='
38
+ },
39
+ templateUrl: 'src/components/nice-dtp/nice-dtp.html',
40
+ controller: function ($scope, $element, $attrs, gettextCatalog) {
41
+ console.warn("[NICE ELEMENTS] nice-dtp component is deprecated!");
42
+
43
+ // default parameters
44
+ var params = {
45
+ title: '',
46
+ noMargin: false,
47
+ fieldWidth: 'col-sm-8',
48
+ labelWidth: 'col-sm-4',
49
+ format: 'D.M.YYYY • H:mm',
50
+ modelFormat: 'YYYY-MM-DDTHH:mm:ss.SSS',
51
+ minDate: null,
52
+ maxDate: null,
53
+ lang: 'en',
54
+ weekStart: 1,
55
+ shortTime: false,
56
+ cancelText: gettextCatalog.getString('Cancel', null, 'Nice'),
57
+ okText: gettextCatalog.getString('OK', null, 'Nice'),
58
+ date: true,
59
+ time: false,
60
+ width: 300,
61
+ enableOkButtons: false
62
+ };
63
+
64
+ var prepareAttrs = function () {
65
+ // prepare attributes
66
+ params.date = $attrs.date === 'true' || $attrs.date === true;
67
+ params.time = $attrs.time === 'true' || $attrs.time === true;
68
+ params.inline = $attrs.inline === 'true' || $attrs.inline === true;
69
+ if ($attrs.format && $attrs.format != "")
70
+ params.format = $attrs.format;
71
+ if ($scope.enableOkButtons && $attrs.enableOkButtons != "")
72
+ params.enableOkButtons = $attrs.enableOkButtons === 'true';
73
+ if ($attrs.lang && $attrs.lang != "")
74
+ params.lang = $attrs.lang;
75
+ if ($attrs.minDate && $attrs.minDate != "")
76
+ params.minDate = $attrs.minDate;
77
+ if ($attrs.maxDate && $attrs.maxDate != "")
78
+ params.maxDate = $attrs.maxDate;
79
+ if ($scope.weekStart && $attrs.weekStart != "")
80
+ params.weekStart = parseInt($attrs.weekStart);
81
+ if ($attrs.okText && $attrs.okText != "")
82
+ params.okText = $attrs.okText;
83
+ if ($attrs.cancelText && $attrs.cancelText != "")
84
+ params.cancelText = $attrs.cancelText;
85
+ if ($attrs.noMargin && $attrs.noMargin != "")
86
+ params.noMargin = $attrs.noMargin === 'true';
87
+ if ($attrs.modelFormat && $attrs.modelFormat != "")
88
+ params.modelFormat = $attrs.modelFormat;
89
+
90
+ if ($attrs.width) {
91
+ params.width = parseInt($attrs.width);
92
+ }
93
+ //$scope.dtp_content_style = {width: params.width + 'px'};
94
+
95
+ // copy attributes back to scope - for template usage
96
+ $scope = angular.extend($scope, params);
97
+
98
+ };
99
+
100
+ $scope.date = $attrs.date === 'true' || $attrs.date === true;
101
+ $scope.time = $attrs.time === 'true' || $attrs.time === true;
102
+
103
+ // functions are defined in a variable 'var that', not in $scope
104
+ var that = {
105
+ init: function () {
106
+ //console.log('init', $scope);
107
+
108
+ $scope.showDtp = false;
109
+ that.initDays();
110
+ that.initDates();
111
+ },
112
+ initDays: function () {
113
+ //console.log('initDays');
114
+ $scope.days = [];
115
+ for (var i = params.weekStart; $scope.days.length < 7; i++) {
116
+ if (i > 6) {
117
+ i = 0;
118
+ }
119
+ $scope.days.push(i.toString());
120
+ }
121
+ },
122
+ fixMinMaxDate: function () {
123
+ if ($scope.minDate === "")
124
+ $scope.minDate = null;
125
+ if ($scope.maxDate === "")
126
+ $scope.maxDate = null;
127
+ },
128
+ initDates: function () {
129
+ that.fixMinMaxDate();
130
+ if (typeof ($scope.model) === 'undefined' || $scope.model === null) {
131
+ $scope.currentDate = moment();
132
+ } else {
133
+ //// all other combinations
134
+ //if (typeof($scope.model) === 'string') {
135
+ // $scope.currentDate = moment($scope.model, params.modelFormat).locale(params.lang);
136
+ //}
137
+ //else {
138
+ $scope.currentDate = moment($scope.model).locale(params.lang);
139
+ //}
140
+ }
141
+
142
+ that.setDateModel();
143
+ that.setElementValue();
144
+
145
+ // Parse minDate
146
+ if (typeof ($scope.minDate) !== 'undefined' && $scope.minDate !== null) {
147
+ if (typeof ($scope.minDate) === 'string') {
148
+ $scope.minDate = moment($scope.minDate).locale(params.lang);
149
+ }
150
+ }
151
+
152
+ // Parse maxDate
153
+ if (typeof ($scope.maxDate) !== 'undefined' && $scope.maxDate !== null) {
154
+ if (typeof ($scope.maxDate) === 'string') {
155
+ $scope.maxDate = moment($scope.maxDate).locale(params.lang);
156
+ }
157
+ }
158
+
159
+ // Fix currentDate if violates minDate and maxDate constraints
160
+ if (params.date === true) {
161
+ if (!that.isAfterMinDate($scope.currentDate)) {
162
+ $scope.currentDate = moment($scope.minDate);
163
+ }
164
+ if (!that.isBeforeMaxDate($scope.currentDate)) {
165
+ $scope.currentDate = moment($scope.maxDate);
166
+ }
167
+ }
168
+ },
169
+ initDate: function () {
170
+ that.fixMinMaxDate();
171
+
172
+ $scope.currentView = 0;
173
+
174
+ $scope.showCalendar = true;
175
+ $scope.showTime = false;
176
+
177
+ var _date = ((typeof ($scope.currentDate) !== 'undefined' && $scope.currentDate !== null) ? $scope.currentDate : null);
178
+ $scope.calendar = that.generateCalendar($scope.currentDate);
179
+
180
+ if (typeof ($scope.calendar.week) !== 'undefined' && typeof ($scope.calendar.days) !== 'undefined') {
181
+ that.constructHTMLCalendar(_date, $scope.calendar);
182
+ that.toggleButtons(_date);
183
+ }
184
+
185
+ that._centerBox();
186
+ that.showDate(_date);
187
+ },
188
+ initHours: function () {
189
+ that.fixMinMaxDate();
190
+ $scope.currentView = 1;
191
+ $scope.hours = [];
192
+ $scope.minutes = [];
193
+ $scope.showTime = true;
194
+ $scope.showCalendar = false;
195
+
196
+ that.showTime($scope.currentDate);
197
+
198
+ var pL = 10;
199
+ var pT = 10;
200
+ var mL = 20;
201
+ var mT = 10;
202
+ var r = 100;
203
+
204
+ var j = r / 1.55;
205
+ var j_pm = r / 1.15;
206
+
207
+ var _hours = [];
208
+
209
+ // AM hours
210
+ for (var h = 0; h < 12; ++h) {
211
+ var cH = (($scope.currentDate.format('HH') == 24) ? 0 : $scope.currentDate.format('HH'));
212
+ var x = j * Math.sin(Math.PI * 2 * (h / 12));
213
+ var y = j * Math.cos(Math.PI * 2 * (h / 12));
214
+
215
+ var _hour = {
216
+ style: {
217
+ x: x,
218
+ y: y,
219
+ marginLeft: (r + x + parseInt(pL) / 2) - (parseInt(pL) + parseInt(mL)) + 'px',
220
+ marginTop: (r - y - parseInt(mT) / 2) - (parseInt(pT) + parseInt(mT)) + 'px'
221
+ },
222
+ h: h == 0 ? 12 : h,
223
+ selected: h == parseInt(cH)
224
+ };
225
+
226
+ _hours.push(_hour);
227
+ }
228
+
229
+ // PM hours
230
+ for (var h = 0; h < 12; ++h) {
231
+ var cH = (($scope.currentDate.format('HH') == 24) ? 0 : $scope.currentDate.format('HH'));
232
+ var x = j_pm * Math.sin(Math.PI * 2 * (h / 12));
233
+ var y = j_pm * Math.cos(Math.PI * 2 * (h / 12));
234
+
235
+ var _hour = {
236
+ style: {
237
+ x: x,
238
+ y: y,
239
+ marginLeft: (r + x + parseInt(pL) / 2) - (parseInt(pL) + parseInt(mL)) + 'px',
240
+ marginTop: (r - y - parseInt(mT) / 2) - (parseInt(pT) + parseInt(mT)) + 'px'
241
+ },
242
+ h: h == 0 ? 0 : h + 12,
243
+ selected: h + 12 == parseInt(cH)
244
+ };
245
+
246
+ _hours.push(_hour);
247
+ }
248
+
249
+ $scope.hours = _hours;
250
+ that.toggleTime(true);
251
+ that.initHands(true);
252
+ },
253
+ initMinutes: function () {
254
+ that.fixMinMaxDate();
255
+ $scope.currentView = 2;
256
+ $scope.hours = [];
257
+ $scope.minutes = [];
258
+ $scope.showCalendar = false;
259
+ $scope.showTime = true;
260
+
261
+ that.showTime($scope.currentDate);
262
+
263
+ var pL = 10;
264
+ var pT = 10;
265
+ var mL = 20;
266
+ var mT = 10;
267
+ var w = 200;
268
+ var r = w / 2;
269
+ var j = r / 1.2;
270
+ var _minutes = [];
271
+
272
+ for (var m = 0; m < 60; m += 5) {
273
+ var x = j * Math.sin(Math.PI * 2 * (m / 60));
274
+ var y = j * Math.cos(Math.PI * 2 * (m / 60));
275
+
276
+ var _minute = {
277
+ style: {
278
+ x: x,
279
+ y: y,
280
+ marginLeft: (r + x + parseInt(pL) / 2) - (parseInt(pL) + parseInt(mL)) + 'px',
281
+ marginTop: (r - y - parseInt(mT) / 2) - (parseInt(pT) + parseInt(mT)) + 'px'
282
+ },
283
+ m: ((m.toString().length == 2) ? m : '0' + m),
284
+ selected: m == 5 * Math.round($scope.currentDate.minute() / 5)
285
+ };
286
+ _minutes.push(_minute);
287
+ }
288
+
289
+ $scope.minutes = _minutes;
290
+ that.toggleTime(false);
291
+ that.initHands(false);
292
+ that._centerBox();
293
+ },
294
+ initHands: function (t) {
295
+ var pL = 10;
296
+ var mL = 20;
297
+ var w = 7.5;
298
+ var h = 7.5;
299
+ var r = 100;
300
+ var _hL = r / 1.7;
301
+ var _mL = r / 1.5;
302
+
303
+ var dtpHourHand = $element[0].getElementsByClassName('dtp-hour-hand')[0];
304
+ dtpHourHand.style.left = r + (parseInt(mL) * 1.5) + 'px';
305
+ dtpHourHand.style.height = _hL + 'px';
306
+ dtpHourHand.style.marginTop = (r - _hL - parseInt(pL)) + 'px';
307
+ if (t) dtpHourHand.classList.add("on");
308
+
309
+ var dtpMinuteHand = $element[0].getElementsByClassName('dtp-minute-hand')[0];
310
+ dtpMinuteHand.style.left = r + (parseInt(mL) * 1.5) + 'px';
311
+ dtpMinuteHand.style.height = _mL + 'px';
312
+ dtpMinuteHand.style.marginTop = (r - _mL - parseInt(pL)) + 'px';
313
+ if (t) dtpMinuteHand.classList.add("on");
314
+
315
+ var dtpClockCenter = $element[0].getElementsByClassName('dtp-clock-center')[0];
316
+ dtpClockCenter.style.left = r + parseInt(pL) + parseInt(mL) - w + 'px';
317
+ dtpClockCenter.style.marginTop = (r - (parseInt(mL) / 2)) - h + 'px';
318
+
319
+ that.animateHands();
320
+
321
+ that._centerBox();
322
+ },
323
+ animateHands: function () {
324
+ var h = $scope.currentDate.hour();
325
+ var m = $scope.currentDate.minute();
326
+
327
+ var dtpHourHand = $element[0].getElementsByClassName('dtp-hour-hand')[0];
328
+ var dtpMinuteHand = $element[0].getElementsByClassName('dtp-minute-hand')[0];
329
+ that.rotateElement(dtpHourHand, (360 / 12) * h);
330
+ that.rotateElement(dtpMinuteHand, ((360 / 60) * (5 * Math.round(m / 5))));
331
+ },
332
+ isAfterMinDate: function (date, checkHour, checkMinute) {
333
+ var _return = true;
334
+
335
+ if (typeof ($scope.minDate) !== 'undefined' && $scope.minDate !== null) {
336
+ var _minDate = moment($scope.minDate);
337
+ var _date = moment(date);
338
+
339
+ if (!checkHour && !checkMinute) {
340
+ _minDate.hour(0);
341
+ _minDate.minute(0);
342
+
343
+ _date.hour(0);
344
+ _date.minute(0);
345
+ }
346
+
347
+ _minDate.second(0);
348
+ _date.second(0);
349
+ _minDate.millisecond(0);
350
+ _date.millisecond(0);
351
+
352
+ if (!checkMinute) {
353
+ _date.minute(0);
354
+ _minDate.minute(0);
355
+
356
+ _return = (parseInt(_date.format("X")) >= parseInt(_minDate.format("X")));
357
+ } else {
358
+ _return = (parseInt(_date.format("X")) >= parseInt(_minDate.format("X")));
359
+ }
360
+ }
361
+
362
+ return _return;
363
+ },
364
+ isBeforeMaxDate: function (date, checkTime, checkMinute) {
365
+ var _return = true;
366
+
367
+ if (typeof ($scope.maxDate) !== 'undefined' && $scope.maxDate !== null) {
368
+ var _maxDate = moment($scope.maxDate);
369
+ var _date = moment(date);
370
+
371
+ if (!checkTime && !checkMinute) {
372
+ _maxDate.hour(0);
373
+ _maxDate.minute(0);
374
+
375
+ _date.hour(0);
376
+ _date.minute(0);
377
+ }
378
+
379
+ _maxDate.second(0);
380
+ _date.second(0);
381
+ _maxDate.millisecond(0);
382
+ _date.millisecond(0);
383
+
384
+ if (!checkMinute) {
385
+ _date.minute(0);
386
+ _maxDate.minute(0);
387
+
388
+ _return = (parseInt(_date.format("X")) <= parseInt(_maxDate.format("X")));
389
+ } else {
390
+ _return = (parseInt(_date.format("X")) <= parseInt(_maxDate.format("X")));
391
+ }
392
+ }
393
+
394
+ return _return;
395
+ },
396
+ rotateElement: function (el, deg) {
397
+ el.style.transform = 'rotate(' + deg + 'deg)';
398
+ },
399
+ showDate: function (date) {
400
+ //console.log('showDate');
401
+ $scope.showTimeHeader = true;
402
+ if (date) {
403
+ $scope.showDateHeader = true;
404
+ $scope.actualDay = date.locale(params.lang).format('dddd');
405
+ $scope.actualMonth = date.locale(params.lang).format('MMM').toUpperCase();
406
+ $scope.actualNum = date.locale(params.lang).format('DD');
407
+ $scope.actualYear = date.locale(params.lang).format('YYYY');
408
+ }
409
+ },
410
+ showTime: function (date) {
411
+ //console.log('showTime', date);
412
+ if (date) {
413
+ var _minutes = (5 * Math.round(date.minute() / 5));
414
+ var _time = {
415
+ hours: date.format('HH'),
416
+ minutes: ((_minutes.toString().length == 2) ? _minutes : '0' + _minutes)
417
+ };
418
+
419
+ if (params.date) {
420
+ $scope.showTimeHeader = true;
421
+ $scope.actualTime = _time;
422
+ } else {
423
+ if (params.shortTime)
424
+ $scope.actualDay = date.format('A');
425
+ else
426
+ $scope.actualDay = ' ';
427
+
428
+ $scope.showTimeHeader = false;
429
+ $scope.actualTime = _time;
430
+ }
431
+ }
432
+ },
433
+ selectDate: function (date) {
434
+ //console.log('selectDate');
435
+ if (date) {
436
+ $scope.currentDate = date;
437
+ that.showDate($scope.currentDate);
438
+ $scope.$emit('dateSelected', {
439
+ date: date
440
+ });
441
+ }
442
+ },
443
+ generateCalendar: function (date) {
444
+ //console.log('generateCalendar');
445
+ var _calendar = {};
446
+
447
+ if (date !== null) {
448
+ var startOfMonth = moment(date).locale(params.lang).startOf('month');
449
+ var endOfMonth = moment(date).locale(params.lang).endOf('month');
450
+
451
+ var iNumDay = startOfMonth.format('d');
452
+
453
+ _calendar.week = $scope.days;
454
+ _calendar.days = [];
455
+
456
+ for (var i = startOfMonth.date(); i <= endOfMonth.date(); i++) {
457
+ if (i === startOfMonth.date()) {
458
+ var iWeek = _calendar.week.indexOf(iNumDay.toString());
459
+ if (iWeek > 0) {
460
+ for (var x = 0; x < iWeek; x++) {
461
+ _calendar.days.push(0);
462
+ }
463
+ }
464
+ }
465
+ _calendar.days.push(moment(startOfMonth).locale(params.lang).date(i));
466
+ }
467
+ }
468
+
469
+ return _calendar;
470
+ },
471
+ constructHTMLCalendar: function (date, calendar) {
472
+ $scope.monthAndYear = date.locale(params.lang).format('MMMM YYYY');
473
+
474
+ var _weekDays = [];
475
+ for (var i = 0; i < calendar.week.length; i++) {
476
+ _weekDays.push(moment(parseInt(calendar.week[i]), "d").locale(params.lang).format("dd").substring(0, 1));
477
+ }
478
+ $scope.weekDays = _weekDays;
479
+
480
+ var _weeks = [];
481
+
482
+ var _week = [];
483
+ for (var i = 0; i < calendar.days.length; i++) {
484
+ if (i % 7 == 0) {
485
+ if (i != 0) {
486
+ _weeks.push(_week);
487
+ }
488
+ var _week = [];
489
+ }
490
+
491
+ var _day = {
492
+ label: null,
493
+ selected: false,
494
+ disabled: true,
495
+ data: {}
496
+ };
497
+
498
+ if (calendar.days[i] != 0) {
499
+ _day.disabled = false;
500
+ _day.label = moment(calendar.days[i]).locale(params.lang).format("DD");
501
+ _day.data = calendar.days[i];
502
+ if (that.isBeforeMaxDate(moment(calendar.days[i]), false, false) === false || that.isAfterMinDate(moment(calendar.days[i]), false, false) === false) {
503
+ _day.disabled = true;
504
+ } else {
505
+ if (moment(calendar.days[i]).locale(params.lang).format("DD") === moment($scope.currentDate).locale(params.lang).format("DD")) {
506
+ _day.selected = true;
507
+
508
+ }
509
+ }
510
+ }
511
+ _week.push(_day);
512
+ }
513
+
514
+ if (_week.length > 0) {
515
+ _weeks.push(_week);
516
+ }
517
+
518
+ $scope.weeks = _weeks;
519
+ //console.log('$scope.weeks', $scope.weeks);
520
+ //console.log('$scope.weekDays', $scope.weekDays);
521
+ },
522
+ setName: function () {
523
+ var text = "";
524
+ var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
525
+
526
+ for (var i = 0; i < 5; i++) {
527
+ text += possible.charAt(Math.floor(Math.random() * possible.length));
528
+ }
529
+
530
+ return text;
531
+ },
532
+ isPM: function () {
533
+ return $scope.isPM;
534
+ },
535
+ setElementValue: function (date) {
536
+
537
+ //if (typeof(date) !== 'undefined'){
538
+ // $scope.currentDate = moment(date).locale(params.lang);
539
+ //}
540
+
541
+ $scope.value = moment($scope.currentDate).locale(params.lang).format(params.format);
542
+ },
543
+ setDateModel: function () {
544
+ $scope.model = angular.copy($scope.currentDate);
545
+ if ($scope.onChange) $scope.onChange({ model: $scope.model });
546
+ //$scope.model = $scope.currentDate.format(params.modelFormat);
547
+ //$scope.formDatetimePicker.$setDirty();
548
+ },
549
+ toggleButtons: function (date) {
550
+ if (date && date.isValid()) {
551
+ var startOfMonth = moment(date).locale(params.lang).startOf('month');
552
+ var endOfMonth = moment(date).locale(params.lang).endOf('month');
553
+
554
+ $scope.btnMonthBeforeEnabled = that.isAfterMinDate(startOfMonth, false, false);
555
+ $scope.btnMonthAfterEnabled = that.isBeforeMaxDate(endOfMonth, false, false);
556
+
557
+ var startOfYear = moment(date).locale(params.lang).startOf('year');
558
+ var endOfYear = moment(date).locale(params.lang).endOf('year');
559
+
560
+ $scope.btnYearBeforeEnabled = that.isAfterMinDate(startOfYear, false, false);
561
+ $scope.btnYearAfterEnabled = that.isBeforeMaxDate(endOfYear, false, false);
562
+ }
563
+ },
564
+ toggleTime: function (isHours) {
565
+ if (isHours) {
566
+ angular.forEach($scope.hours, function (hour, hourKey) {
567
+ var _date = moment($scope.currentDate);
568
+ _date.hour(that.convertHours(hour.h)).minute(0).second(0);
569
+
570
+ if (that.isAfterMinDate(_date, true, false) === false || that.isBeforeMaxDate(_date, true, false) === false) {
571
+ hour.disabled = true;
572
+ } else {
573
+ hour.disabled = false;
574
+ }
575
+ });
576
+ } else {
577
+ angular.forEach($scope.minutes, function (minute, minuteKey) {
578
+ var _minute = minute.m;
579
+ var _date = moment($scope.currentDate);
580
+ _date.minute(_minute).second(0);
581
+
582
+ if (that.isAfterMinDate(_date, true, true) === false || that.isBeforeMaxDate(_date, true, true) === false) {
583
+ minute.disabled = true;
584
+ } else {
585
+ minute.disabled = false;
586
+ }
587
+ });
588
+ }
589
+ },
590
+ _onClick: function () {
591
+ $scope.currentView = 0;
592
+
593
+ that.initDates();
594
+
595
+ that.show();
596
+
597
+ if (params.date) {
598
+ $scope.showDate = true;
599
+ that.initDate();
600
+ } else {
601
+ if (params.time) {
602
+ $scope.showTime = true;
603
+ that.initHours();
604
+ }
605
+ }
606
+ },
607
+ _onBackgroundClick: function (e) {
608
+ e.stopPropagation();
609
+ that.hide();
610
+ },
611
+ _onElementClick: function (e) {
612
+ e.stopPropagation();
613
+ },
614
+ _onCloseClick: function () {
615
+ that.hide();
616
+ if ($scope.closed) $scope.closed(true);
617
+ },
618
+ _onOKClick: function () {
619
+ switch ($scope.currentView) {
620
+ case 0:
621
+ if (params.time === true) {
622
+ that.initHours();
623
+ } else {
624
+ that.setElementValue();
625
+ that.setDateModel();
626
+ if (!$scope.inline)
627
+ that.hide();
628
+ }
629
+ break;
630
+ case 1:
631
+ that.initMinutes();
632
+ break;
633
+ case 2:
634
+ that.setElementValue();
635
+ that.setDateModel();
636
+ if ($scope.inline) {
637
+ that._onClick();
638
+ } else {
639
+ that.hide();
640
+ }
641
+ break;
642
+ }
643
+ },
644
+ _onCancelClick: function () {
645
+ if (params.time) {
646
+ switch ($scope.currentView) {
647
+ case 0:
648
+ that.hide();
649
+ break;
650
+ case 1:
651
+ if (params.date) {
652
+ that.initDate();
653
+ } else {
654
+ that.hide();
655
+ }
656
+ break;
657
+ case 2:
658
+ that.initHours();
659
+ break;
660
+ }
661
+ } else {
662
+ that.hide();
663
+ }
664
+ },
665
+ _onMonthBeforeClick: function () {
666
+ if ($scope.btnMonthBeforeEnabled) {
667
+ $scope.currentDate.subtract(1, 'months');
668
+ that.initDate($scope.currentDate);
669
+ }
670
+ },
671
+ _onMonthAfterClick: function () {
672
+ if ($scope.btnMonthAfterEnabled) {
673
+ $scope.currentDate.add(1, 'months');
674
+ that.initDate($scope.currentDate);
675
+ }
676
+ },
677
+ _onYearBeforeClick: function () {
678
+ if ($scope.btnYearBeforeEnabled) {
679
+ $scope.currentDate.subtract(1, 'years');
680
+ that.initDate($scope.currentDate);
681
+ }
682
+ },
683
+ _onYearAfterClick: function () {
684
+ if ($scope.btnYearAfterEnabled) {
685
+ $scope.currentDate.add(1, 'years');
686
+ that.initDate($scope.currentDate);
687
+ }
688
+ },
689
+ _onSelectDate: function (date) {
690
+ // remove selected from all dates in $scope.weeks
691
+ angular.forEach($scope.weeks, function (week, weekKey) {
692
+ angular.forEach($scope.weeks[weekKey], function (day, dayKey) {
693
+ $scope.weeks[weekKey][dayKey].selected = false;
694
+ });
695
+ });
696
+ date.selected = true;
697
+ that.selectDate(date.data);
698
+
699
+ if (!params.enableOkButtons) {
700
+ that._onOKClick();
701
+ }
702
+ },
703
+ _onSelectHour: function (hourSelected) {
704
+
705
+ if (!hourSelected.disabled) {
706
+ // remove selected from all dates in $scope.weeks
707
+ angular.forEach($scope.hours, function (hour, hourKey) {
708
+ $scope.hours[hourKey].selected = false;
709
+ });
710
+ hourSelected.selected = true;
711
+
712
+ var dataHour = parseInt(hourSelected.h);
713
+ if (that.isPM())
714
+ dataHour += 12;
715
+
716
+ $scope.currentDate.hour(dataHour);
717
+ that.showTime($scope.currentDate);
718
+
719
+ that.animateHands();
720
+ if (!params.enableOkButtons) {
721
+ that._onOKClick();
722
+ }
723
+ } else {
724
+ //console.log('hour disabled');
725
+ }
726
+ },
727
+ _onSelectMinute: function (minuteSelected) {
728
+
729
+ if (!minuteSelected.disabled) {
730
+ // remove selected from all minutes in $scope.minutes
731
+ angular.forEach($scope.minutes, function (minute, minuteKey) {
732
+ $scope.minutes[minuteKey].selected = false;
733
+ });
734
+ minuteSelected.selected = true;
735
+
736
+
737
+ $scope.currentDate.minute(parseInt(minuteSelected.m));
738
+ that.showTime($scope.currentDate);
739
+
740
+ that.animateHands();
741
+ if (!params.enableOkButtons) {
742
+ that._onOKClick();
743
+ }
744
+ }
745
+ },
746
+ convertHours: function (h) {
747
+ var _return = h;
748
+
749
+ if ((h < 12) && that.isPM())
750
+ _return += 12;
751
+
752
+ return _return;
753
+ },
754
+ setDate: function (date) {
755
+ //console.log('setDate');
756
+ params.currentDate = date;
757
+ that.initDates();
758
+ },
759
+ setMinDate: function (date) {
760
+ params.minDate = date;
761
+ that.initDates();
762
+ },
763
+ setMaxDate: function (date) {
764
+ params.maxDate = date;
765
+ that.initDates();
766
+ },
767
+ show: function () {
768
+ $scope.showDtp = true;
769
+ that._centerBox();
770
+ },
771
+ hide: function () {
772
+ $scope.showDtp = false;
773
+ },
774
+ resetDate: function () {
775
+
776
+ },
777
+ _centerBox: function () {
778
+ //var h = (this.$dtpElement.height() - this.$dtpElement.find('.dtp-content').height()) / 2;
779
+ //this.$dtpElement.find('.dtp-content').css('marginLeft', -(this.$dtpElement.find('.dtp-content').width() / 2) + 'px');
780
+ //this.$dtpElement.find('.dtp-content').css('top', h + 'px');
781
+ }
782
+ };
783
+
784
+ $scope.onClick = that._onClick;
785
+ $scope.onOKClick = that._onOKClick;
786
+ $scope.onCancelClick = that._onCancelClick;
787
+ $scope.onCloseClick = that._onCloseClick;
788
+
789
+ $scope.onSelectDate = that._onSelectDate;
790
+ $scope.onMonthBeforeClick = that._onMonthBeforeClick;
791
+ $scope.onMonthAfterClick = that._onMonthAfterClick;
792
+ $scope.onYearBeforeClick = that._onYearBeforeClick;
793
+ $scope.onYearAfterClick = that._onYearAfterClick;
794
+
795
+ $scope.onSelectHour = that._onSelectHour;
796
+ $scope.onSelectMinute = that._onSelectMinute;
797
+
798
+ $scope.initDate = that.initDate;
799
+ $scope.initHours = that.initHours;
800
+ $scope.initMinutes = that.initMinutes;
801
+
802
+ prepareAttrs();
803
+ that.init();
804
+
805
+ if ($scope.inline) {
806
+ //console.log('auto show inline');
807
+ that._onClick();
808
+ }
809
+
810
+ $scope.$on('dtp-open-click', function () {
811
+ that._onClick();
812
+ });
813
+
814
+ $scope.$on('dtp-close-click', function () {
815
+ that.hide();
816
+ });
817
+
818
+ $scope.$watch('model', function (newDate) {
819
+ $scope.currentDate = newDate;
820
+ that.showDate($scope.currentDate);
821
+ that.initDate();
822
+ });
823
+
824
+
825
+ // Close the dropdown if clicked outside
826
+ //$document.bind('click', function(event){
827
+ // console.log($element.find(event.target));
828
+ // var isClickedElementChildOfPopup = $element.find(event.target).length == 0;
829
+ // if (isClickedElementChildOfPopup){
830
+ // that.hide();
831
+ // }
832
+ //});
833
+ }
834
+ };
835
+
835
836
  });