fng-bootstrap-date 0.12.0-beta.20 → 0.12.0-beta.201

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 (2) hide show
  1. package/fng-bootstrap-date.js +146 -32
  2. package/package.json +1 -1
@@ -1,37 +1,151 @@
1
1
  (function () {
2
- 'use strict';
2
+ 'use strict';
3
3
 
4
- var uiBootstrapDateModule = angular.module('fng.uiBootstrapDate', ['ui.bootstrap']);
4
+ var uiBootstrapDateModule = angular.module('fng.uiBootstrapDate', ['ui.bootstrap']);
5
5
 
6
- uiBootstrapDateModule.controller('FngUIBootstrapDateCtrl', ['$scope', function ($scope) {
7
- $scope.popup = {
8
- opened: false
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', '$timeout', 'pluginHelper', 'formMarkupHelper', 'cssFrameworkService',
16
+ function ($compile, $timeout, pluginHelper, formMarkupHelper) {
17
+ return {
18
+ restrict: 'E',
19
+ replace: true,
20
+ priority: 1,
21
+ controller: 'FngUIBootstrapDateCtrl',
22
+ scope: true, // our own scope, but not isolated - prevents multiple instances on the same page from opening each other
23
+ link: function (scope, element, attrs) {
24
+ function afterTimeout() {
25
+ $timeout(function() {
26
+ if (element[0].parentElement) {
27
+ element.replaceWith(html);
28
+ } else {
29
+ afterTimeout();
30
+ }
31
+ });
32
+ }
33
+
34
+ var template;
35
+ var processedAttrs = pluginHelper.extractFromAttr(attrs, 'fngUiBootstrapDatePicker');
36
+ var overriddenDefaults = {
37
+ 'show-button-bar': false,
38
+ 'show-meridian': false,
39
+ 'date-format': 'dd/MM/yyyy'
40
+ };
41
+ overriddenDefaults = Object.assign({}, overriddenDefaults, processedAttrs.directiveOptions);
42
+ var overriddenDateDefaults = {
43
+ showWeeks: false
44
+ };
45
+ var jsonDateOptions = {
46
+ 'showWeeks': false
47
+ };
48
+ if (processedAttrs.directiveOptions['date-options']) {
49
+ jsonDateOptions = JSON.parse(processedAttrs.directiveOptions['date-options'].replace(/'/g, '"'));
50
+ }
51
+ scope.dateOptions = Object.assign(overriddenDateDefaults, jsonDateOptions);
52
+ ["minDate","maxDate"].forEach(v => {
53
+ if (scope.dateOptions[v] && typeof scope.dateOptions[v] === "string") {
54
+ scope.dateOptions[v] = new Date(scope.dateOptions[v]);
55
+ }
56
+ })
10
57
 
11
- $scope.open = function() {
12
- $scope.popup.opened = true;
13
- }
14
- }])
15
- .directive('fngUiBootstrapDatePicker', ['$compile', '$filter', 'pluginHelper', 'formMarkupHelper', 'cssFrameworkService',
16
- function ($compile, $filter, pluginHelper, formMarkupHelper, cssFrameworkService) {
17
- return {
18
- restrict: 'E',
19
- replace: true,
20
- priority: 1,
21
- controller: 'FngUIBootstrapDateCtrl',
22
- link: function (scope, element, attrs) {
23
- var template;
24
- var processedAttr = pluginHelper.extractFromAttr(attrs, 'fngUiBootstrapDatePicker');
25
- template = pluginHelper.buildInputMarkup(scope, attrs.model, processedAttr.info, processedAttr.options, false, false, function (buildingBlocks) {
26
- return formMarkupHelper.generateSimpleInput(
27
- buildingBlocks.common + ' uib-datepicker-popup="' + (processedAttr.directiveOptions.format || 'dd/MM/yy') + '" is-open="popup.opened" ng-click="open()" ' + formMarkupHelper.addTextInputMarkup(buildingBlocks, processedAttr.info, ''),
28
- processedAttr.info,
29
- processedAttr.options
30
- );
31
- });
32
- element.replaceWith($compile(template)(scope));
58
+ const isArray = processedAttrs.info.array;
59
+ template = pluginHelper.buildInputMarkup(
60
+ scope,
61
+ attrs,
62
+ {
63
+ processedAttrs,
64
+ addButtons: isArray,
65
+ needsX: isArray,
66
+ },
67
+ function (buildingBlocks) {
68
+ var str = buildingBlocks.common.trim();
69
+ for (var opt in overriddenDefaults) {
70
+ if (opt !== 'date-options') {
71
+ str += ` ${opt}="${overriddenDefaults[opt]}"`;
72
+ }
73
+ }
74
+ if (processedAttrs.info.title) {
75
+ str += ` title="${processedAttrs.info.title}"`;
76
+ }
77
+ if (processedAttrs.info.arialabel) {
78
+ str += ` aria-label="${processedAttrs.info.arialabel}"`;
79
+ }
80
+ if (processedAttrs.info.required) {
81
+ str += " required";
82
+ }
83
+ const markup = formMarkupHelper.addTextInputMarkup(buildingBlocks, processedAttrs.info, '');
84
+ const disabled = pluginHelper.genDisabledStr(scope, processedAttrs, "");
85
+ const dateFormat = processedAttrs.directiveOptions.format || processedAttrs.directiveOptions['date-format'] || 'dd/MM/yy';
86
+ str += ` ${markup}${disabled}datepicker-options="dateOptions" uib-datepicker-popup="${dateFormat}"`;
87
+
88
+ if (disabled && disabled.trim().toLowerCase() !== "disabled") {
89
+ scope.popup = { opened: false };
90
+ scope.open = function () {
91
+ scope.popup.opened = true;
92
+ }
93
+ str += ' is-open="popup.opened" ng-click="open()" validdate '; // don't remove the trailing space here
94
+ }
95
+ return formMarkupHelper.generateSimpleInput(
96
+ str,
97
+ processedAttrs.info,
98
+ processedAttrs.options
99
+ );
100
+ }
101
+ );
102
+ var html = $compile(template)(scope);
103
+ if (element[0].parentElement) {
104
+ element.replaceWith(html);
105
+ } else {
106
+ afterTimeout();
107
+ }
108
+ }
109
+ };
110
+ }]
111
+ )
112
+ .directive('validdate', [function() {
113
+ return {
114
+ require: 'ngModel',
115
+ link: function(scope, elm, attrs, ctrl) {
116
+ var minDate;
117
+ var maxDate;
118
+ if (scope.dateOptions.minDate) {
119
+ minDate = new Date(scope.dateOptions.minDate).valueOf();
120
+ }
121
+ if (scope.dateOptions.maxDate) {
122
+ maxDate = new Date(scope.dateOptions.maxDate).valueOf();
123
+ }
124
+ if (minDate || maxDate) {
125
+ if (attrs.format !== 'dd/MM/yyyy') {
126
+ throw new Error('Unsupported date format in validdate: ' + attrs.format)
127
+ }
128
+ }
129
+
130
+ ctrl.$validators.validdate = function(modelValue, viewValue) {
131
+ if (ctrl.$isEmpty(modelValue)) {
132
+ // if empty should be considered invalid, the field should be set to required (which will
133
+ // then be validated elsewhere)
134
+ return true;
135
+ }
136
+ var retVal = true;
137
+ if (minDate || maxDate) {
138
+ var dateVal = modelValue.valueOf();
139
+ if (minDate && dateVal < minDate) {
140
+ retVal = false;
141
+ }
142
+ if (maxDate && dateVal > maxDate) {
143
+ retVal = false;
144
+ }
145
+ }
146
+ return retVal;
147
+ };
148
+ }
33
149
  }
34
- };
35
- }]
36
- )
37
- })();
150
+ }])
151
+ })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fng-bootstrap-date",
3
- "version": "0.12.0-beta.20",
3
+ "version": "0.12.0-beta.201",
4
4
  "description": "Date input plugin for forms-angular, using the Bootstrap datepicker from Angular-ui-bootstrap",
5
5
  "main": "fng-bootstrap-date.js",
6
6
  "scripts": {