fng-bootstrap-datetime 0.12.0-beta.26 → 0.12.0-beta.261
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-datetime.js +83 -31
- package/package.json +1 -1
@@ -55,7 +55,7 @@ angular.module('ui.bootstrap.datetimepicker', ["ui.bootstrap.dateparser", "ui.bo
|
|
55
55
|
hiddenDate: "=",
|
56
56
|
datepickerTemplateUrl: "@",
|
57
57
|
datepickerPopupTemplateUrl: "@",
|
58
|
-
timepickerTemplateUrl: "@"
|
58
|
+
timepickerTemplateUrl: "@",
|
59
59
|
},
|
60
60
|
template: function (elem, attrs) {
|
61
61
|
function dashCase(name) {
|
@@ -67,9 +67,10 @@ angular.module('ui.bootstrap.datetimepicker', ["ui.bootstrap.dateparser", "ui.bo
|
|
67
67
|
function createAttr(innerAttr, dateTimeAttrOpt) {
|
68
68
|
var dateTimeAttr = angular.isDefined(dateTimeAttrOpt) ? dateTimeAttrOpt : innerAttr;
|
69
69
|
if (attrs[dateTimeAttr]) {
|
70
|
-
return dashCase(innerAttr)
|
71
|
-
} else if (dateTimeAttr in attrs) {
|
72
|
-
|
70
|
+
return `${dashCase(innerAttr)}="${attrs[dateTimeAttr]}" `;
|
71
|
+
} else if (dateTimeAttr in attrs) {
|
72
|
+
// attribute with an empty value such as "required"
|
73
|
+
return `${dateTimeAttr} `;
|
73
74
|
} else {
|
74
75
|
return '';
|
75
76
|
}
|
@@ -78,18 +79,18 @@ angular.module('ui.bootstrap.datetimepicker', ["ui.bootstrap.dateparser", "ui.bo
|
|
78
79
|
function createFuncAttr(innerAttr, funcArgs, dateTimeAttrOpt, defaultImpl) {
|
79
80
|
var dateTimeAttr = angular.isDefined(dateTimeAttrOpt) ? dateTimeAttrOpt : innerAttr;
|
80
81
|
if (attrs[dateTimeAttr]) {
|
81
|
-
return dashCase(innerAttr)
|
82
|
+
return `${dashCase(innerAttr)}="${dateTimeAttr}({${funcArgs}})" `;
|
82
83
|
} else {
|
83
|
-
return angular.isDefined(defaultImpl) ? dashCase(innerAttr)
|
84
|
+
return angular.isDefined(defaultImpl) ? `${dashCase(innerAttr)}="${defaultImpl}" ` : "";
|
84
85
|
}
|
85
86
|
}
|
86
87
|
|
87
88
|
function createEvalAttr(innerAttr, dateTimeAttrOpt) {
|
88
89
|
var dateTimeAttr = angular.isDefined(dateTimeAttrOpt) ? dateTimeAttrOpt : innerAttr;
|
89
90
|
if (attrs[dateTimeAttr]) {
|
90
|
-
return dashCase(innerAttr)
|
91
|
+
return `${dashCase(innerAttr)}="${attrs[dateTimeAttr]}" `;
|
91
92
|
} else {
|
92
|
-
return dashCase(innerAttr)
|
93
|
+
return `${dashCase(innerAttr)} `;
|
93
94
|
}
|
94
95
|
}
|
95
96
|
|
@@ -98,8 +99,10 @@ angular.module('ui.bootstrap.datetimepicker', ["ui.bootstrap.dateparser", "ui.bo
|
|
98
99
|
}
|
99
100
|
|
100
101
|
var dateTmpl = "<div class=\"datetimepicker-wrapper\">" +
|
101
|
-
"<input class=\"form-control\"
|
102
|
+
"<input class=\"form-control\" " +
|
103
|
+
"type=\"text\" " +
|
102
104
|
"name=\"datepicker\"" +
|
105
|
+
'aria-label="' + (attrs.name || attrs.ngModel).replace(/[\.,-]/g, ' ') + '"' +
|
103
106
|
"ng-change=\"date_change($event)\" " +
|
104
107
|
"is-open=\"innerDateOpened\" " +
|
105
108
|
"datepicker-options=\"dateOptions\" " +
|
@@ -114,9 +117,9 @@ angular.module('ui.bootstrap.datetimepicker', ["ui.bootstrap.dateparser", "ui.bo
|
|
114
117
|
["yearRange"],
|
115
118
|
["required"],
|
116
119
|
["showButtonBar"],
|
117
|
-
["ngHide", "
|
118
|
-
["ngReadonly", "
|
119
|
-
["ngDisabled", "
|
120
|
+
["ngHide", "hiddendate"],
|
121
|
+
["ngReadonly", "readonlydate"],
|
122
|
+
["ngDisabled", "disableddate"]
|
120
123
|
].reduce(createAttrConcat, '') +
|
121
124
|
createFuncAttr("ngClick",
|
122
125
|
"$event: $event, opened: opened",
|
@@ -143,8 +146,8 @@ angular.module('ui.bootstrap.datetimepicker', ["ui.bootstrap.dateparser", "ui.bo
|
|
143
146
|
["required"],
|
144
147
|
["meredians"],
|
145
148
|
["mousewheel"],
|
146
|
-
["ngHide", "
|
147
|
-
["ngDisabled", "
|
149
|
+
["ngHide", "hiddentime"],
|
150
|
+
["ngDisabled", "readonlytime"]
|
148
151
|
].reduce(createAttrConcat, '') +
|
149
152
|
createEvalAttr("showSpinners", "showSpinners") +
|
150
153
|
createEvalAttr("templateUrl", "timepickerTemplateUrl") +
|
@@ -156,6 +159,35 @@ angular.module('ui.bootstrap.datetimepicker', ["ui.bootstrap.dateparser", "ui.bo
|
|
156
159
|
},
|
157
160
|
controller: ['$scope', '$attrs',
|
158
161
|
function ($scope, $attrs) {
|
162
|
+
var form;
|
163
|
+
function getForm() {
|
164
|
+
if (!form) {
|
165
|
+
var workingScope = $scope;
|
166
|
+
while (typeof workingScope.topLevelFormName !== "string" && workingScope.$parent) {
|
167
|
+
workingScope = workingScope.$parent;
|
168
|
+
}
|
169
|
+
form = workingScope[workingScope.topLevelFormName];
|
170
|
+
}
|
171
|
+
}
|
172
|
+
getForm();
|
173
|
+
// ****************************************************
|
174
|
+
// HACK RIGHT HERE!
|
175
|
+
// For cases where formsAngular.elemSecurityFuncBinding is set to either "one-time" or "normal", the
|
176
|
+
// result of the call to handleReadOnlyDisabled() made by the fngUiBootstrapDatetimePicker directive might
|
177
|
+
// include reference(s) to two functions which our ancestor form scope should have been decorated with -
|
178
|
+
// isSecurelyDisabled and requiresDisabledChildren. Because our scope is isolated, these will be
|
179
|
+
// inaccessible to us unless we do the following...:
|
180
|
+
if (formsAngular.disabledSecurityFuncName) {
|
181
|
+
$scope.isSecurelyDisabled = $scope.$parent.isSecurelyDisabled;
|
182
|
+
$scope.requiresDisabledChildren = $scope.$parent.requiresDisabledChildren;
|
183
|
+
}
|
184
|
+
// as this is only going to work for disabled state arising from fng security, and not the case
|
185
|
+
// where an fng field has a string-valued readonly attribute that refers to a function on the parent
|
186
|
+
// scope, it's only a partial solution. the general solution would presumably be to replace our isolated
|
187
|
+
// scope definition with "scope:true", thus giving it full ancestor access. however, I gave
|
188
|
+
// that a quick try and found that it broke things, and it doesn't seem worth spending any more time
|
189
|
+
// on that right now.
|
190
|
+
// ****************************************************
|
159
191
|
$scope.date_change = function () {
|
160
192
|
// If we changed the date only, set the time (h,m) on it.
|
161
193
|
// This is important in case the previous date was null.
|
@@ -166,11 +198,19 @@ angular.module('ui.bootstrap.datetimepicker', ["ui.bootstrap.dateparser", "ui.bo
|
|
166
198
|
$scope.ngModel.setHours(time.getHours(), time.getMinutes(), 0, 0);
|
167
199
|
$scope.ngModel = new Date($scope.ngModel); // By default, ngModel watches the model by reference, not value. This is important to know when binding inputs to models that are objects (e.g. Date) (from: https://docs.angularjs.org/api/ng/directive/ngModel)
|
168
200
|
}
|
201
|
+
getForm();
|
202
|
+
if (form) {
|
203
|
+
form.$setDirty();
|
204
|
+
}
|
169
205
|
};
|
170
206
|
$scope.time_change = function () {
|
171
207
|
if ($scope.ngModel && $scope.time) {
|
172
208
|
$scope.ngModel.setHours($scope.time.getHours(), $scope.time.getMinutes(), 0, 0);
|
173
209
|
$scope.ngModel = new Date($scope.ngModel); // By default, ngModel watches the model by reference, not value. This is important to know when binding inputs to models that are objects (e.g. Date) (from: https://docs.angularjs.org/api/ng/directive/ngModel)
|
210
|
+
getForm();
|
211
|
+
if (form) {
|
212
|
+
form.$setDirty();
|
213
|
+
}
|
174
214
|
} // else the time is invalid, keep the current Date value in datepicker
|
175
215
|
};
|
176
216
|
$scope.open = function ($event) {
|
@@ -349,8 +389,8 @@ angular.module('ui.bootstrap.datetimepicker', ["ui.bootstrap.dateparser", "ui.bo
|
|
349
389
|
uiBootstrapDateModule.controller('fngUiBootstrapDatetimePickerCtrl',['$scope', function($scope) {
|
350
390
|
$scope.dateOptions = {};
|
351
391
|
}])
|
352
|
-
.directive('fngUiBootstrapDatetimePicker', ['$compile', '
|
353
|
-
function ($compile,
|
392
|
+
.directive('fngUiBootstrapDatetimePicker', ['$compile', 'PluginHelperService',
|
393
|
+
function ($compile, PluginHelperService) {
|
354
394
|
return {
|
355
395
|
restrict: 'E',
|
356
396
|
replace: true,
|
@@ -358,8 +398,8 @@ angular.module('ui.bootstrap.datetimepicker', ["ui.bootstrap.dateparser", "ui.bo
|
|
358
398
|
priority: 1,
|
359
399
|
link: function (scope, element, attrs) {
|
360
400
|
var template;
|
361
|
-
var
|
362
|
-
var
|
401
|
+
var processedAttrs = PluginHelperService.extractFromAttr(attrs, 'fngUiBootstrapDatetimePicker', scope);
|
402
|
+
var overriddenDefaults = {
|
363
403
|
'show-button-bar': false,
|
364
404
|
'show-meridian': false,
|
365
405
|
'date-format': 'dd/MM/yyyy'
|
@@ -378,25 +418,37 @@ angular.module('ui.bootstrap.datetimepicker', ["ui.bootstrap.dateparser", "ui.bo
|
|
378
418
|
}
|
379
419
|
});
|
380
420
|
|
381
|
-
|
382
|
-
var
|
421
|
+
overriddenDefaults = Object.assign({}, overriddenDefaults, processedAttrs.directiveOptions);
|
422
|
+
var overriddenDateDefaults = {
|
383
423
|
showWeeks: false
|
384
424
|
};
|
385
425
|
var jsonDateOptions = {};
|
386
|
-
if (
|
387
|
-
jsonDateOptions = JSON.parse(
|
426
|
+
if (processedAttrs.directiveOptions['date-options']) {
|
427
|
+
jsonDateOptions = JSON.parse(processedAttrs.directiveOptions['date-options'].replace(/'/g, '"'));
|
388
428
|
}
|
389
|
-
scope.dateOptions = Object.assign({},
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
429
|
+
scope.dateOptions = Object.assign({}, overriddenDateDefaults, jsonDateOptions);
|
430
|
+
|
431
|
+
const isArray = processedAttrs.info.array;
|
432
|
+
template = PluginHelperService.buildInputMarkup(
|
433
|
+
scope,
|
434
|
+
attrs,
|
435
|
+
{
|
436
|
+
processedAttrs,
|
437
|
+
addButtons: isArray,
|
438
|
+
needsX: isArray,
|
439
|
+
},
|
440
|
+
function (buildingBlocks) {
|
441
|
+
var str = '<div class="dtwrap"><datetimepicker ' + buildingBlocks.common.trim();
|
442
|
+
for (var opt in overriddenDefaults) {
|
443
|
+
if (opt !== 'date-options') {
|
444
|
+
str += ` ${opt}="${overriddenDefaults[opt]}"`;
|
445
|
+
}
|
395
446
|
}
|
447
|
+
str += " " + PluginHelperService.genDateTimePickerDisabledStr(scope, processedAttrs, "");
|
448
|
+
str += ' date-options="dateOptions"></datetimepicker></div>';
|
449
|
+
return str;
|
396
450
|
}
|
397
|
-
|
398
|
-
return str;
|
399
|
-
});
|
451
|
+
);
|
400
452
|
element.replaceWith($compile(template)(scope));
|
401
453
|
}
|
402
454
|
};
|