fng-bootstrap-date 0.12.0-beta.18 → 0.12.0-beta.182
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.
- package/fng-bootstrap-date.js +132 -32
- package/package.json +1 -1
package/fng-bootstrap-date.js
CHANGED
|
@@ -1,37 +1,137 @@
|
|
|
1
1
|
(function () {
|
|
2
|
-
|
|
2
|
+
'use strict';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
var uiBootstrapDateModule = angular.module('fng.uiBootstrapDate', ['ui.bootstrap']);
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
uiBootstrapDateModule.controller('FngUIBootstrapDateCtrl', ['$scope', function ($scope) {
|
|
7
|
+
$scope.popup = {
|
|
8
|
+
opened: false
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
$scope.open = function () {
|
|
12
|
+
$scope.popup.opened = true;
|
|
13
|
+
}
|
|
14
|
+
}])
|
|
15
|
+
.directive('fngUiBootstrapDatePicker', ['$compile', '$filter', '$timeout', 'pluginHelper', 'formMarkupHelper', 'cssFrameworkService',
|
|
16
|
+
function ($compile, $filter, $timeout, pluginHelper, formMarkupHelper) {
|
|
17
|
+
return {
|
|
18
|
+
restrict: 'E',
|
|
19
|
+
replace: true,
|
|
20
|
+
priority: 1,
|
|
21
|
+
controller: 'FngUIBootstrapDateCtrl',
|
|
22
|
+
link: function (scope, element, attrs) {
|
|
23
|
+
function afterTimeout() {
|
|
24
|
+
$timeout(function() {
|
|
25
|
+
if (element[0].parentElement) {
|
|
26
|
+
element.replaceWith(html);
|
|
27
|
+
} else {
|
|
28
|
+
afterTimeout();
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
var template;
|
|
34
|
+
var processedAttr = pluginHelper.extractFromAttr(attrs, 'fngUiBootstrapDatePicker');
|
|
35
|
+
var overRiddenDefaults = {
|
|
36
|
+
'show-button-bar': false,
|
|
37
|
+
'show-meridian': false,
|
|
38
|
+
'date-format': 'dd/MM/yyyy'
|
|
39
|
+
};
|
|
40
|
+
overRiddenDefaults = Object.assign({}, overRiddenDefaults, processedAttr.directiveOptions);
|
|
41
|
+
var overRiddenDateDefaults = {
|
|
42
|
+
showWeeks: false
|
|
43
|
+
};
|
|
44
|
+
var jsonDateOptions = {
|
|
45
|
+
'showWeeks': false
|
|
46
|
+
};
|
|
47
|
+
if (processedAttr.directiveOptions['date-options']) {
|
|
48
|
+
jsonDateOptions = JSON.parse(processedAttr.directiveOptions['date-options'].replace(/'/g, '"'));
|
|
49
|
+
}
|
|
50
|
+
scope.dateOptions = Object.assign(overRiddenDateDefaults, jsonDateOptions);
|
|
51
|
+
["minDate","maxDate"].forEach(v => {
|
|
52
|
+
if (scope.dateOptions[v] && typeof scope.dateOptions[v] === "string") {
|
|
53
|
+
scope.dateOptions[v] = new Date(scope.dateOptions[v]);
|
|
54
|
+
}
|
|
55
|
+
})
|
|
10
56
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
57
|
+
const isArray = processedAttr.info.array;
|
|
58
|
+
template = pluginHelper.buildInputMarkup(scope, attrs.model, processedAttr.info, processedAttr.options, isArray, isArray, function (buildingBlocks) {
|
|
59
|
+
var str = '';
|
|
60
|
+
for (var opt in overRiddenDefaults) {
|
|
61
|
+
if (opt !== 'date-options') {
|
|
62
|
+
str += ' ' + opt + '="' + overRiddenDefaults[opt] + '"';
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (processedAttr.info.title) {
|
|
66
|
+
str += ' title="' + processedAttr.info.title + '"';
|
|
67
|
+
}
|
|
68
|
+
if (processedAttr.info.arialabel) {
|
|
69
|
+
str += ' aria-label="' + processedAttr.info.arialabel + '"';
|
|
70
|
+
}
|
|
71
|
+
const prefix = "uibDatePopup";
|
|
72
|
+
const random = Math.floor(Math.random() * 10000);
|
|
73
|
+
scope[prefix + random] = {
|
|
74
|
+
opened: {}
|
|
75
|
+
};
|
|
76
|
+
scope["open" + random] = function ($index) {
|
|
77
|
+
const all = Object.keys(scope).filter((k) => k.startsWith(prefix));
|
|
78
|
+
for (const key of all) {
|
|
79
|
+
scope[key].opened = {};
|
|
80
|
+
}
|
|
81
|
+
scope[prefix + random].opened[$index || 0] = true;
|
|
82
|
+
}
|
|
83
|
+
return formMarkupHelper.generateSimpleInput(
|
|
84
|
+
buildingBlocks.common + str + ' validdate datepicker-options="dateOptions" uib-datepicker-popup="' + (processedAttr.directiveOptions.format || processedAttr.directiveOptions['date-format'] || 'dd/MM/yy') + '" is-open="' + prefix + random + '.opened[$index || 0]" ng-click="open' + random + '($index)" ' + formMarkupHelper.addTextInputMarkup(buildingBlocks, processedAttr.info, ''),
|
|
85
|
+
processedAttr.info,
|
|
86
|
+
processedAttr.options
|
|
87
|
+
);
|
|
88
|
+
});
|
|
89
|
+
var html = $compile(template)(scope);
|
|
90
|
+
if (element[0].parentElement) {
|
|
91
|
+
element.replaceWith(html);
|
|
92
|
+
} else {
|
|
93
|
+
afterTimeout();
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
}]
|
|
98
|
+
)
|
|
99
|
+
.directive('validdate', [function() {
|
|
100
|
+
return {
|
|
101
|
+
require: 'ngModel',
|
|
102
|
+
link: function(scope, elm, attrs, ctrl) {
|
|
103
|
+
var minDate;
|
|
104
|
+
var maxDate;
|
|
105
|
+
if (scope.dateOptions.minDate) {
|
|
106
|
+
minDate = new Date(scope.dateOptions.minDate).valueOf();
|
|
107
|
+
}
|
|
108
|
+
if (scope.dateOptions.maxDate) {
|
|
109
|
+
maxDate = new Date(scope.dateOptions.maxDate).valueOf();
|
|
110
|
+
}
|
|
111
|
+
if (minDate || maxDate) {
|
|
112
|
+
if (attrs.format !== 'dd/MM/yyyy') {
|
|
113
|
+
throw new Error('Unsupported date format in validdate: ' + attrs.format)
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
ctrl.$validators.validdate = function(modelValue, viewValue) {
|
|
118
|
+
if (ctrl.$isEmpty(modelValue)) {
|
|
119
|
+
// consider empty models to be invalid
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
var retVal = true;
|
|
123
|
+
if (minDate || maxDate) {
|
|
124
|
+
var dateVal = modelValue.valueOf();
|
|
125
|
+
if (minDate && dateVal < minDate) {
|
|
126
|
+
retVal = false;
|
|
127
|
+
}
|
|
128
|
+
if (maxDate && dateVal > maxDate) {
|
|
129
|
+
retVal = false;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return retVal;
|
|
133
|
+
};
|
|
134
|
+
}
|
|
33
135
|
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
)
|
|
37
|
-
})();
|
|
136
|
+
}])
|
|
137
|
+
})();
|
package/package.json
CHANGED