fng-bootstrap-date 0.12.0-beta.17 → 0.12.0-beta.170
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 +114 -32
- package/package.json +1 -1
package/fng-bootstrap-date.js
CHANGED
|
@@ -1,37 +1,119 @@
|
|
|
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);
|
|
10
51
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
52
|
+
template = pluginHelper.buildInputMarkup(scope, attrs.model, processedAttr.info, processedAttr.options, false, false, function (buildingBlocks) {
|
|
53
|
+
var str = '';
|
|
54
|
+
for (var opt in overRiddenDefaults) {
|
|
55
|
+
if (opt !== 'date-options') {
|
|
56
|
+
str += ' ' + opt + '="' + overRiddenDefaults[opt] + '"';
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (processedAttr.info.title) {
|
|
60
|
+
str += ' title="' + processedAttr.info.title + '"';
|
|
61
|
+
}
|
|
62
|
+
if (processedAttr.info.arialabel) {
|
|
63
|
+
str += ' aria-label="' + processedAttr.info.arialabel + '"';
|
|
64
|
+
}
|
|
65
|
+
return formMarkupHelper.generateSimpleInput(
|
|
66
|
+
buildingBlocks.common + str + ' validdate datepicker-options="dateOptions" uib-datepicker-popup="' + (processedAttr.directiveOptions.format || processedAttr.directiveOptions['date-format'] || 'dd/MM/yy') + '" is-open="popup.opened" ng-click="open()" ' + formMarkupHelper.addTextInputMarkup(buildingBlocks, processedAttr.info, ''),
|
|
67
|
+
processedAttr.info,
|
|
68
|
+
processedAttr.options
|
|
69
|
+
);
|
|
70
|
+
});
|
|
71
|
+
var html = $compile(template)(scope);
|
|
72
|
+
if (element[0].parentElement) {
|
|
73
|
+
element.replaceWith(html);
|
|
74
|
+
} else {
|
|
75
|
+
afterTimeout();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
}]
|
|
80
|
+
)
|
|
81
|
+
.directive('validdate', [function() {
|
|
82
|
+
return {
|
|
83
|
+
require: 'ngModel',
|
|
84
|
+
link: function(scope, elm, attrs, ctrl) {
|
|
85
|
+
var minDate;
|
|
86
|
+
var maxDate;
|
|
87
|
+
if (scope.dateOptions.minDate) {
|
|
88
|
+
minDate = new Date(scope.dateOptions.minDate).valueOf();
|
|
89
|
+
}
|
|
90
|
+
if (scope.dateOptions.maxDate) {
|
|
91
|
+
maxDate = new Date(scope.dateOptions.maxDate).valueOf();
|
|
92
|
+
}
|
|
93
|
+
if (minDate || maxDate) {
|
|
94
|
+
if (attrs.format !== 'dd/MM/yyyy') {
|
|
95
|
+
throw new Error('Unsupported date format in validdate: ' + attrs.format)
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
ctrl.$validators.validdate = function(modelValue, viewValue) {
|
|
100
|
+
if (ctrl.$isEmpty(modelValue)) {
|
|
101
|
+
// consider empty models to be invalid
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
var retVal = true;
|
|
105
|
+
if (minDate || maxDate) {
|
|
106
|
+
var dateVal = new Date(parseInt(viewValue.slice(6,10),10), parseInt(viewValue.slice(3,5),10)-1,parseInt(viewValue.slice(0,2),10)).valueOf();
|
|
107
|
+
if (minDate && dateVal < minDate) {
|
|
108
|
+
retVal = false;
|
|
109
|
+
}
|
|
110
|
+
if (maxDate && dateVal > maxDate) {
|
|
111
|
+
retVal = false;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return retVal;
|
|
115
|
+
};
|
|
116
|
+
}
|
|
33
117
|
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
)
|
|
37
|
-
})();
|
|
118
|
+
}])
|
|
119
|
+
})();
|
package/package.json
CHANGED