nice-elements 1.9.16 → 1.10.0

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