gd-sprest-bs 10.3.2 → 10.3.3
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/build/components/field/index.js +96 -2
- package/build/components/listForm/index.js +180 -28
- package/dist/gd-sprest-bs-icons.js +1 -1
- package/dist/gd-sprest-bs-icons.js.LICENSE.txt +81 -81
- package/dist/gd-sprest-bs-icons.min.js +1 -1
- package/dist/gd-sprest-bs.d.ts +23 -1
- package/dist/gd-sprest-bs.js +1 -1
- package/dist/gd-sprest-bs.js.LICENSE.txt +1 -1
- package/dist/gd-sprest-bs.min.js +1 -1
- package/package.json +2 -2
- package/pnpm-lock.yaml +9 -5
- package/src/components/field/index.ts +109 -4
- package/src/components/field/types.d.ts +23 -1
- package/src/components/listForm/index.ts +194 -32
|
@@ -306,6 +306,85 @@ var Field = function (props) {
|
|
|
306
306
|
}
|
|
307
307
|
}
|
|
308
308
|
break;
|
|
309
|
+
// Image
|
|
310
|
+
case gd_sprest_1.SPTypes.FieldType.Image:
|
|
311
|
+
var fileInfo_1 = null;
|
|
312
|
+
var imageValue_1 = controlProps.value;
|
|
313
|
+
// Set the type
|
|
314
|
+
controlProps.type = core_1.Components.FormControlTypes.TextField;
|
|
315
|
+
controlProps.placeholder = "Add an image";
|
|
316
|
+
controlProps.isDisabled = true;
|
|
317
|
+
// Update the value
|
|
318
|
+
if (controlProps.value) {
|
|
319
|
+
// Update the value to only display the file name
|
|
320
|
+
try {
|
|
321
|
+
var imageProps = JSON.parse(controlProps.value);
|
|
322
|
+
controlProps.value = imageProps.fileName;
|
|
323
|
+
}
|
|
324
|
+
catch (_a) { }
|
|
325
|
+
}
|
|
326
|
+
// Validate the extension
|
|
327
|
+
baseValidation = function (ctrl, results) {
|
|
328
|
+
// See if we are uploading a new file
|
|
329
|
+
if (fileInfo_1) {
|
|
330
|
+
// Ensure it's an image
|
|
331
|
+
var info = fileInfo_1.name.split('.');
|
|
332
|
+
var fileExt = info[info.length - 1].toLowerCase();
|
|
333
|
+
if (["tiff", "pjp", "jfif", "bmp", "gif", "svg", "png", "xbm", "dib", "jxl",
|
|
334
|
+
"jpeg", "svgz", "jpg", "webp", "ico", "tif", "pjpeg", "avif"].indexOf(fileExt) < 0) {
|
|
335
|
+
// Set the flag
|
|
336
|
+
results.isValid = false;
|
|
337
|
+
results.invalidMessage = "The file must be an image.";
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
// Else, see if a value doesn't exist
|
|
341
|
+
else if (results.value == null) {
|
|
342
|
+
// Set the flag based on if it's required
|
|
343
|
+
results.isValid = ctrl.props.required ? false : results.isValid;
|
|
344
|
+
}
|
|
345
|
+
// Return the results
|
|
346
|
+
return results;
|
|
347
|
+
};
|
|
348
|
+
onControlRendered = controlProps.onControlRendered;
|
|
349
|
+
controlProps.onControlRendered = function (ctrl) {
|
|
350
|
+
// Append the edit button
|
|
351
|
+
core_1.Components.Button({
|
|
352
|
+
el: ctrl.textbox.el,
|
|
353
|
+
type: core_1.Components.ButtonTypes.OutlineSecondary,
|
|
354
|
+
text: "Edit",
|
|
355
|
+
onClick: function () {
|
|
356
|
+
// Show a file loader
|
|
357
|
+
gd_sprest_1.Helper.ListForm.showFileDialog().then(function (file) {
|
|
358
|
+
// Save the file info
|
|
359
|
+
fileInfo_1 = file;
|
|
360
|
+
fileInfo_1.fieldId = props.field.Id;
|
|
361
|
+
fileInfo_1.fieldName = props.field.InternalName;
|
|
362
|
+
// Set the value to the file name
|
|
363
|
+
ctrl.textbox.setValue(file.name);
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
});
|
|
367
|
+
// Append the clear button
|
|
368
|
+
core_1.Components.Button({
|
|
369
|
+
el: ctrl.textbox.el,
|
|
370
|
+
type: core_1.Components.ButtonTypes.OutlineSecondary,
|
|
371
|
+
text: "Clear",
|
|
372
|
+
onClick: function () {
|
|
373
|
+
// Clear the value
|
|
374
|
+
ctrl.textbox.setValue("");
|
|
375
|
+
fileInfo_1 = null;
|
|
376
|
+
imageValue_1 = null;
|
|
377
|
+
}
|
|
378
|
+
});
|
|
379
|
+
// Call the rendered event
|
|
380
|
+
onControlRendered ? onControlRendered(ctrl) : null;
|
|
381
|
+
};
|
|
382
|
+
// Set the get value event
|
|
383
|
+
controlProps.onGetValue = function () {
|
|
384
|
+
// Return the file information
|
|
385
|
+
return fileInfo_1 || imageValue_1;
|
|
386
|
+
};
|
|
387
|
+
break;
|
|
309
388
|
// Lookup
|
|
310
389
|
case gd_sprest_1.SPTypes.FieldType.Lookup:
|
|
311
390
|
// Default the lookup field props will determine the default type
|
|
@@ -852,6 +931,11 @@ var Field = function (props) {
|
|
|
852
931
|
name: props.field.InternalName,
|
|
853
932
|
value: control ? control.getValue() : null
|
|
854
933
|
};
|
|
934
|
+
// See if there is a custom value
|
|
935
|
+
if (control.props.onGetValue) {
|
|
936
|
+
// Update the value
|
|
937
|
+
fieldValue.value = control.props.onGetValue(control.props);
|
|
938
|
+
}
|
|
855
939
|
// Update the field name/value, based on the type
|
|
856
940
|
switch (props.field.FieldTypeKind) {
|
|
857
941
|
// Boolean
|
|
@@ -895,6 +979,9 @@ var Field = function (props) {
|
|
|
895
979
|
// Ensure a value exists, otherwise null
|
|
896
980
|
fieldValue.value = fieldValue.value ? fieldValue.value.toISOString() : null;
|
|
897
981
|
break;
|
|
982
|
+
// Image
|
|
983
|
+
case gd_sprest_1.SPTypes.FieldType.Image:
|
|
984
|
+
break;
|
|
898
985
|
// Lookup
|
|
899
986
|
case gd_sprest_1.SPTypes.FieldType.Lookup:
|
|
900
987
|
// Append 'Id' to the field name
|
|
@@ -988,14 +1075,16 @@ var Field = function (props) {
|
|
|
988
1075
|
// See if this is a multi-value field
|
|
989
1076
|
if (props.field.AllowMultipleValues) {
|
|
990
1077
|
var values_2 = fieldValue.value || [];
|
|
991
|
-
// Default the value
|
|
992
|
-
fieldValue.value = { results: [] };
|
|
993
1078
|
// Parse the options
|
|
994
1079
|
for (var j = 0; j < values_2.length; j++) {
|
|
995
1080
|
var userValue = values_2[j];
|
|
996
1081
|
// Add the field value
|
|
997
1082
|
userValue.Id ? fieldValue.value.results.push(userValue.Id) : null;
|
|
998
1083
|
}
|
|
1084
|
+
// Clear the value if no values exist
|
|
1085
|
+
if (fieldValue.value.results.length == 0) {
|
|
1086
|
+
fieldValue.value = null;
|
|
1087
|
+
}
|
|
999
1088
|
}
|
|
1000
1089
|
else {
|
|
1001
1090
|
var userValue = fieldValue.value ? fieldValue.value[0] : null;
|
|
@@ -1039,6 +1128,11 @@ var Field = function (props) {
|
|
|
1039
1128
|
var baseResult = baseValidation(control, { isValid: control.isValid, value: control.getValue() });
|
|
1040
1129
|
// Validate the current control
|
|
1041
1130
|
var result = controlProps.onValidate ? controlProps.onValidate(controlProps, baseResult) : baseResult;
|
|
1131
|
+
// See if a custom validation method exists
|
|
1132
|
+
if (controlProps.onValidate) {
|
|
1133
|
+
// Call the custom validation method
|
|
1134
|
+
result = controlProps.onValidate(controlProps, baseResult);
|
|
1135
|
+
}
|
|
1042
1136
|
// Return the flag
|
|
1043
1137
|
if (typeof (result) === "boolean") {
|
|
1044
1138
|
// Update the validation
|
|
@@ -83,8 +83,20 @@ var renderDisplay = function (fieldName, props) {
|
|
|
83
83
|
if (field.SchemaXml.indexOf('ShowInDisplayForm="FALSE"') > 0) {
|
|
84
84
|
return control;
|
|
85
85
|
}
|
|
86
|
-
// See if this is
|
|
87
|
-
if (field.FieldTypeKind == gd_sprest_1.SPTypes.FieldType.
|
|
86
|
+
// See if this is an image field
|
|
87
|
+
if (field.FieldTypeKind == gd_sprest_1.SPTypes.FieldType.Image) {
|
|
88
|
+
// Ensure a value exists
|
|
89
|
+
if (value) {
|
|
90
|
+
// Update the html
|
|
91
|
+
try {
|
|
92
|
+
var imgInfo = JSON.parse(value);
|
|
93
|
+
html = "<img style='height: 64px; width: 64px;' src='" + imgInfo.serverRelativeUrl + "' alt='" + imgInfo.fileName + "' />";
|
|
94
|
+
}
|
|
95
|
+
catch (_a) { }
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
// Else, see if this is a note field
|
|
99
|
+
else if (field.FieldTypeKind == gd_sprest_1.SPTypes.FieldType.Note) {
|
|
88
100
|
// Update the html
|
|
89
101
|
html = html.replace(/\r?\n/g, '<br />');
|
|
90
102
|
}
|
|
@@ -170,8 +182,16 @@ var renderDisplay = function (fieldName, props) {
|
|
|
170
182
|
// Detect html
|
|
171
183
|
if (/<*>/g.test(html)) {
|
|
172
184
|
var isMultiLine = html.indexOf("<br />") >= 0 ? true : false;
|
|
173
|
-
//
|
|
174
|
-
if (
|
|
185
|
+
// See if it's an image
|
|
186
|
+
if (field.FieldTypeKind == gd_sprest_1.SPTypes.FieldType.Image) {
|
|
187
|
+
// Set the rendered event
|
|
188
|
+
control.onControlRendered = function (control) {
|
|
189
|
+
// Override the html rendered
|
|
190
|
+
control.el.innerHTML = html;
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
// Else, ensure this isn't a rich text field or multi-line
|
|
194
|
+
else if (!isRichText && !isMultiLine) {
|
|
175
195
|
// Update the control to be read-only
|
|
176
196
|
control.type = core_1.Components.FormControlTypes.Readonly;
|
|
177
197
|
// Set the rendered event
|
|
@@ -445,6 +465,136 @@ exports.ListForm.renderEditForm = function (props) {
|
|
|
445
465
|
});
|
|
446
466
|
});
|
|
447
467
|
};
|
|
468
|
+
// Method to upload the images
|
|
469
|
+
var images = [];
|
|
470
|
+
var uploadImages = function (info) {
|
|
471
|
+
// Return a promise
|
|
472
|
+
return new Promise(function (resolve) {
|
|
473
|
+
var values = {};
|
|
474
|
+
// Ensure we have images
|
|
475
|
+
if (images.length == 0) {
|
|
476
|
+
// Do nothing
|
|
477
|
+
resolve(values);
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
480
|
+
// Get the list folder
|
|
481
|
+
gd_sprest_1.Helper.ListFormField.getOrCreateImageFolder(info).then(function (fld) {
|
|
482
|
+
// Removes the existing image
|
|
483
|
+
var removeExisting = function (value) {
|
|
484
|
+
// Return a promise
|
|
485
|
+
return new Promise(function (resolve) {
|
|
486
|
+
// Try to get the image info
|
|
487
|
+
var imageInfo = null;
|
|
488
|
+
try {
|
|
489
|
+
imageInfo = JSON.parse(value);
|
|
490
|
+
}
|
|
491
|
+
catch (_a) { }
|
|
492
|
+
// Ensure the info exists
|
|
493
|
+
if (imageInfo) {
|
|
494
|
+
// See if the file exists
|
|
495
|
+
fld.Files(imageInfo.fileName).execute(
|
|
496
|
+
// Exists
|
|
497
|
+
function (file) {
|
|
498
|
+
// Delete the file
|
|
499
|
+
file.delete().execute(function () {
|
|
500
|
+
// Resolve the request
|
|
501
|
+
resolve(null);
|
|
502
|
+
});
|
|
503
|
+
},
|
|
504
|
+
// Doesn't exist
|
|
505
|
+
function () {
|
|
506
|
+
// Resolve the request
|
|
507
|
+
resolve(null);
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
else {
|
|
511
|
+
// Resolve the request
|
|
512
|
+
resolve(null);
|
|
513
|
+
}
|
|
514
|
+
});
|
|
515
|
+
};
|
|
516
|
+
// Validates the list name
|
|
517
|
+
var validateFileName = function (fileName) {
|
|
518
|
+
// Return a promise
|
|
519
|
+
return new Promise(function (resolve) {
|
|
520
|
+
// Get the file name w/out the extension
|
|
521
|
+
var info = fileName.toLowerCase().split('.');
|
|
522
|
+
var fileExt = info[info.length - 1];
|
|
523
|
+
var fileNameNoExt = "";
|
|
524
|
+
for (var i = 0; i < info.length - 1; i++) {
|
|
525
|
+
fileNameNoExt += info[i];
|
|
526
|
+
}
|
|
527
|
+
// Get the files with a similar name
|
|
528
|
+
fld.Files().query({
|
|
529
|
+
Filter: "startswith(Name, '" + fileNameNoExt + "')",
|
|
530
|
+
Top: 5000
|
|
531
|
+
}).execute(function (files) {
|
|
532
|
+
var isValid = true;
|
|
533
|
+
var counter = -1;
|
|
534
|
+
var validFileName = null;
|
|
535
|
+
// See if no files were found
|
|
536
|
+
if (files.results.length == 0) {
|
|
537
|
+
// Resolve the request
|
|
538
|
+
resolve(fileName);
|
|
539
|
+
return;
|
|
540
|
+
}
|
|
541
|
+
// Loop until it's valid
|
|
542
|
+
do {
|
|
543
|
+
// Reset the flag and file name
|
|
544
|
+
validFileName = fileNameNoExt + (++counter == 0 ? "" : counter) + "." + fileExt;
|
|
545
|
+
isValid = true;
|
|
546
|
+
// Parse the files
|
|
547
|
+
for (var i = 0; i < files.results.length; i++) {
|
|
548
|
+
var file = files.results[i];
|
|
549
|
+
// See if there is a match
|
|
550
|
+
if (file.Name.toLowerCase() == validFileName) {
|
|
551
|
+
// Set the flag
|
|
552
|
+
isValid = false;
|
|
553
|
+
break;
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
} while (!isValid);
|
|
557
|
+
// Resolve the request
|
|
558
|
+
resolve(validFileName);
|
|
559
|
+
});
|
|
560
|
+
});
|
|
561
|
+
};
|
|
562
|
+
// Parse the images
|
|
563
|
+
gd_sprest_1.Helper.Executor(images, function (imageInfo) {
|
|
564
|
+
// See if this is a file that needs to be uploaded
|
|
565
|
+
if (imageInfo.name && imageInfo.data && imageInfo.fieldName) {
|
|
566
|
+
// Return a promise
|
|
567
|
+
return new Promise(function (resolve) {
|
|
568
|
+
// Remove the existing image
|
|
569
|
+
removeExisting(info.item ? info.item[imageInfo.fieldName] : null).then(function () {
|
|
570
|
+
// Validate the name
|
|
571
|
+
validateFileName(imageInfo.name).then(function (fileName) {
|
|
572
|
+
// Upload the file
|
|
573
|
+
fld.Files().add(fileName, true, imageInfo.data).execute(function (file) {
|
|
574
|
+
// Update the field value
|
|
575
|
+
values[imageInfo.fieldName] = JSON.stringify({
|
|
576
|
+
fieldId: imageInfo.fieldId,
|
|
577
|
+
fieldName: imageInfo.fieldName,
|
|
578
|
+
fileName: file.Name,
|
|
579
|
+
id: file.UniqueId,
|
|
580
|
+
nativeFile: {},
|
|
581
|
+
serverRelativeUrl: file.ServerRelativeUrl,
|
|
582
|
+
type: "thumbnail"
|
|
583
|
+
});
|
|
584
|
+
// Resolve the request
|
|
585
|
+
resolve(null);
|
|
586
|
+
});
|
|
587
|
+
});
|
|
588
|
+
});
|
|
589
|
+
});
|
|
590
|
+
}
|
|
591
|
+
}).then(function () {
|
|
592
|
+
// Resolve the request
|
|
593
|
+
resolve(values);
|
|
594
|
+
});
|
|
595
|
+
});
|
|
596
|
+
});
|
|
597
|
+
};
|
|
448
598
|
// Render a loading message
|
|
449
599
|
var progress = core_1.Components.Progress({
|
|
450
600
|
el: props.el,
|
|
@@ -803,6 +953,8 @@ exports.ListForm.renderEditForm = function (props) {
|
|
|
803
953
|
// Set the content type id
|
|
804
954
|
values["ContentTypeId"] = props.info.contentType.Id.StringValue;
|
|
805
955
|
}
|
|
956
|
+
// Clear the image values
|
|
957
|
+
images = [];
|
|
806
958
|
// Parse the fields
|
|
807
959
|
for (var fieldName in props.info.fields) {
|
|
808
960
|
// Get the form field and skip readonly fields
|
|
@@ -812,11 +964,6 @@ exports.ListForm.renderEditForm = function (props) {
|
|
|
812
964
|
}
|
|
813
965
|
// Get the field value
|
|
814
966
|
var fieldValue = formField.getValue();
|
|
815
|
-
// See if an event exists
|
|
816
|
-
if (formField.controlProps.onGetValue) {
|
|
817
|
-
// Update the value
|
|
818
|
-
fieldValue.value = formField.controlProps.onGetValue(formField.controlProps);
|
|
819
|
-
}
|
|
820
967
|
// Set the item value
|
|
821
968
|
values[fieldValue.name] = fieldValue.value;
|
|
822
969
|
// See if this is the file leaf ref
|
|
@@ -824,6 +971,12 @@ exports.ListForm.renderEditForm = function (props) {
|
|
|
824
971
|
// Update the 'Title'
|
|
825
972
|
values["Title"] = values["Title"] || values[fieldValue.name];
|
|
826
973
|
}
|
|
974
|
+
// See if this is an image field
|
|
975
|
+
var field = props.info.fields[fieldName];
|
|
976
|
+
if (field && field.FieldTypeKind == gd_sprest_1.SPTypes.FieldType.Image) {
|
|
977
|
+
// Add the value if it exists
|
|
978
|
+
fieldValue.value ? images.push(fieldValue.value) : null;
|
|
979
|
+
}
|
|
827
980
|
}
|
|
828
981
|
// Return the form values
|
|
829
982
|
return values;
|
|
@@ -909,11 +1062,6 @@ exports.ListForm.renderEditForm = function (props) {
|
|
|
909
1062
|
}
|
|
910
1063
|
// Validate the form field and update the status flag
|
|
911
1064
|
var controlIsValid = formField.isValid();
|
|
912
|
-
// See if there is a custom method
|
|
913
|
-
if (formField.controlProps.onValidate) {
|
|
914
|
-
// Call the event
|
|
915
|
-
controlIsValid = formField.controlProps.onValidate(formField.controlProps, formField.getValue());
|
|
916
|
-
}
|
|
917
1065
|
// Update the flag
|
|
918
1066
|
isValid = isValid && controlIsValid;
|
|
919
1067
|
}
|
|
@@ -947,21 +1095,25 @@ exports.ListForm.renderEditForm = function (props) {
|
|
|
947
1095
|
};
|
|
948
1096
|
// Return a promise
|
|
949
1097
|
return new Promise(function (resolve, reject) {
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
1098
|
+
var formValues = getValues();
|
|
1099
|
+
// Upload the images
|
|
1100
|
+
uploadImages(props.info).then(function (imageValues) {
|
|
1101
|
+
// Call the saving event
|
|
1102
|
+
onSaving(__assign(__assign(__assign({}, formValues), imageValues), customValues)).then(function (values) {
|
|
1103
|
+
// Update the item
|
|
1104
|
+
exports.ListForm.saveItem(props.info, values).then(function (info) {
|
|
1105
|
+
// Remove the attachments
|
|
1106
|
+
removeAttachments(info).then(function () {
|
|
1107
|
+
// Save the attachments
|
|
1108
|
+
saveAttachments(info).then(function () {
|
|
1109
|
+
// Update the info
|
|
1110
|
+
props.info = info;
|
|
1111
|
+
// Resolve the promise
|
|
1112
|
+
resolve(props.info.item);
|
|
1113
|
+
});
|
|
962
1114
|
});
|
|
963
|
-
});
|
|
964
|
-
}
|
|
1115
|
+
}, reject);
|
|
1116
|
+
});
|
|
965
1117
|
});
|
|
966
1118
|
});
|
|
967
1119
|
}
|