forms-angular 0.12.0-beta.300 → 0.12.0-beta.302
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.
|
@@ -3649,7 +3649,8 @@ var fng;
|
|
|
3649
3649
|
// TODO: Put this in a service
|
|
3650
3650
|
var makeMongoId = function (rnd) {
|
|
3651
3651
|
if (rnd === void 0) { rnd = function (r16) { return Math.floor(r16).toString(16); }; }
|
|
3652
|
-
return rnd(Date.now() / 1000) +
|
|
3652
|
+
return rnd(Date.now() / 1000) +
|
|
3653
|
+
" ".repeat(16).replace(/./g, function () { return rnd(Math.random() * 16); });
|
|
3653
3654
|
};
|
|
3654
3655
|
function _handleCancel(resp) {
|
|
3655
3656
|
if (["cancel", "backdrop click", "escape key press"].indexOf(resp) === -1) {
|
|
@@ -3700,7 +3701,7 @@ var fng;
|
|
|
3700
3701
|
}
|
|
3701
3702
|
return {
|
|
3702
3703
|
lastObject: workingRec,
|
|
3703
|
-
key: workingRec ? parts[higherLevels] : undefined
|
|
3704
|
+
key: workingRec ? parts[higherLevels] : undefined,
|
|
3704
3705
|
};
|
|
3705
3706
|
};
|
|
3706
3707
|
var setData = function setData(object, fieldname, element, value) {
|
|
@@ -3739,7 +3740,9 @@ var fng;
|
|
|
3739
3740
|
var updateRecordWithLookupValues = function (schemaElement, $scope, ctrlState, ignoreDirty) {
|
|
3740
3741
|
if (ignoreDirty === void 0) { ignoreDirty = false; }
|
|
3741
3742
|
// Update the master and the record with the lookup values, master first
|
|
3742
|
-
if (!$scope.topLevelFormName ||
|
|
3743
|
+
if (!$scope.topLevelFormName ||
|
|
3744
|
+
($scope[$scope.topLevelFormName] &&
|
|
3745
|
+
(ignoreDirty || $scope[$scope.topLevelFormName].$pristine))) {
|
|
3743
3746
|
updateObject(schemaElement.name, ctrlState.master, function (value) {
|
|
3744
3747
|
if (typeof value == "object" && value.id) {
|
|
3745
3748
|
return value;
|
|
@@ -3768,7 +3771,7 @@ var fng;
|
|
|
3768
3771
|
var retVal = getData(record, fieldName) || "";
|
|
3769
3772
|
if (retVal && listSchema) {
|
|
3770
3773
|
// Convert list fields as per instructions in params (ideally should be the same as what is found in data_form getListFields
|
|
3771
|
-
var schemaElm = _.find(listSchema, function (elm) { return
|
|
3774
|
+
var schemaElm = _.find(listSchema, function (elm) { return elm["name"] === fieldName; });
|
|
3772
3775
|
if (schemaElm) {
|
|
3773
3776
|
switch (schemaElm["params"]) {
|
|
3774
3777
|
case undefined:
|
|
@@ -3776,7 +3779,8 @@ var fng;
|
|
|
3776
3779
|
case "timestamp":
|
|
3777
3780
|
var timestamp = retVal.toString().substring(0, 8);
|
|
3778
3781
|
var date = new Date(parseInt(timestamp, 16) * 1000);
|
|
3779
|
-
retVal =
|
|
3782
|
+
retVal =
|
|
3783
|
+
date.toLocaleDateString() + " " + date.toLocaleTimeString();
|
|
3780
3784
|
break;
|
|
3781
3785
|
default:
|
|
3782
3786
|
retVal = $scope.dataEventFunctions[schemaElm["params"]](record);
|
|
@@ -3796,7 +3800,8 @@ var fng;
|
|
|
3796
3800
|
if (angular.isArray(theValue)) {
|
|
3797
3801
|
for (var i = theValue.length - 1; i >= 0; i--) {
|
|
3798
3802
|
var type = typeof theValue[i];
|
|
3799
|
-
if (type === "undefined" ||
|
|
3803
|
+
if (type === "undefined" ||
|
|
3804
|
+
(type === "object" && Object.keys(theValue[i]).length === 0)) {
|
|
3800
3805
|
theValue.splice(i, 1);
|
|
3801
3806
|
}
|
|
3802
3807
|
}
|
|
@@ -3818,11 +3823,11 @@ var fng;
|
|
|
3818
3823
|
}
|
|
3819
3824
|
// Set up the lookup lists (value and id) on the scope for an internal lookup. Called by convertToAngularModel and $watch
|
|
3820
3825
|
function setUpInternalLookupLists($scope, options, ids, newVal, valueAttrib) {
|
|
3821
|
-
var optionsArray =
|
|
3822
|
-
var idsArray =
|
|
3826
|
+
var optionsArray = typeof options === "string" ? $scope[options] : options;
|
|
3827
|
+
var idsArray = typeof ids === "string" ? $scope[ids] : ids;
|
|
3823
3828
|
optionsArray.length = 0;
|
|
3824
3829
|
idsArray.length = 0;
|
|
3825
|
-
if (!!newVal &&
|
|
3830
|
+
if (!!newVal && newVal.length > 0) {
|
|
3826
3831
|
newVal.forEach(function (a) {
|
|
3827
3832
|
var value = a[valueAttrib];
|
|
3828
3833
|
if (value && value.length > 0) {
|
|
@@ -3866,10 +3871,10 @@ var fng;
|
|
|
3866
3871
|
var schemaEntry = schema[i];
|
|
3867
3872
|
var fieldName = schemaEntry.name.slice(prefixLength);
|
|
3868
3873
|
if (!fieldName.length) {
|
|
3869
|
-
fieldName = schemaEntry.name.split(
|
|
3874
|
+
fieldName = schemaEntry.name.split(".").pop();
|
|
3870
3875
|
}
|
|
3871
3876
|
var fieldValue = getData(anObject, fieldName);
|
|
3872
|
-
if (schemaEntry.intType ===
|
|
3877
|
+
if (schemaEntry.intType === "date" && typeof fieldValue === "string") {
|
|
3873
3878
|
setData(anObject, fieldName, null, new Date(fieldValue));
|
|
3874
3879
|
}
|
|
3875
3880
|
if (schemaEntry.schema) {
|
|
@@ -3911,9 +3916,10 @@ var fng;
|
|
|
3911
3916
|
else if (schemaEntry.select2) {
|
|
3912
3917
|
// Do nothing with these - handled elsewhere (and deprecated)
|
|
3913
3918
|
console.log("fng-select2 is deprecated - use fng-ui-select instead");
|
|
3914
|
-
void
|
|
3919
|
+
void schemaEntry.select2;
|
|
3915
3920
|
}
|
|
3916
|
-
else if (fieldValue &&
|
|
3921
|
+
else if (fieldValue &&
|
|
3922
|
+
(thisConversion = getConversionObject($scope, fieldName, schemaName)) &&
|
|
3917
3923
|
thisConversion.fngajax &&
|
|
3918
3924
|
typeof thisConversion.fngajax === "function" && // if the field is securely hidden, the directive won't have been invoked at all and therefore the conversion will not have been initialised. but if it's hidden, we don't need to do the conversion anyway
|
|
3919
3925
|
!thisConversion.noconvert) {
|
|
@@ -3935,7 +3941,8 @@ var fng;
|
|
|
3935
3941
|
function convertForeignKeys(schemaElement, input, values, ids) {
|
|
3936
3942
|
if (schemaElement.array || angular.isArray(input)) {
|
|
3937
3943
|
var returnArray = [];
|
|
3938
|
-
var needsX = schemaElement.array &&
|
|
3944
|
+
var needsX = schemaElement.array &&
|
|
3945
|
+
(!schemaElement.directive || simpleArrayNeedsX(schemaElement));
|
|
3939
3946
|
for (var j = 0; j < input.length; j++) {
|
|
3940
3947
|
var val = input[j];
|
|
3941
3948
|
if (val && val.x) {
|
|
@@ -3950,7 +3957,10 @@ var fng;
|
|
|
3950
3957
|
return returnArray;
|
|
3951
3958
|
}
|
|
3952
3959
|
else if (schemaElement.select2) {
|
|
3953
|
-
return {
|
|
3960
|
+
return {
|
|
3961
|
+
id: input,
|
|
3962
|
+
text: convertIdToListValue(input, ids, values, schemaElement.name),
|
|
3963
|
+
};
|
|
3954
3964
|
}
|
|
3955
3965
|
else {
|
|
3956
3966
|
return convertIdToListValue(input, ids, values, schemaElement.name);
|
|
@@ -3972,14 +3982,21 @@ var fng;
|
|
|
3972
3982
|
}
|
|
3973
3983
|
}
|
|
3974
3984
|
var convertListValueToId = function (value, valuesArray, idsArray, fname) {
|
|
3975
|
-
var textToConvert = _.isObject(value)
|
|
3985
|
+
var textToConvert = _.isObject(value)
|
|
3986
|
+
? value.x || value.text
|
|
3987
|
+
: value;
|
|
3976
3988
|
if (textToConvert && textToConvert.match(/^[0-9a-f]{24}$/)) {
|
|
3977
3989
|
return textToConvert; // a plugin probably added this
|
|
3978
3990
|
}
|
|
3979
3991
|
else {
|
|
3980
3992
|
var index = valuesArray.indexOf(textToConvert);
|
|
3981
3993
|
if (index === -1) {
|
|
3982
|
-
throw new Error("convertListValueToId: Invalid data - value " +
|
|
3994
|
+
throw new Error("convertListValueToId: Invalid data - value " +
|
|
3995
|
+
textToConvert +
|
|
3996
|
+
" not found in " +
|
|
3997
|
+
valuesArray +
|
|
3998
|
+
" processing " +
|
|
3999
|
+
fname);
|
|
3983
4000
|
}
|
|
3984
4001
|
return idsArray[index];
|
|
3985
4002
|
}
|
|
@@ -3988,7 +4005,7 @@ var fng;
|
|
|
3988
4005
|
// stop the form being set to dirty when a fn is called
|
|
3989
4006
|
// Use when the record (and master) need to be updated by lookup values displayed asynchronously
|
|
3990
4007
|
var modelController = element.inheritedData("$ngModelController");
|
|
3991
|
-
var isClean =
|
|
4008
|
+
var isClean = modelController && modelController.$pristine;
|
|
3992
4009
|
if (isClean) {
|
|
3993
4010
|
// fake it to dirty here and reset after call to fn
|
|
3994
4011
|
modelController.$pristine = false;
|
|
@@ -3999,14 +4016,19 @@ var fng;
|
|
|
3999
4016
|
}
|
|
4000
4017
|
};
|
|
4001
4018
|
var convertIdToListValue = function convertIdToListValue(id, idsArray, valuesArray, fname) {
|
|
4002
|
-
if (typeof
|
|
4019
|
+
if (typeof id === "object") {
|
|
4003
4020
|
id = id.id;
|
|
4004
4021
|
}
|
|
4005
4022
|
var index = idsArray.indexOf(id);
|
|
4006
4023
|
if (index === -1) {
|
|
4007
4024
|
index = valuesArray.indexOf(id); // This can get called twice - second time with converted value (not sure how atm) so protect against that...
|
|
4008
4025
|
if (index === -1) {
|
|
4009
|
-
throw new Error("convertIdToListValue: Invalid data - id " +
|
|
4026
|
+
throw new Error("convertIdToListValue: Invalid data - id " +
|
|
4027
|
+
id +
|
|
4028
|
+
" not found in " +
|
|
4029
|
+
idsArray +
|
|
4030
|
+
" processing " +
|
|
4031
|
+
fname);
|
|
4010
4032
|
}
|
|
4011
4033
|
}
|
|
4012
4034
|
return valuesArray[index];
|
|
@@ -4018,7 +4040,10 @@ var fng;
|
|
|
4018
4040
|
};
|
|
4019
4041
|
function convertOldToNew(ref, val, attrib, newVals, oldVals) {
|
|
4020
4042
|
// check this is a change to an existing value, rather than a new one or one being deleted
|
|
4021
|
-
if (oldVals &&
|
|
4043
|
+
if (oldVals &&
|
|
4044
|
+
oldVals.length > 0 &&
|
|
4045
|
+
oldVals.length === newVals.length &&
|
|
4046
|
+
val[attrib]) {
|
|
4022
4047
|
var index = oldVals.findIndex(function (a) { return a[ref.value] === val[attrib]; });
|
|
4023
4048
|
if (index > -1) {
|
|
4024
4049
|
var newVal = newVals[index][ref.value];
|
|
@@ -4029,8 +4054,9 @@ var fng;
|
|
|
4029
4054
|
}
|
|
4030
4055
|
}
|
|
4031
4056
|
function fillFormFromBackendCustomSchema(schema, $scope, formGeneratorInstance, recordHandlerInstance, ctrlState) {
|
|
4032
|
-
var listOnly =
|
|
4033
|
-
if ($scope.id &&
|
|
4057
|
+
var listOnly = !$scope.id && !$scope.newRecord;
|
|
4058
|
+
if ($scope.id &&
|
|
4059
|
+
typeof $scope.dataEventFunctions.onBeforeRead !== "function") {
|
|
4034
4060
|
// Get started with reading the record now. We'll wait for the promise to resolve later, in finishReadingThenProcessRecord().
|
|
4035
4061
|
// We DON'T do this when an onBeforeRead hook is provided - in that case, we'll call beginReadingRecord() immediately before
|
|
4036
4062
|
// calling finishReadingThenProcessRecord(), later...
|
|
@@ -4046,12 +4072,15 @@ var fng;
|
|
|
4046
4072
|
var oldVal = oldValue[lkp.ref.property];
|
|
4047
4073
|
setUpInternalLookupLists($scope, lkp.lookupOptions, lkp.lookupIds, newVal, lkp.ref.value);
|
|
4048
4074
|
// now change the looked-up values that matched the old to the new
|
|
4049
|
-
if ((newVal && newVal.length > 0) ||
|
|
4075
|
+
if ((newVal && newVal.length > 0) ||
|
|
4076
|
+
(oldVal && oldVal.length > 0)) {
|
|
4050
4077
|
lkp.handlers.forEach(function (h) {
|
|
4051
4078
|
if (h.possibleArray) {
|
|
4052
4079
|
var arr = getData($scope.record, h.possibleArray, null);
|
|
4053
4080
|
if (arr && arr.length > 0) {
|
|
4054
|
-
arr.forEach(function (a) {
|
|
4081
|
+
arr.forEach(function (a) {
|
|
4082
|
+
return convertOldToNew(lkp.ref, a, h.lastPart, newVal, oldVal);
|
|
4083
|
+
});
|
|
4055
4084
|
}
|
|
4056
4085
|
}
|
|
4057
4086
|
else if (angular.isArray($scope.record[h.lastPart])) {
|
|
@@ -4094,7 +4123,8 @@ var fng;
|
|
|
4094
4123
|
});
|
|
4095
4124
|
}
|
|
4096
4125
|
else {
|
|
4097
|
-
h.oldId =
|
|
4126
|
+
h.oldId =
|
|
4127
|
+
$scope[h.formInstructions.ids][$scope[h.formInstructions.options].indexOf(h.oldValue)];
|
|
4098
4128
|
}
|
|
4099
4129
|
});
|
|
4100
4130
|
}
|
|
@@ -4175,12 +4205,13 @@ var fng;
|
|
|
4175
4205
|
}
|
|
4176
4206
|
$scope.$watch("record", function (newValue, oldValue) {
|
|
4177
4207
|
if (newValue !== oldValue) {
|
|
4178
|
-
if (Object.keys(oldValue).length > 0 &&
|
|
4208
|
+
if (Object.keys(oldValue).length > 0 &&
|
|
4209
|
+
$scope.dropConversionWatcher) {
|
|
4179
4210
|
// We don't want to convert changed data, so we need to stop watching the conversions
|
|
4180
4211
|
// after the record has finished its initialisation and this watch has begun detecting actual changes.
|
|
4181
4212
|
// In some rare cases, it is possible that a "change" to the record can be made programatically
|
|
4182
|
-
// before all of the directives that might need to add conversions have finished doing so.
|
|
4183
|
-
// This can happen in situations where promise resolutions interrupt the compilation process.
|
|
4213
|
+
// before all of the directives that might need to add conversions have finished doing so.
|
|
4214
|
+
// This can happen in situations where promise resolutions interrupt the compilation process.
|
|
4184
4215
|
// If we're not careful, we can end up with <select> inputs that are blank even when the underlying
|
|
4185
4216
|
// field does have a value.
|
|
4186
4217
|
// To avoid this, we'll use a $timeout to give for the digest queue to fully clear out - this should
|
|
@@ -4194,9 +4225,9 @@ var fng;
|
|
|
4194
4225
|
force = formGeneratorInstance.updateDataDependentDisplay(newValue, oldValue, force, $scope);
|
|
4195
4226
|
processLookupHandlers(newValue, oldValue);
|
|
4196
4227
|
if (fng.formsAngular.title) {
|
|
4197
|
-
var title = fng.formsAngular.title.prefix ||
|
|
4198
|
-
if ($scope[
|
|
4199
|
-
title += $scope[
|
|
4228
|
+
var title = fng.formsAngular.title.prefix || "";
|
|
4229
|
+
if ($scope["editFormHeader"]) {
|
|
4230
|
+
title += $scope["editFormHeader"]();
|
|
4200
4231
|
}
|
|
4201
4232
|
else {
|
|
4202
4233
|
for (var listElm in $scope.listSchema) {
|
|
@@ -4205,11 +4236,12 @@ var fng;
|
|
|
4205
4236
|
if (typeof listVal === "object") {
|
|
4206
4237
|
return;
|
|
4207
4238
|
}
|
|
4208
|
-
title +=
|
|
4239
|
+
title +=
|
|
4240
|
+
$scope.getListData($scope.record, $scope.listSchema[listElm].name) + " ";
|
|
4209
4241
|
}
|
|
4210
4242
|
}
|
|
4211
4243
|
}
|
|
4212
|
-
title = title.trimEnd() + (fng.formsAngular.title.suffix ||
|
|
4244
|
+
title = title.trimEnd() + (fng.formsAngular.title.suffix || "");
|
|
4213
4245
|
$window.document.title = title.replace(/<\/?[^>]+(>|$)/g, "");
|
|
4214
4246
|
}
|
|
4215
4247
|
}
|
|
@@ -4254,7 +4286,8 @@ var fng;
|
|
|
4254
4286
|
console.log("Error parsing specified record : " + e.message);
|
|
4255
4287
|
}
|
|
4256
4288
|
}
|
|
4257
|
-
if (typeof $scope.dataEventFunctions.onInitialiseNewRecord ===
|
|
4289
|
+
if (typeof $scope.dataEventFunctions.onInitialiseNewRecord ===
|
|
4290
|
+
"function") {
|
|
4258
4291
|
console.log("onInitialiseNewRecord is deprecated - use the async version - onNewRecordInit(data,cb)");
|
|
4259
4292
|
$scope.dataEventFunctions.onInitialiseNewRecord(ctrlState.master);
|
|
4260
4293
|
}
|
|
@@ -4281,10 +4314,12 @@ var fng;
|
|
|
4281
4314
|
if (response.data && response.data.errors) {
|
|
4282
4315
|
for (var errorField in response.data.errors) {
|
|
4283
4316
|
if (response.data.errors.hasOwnProperty(errorField)) {
|
|
4284
|
-
errorMessage +=
|
|
4317
|
+
errorMessage +=
|
|
4318
|
+
"<li><b>" + $filter("titleCase")(errorField) + ": </b> ";
|
|
4285
4319
|
switch (response.data.errors[errorField].type) {
|
|
4286
4320
|
case "enum":
|
|
4287
|
-
errorMessage +=
|
|
4321
|
+
errorMessage +=
|
|
4322
|
+
"You need to select from the list of values";
|
|
4288
4323
|
break;
|
|
4289
4324
|
default:
|
|
4290
4325
|
errorMessage += response.data.errors[errorField].message;
|
|
@@ -4295,10 +4330,18 @@ var fng;
|
|
|
4295
4330
|
}
|
|
4296
4331
|
}
|
|
4297
4332
|
if (errorMessage.length > 0) {
|
|
4298
|
-
errorMessage =
|
|
4333
|
+
errorMessage =
|
|
4334
|
+
(response.data.message || response.data._message) +
|
|
4335
|
+
"<br /><ul>" +
|
|
4336
|
+
errorMessage +
|
|
4337
|
+
"</ul>";
|
|
4299
4338
|
}
|
|
4300
4339
|
else {
|
|
4301
|
-
errorMessage =
|
|
4340
|
+
errorMessage =
|
|
4341
|
+
response.data.message ||
|
|
4342
|
+
response.data._message ||
|
|
4343
|
+
response.data.err ||
|
|
4344
|
+
"Error! Sorry - No further details available.";
|
|
4302
4345
|
}
|
|
4303
4346
|
// anyone using a watch on $scope.phase, and waiting for it to become "ready" before proceeding, will probably
|
|
4304
4347
|
// want to know that an error has occurred. This value is NOT used anywhere in forms-angular.
|
|
@@ -4306,9 +4349,7 @@ var fng;
|
|
|
4306
4349
|
$scope.showError(errorMessage);
|
|
4307
4350
|
}
|
|
4308
4351
|
else if (response.status === 404) {
|
|
4309
|
-
$location
|
|
4310
|
-
.search({})
|
|
4311
|
-
.path('/404');
|
|
4352
|
+
$location.search({}).path("/404");
|
|
4312
4353
|
}
|
|
4313
4354
|
else {
|
|
4314
4355
|
var msg = response.data;
|
|
@@ -4339,14 +4380,14 @@ var fng;
|
|
|
4339
4380
|
var thisHandler = {
|
|
4340
4381
|
formInstructions: formInstructions,
|
|
4341
4382
|
lastPart: nameElements.pop(),
|
|
4342
|
-
possibleArray: nameElements.join(".")
|
|
4383
|
+
possibleArray: nameElements.join("."),
|
|
4343
4384
|
};
|
|
4344
4385
|
if (!refHandler) {
|
|
4345
4386
|
refHandler = {
|
|
4346
4387
|
ref: ref,
|
|
4347
4388
|
lookupOptions: [],
|
|
4348
4389
|
lookupIds: [],
|
|
4349
|
-
handlers: []
|
|
4390
|
+
handlers: [],
|
|
4350
4391
|
};
|
|
4351
4392
|
lookups.push(refHandler);
|
|
4352
4393
|
}
|
|
@@ -4378,12 +4419,16 @@ var fng;
|
|
|
4378
4419
|
}); },
|
|
4379
4420
|
finishReadingThenProcessRecord: function ($scope, ctrlState) {
|
|
4380
4421
|
var multi = typeof fng.formsAngular.beforeHandleIncomingDataPromises === "function";
|
|
4381
|
-
var promise = multi
|
|
4382
|
-
Promise.all(__spreadArray([
|
|
4383
|
-
|
|
4422
|
+
var promise = multi
|
|
4423
|
+
? Promise.all(__spreadArray([
|
|
4424
|
+
$scope.readingRecord
|
|
4425
|
+
], fng.formsAngular.beforeHandleIncomingDataPromises(), true))
|
|
4426
|
+
: $scope.readingRecord;
|
|
4384
4427
|
promise
|
|
4385
4428
|
.then(function (response) {
|
|
4386
|
-
var data = multi
|
|
4429
|
+
var data = multi
|
|
4430
|
+
? angular.copy(response[0].data)
|
|
4431
|
+
: response.data;
|
|
4387
4432
|
handleIncomingData(data, $scope, ctrlState);
|
|
4388
4433
|
})
|
|
4389
4434
|
.catch(function (e) {
|
|
@@ -4408,16 +4453,16 @@ var fng;
|
|
|
4408
4453
|
limit: $scope.pageSize,
|
|
4409
4454
|
skip: pagesLoaded * $scope.pageSize,
|
|
4410
4455
|
order: $location.$$search.o,
|
|
4411
|
-
concatenate: false
|
|
4412
|
-
})
|
|
4413
|
-
.then(function (response) {
|
|
4456
|
+
concatenate: false,
|
|
4457
|
+
}).then(function (response) {
|
|
4414
4458
|
var data = response.data;
|
|
4415
4459
|
if (angular.isArray(data)) {
|
|
4416
4460
|
// if the options for the resource identified by $scope.modelName has disambiguation parameters,
|
|
4417
4461
|
// and that resource has more than one list field, the items returned by getPagedAndFilteredList
|
|
4418
4462
|
// might include a "disambiguation" property. for this to appear on the list page, we need
|
|
4419
4463
|
// to add an item for it to the list schema
|
|
4420
|
-
if (!$scope.listSchema.find(function (f) { return f.name === "disambiguation"; }) &&
|
|
4464
|
+
if (!$scope.listSchema.find(function (f) { return f.name === "disambiguation"; }) &&
|
|
4465
|
+
data.some(function (d) { return d.disambiguation; })) {
|
|
4421
4466
|
$scope.listSchema.push({
|
|
4422
4467
|
name: "disambiguation",
|
|
4423
4468
|
});
|
|
@@ -4428,7 +4473,8 @@ var fng;
|
|
|
4428
4473
|
$scope.recordList = $scope.recordList.concat(data);
|
|
4429
4474
|
}
|
|
4430
4475
|
else {
|
|
4431
|
-
console.log("DEBUG: infinite scroll component asked for a page twice - the model was " +
|
|
4476
|
+
console.log("DEBUG: infinite scroll component asked for a page twice - the model was " +
|
|
4477
|
+
$scope.modelName);
|
|
4432
4478
|
}
|
|
4433
4479
|
}
|
|
4434
4480
|
else {
|
|
@@ -4438,8 +4484,7 @@ var fng;
|
|
|
4438
4484
|
},
|
|
4439
4485
|
deleteRecord: function deleteRecord(id, $scope, ctrlState) {
|
|
4440
4486
|
$scope.phase = "deleting";
|
|
4441
|
-
SubmissionsService.deleteRecord($scope.modelName, id, $scope.formName)
|
|
4442
|
-
.then(function () {
|
|
4487
|
+
SubmissionsService.deleteRecord($scope.modelName, id, $scope.formName).then(function () {
|
|
4443
4488
|
if (typeof $scope.dataEventFunctions.onAfterDelete === "function") {
|
|
4444
4489
|
$scope.dataEventFunctions.onAfterDelete(ctrlState.master);
|
|
4445
4490
|
}
|
|
@@ -4451,17 +4496,16 @@ var fng;
|
|
|
4451
4496
|
RoutingService.redirectTo()("onDelete", $scope, $location);
|
|
4452
4497
|
}
|
|
4453
4498
|
else if (err.status === 403) {
|
|
4454
|
-
$scope.showError(((_a = err.data) === null || _a === void 0 ? void 0 : _a.message) || err.message || err.data || err,
|
|
4499
|
+
$scope.showError(((_a = err.data) === null || _a === void 0 ? void 0 : _a.message) || err.message || err.data || err, "Permission denied");
|
|
4455
4500
|
}
|
|
4456
4501
|
else {
|
|
4457
|
-
$scope.showError("".concat(err.statusText, " (").concat(err.status, ") while deleting record<br />").concat(err.data),
|
|
4502
|
+
$scope.showError("".concat(err.statusText, " (").concat(err.status, ") while deleting record<br />").concat(err.data), "Error deleting record");
|
|
4458
4503
|
}
|
|
4459
4504
|
});
|
|
4460
4505
|
},
|
|
4461
4506
|
updateDocument: function updateDocument(dataToSave, options, $scope, ctrlState) {
|
|
4462
4507
|
$scope.phase = "updating";
|
|
4463
|
-
SubmissionsService.updateRecord($scope.modelName, $scope.id, dataToSave, $scope.formName)
|
|
4464
|
-
.then(function (response) {
|
|
4508
|
+
SubmissionsService.updateRecord($scope.modelName, $scope.id, dataToSave, $scope.formName).then(function (response) {
|
|
4465
4509
|
var data = response.data;
|
|
4466
4510
|
if (data.success !== false) {
|
|
4467
4511
|
if (typeof $scope.dataEventFunctions.onAfterUpdate === "function") {
|
|
@@ -4484,14 +4528,14 @@ var fng;
|
|
|
4484
4528
|
}, function (err) {
|
|
4485
4529
|
var _a, _b;
|
|
4486
4530
|
if ((_b = (_a = err.data) === null || _a === void 0 ? void 0 : _a.message) === null || _b === void 0 ? void 0 : _b.match(/^No matching document found for id "[0-9a-f]{24}" version [\d]+ modifiedPaths "/)) {
|
|
4487
|
-
err.data.message =
|
|
4531
|
+
err.data.message =
|
|
4532
|
+
"This record has been modified by somebody else since it was read. To prevent your change overwriting theirs your update has been rejected. You will have to refresh the form and re-do your work. Sorry for the inconvenience.";
|
|
4488
4533
|
}
|
|
4489
4534
|
$scope.handleHttpError(err);
|
|
4490
4535
|
});
|
|
4491
4536
|
},
|
|
4492
4537
|
createNew: function createNew(dataToSave, options, $scope, ctrlState) {
|
|
4493
|
-
SubmissionsService.createRecord($scope.modelName, dataToSave, $scope.formName)
|
|
4494
|
-
.then(function (response) {
|
|
4538
|
+
SubmissionsService.createRecord($scope.modelName, dataToSave, $scope.formName).then(function (response) {
|
|
4495
4539
|
var data = response.data;
|
|
4496
4540
|
if (data.success !== false) {
|
|
4497
4541
|
ctrlState.allowLocationChange = true;
|
|
@@ -4515,8 +4559,8 @@ var fng;
|
|
|
4515
4559
|
getData: getData,
|
|
4516
4560
|
setData: setData,
|
|
4517
4561
|
setUpLookupOptions: function setUpLookupOptions(lookupCollection, schemaElement, $scope, ctrlState) {
|
|
4518
|
-
var optionsList = $scope[schemaElement.options] = [];
|
|
4519
|
-
var idList = $scope[schemaElement.ids] = [];
|
|
4562
|
+
var optionsList = ($scope[schemaElement.options] = []);
|
|
4563
|
+
var idList = ($scope[schemaElement.ids] = []);
|
|
4520
4564
|
var dataRequest = !!schemaElement.filter
|
|
4521
4565
|
? SubmissionsService.getPagedAndFilteredList(lookupCollection, Object.assign({ concatenate: true }, schemaElement.filter)) // { concatenate: true } causes it to concatenate the list fields into the .text property of ILookupItem objects
|
|
4522
4566
|
: SubmissionsService.getAllListAttributes(lookupCollection);
|
|
@@ -4544,8 +4588,7 @@ var fng;
|
|
|
4544
4588
|
}
|
|
4545
4589
|
});
|
|
4546
4590
|
if ($scope.readingRecord) {
|
|
4547
|
-
$scope.readingRecord
|
|
4548
|
-
.then(function () {
|
|
4591
|
+
$scope.readingRecord.then(function () {
|
|
4549
4592
|
updateRecordWithLookupValues(schemaElement, $scope, ctrlState);
|
|
4550
4593
|
});
|
|
4551
4594
|
}
|
|
@@ -4556,8 +4599,8 @@ var fng;
|
|
|
4556
4599
|
});
|
|
4557
4600
|
},
|
|
4558
4601
|
setUpLookupListOptions: function setUpLookupListOptions(ref, formInstructions, $scope, ctrlState) {
|
|
4559
|
-
var optionsList = $scope[formInstructions.options] = [];
|
|
4560
|
-
var idList = $scope[formInstructions.ids] = [];
|
|
4602
|
+
var optionsList = ($scope[formInstructions.options] = []);
|
|
4603
|
+
var idList = ($scope[formInstructions.ids] = []);
|
|
4561
4604
|
if (ref.id[0] === "$") {
|
|
4562
4605
|
// id of document that contains out lookup list comes from record, so we need to deal with in $watch by adding it to listLookups
|
|
4563
4606
|
addArrayLookupToLookupList($scope, formInstructions, ref, $scope.listLookups);
|
|
@@ -4702,17 +4745,18 @@ var fng;
|
|
|
4702
4745
|
$scope.clearTimeout();
|
|
4703
4746
|
}
|
|
4704
4747
|
if ($scope.errorMessage) {
|
|
4705
|
-
$scope.errorMessage +=
|
|
4748
|
+
$scope.errorMessage += "<br /><br />";
|
|
4706
4749
|
}
|
|
4707
4750
|
else {
|
|
4708
|
-
$scope.errorMessage =
|
|
4751
|
+
$scope.errorMessage = "";
|
|
4709
4752
|
}
|
|
4710
4753
|
$scope.errorMessage += generateErrorText();
|
|
4711
4754
|
$scope.alertTitle = alertTitle ? alertTitle : "Error!";
|
|
4712
4755
|
$scope.errorHideTimer = window.setTimeout(function () {
|
|
4713
4756
|
$scope.dismissError();
|
|
4714
4757
|
$scope.$digest();
|
|
4715
|
-
}, 3500 +
|
|
4758
|
+
}, 3500 +
|
|
4759
|
+
(1000 * ($scope.alertTitle + $scope.errorMessage).length) / 50);
|
|
4716
4760
|
$scope.errorVisible = true;
|
|
4717
4761
|
window.setTimeout(function () {
|
|
4718
4762
|
$scope.$digest();
|
|
@@ -4812,7 +4856,7 @@ var fng;
|
|
|
4812
4856
|
var modalInstance = $uibModal.open({
|
|
4813
4857
|
template: "<div class=\"modal-header\">\n <h3>Record modified</h3>\n</div>\n<div class=\"modal-body\">\n <p>Would you like to save your changes?</p>\n</div>\n<div class=\"modal-footer\">\n <button class=\"btn btn-primary dlg-yes\" ng-click=\"yes()\">Yes</button>\n <button class=\"btn btn-warning dlg-no\" ng-click=\"no()\">No</button>\n <button class=\"btn dlg-cancel\" ng-click=\"cancel()\">Cancel</button>\n</div>",
|
|
4814
4858
|
controller: "SaveChangesModalCtrl",
|
|
4815
|
-
backdrop: "static"
|
|
4859
|
+
backdrop: "static",
|
|
4816
4860
|
});
|
|
4817
4861
|
modalInstance.result
|
|
4818
4862
|
.then(function (result) {
|
|
@@ -4827,6 +4871,16 @@ var fng;
|
|
|
4827
4871
|
.catch(_handleCancel);
|
|
4828
4872
|
}
|
|
4829
4873
|
});
|
|
4874
|
+
window.onbeforeunload = function (event) {
|
|
4875
|
+
if (!ctrlState.allowLocationChange && !$scope.isCancelDisabled()) {
|
|
4876
|
+
if (!confirm("You have unsaved changes. Do you really want to lose them?")) {
|
|
4877
|
+
event.preventDefault();
|
|
4878
|
+
}
|
|
4879
|
+
}
|
|
4880
|
+
};
|
|
4881
|
+
$scope.$on("$destroy", function () {
|
|
4882
|
+
window.onbeforeunload = null;
|
|
4883
|
+
});
|
|
4830
4884
|
$scope.deleteClick = function () {
|
|
4831
4885
|
if ($scope.record._id) {
|
|
4832
4886
|
var confirmDelete = void 0;
|
|
@@ -4837,16 +4891,18 @@ var fng;
|
|
|
4837
4891
|
var modalInstance = $uibModal.open({
|
|
4838
4892
|
template: "<div class=\"modal-header\">\n <h3>Delete Item</h3>\n</div>\n<div class=\"modal-body\">\n <p>Are you sure you want to delete this record?</p>\n</div>\n<div class=\"modal-footer\">\n <button class=\"btn btn-primary dlg-no\" ng-click=\"cancel()\">No</button>\n <button class=\"btn btn-warning dlg-yes\" ng-click=\"yes()\">Yes</button>\n</div>",
|
|
4839
4893
|
controller: "SaveChangesModalCtrl",
|
|
4840
|
-
backdrop: "static"
|
|
4894
|
+
backdrop: "static",
|
|
4841
4895
|
});
|
|
4842
4896
|
confirmDelete = modalInstance.result;
|
|
4843
4897
|
}
|
|
4844
|
-
confirmDelete
|
|
4898
|
+
confirmDelete
|
|
4899
|
+
.then(function (result) {
|
|
4845
4900
|
function doTheDeletion() {
|
|
4846
4901
|
recordHandlerInstance.deleteRecord($scope.id, $scope, ctrlState);
|
|
4847
4902
|
}
|
|
4848
4903
|
if (result) {
|
|
4849
|
-
if (typeof $scope.dataEventFunctions.onBeforeDelete ===
|
|
4904
|
+
if (typeof $scope.dataEventFunctions.onBeforeDelete ===
|
|
4905
|
+
"function") {
|
|
4850
4906
|
$scope.dataEventFunctions.onBeforeDelete(ctrlState.master, function (err) {
|
|
4851
4907
|
if (err) {
|
|
4852
4908
|
if (err !== "_delete_handled_") {
|
|
@@ -4868,7 +4924,9 @@ var fng;
|
|
|
4868
4924
|
};
|
|
4869
4925
|
$scope.isCancelDisabled = function () {
|
|
4870
4926
|
var _a;
|
|
4871
|
-
if (($scope[$scope.topLevelFormName] &&
|
|
4927
|
+
if (($scope[$scope.topLevelFormName] &&
|
|
4928
|
+
$scope[$scope.topLevelFormName].$pristine) ||
|
|
4929
|
+
$scope.phase !== "ready") {
|
|
4872
4930
|
return true;
|
|
4873
4931
|
}
|
|
4874
4932
|
else if (typeof ((_a = $scope.disableFunctions) === null || _a === void 0 ? void 0 : _a.isCancelDisabled) === "function") {
|
|
@@ -4892,7 +4950,7 @@ var fng;
|
|
|
4892
4950
|
else {
|
|
4893
4951
|
$scope.whyDisabled += "<br /><strong>";
|
|
4894
4952
|
if (subFormName) {
|
|
4895
|
-
$scope.whyDisabled += subFormName +
|
|
4953
|
+
$scope.whyDisabled += subFormName + " ";
|
|
4896
4954
|
}
|
|
4897
4955
|
if (CssFrameworkService.framework() === "bs2" &&
|
|
4898
4956
|
c.$$element &&
|
|
@@ -4900,7 +4958,11 @@ var fng;
|
|
|
4900
4958
|
c.$$element.parent().parent() &&
|
|
4901
4959
|
c.$$element.parent().parent().find("label") &&
|
|
4902
4960
|
c.$$element.parent().parent().find("label").text()) {
|
|
4903
|
-
$scope.whyDisabled += c.$$element
|
|
4961
|
+
$scope.whyDisabled += c.$$element
|
|
4962
|
+
.parent()
|
|
4963
|
+
.parent()
|
|
4964
|
+
.find("label")
|
|
4965
|
+
.text();
|
|
4904
4966
|
}
|
|
4905
4967
|
else if (CssFrameworkService.framework() === "bs3" &&
|
|
4906
4968
|
c.$$element &&
|
|
@@ -4909,7 +4971,12 @@ var fng;
|
|
|
4909
4971
|
c.$$element.parent().parent().parent() &&
|
|
4910
4972
|
c.$$element.parent().parent().parent().find("label") &&
|
|
4911
4973
|
c.$$element.parent().parent().parent().find("label").text()) {
|
|
4912
|
-
$scope.whyDisabled += c.$$element
|
|
4974
|
+
$scope.whyDisabled += c.$$element
|
|
4975
|
+
.parent()
|
|
4976
|
+
.parent()
|
|
4977
|
+
.parent()
|
|
4978
|
+
.find("label")
|
|
4979
|
+
.text();
|
|
4913
4980
|
}
|
|
4914
4981
|
else {
|
|
4915
4982
|
$scope.whyDisabled += c.$name;
|
|
@@ -4920,10 +4987,12 @@ var fng;
|
|
|
4920
4987
|
if (c.$error.hasOwnProperty(type)) {
|
|
4921
4988
|
switch (type) {
|
|
4922
4989
|
case "required":
|
|
4923
|
-
$scope.whyDisabled +=
|
|
4990
|
+
$scope.whyDisabled +=
|
|
4991
|
+
"Field missing required value. ";
|
|
4924
4992
|
break;
|
|
4925
4993
|
case "pattern":
|
|
4926
|
-
$scope.whyDisabled +=
|
|
4994
|
+
$scope.whyDisabled +=
|
|
4995
|
+
"Field does not match required pattern. ";
|
|
4927
4996
|
break;
|
|
4928
4997
|
default:
|
|
4929
4998
|
$scope.whyDisabled += type + ". ";
|
|
@@ -4937,7 +5006,7 @@ var fng;
|
|
|
4937
5006
|
}
|
|
4938
5007
|
if ($scope[$scope.topLevelFormName]) {
|
|
4939
5008
|
if ($scope[$scope.topLevelFormName].$invalid) {
|
|
4940
|
-
$scope.whyDisabled =
|
|
5009
|
+
$scope.whyDisabled = "The form data is invalid:";
|
|
4941
5010
|
generateWhyDisabledMessage($scope[$scope.topLevelFormName]);
|
|
4942
5011
|
}
|
|
4943
5012
|
else if ($scope[$scope.topLevelFormName].$pristine) {
|
|
@@ -4961,7 +5030,8 @@ var fng;
|
|
|
4961
5030
|
$scope.whyDisabled = retVal;
|
|
4962
5031
|
}
|
|
4963
5032
|
else {
|
|
4964
|
-
$scope.whyDisabled =
|
|
5033
|
+
$scope.whyDisabled =
|
|
5034
|
+
"An application level user-specified function is inhibiting saving the record";
|
|
4965
5035
|
}
|
|
4966
5036
|
return !!retVal;
|
|
4967
5037
|
}
|
|
@@ -4988,11 +5058,11 @@ var fng;
|
|
|
4988
5058
|
}
|
|
4989
5059
|
};
|
|
4990
5060
|
$scope.setDefaults = function (formSchema, base) {
|
|
4991
|
-
if (base === void 0) { base =
|
|
5061
|
+
if (base === void 0) { base = ""; }
|
|
4992
5062
|
var retVal = {};
|
|
4993
5063
|
formSchema.forEach(function (s) {
|
|
4994
5064
|
if (s.defaultValue !== undefined) {
|
|
4995
|
-
var nameParts = s.name.replace(base,
|
|
5065
|
+
var nameParts = s.name.replace(base, "").split(".");
|
|
4996
5066
|
var target = retVal;
|
|
4997
5067
|
for (var i = 0; i < nameParts.length - 1; i++) {
|
|
4998
5068
|
if (!target[nameParts[i]]) {
|
|
@@ -5006,7 +5076,8 @@ var fng;
|
|
|
5006
5076
|
return retVal;
|
|
5007
5077
|
};
|
|
5008
5078
|
$scope.getVal = function (expression, index) {
|
|
5009
|
-
if (expression.indexOf("$index") === -1 ||
|
|
5079
|
+
if (expression.indexOf("$index") === -1 ||
|
|
5080
|
+
typeof index !== "undefined") {
|
|
5010
5081
|
expression = expression.replace(/\$index/g, index);
|
|
5011
5082
|
return $scope.$eval("record." + expression);
|
|
5012
5083
|
}
|
|
@@ -5041,7 +5112,7 @@ var fng;
|
|
|
5041
5112
|
var scope = _a[_i];
|
|
5042
5113
|
if (scope) {
|
|
5043
5114
|
// need to be accessible on our scope for generation of the select options, and - for nested schemas -
|
|
5044
|
-
// on baseScope for the conversion back to ids done by prepareForSave
|
|
5115
|
+
// on baseScope for the conversion back to ids done by prepareForSave
|
|
5045
5116
|
scope[schemaElement.ids] = ids;
|
|
5046
5117
|
scope[schemaElement.options] = options;
|
|
5047
5118
|
}
|
|
@@ -5059,12 +5130,11 @@ var fng;
|
|
|
5059
5130
|
},
|
|
5060
5131
|
fillFormFromBackendCustomSchema: fillFormFromBackendCustomSchema,
|
|
5061
5132
|
fillFormWithBackendSchema: function fillFormWithBackendSchema($scope, formGeneratorInstance, recordHandlerInstance, ctrlState) {
|
|
5062
|
-
SchemasService.getSchema($scope.modelName, $scope.formName)
|
|
5063
|
-
.then(function (response) {
|
|
5133
|
+
SchemasService.getSchema($scope.modelName, $scope.formName).then(function (response) {
|
|
5064
5134
|
var schema = response.data;
|
|
5065
5135
|
fillFormFromBackendCustomSchema(schema, $scope, formGeneratorInstance, recordHandlerInstance, ctrlState);
|
|
5066
5136
|
}, $scope.handleHttpError);
|
|
5067
|
-
}
|
|
5137
|
+
},
|
|
5068
5138
|
};
|
|
5069
5139
|
}
|
|
5070
5140
|
services.RecordHandlerService = RecordHandlerService;
|