gd-sprest-bs 9.0.8 → 9.0.9

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.
@@ -316,7 +316,7 @@ exports.Field = function (props) {
316
316
  // Save the field information
317
317
  lookupFieldInfo = fieldInfo;
318
318
  // Set the lookup filter
319
- lookupFieldInfo.lookupFilter = props.lookupFilter;
319
+ lookupFieldInfo.lookupFilter = controlProps.lookupFilter;
320
320
  // Update the multi property
321
321
  controlProps.multi = lookupFieldInfo.multi;
322
322
  // Get the drop down information
@@ -488,7 +488,7 @@ exports.Field = function (props) {
488
488
  // Clear the element
489
489
  control.el.innerHTML = "";
490
490
  // See if we are rendering the description
491
- var showDesc = props.showDescription;
491
+ var showDesc = controlProps.showDescription;
492
492
  showDesc = typeof (showDesc) === "boolean" ? showDesc : true;
493
493
  if (showDesc) {
494
494
  // Render the description
@@ -499,14 +499,14 @@ exports.ListForm.renderEditForm = function (props) {
499
499
  }
500
500
  // Parse the fields to render
501
501
  var fieldNames = getFieldsToRender(props);
502
- for (var i = 0; i < fieldNames.length; i++) {
502
+ var _loop_1 = function (i) {
503
503
  var fieldName = fieldNames[i];
504
504
  var field = props.info.fields[fieldName];
505
505
  // Ensure the field exists
506
506
  if (field == null) {
507
507
  // Log
508
508
  console.error("[List Form] Field '" + fieldName + "' does not exist. Check the list or query.");
509
- continue;
509
+ return "continue";
510
510
  }
511
511
  // See if the item exists
512
512
  value[fieldName] = null;
@@ -528,43 +528,43 @@ exports.ListForm.renderEditForm = function (props) {
528
528
  var controlMode = props.controlMode || (props.info.item ? gd_sprest_1.SPTypes.ControlMode.Edit : gd_sprest_1.SPTypes.ControlMode.New);
529
529
  // See if this is an edit form and we are hiding this field
530
530
  if (controlMode == gd_sprest_1.SPTypes.ControlMode.Edit && field.SchemaXml.indexOf('ShowInEditForm="FALSE"') > 0) {
531
- continue;
531
+ return "continue";
532
532
  }
533
533
  // See if this is a new form and we are hiding this field
534
534
  if (controlMode == gd_sprest_1.SPTypes.ControlMode.New && field.SchemaXml.indexOf('ShowInNewForm="FALSE"') > 0) {
535
- continue;
535
+ return "continue";
536
536
  }
537
537
  // See if thi sis a new form and this is an associated lookup field
538
538
  if (controlMode == gd_sprest_1.SPTypes.ControlMode.New && field.IsDependentLookup) {
539
- continue;
539
+ return "continue";
540
540
  }
541
541
  // See if this is a display form and we are hiding this field
542
542
  if (controlMode == gd_sprest_1.SPTypes.ControlMode.Display && field.SchemaXml.indexOf('ShowInDisplayForm="FALSE"') > 0) {
543
- continue;
543
+ return "continue";
544
544
  }
545
545
  // See if this is a read-only field
546
546
  if (field.ReadOnlyField) {
547
547
  // Do not render in the new form
548
548
  if (props.controlMode == gd_sprest_1.SPTypes.ControlMode.New) {
549
- continue;
549
+ return "continue";
550
550
  }
551
551
  }
552
552
  // Do not render a hidden taxonomy field
553
553
  if (field.Hidden && field.FieldTypeKind == gd_sprest_1.SPTypes.FieldType.Note && /_0$/.test(field.Title)) {
554
- continue;
554
+ return "continue";
555
555
  }
556
556
  // See if this is an invalid field type
557
557
  if (field.FieldTypeKind == gd_sprest_1.SPTypes.FieldType.Invalid) {
558
558
  // Ensure it's not a taxonomy field
559
559
  if (!/^TaxonomyFieldType/.test(field.TypeAsString)) {
560
- continue;
560
+ return "continue";
561
561
  }
562
562
  }
563
563
  // Else, see if this is a calculated column
564
564
  else if (field.FieldTypeKind == gd_sprest_1.SPTypes.FieldType.Calculated) {
565
565
  // Do not render in the new/edit forms
566
566
  if (props.controlMode != gd_sprest_1.SPTypes.ControlMode.Display) {
567
- continue;
567
+ return "continue";
568
568
  }
569
569
  }
570
570
  // See if this is a lookup field
@@ -578,8 +578,11 @@ exports.ListForm.renderEditForm = function (props) {
578
578
  controlMode: props.controlMode,
579
579
  field: field,
580
580
  listInfo: props.info,
581
- lookupFilter: lookupFilter,
582
581
  value: value[fieldName],
582
+ onControlRendering: function (control, field) {
583
+ // Set the lookup field filter
584
+ lookupFilter ? control.lookupFilter = lookupFilter : null;
585
+ },
583
586
  onControlRendered: function (control, field) {
584
587
  // Update the mapper
585
588
  mapper[field.InternalName].control = control;
@@ -600,6 +603,9 @@ exports.ListForm.renderEditForm = function (props) {
600
603
  control: fieldControl.controlProps
601
604
  }]
602
605
  });
606
+ };
607
+ for (var i = 0; i < fieldNames.length; i++) {
608
+ _loop_1(i);
603
609
  }
604
610
  // See if there is a template
605
611
  if (props.template) {
@@ -665,7 +665,7 @@ eval("\n\nObject.defineProperty(exports, \"__esModule\", ({\n value: true\n}));
665
665
  /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
666
666
 
667
667
  "use strict";
668
- eval("\n\nObject.defineProperty(exports, \"__esModule\", ({\n value: true\n}));\nexports.Field = void 0;\n\nvar gd_sprest_1 = __webpack_require__(/*! gd-sprest */ \"./node_modules/.pnpm/gd-sprest@6.8.4/node_modules/gd-sprest/build/index.js\");\n\nvar core_1 = __webpack_require__(/*! ../core */ \"./build/components/core.js\");\n\nvar datetime_1 = __webpack_require__(/*! ../datetime */ \"./build/components/datetime/index.js\");\n\nvar peoplePicker_1 = __webpack_require__(/*! ../peoplePicker */ \"./build/components/peoplePicker/index.js\");\n/**\r\n * Field\r\n */\n\n\nexports.Field = function (props) {\n var control;\n var lookupFieldInfo = null;\n var mmsFieldInfo = null; // Method to get the choice options\n\n var getChoiceItems = function getChoiceItems(isCheckbox, field, selectedValues) {\n var items = []; // Update the selected values\n\n selectedValues = selectedValues && selectedValues.results ? selectedValues.results : [selectedValues]; // Parse the choices\n\n for (var i = 0; i < field.Choices.results.length; i++) {\n var choice = field.Choices.results[i];\n var isSelected = false; // Determine if this choice is selected\n\n for (var j = 0; j < selectedValues.length; j++) {\n // See if this choice is selected\n if (choice == selectedValues[j]) {\n // Set the flag and break from the loop\n isSelected = true;\n break;\n }\n } // See if this is a checkbox\n\n\n if (isCheckbox) {\n // Add the item\n items.push({\n isSelected: isSelected,\n label: choice\n });\n } else {\n // Add the item\n items.push({\n isSelected: isSelected,\n label: choice,\n text: choice,\n value: choice\n });\n }\n } // See if this is a dropdown and no selected values exists, and this is a required field\n\n\n if (!isCheckbox && items.length > 0 && selectedValues.length == 0 && field.Required) {\n // Select the first item\n items[0].isSelected = true;\n } // Return the items\n\n\n return items;\n }; // Method to get the file extension\n\n\n var getFileExtension = function getFileExtension(fileName) {\n if (fileName === void 0) {\n fileName = \"\";\n }\n\n var extension = fileName.split('.');\n return extension[extension.length - 1].toLowerCase();\n }; // Method to generate the lookup dropdown items\n\n\n var getLookupItems = function getLookupItems(field, lookupItems, selectedValues) {\n var items = []; // Update the selected values\n\n selectedValues = selectedValues && selectedValues.results ? selectedValues.results : [selectedValues]; // Parse the lookup items\n\n for (var i = 0; i < lookupItems.length; i++) {\n var item = lookupItems[i];\n var isSelected = false; // Determine if this lookup is selected\n\n for (var j = 0; j < selectedValues.length; j++) {\n var id = selectedValues[j] && selectedValues[j].Id ? selectedValues[j].Id : selectedValues[j]; // See if this choice is selected\n\n if (item.Id == id) {\n // Set the flag and break from the loop\n isSelected = true;\n break;\n }\n } // Add the item\n\n\n items.push({\n data: item,\n isSelected: isSelected,\n text: item[field.LookupField],\n value: item.Id.toString()\n });\n } // See if no selected values exists, and this is a required field\n\n\n if (items.length > 0 && selectedValues.length == 0 && field.Required) {\n // Select the first item\n items[0].isSelected = true;\n } // Return the items\n\n\n return items;\n }; // Method to get the mms dropdown items\n\n\n var getMMSItems = function getMMSItems(term, selectedValues, isRoot) {\n if (selectedValues === void 0) {\n selectedValues = [];\n }\n\n if (isRoot === void 0) {\n isRoot = true;\n }\n\n var items = []; // See if information exists\n\n if (term.info && !isRoot) {\n var isSelected = false; // Parse the selected values\n\n for (var i = 0; i < selectedValues.length; i++) {\n // See if this item is selected\n if (selectedValues[i] == term.info.id) {\n isSelected = true;\n break;\n }\n } // Add the heading\n\n\n items.push({\n data: term,\n isSelected: isSelected,\n text: term.info.name,\n value: term.info.id\n });\n } // Parse the terms\n\n\n for (var termName in term) {\n var child = term[termName]; // Skip the info and parent properties\n\n if (termName == \"info\" || termName == \"parent\") {\n continue;\n } // Get the child items\n\n\n var childItems = getMMSItems(child, selectedValues, false); // Add the item\n\n items = items.concat(childItems);\n } // See if no selected values exists, and this is a required field\n\n\n if (items.length > 0 && selectedValues.length == 0 && isRequired) {\n // Select the first item\n items[0].isSelected = true;\n } // Return the items\n\n\n return items;\n }; // Set the properties based on the field link\n\n\n var fieldLink = props.listInfo.fieldLinks ? props.listInfo.fieldLinks[props.field.InternalName] : null;\n var isReadonly = fieldLink && typeof fieldLink.ReadOnly === \"boolean\" ? fieldLink.ReadOnly : props.field.ReadOnlyField;\n var isRequired = fieldLink && typeof fieldLink.Required === \"boolean\" ? fieldLink.Required : props.field.Required; // See if this is an internal field\n\n if (props.field.CanBeDeleted == false) {\n // Override the property based on the field property\n isReadonly = isReadonly || props.field.ReadOnlyField;\n } // Set the default properties for the control\n\n\n var controlProps = {\n description: props.field.Description,\n errorMessage: props.errorMessage,\n id: props.field.InternalName,\n isReadonly: isReadonly,\n label: (isRequired ? \"* \" : \"\") + props.field.Title,\n name: props.field.InternalName,\n onControlRendering: function onControlRendering(control) {\n // Execute the event\n return props.onControlRendering ? props.onControlRendering(control, props.field) : null;\n },\n onControlRendered: function onControlRendered(formControl) {\n // Save the control\n control = formControl; // Execute the event\n\n return props.onControlRendered ? props.onControlRendered(control, props.field) : null;\n },\n required: isRequired,\n type: core_1.Components.FormControlTypes.TextField,\n value: props.value\n }; // Define a base validation method\n\n var baseValidation = null; // See if this is a new form, a default value exists and no value has been defined\n\n if (props.controlMode == gd_sprest_1.SPTypes.ControlMode.New && props.field.DefaultValue && props.value == null) {\n // Set the default value\n controlProps.value = props.field.DefaultValue;\n } // Set the type\n\n\n var onControlRendered = null;\n var onControlRendering = null;\n\n switch (props.field.FieldTypeKind) {\n // Boolean\n case gd_sprest_1.SPTypes.FieldType.Boolean:\n // Set the type\n controlProps.type = core_1.Components.FormControlTypes.Checkbox; // Create the item\n\n controlProps.items = [{\n label: controlProps.label\n }]; // Clear the label\n\n controlProps.label = \"\";\n break;\n // Choice\n\n case gd_sprest_1.SPTypes.FieldType.Choice:\n var displayRadioButtons = props.field.SchemaXml.indexOf('Format=\"RadioButtons\"') > 0 ? true : false; // See if we are displaying radio buttons\n\n if (displayRadioButtons) {\n // Set the type\n controlProps.type = core_1.Components.FormControlTypes.Switch;\n } else {\n // Set the type\n controlProps.type = core_1.Components.FormControlTypes.Dropdown;\n } // Get the items\n\n\n var items = getChoiceItems(displayRadioButtons, props.field, props.value); // See if this is not a required field\n\n if (!isRequired) {\n // Add a blank entry\n items = [{\n text: \"\",\n value: null\n }].concat(items);\n } // Set the items\n\n\n controlProps.items = items;\n break;\n // Currency Field\n\n case gd_sprest_1.SPTypes.FieldType.Currency:\n // Set the type\n controlProps.type = core_1.Components.FormControlTypes.TextField; // Set the rendered event\n\n onControlRendered = controlProps.onControlRendered;\n\n controlProps.onControlRendered = function (formControl) {\n // Save the control\n control = formControl; // Call the event\n\n onControlRendered ? onControlRendered(formControl) : null;\n };\n\n break;\n // Date/Time\n\n case gd_sprest_1.SPTypes.FieldType.DateTime:\n // Set the time flag\n var showTime = props.field.DisplayFormat == gd_sprest_1.SPTypes.DateFormat.DateTime;\n controlProps.showTime = showTime; // Set the type\n\n controlProps.type = datetime_1.DateTimeControlType; // See if there is a formula and this is a new form\n\n var dtValue = (props.field.DefaultFormula || props.field.DefaultValue || \"\").toLowerCase();\n\n if (dtValue && props.controlMode == gd_sprest_1.SPTypes.ControlMode.New) {\n var idx = dtValue.indexOf(\"today\"); // See if the date is a formula\n\n if (idx >= 0) {\n var dtNow = new Date(Date.now()); // See if we are adding days\n\n var daysIdx = dtValue.indexOf(\"+\", idx);\n\n if (daysIdx > 0) {\n // Get the number of days to add\n var days = parseInt(dtValue.substr(daysIdx + 1));\n\n if (days > 0) {\n // Add the days\n dtNow.setDate(dtNow.getDate() + days);\n }\n } // See if we are subtracting days\n\n\n daysIdx = dtValue.indexOf(\"-\", idx);\n\n if (daysIdx > 0) {\n // Get the number of days to add\n var days = parseInt(dtValue.substr(daysIdx + 1));\n\n if (days > 0) {\n // Add the days\n dtNow.setDate(dtNow.getDate() - days);\n }\n } // Set the value\n\n\n controlProps.value = dtNow;\n } else {\n // Set the value\n controlProps.value = new Date(dtValue);\n }\n }\n\n break;\n // Lookup\n\n case gd_sprest_1.SPTypes.FieldType.Lookup:\n // Default the lookup field props will determine the default type\n controlProps.type = props.field.AllowMultipleValues ? core_1.Components.FormControlTypes.MultiDropdown : core_1.Components.FormControlTypes.Dropdown; // See if this field is readonly and a value exists\n\n if (isReadonly) {\n // Update the value\n controlProps.type = core_1.Components.FormControlTypes.Readonly; // Ensure a value exists\n\n if (props.value) {\n // Set the rendered event\n onControlRendered = controlProps.onControlRendered;\n\n controlProps.onControlRendered = function (formControl) {\n // Set the class name\n control.el.classList.add(\"form-control\");\n control.el.style.backgroundColor = \"#e9ecef\"; // Override the html rendered\n\n control.el.innerHTML = props.listInfo.fieldValuesAsHtml[props.field.InternalName];\n };\n }\n } else {\n // Set the rendering event\n onControlRendering = controlProps.onControlRendering;\n\n controlProps.onControlRendering = function (newProps) {\n // Update the control properties\n controlProps = newProps; // Display a loading message\n\n controlProps.loadingMessage = \"Loading the Lookup Data\"; // Return a promise\n\n return new Promise(function (resolve, reject) {\n // Load the field information\n gd_sprest_1.Helper.ListFormField.create({\n field: props.field,\n listName: props.listInfo.list.Title,\n name: props.field.InternalName,\n webUrl: props.listInfo.webUrl\n }).then( // Success\n function (fieldInfo) {\n // Save the field information\n lookupFieldInfo = fieldInfo; // Set the lookup filter\n\n lookupFieldInfo.lookupFilter = props.lookupFilter; // Update the multi property\n\n controlProps.multi = lookupFieldInfo.multi; // Get the drop down information\n\n gd_sprest_1.Helper.ListFormField.loadLookupData(lookupFieldInfo, 500).then( // Success\n function (items) {\n // Get the dropdown items\n var ddlItems = getLookupItems(props.field, items, props.value); // See if this is not a required field and not a multi-select\n\n if (!isRequired && !lookupFieldInfo.multi) {\n // Add a blank entry\n ddlItems = [{\n text: \"\",\n value: null\n }].concat(ddlItems);\n } // Set the items\n\n\n controlProps.items = ddlItems; // Clear the element\n\n controlProps.el ? controlProps.el.innerHTML = \"\" : null; // Clear the value, since the getLookupItems method takes care of this for us\n\n controlProps.value = null; // Call the event\n\n var returnVal = onControlRendering ? onControlRendering(controlProps) : null;\n\n if (returnVal && returnVal.then) {\n // Wait for the promise to complete\n returnVal.then(function (props) {\n // Resolve the promise\n resolve(props || controlProps);\n });\n } else {\n // Resolve the promise\n resolve(controlProps);\n }\n }, // Error\n function (msg) {\n // Set the error message\n var errorMessage = \"Error loading the lookup field values for '\" + props.field.InternalName + \"'.\"; // Display an error message\n\n core_1.Components.Alert({\n el: controlProps.el,\n content: errorMessage,\n type: core_1.Components.AlertTypes.Danger\n }); // Call the error event\n\n props.onError ? props.onError(errorMessage) : null;\n });\n }, // Error\n function (msg) {\n // Set the error message\n var errorMessage = \"Error loading the field information for field '\" + props.field.InternalName + \"'.\"; // Display an error message\n\n controlProps.el.innerHTML = \"\";\n core_1.Components.Alert({\n el: controlProps.el,\n content: \"Error loading the lookup field information.\",\n type: core_1.Components.AlertTypes.Danger\n }); // Call the error event\n\n props.onError ? props.onError(errorMessage) : null; // Reject the request\n\n reject(msg);\n });\n });\n };\n }\n\n break;\n // Multi-Choice\n\n case gd_sprest_1.SPTypes.FieldType.MultiChoice:\n var isChoice = props.field.SchemaXml.indexOf('Format=\"RadioButtons\"') > 0 ? true : false; // Set the type\n\n controlProps.type = isChoice ? core_1.Components.FormControlTypes.MultiSwitch : core_1.Components.FormControlTypes.MultiDropdown; // Update the value\n\n controlProps.value = (props.value ? props.value.results : null) || props.value; // Set the items\n\n controlProps.items = getChoiceItems(isChoice, props.field, props.value);\n break;\n // Note\n\n case gd_sprest_1.SPTypes.FieldType.Note:\n // Set the properties\n controlProps.type = core_1.Components.FormControlTypes.TextArea;\n controlProps.rows = props.field.NumberOfLines;\n break;\n // Number Field\n\n case gd_sprest_1.SPTypes.FieldType.Number:\n var numberField_1 = props.field;\n var numberProps = controlProps; // Set the default value\n\n numberProps.value = numberProps.value == null ? numberField_1.DefaultValue : numberProps.value; // See if this is a percentage\n\n var isPercent = numberField_1.ShowAsPercentage;\n\n if (isPercent == null) {\n // Set the value from the schema (2013 environments)\n isPercent = numberField_1.SchemaXml.toLowerCase().indexOf('percentage=\"true\"') > 0;\n }\n\n if (isPercent) {\n // Set the type\n numberProps.type = core_1.Components.FormControlTypes.Range; // Default the max\n\n numberProps.max = numberField_1.MaximumValue == 1 || numberField_1.MaximumValue == Number.MAX_VALUE ? 100 : numberField_1.MaximumValue; // Set the min value\n\n numberProps.min = numberField_1.MinimumValue == -1.7976931348623157e+308 ? 0 : numberField_1.MinimumValue; // Set the value\n\n numberProps.value = numberProps.value == null || numberProps.value == Number.MIN_VALUE ? 0 : numberProps.value;\n numberProps.value = numberProps.value * (numberProps.max == 100 && numberProps.value < 1 ? 100 : 1);\n } // Else, see if the min/max values are defined\n else if (typeof numberField_1.MaximumValue == \"number\" && numberField_1.MaximumValue != Number.MAX_VALUE && typeof numberField_1.MinimumValue == \"number\" && numberField_1.MinimumValue != Number.MIN_VALUE) {\n // Update the properties to display a range\n numberProps.type = core_1.Components.FormControlTypes.Range;\n numberProps.max = numberField_1.MaximumValue;\n numberProps.min = numberField_1.MinimumValue;\n numberProps.value = typeof numberProps.value == \"number\" ? numberProps.value : numberProps.min; // Set validation\n\n if (numberField_1.MinimumValue || numberField_1.MaximumValue) {\n // Add validation\n baseValidation = function baseValidation(control, result) {\n // Ensure the value is a number\n if (/^[0-9]*$/.test(result.value) == false) {\n // Update the validation and return it\n result.isValid = false;\n result.invalidMessage = \"The value must be a number.\";\n return result;\n } // Validate the min value\n\n\n if (numberField_1.MinimumValue && result.value < numberField_1.MinimumValue) {\n // Update the validation and return it\n result.isValid = false;\n result.invalidMessage = \"The value must be greater than or equal to \" + numberField_1.MinimumValue;\n return result;\n } // Validate the max value\n\n\n if (numberField_1.MaximumValue && result.value > numberField_1.MaximumValue) {\n // Update the validation and return it\n result.isValid = false;\n result.invalidMessage = \"The value must be less than or equal to \" + numberField_1.MaximumValue;\n return result;\n } // Valid\n\n\n result.isValid = true; // Return the result\n\n return result;\n };\n }\n } else {\n // Set the type\n numberProps.type = core_1.Components.FormControlTypes.TextField;\n }\n\n break;\n // URL\n\n case gd_sprest_1.SPTypes.FieldType.URL:\n var desc_1 = null;\n var url_1 = null;\n var value_1 = props.value; // See if a value exists\n\n if (props.value) {\n // Update the value\n controlProps.value = props.value.Url;\n } // Set the render event\n\n\n onControlRendered = controlProps.onControlRendered;\n\n controlProps.onControlRendered = function (formControl) {\n // Save the control\n control = formControl; // Clear the element\n\n control.el.innerHTML = \"\"; // See if we are rendering the description\n\n var showDesc = props.showDescription;\n showDesc = typeof showDesc === \"boolean\" ? showDesc : true;\n\n if (showDesc) {\n // Render the description\n desc_1 = core_1.Components.FormControl({\n className: \"mb-1\",\n el: control.el,\n placeholder: \"Description\",\n type: core_1.Components.FormControlTypes.TextField,\n value: value_1 ? value_1.Description : null\n });\n } // Render the url\n\n\n url_1 = core_1.Components.FormControl({\n el: control.el,\n placeholder: \"Url\",\n type: core_1.Components.FormControlTypes.TextField,\n value: value_1 ? value_1.Url : null\n }); // Set the get value event\n\n control.props.onGetValue = function () {\n // Return the value\n return {\n Description: desc_1 ? desc_1.getValue() : url_1.getValue(),\n Url: url_1.getValue()\n };\n }; // Call the event\n\n\n onControlRendered ? onControlRendered(formControl) : null;\n }; // Set the validate event\n\n\n baseValidation = function baseValidation(control, result) {\n var descValid,\n urlValid = false; // Get the form control elements\n\n var elFormControl = control.el.querySelectorAll(\".form-control\");\n var elDesc = elFormControl[0];\n var elUrl = elFormControl[1]; // See if the description exists\n\n if (elDesc) {\n // Clear the classes\n elDesc.classList.remove(\"is-invalid\");\n elDesc.classList.remove(\"is-valid\"); // Set the flag\n\n descValid = control.props.required ? desc_1.getValue() ? true : false : true; // Set the class\n\n elDesc.classList.add(descValid ? \"is-valid\" : \"is-invalid\");\n } // See if the url exists\n\n\n if (elUrl) {\n // Clear the classes\n elUrl.classList.remove(\"is-invalid\");\n elUrl.classList.remove(\"is-valid\"); // Set the flag\n\n urlValid = control.props.required ? url_1.getValue() ? true : false : true; // Set the class\n\n elUrl.classList.add(urlValid ? \"is-valid\" : \"is-invalid\");\n } // Set the validation falg\n\n\n result.isValid = descValid && urlValid; // Return the result\n\n return result;\n };\n\n break;\n // User\n\n case gd_sprest_1.SPTypes.FieldType.User:\n // Set the type\n controlProps.type = isReadonly ? core_1.Components.FormControlTypes.Readonly : peoplePicker_1.PeoplePickerControlType; // Set the flag to allow multiple selections\n\n controlProps.multi = props.field.AllowMultipleValues; // Set the rendered event\n\n onControlRendered = controlProps.onControlRendered;\n\n controlProps.onControlRendered = function (formControl) {\n // Save the control\n control = formControl; // See if this field is readonly and a value exists\n\n if (props.value && isReadonly) {\n // Set the class name\n control.el.classList.add(\"form-control\");\n control.el.style.backgroundColor = \"#e9ecef\"; // Override the html rendered\n\n control.el.innerHTML = props.listInfo.fieldValuesAsHtml[props.field.InternalName];\n } // Call the event\n\n\n onControlRendered ? onControlRendered(formControl) : null;\n };\n\n break;\n } // See if this is the document name field\n\n\n if (props.field.InternalName == \"FileLeafRef\") {\n // Set base validation\n baseValidation = function baseValidation(control, result) {\n var value = result.value; // Ensure the value exists\n\n result.isValid = value ? true : false;\n\n if (result.isValid) {\n // See if it ends w/ a .\n if (value[value.length - 1] == '.') {\n // Update the validation\n result.isValid = false;\n result.invalidMessage = \"The value cannot end with a '.' character.\";\n } // Else, see if it contains invalid characters\n else if (/[~\"\\#\\%\\&\\*\\:\\<\\>\\?\\/\\\\\\{\\|\\}\"]/.test(value) || value.indexOf('\\\\') >= 0) {\n // Update the validation\n result.isValid = false;\n result.invalidMessage = \"The value cannot contain the following characters: ~ \\\" # % & * : < > ? / \\\\ { | }\";\n } // Else, see if we are changing the extension\n else if (control.props.value) {\n // Get the file extensions\n var origExtension = getFileExtension(control.props.value);\n var newExtension = getFileExtension(value); // Update the validation\n\n result.isValid = origExtension == newExtension;\n result.invalidMessage = \"The file extension cannot be changed. It must end with '.\" + origExtension + \"'\";\n }\n } // Return the validation result\n\n\n return result;\n };\n } // See if this is a taxonomy field\n\n\n if (/^TaxonomyFieldType/.test(props.field.TypeAsString)) {\n // Set the type\n controlProps.type = core_1.Components.FormControlTypes.Dropdown; // Set a render event\n\n onControlRendering = controlProps.onControlRendering;\n\n controlProps.onControlRendering = function (newProps) {\n // Update the control properties\n controlProps = newProps; // Return a promise\n\n return new Promise(function (resolve, reject) {\n // Display a loading message\n controlProps.loadingMessage = \"Loading the MMS Data\"; // Load the field information\n\n gd_sprest_1.Helper.ListFormField.create({\n field: props.field,\n listName: props.listInfo.list.Title,\n name: props.field.InternalName,\n webUrl: props.listInfo.webUrl\n }).then( // Success\n function (fieldInfo) {\n // Save the field information\n mmsFieldInfo = fieldInfo; // Set the type\n\n controlProps.type = mmsFieldInfo.multi ? core_1.Components.FormControlTypes.MultiDropdown : core_1.Components.FormControlTypes.Dropdown; // Load the value field\n\n gd_sprest_1.Helper.ListFormField.loadMMSValueField(mmsFieldInfo).then( // Success\n function (valueField) {\n // Set the value field\n mmsFieldInfo.valueField = valueField; // See if this is a new form\n\n if (props.controlMode == gd_sprest_1.SPTypes.ControlMode.New) {\n var fieldValue = []; // Get the default values\n\n var values = (props.field.DefaultValue || \"\").split(\";#\");\n\n for (var i = 0; i < values.length; i++) {\n var value = values[i].split(\"|\");\n\n if (value.length == 2) {\n // Add the term id\n fieldValue.push(value[1]);\n }\n } // Update the field value\n\n\n controlProps.value = fieldValue;\n } else {\n var fieldValue = props.value; // Get the field value\n\n var values = fieldValue && fieldValue.results ? fieldValue.results : [fieldValue]; // Clear the field values\n\n fieldValue = []; // Parse the values\n\n for (var i = 0; i < values.length; i++) {\n // Ensure the value exists\n if (values[i] && values[i].TermGuid) {\n // Add the value\n fieldValue.push(values[i].TermGuid);\n }\n } // Update the field value\n\n\n controlProps.value = fieldValue;\n } // Load the terms\n\n\n gd_sprest_1.Helper.ListFormField.loadMMSData(mmsFieldInfo).then( // Success\n function (terms) {\n // Get the items\n var items = getMMSItems(gd_sprest_1.Helper.Taxonomy.toObject(terms), controlProps.value); // See if this is not a required field and not a multi-select\n\n if (!isRequired && !mmsFieldInfo.multi) {\n // Add a blank entry\n items = [{\n text: \"\",\n value: null\n }].concat(items);\n } // Set the items\n\n\n controlProps.items = items; // Clear the element\n\n controlProps.el ? controlProps.el.innerHTML = \"\" : null; // Call the event\n\n var returnVal = onControlRendering ? onControlRendering(controlProps) : null;\n\n if (returnVal && returnVal.then) {\n // Wait for the promise to complete\n returnVal.then(function (props) {\n // Resolve the promise\n resolve(props || controlProps);\n });\n } else {\n // Resolve the promise\n resolve(controlProps);\n }\n }, // Error\n function (msg) {\n // Set the error message\n var errorMessage = \"Error loading the mms terms for '\" + props.field.InternalName + \"'.\"; // Display an error message\n\n core_1.Components.Alert({\n el: controlProps.el,\n content: errorMessage,\n type: core_1.Components.AlertTypes.Danger\n }); // Call the error event\n\n props.onError ? props.onError(errorMessage) : null;\n });\n }, // Error\n function (msg) {\n // Set the error message\n var errorMessage = \"Error loading the mms value field for '\" + props.field.InternalName + \"'.\"; // Display an error message\n\n core_1.Components.Alert({\n el: controlProps.el,\n content: errorMessage,\n type: core_1.Components.AlertTypes.Danger\n }); // Call the error event\n\n props.onError ? props.onError(errorMessage) : null; // Reject the request\n\n reject(msg);\n });\n }, function (msg) {\n // Display an error message\n core_1.Components.Alert({\n el: controlProps.el,\n content: msg,\n type: core_1.Components.AlertTypes.Danger\n }); // Call the error event\n\n props.onError ? props.onError(msg) : null;\n });\n });\n };\n } // Create the field\n\n\n var field = {\n control: control,\n controlProps: controlProps,\n getValue: function getValue() {\n var fieldValue = {\n name: props.field.InternalName,\n value: control ? control.getValue() : null\n }; // Update the field name/value, based on the type\n\n switch (props.field.FieldTypeKind) {\n // Boolean\n case gd_sprest_1.SPTypes.FieldType.Boolean:\n // Update the value\n fieldValue.value = fieldValue.value ? true : false;\n break;\n // Choice\n\n case gd_sprest_1.SPTypes.FieldType.Choice:\n // See if this is a dropdown\n if (controlProps.type == core_1.Components.FormControlTypes.Dropdown) {\n // See if there is a value\n var ddlValue = fieldValue.value;\n\n if (ddlValue) {\n // Update the field value\n fieldValue.value = ddlValue.value || ddlValue.text;\n }\n } else {\n // See if there is a value\n var cbValue = fieldValue.value;\n\n if (cbValue) {\n // Update the field value\n fieldValue.value = cbValue.label;\n }\n }\n\n break;\n // Number Field\n\n case gd_sprest_1.SPTypes.FieldType.Currency:\n // Ensure a value exists, otherwise null\n fieldValue.value = fieldValue.value || null;\n break;\n // Date/Time\n\n case gd_sprest_1.SPTypes.FieldType.DateTime:\n // Ensure a value exists, otherwise null\n fieldValue.value = fieldValue.value ? fieldValue.value.toISOString() : null;\n break;\n // Lookup\n\n case gd_sprest_1.SPTypes.FieldType.Lookup:\n // Append 'Id' to the field name\n fieldValue.name += fieldValue.name.lastIndexOf(\"Id\") == fieldValue.name.length - 2 ? \"\" : \"Id\"; // See if this is a multi-value field\n\n if (lookupFieldInfo.multi) {\n var values_1 = fieldValue.value || [];\n fieldValue.value = {\n results: []\n }; // Parse the values\n\n for (var j = 0; j < values_1.length; j++) {\n // Add the value\n fieldValue.value.results.push(values_1[j].value || values_1[j].text);\n }\n } else {\n // Update the field value\n fieldValue.value = fieldValue.value ? fieldValue.value.value || fieldValue.value.text : null; // Ensure a value exists, otherwise null\n\n fieldValue.value = fieldValue.value || null;\n }\n\n break;\n // Multi-Choice\n\n case gd_sprest_1.SPTypes.FieldType.MultiChoice:\n var values = fieldValue.value || [];\n fieldValue.value = {\n results: []\n }; // Parse the values\n\n for (var j = 0; j < values.length; j++) {\n // See if this is a dropdown\n if (controlProps.type == core_1.Components.FormControlTypes.MultiDropdown) {\n // See if there is a value\n var ddlValue = values[j]; // Add the values\n\n fieldValue.value.results.push(ddlValue.value || ddlValue.text);\n } else {\n // See if there is a value\n var cbValue = values[j]; // Add the values\n\n fieldValue.value.results.push(cbValue.label);\n }\n }\n\n break;\n // Number Field\n\n case gd_sprest_1.SPTypes.FieldType.Number:\n var numberField = props.field; // Ensure a field value exists\n\n if (fieldValue.value) {\n // See if this is a percentage\n if (numberField.ShowAsPercentage) {\n // Update the value\n fieldValue.value = fieldValue.value / 100;\n }\n } else {\n // Ensure the value is null\n fieldValue.value = null;\n }\n\n break;\n // URL\n\n case gd_sprest_1.SPTypes.FieldType.URL:\n // See if the field value exists\n if (fieldValue.value && fieldValue.value.Url) {\n // Set the url, and validate the format\n var url = fieldValue.value.Url;\n\n if (url && /^http/.test(url.toLowerCase()) == false) {\n // Update the url, otherwise the request will fail\n url = \"https://\" + url;\n } // Add the metadata\n\n\n fieldValue.value = {\n __metadata: {\n type: \"SP.FieldUrlValue\"\n },\n Description: fieldValue.value.Description || \"\",\n Url: url\n };\n } else {\n // Ensure the value is null\n fieldValue.value = null;\n }\n\n break;\n // User\n\n case gd_sprest_1.SPTypes.FieldType.User:\n // Append 'Id' to the field name\n fieldValue.name += fieldValue.name.lastIndexOf(\"Id\") == fieldValue.name.length - 2 ? \"\" : \"Id\"; // See if this is a multi-value field\n\n if (props.field.AllowMultipleValues) {\n var values_2 = fieldValue.value || []; // Default the value\n\n fieldValue.value = {\n results: []\n }; // Parse the options\n\n for (var j = 0; j < values_2.length; j++) {\n var userValue = values_2[j]; // Add the field value\n\n userValue.Id ? fieldValue.value.results.push(userValue.Id) : null;\n }\n } else {\n var userValue = fieldValue.value ? fieldValue.value[0] : null; // Set the field value\n\n fieldValue.value = userValue && userValue.Id ? userValue.Id : null;\n }\n\n break;\n // MMS\n\n default:\n // See if this is a MMS field\n if (mmsFieldInfo) {\n // Update the field name to the value field\n fieldValue.name = mmsFieldInfo ? mmsFieldInfo.valueField.InternalName : fieldValue.name + \"_0\"; // See if this is a multi field\n\n if (mmsFieldInfo.multi) {\n // Parse the field values\n var fieldValues = fieldValue.value || [];\n fieldValue.value = [];\n\n for (var j = 0; j < fieldValues.length; j++) {\n var termInfo = fieldValues[j]; // Add the field value\n\n fieldValue.value.push(-1 + \";#\" + termInfo.text + \"|\" + termInfo.value);\n } // Set the field value\n\n\n fieldValue.value = fieldValue.value.join(\";#\");\n } else {\n // Set the value\n fieldValue.value = fieldValue.value && fieldValue.value.value ? -1 + \";#\" + fieldValue.value.text + \"|\" + fieldValue.value.value : \"\";\n }\n }\n\n break;\n } // Return the field value\n\n\n return fieldValue;\n },\n isValid: function isValid() {\n // See if there is base validation\n if (baseValidation) {\n // Validate the field\n var baseResult = baseValidation(control, {\n isValid: false,\n value: control.getValue()\n }); // Validate the current control\n\n var result = controlProps.onValidate ? controlProps.onValidate(controlProps, baseResult) : baseResult; // Return the flag\n\n if (typeof result === \"boolean\") {\n // Update the validation\n baseResult.isValid = result;\n control.updateValidation(control.el, baseResult); // Return the result\n\n return result;\n } // Update the validation\n\n\n control.updateValidation(control.el, result); // Return the flag\n\n return result.isValid;\n } // Validate the control\n\n\n return control ? control.isValid : false;\n }\n }; // Execute the assign to event\n\n props.assignTo ? props.assignTo(field) : null; // Return the field\n\n return field;\n};\n\n//# sourceURL=webpack://gd-sprest-bs/./build/components/field/index.js?");
668
+ eval("\n\nObject.defineProperty(exports, \"__esModule\", ({\n value: true\n}));\nexports.Field = void 0;\n\nvar gd_sprest_1 = __webpack_require__(/*! gd-sprest */ \"./node_modules/.pnpm/gd-sprest@6.8.4/node_modules/gd-sprest/build/index.js\");\n\nvar core_1 = __webpack_require__(/*! ../core */ \"./build/components/core.js\");\n\nvar datetime_1 = __webpack_require__(/*! ../datetime */ \"./build/components/datetime/index.js\");\n\nvar peoplePicker_1 = __webpack_require__(/*! ../peoplePicker */ \"./build/components/peoplePicker/index.js\");\n/**\r\n * Field\r\n */\n\n\nexports.Field = function (props) {\n var control;\n var lookupFieldInfo = null;\n var mmsFieldInfo = null; // Method to get the choice options\n\n var getChoiceItems = function getChoiceItems(isCheckbox, field, selectedValues) {\n var items = []; // Update the selected values\n\n selectedValues = selectedValues && selectedValues.results ? selectedValues.results : [selectedValues]; // Parse the choices\n\n for (var i = 0; i < field.Choices.results.length; i++) {\n var choice = field.Choices.results[i];\n var isSelected = false; // Determine if this choice is selected\n\n for (var j = 0; j < selectedValues.length; j++) {\n // See if this choice is selected\n if (choice == selectedValues[j]) {\n // Set the flag and break from the loop\n isSelected = true;\n break;\n }\n } // See if this is a checkbox\n\n\n if (isCheckbox) {\n // Add the item\n items.push({\n isSelected: isSelected,\n label: choice\n });\n } else {\n // Add the item\n items.push({\n isSelected: isSelected,\n label: choice,\n text: choice,\n value: choice\n });\n }\n } // See if this is a dropdown and no selected values exists, and this is a required field\n\n\n if (!isCheckbox && items.length > 0 && selectedValues.length == 0 && field.Required) {\n // Select the first item\n items[0].isSelected = true;\n } // Return the items\n\n\n return items;\n }; // Method to get the file extension\n\n\n var getFileExtension = function getFileExtension(fileName) {\n if (fileName === void 0) {\n fileName = \"\";\n }\n\n var extension = fileName.split('.');\n return extension[extension.length - 1].toLowerCase();\n }; // Method to generate the lookup dropdown items\n\n\n var getLookupItems = function getLookupItems(field, lookupItems, selectedValues) {\n var items = []; // Update the selected values\n\n selectedValues = selectedValues && selectedValues.results ? selectedValues.results : [selectedValues]; // Parse the lookup items\n\n for (var i = 0; i < lookupItems.length; i++) {\n var item = lookupItems[i];\n var isSelected = false; // Determine if this lookup is selected\n\n for (var j = 0; j < selectedValues.length; j++) {\n var id = selectedValues[j] && selectedValues[j].Id ? selectedValues[j].Id : selectedValues[j]; // See if this choice is selected\n\n if (item.Id == id) {\n // Set the flag and break from the loop\n isSelected = true;\n break;\n }\n } // Add the item\n\n\n items.push({\n data: item,\n isSelected: isSelected,\n text: item[field.LookupField],\n value: item.Id.toString()\n });\n } // See if no selected values exists, and this is a required field\n\n\n if (items.length > 0 && selectedValues.length == 0 && field.Required) {\n // Select the first item\n items[0].isSelected = true;\n } // Return the items\n\n\n return items;\n }; // Method to get the mms dropdown items\n\n\n var getMMSItems = function getMMSItems(term, selectedValues, isRoot) {\n if (selectedValues === void 0) {\n selectedValues = [];\n }\n\n if (isRoot === void 0) {\n isRoot = true;\n }\n\n var items = []; // See if information exists\n\n if (term.info && !isRoot) {\n var isSelected = false; // Parse the selected values\n\n for (var i = 0; i < selectedValues.length; i++) {\n // See if this item is selected\n if (selectedValues[i] == term.info.id) {\n isSelected = true;\n break;\n }\n } // Add the heading\n\n\n items.push({\n data: term,\n isSelected: isSelected,\n text: term.info.name,\n value: term.info.id\n });\n } // Parse the terms\n\n\n for (var termName in term) {\n var child = term[termName]; // Skip the info and parent properties\n\n if (termName == \"info\" || termName == \"parent\") {\n continue;\n } // Get the child items\n\n\n var childItems = getMMSItems(child, selectedValues, false); // Add the item\n\n items = items.concat(childItems);\n } // See if no selected values exists, and this is a required field\n\n\n if (items.length > 0 && selectedValues.length == 0 && isRequired) {\n // Select the first item\n items[0].isSelected = true;\n } // Return the items\n\n\n return items;\n }; // Set the properties based on the field link\n\n\n var fieldLink = props.listInfo.fieldLinks ? props.listInfo.fieldLinks[props.field.InternalName] : null;\n var isReadonly = fieldLink && typeof fieldLink.ReadOnly === \"boolean\" ? fieldLink.ReadOnly : props.field.ReadOnlyField;\n var isRequired = fieldLink && typeof fieldLink.Required === \"boolean\" ? fieldLink.Required : props.field.Required; // See if this is an internal field\n\n if (props.field.CanBeDeleted == false) {\n // Override the property based on the field property\n isReadonly = isReadonly || props.field.ReadOnlyField;\n } // Set the default properties for the control\n\n\n var controlProps = {\n description: props.field.Description,\n errorMessage: props.errorMessage,\n id: props.field.InternalName,\n isReadonly: isReadonly,\n label: (isRequired ? \"* \" : \"\") + props.field.Title,\n name: props.field.InternalName,\n onControlRendering: function onControlRendering(control) {\n // Execute the event\n return props.onControlRendering ? props.onControlRendering(control, props.field) : null;\n },\n onControlRendered: function onControlRendered(formControl) {\n // Save the control\n control = formControl; // Execute the event\n\n return props.onControlRendered ? props.onControlRendered(control, props.field) : null;\n },\n required: isRequired,\n type: core_1.Components.FormControlTypes.TextField,\n value: props.value\n }; // Define a base validation method\n\n var baseValidation = null; // See if this is a new form, a default value exists and no value has been defined\n\n if (props.controlMode == gd_sprest_1.SPTypes.ControlMode.New && props.field.DefaultValue && props.value == null) {\n // Set the default value\n controlProps.value = props.field.DefaultValue;\n } // Set the type\n\n\n var onControlRendered = null;\n var onControlRendering = null;\n\n switch (props.field.FieldTypeKind) {\n // Boolean\n case gd_sprest_1.SPTypes.FieldType.Boolean:\n // Set the type\n controlProps.type = core_1.Components.FormControlTypes.Checkbox; // Create the item\n\n controlProps.items = [{\n label: controlProps.label\n }]; // Clear the label\n\n controlProps.label = \"\";\n break;\n // Choice\n\n case gd_sprest_1.SPTypes.FieldType.Choice:\n var displayRadioButtons = props.field.SchemaXml.indexOf('Format=\"RadioButtons\"') > 0 ? true : false; // See if we are displaying radio buttons\n\n if (displayRadioButtons) {\n // Set the type\n controlProps.type = core_1.Components.FormControlTypes.Switch;\n } else {\n // Set the type\n controlProps.type = core_1.Components.FormControlTypes.Dropdown;\n } // Get the items\n\n\n var items = getChoiceItems(displayRadioButtons, props.field, props.value); // See if this is not a required field\n\n if (!isRequired) {\n // Add a blank entry\n items = [{\n text: \"\",\n value: null\n }].concat(items);\n } // Set the items\n\n\n controlProps.items = items;\n break;\n // Currency Field\n\n case gd_sprest_1.SPTypes.FieldType.Currency:\n // Set the type\n controlProps.type = core_1.Components.FormControlTypes.TextField; // Set the rendered event\n\n onControlRendered = controlProps.onControlRendered;\n\n controlProps.onControlRendered = function (formControl) {\n // Save the control\n control = formControl; // Call the event\n\n onControlRendered ? onControlRendered(formControl) : null;\n };\n\n break;\n // Date/Time\n\n case gd_sprest_1.SPTypes.FieldType.DateTime:\n // Set the time flag\n var showTime = props.field.DisplayFormat == gd_sprest_1.SPTypes.DateFormat.DateTime;\n controlProps.showTime = showTime; // Set the type\n\n controlProps.type = datetime_1.DateTimeControlType; // See if there is a formula and this is a new form\n\n var dtValue = (props.field.DefaultFormula || props.field.DefaultValue || \"\").toLowerCase();\n\n if (dtValue && props.controlMode == gd_sprest_1.SPTypes.ControlMode.New) {\n var idx = dtValue.indexOf(\"today\"); // See if the date is a formula\n\n if (idx >= 0) {\n var dtNow = new Date(Date.now()); // See if we are adding days\n\n var daysIdx = dtValue.indexOf(\"+\", idx);\n\n if (daysIdx > 0) {\n // Get the number of days to add\n var days = parseInt(dtValue.substr(daysIdx + 1));\n\n if (days > 0) {\n // Add the days\n dtNow.setDate(dtNow.getDate() + days);\n }\n } // See if we are subtracting days\n\n\n daysIdx = dtValue.indexOf(\"-\", idx);\n\n if (daysIdx > 0) {\n // Get the number of days to add\n var days = parseInt(dtValue.substr(daysIdx + 1));\n\n if (days > 0) {\n // Add the days\n dtNow.setDate(dtNow.getDate() - days);\n }\n } // Set the value\n\n\n controlProps.value = dtNow;\n } else {\n // Set the value\n controlProps.value = new Date(dtValue);\n }\n }\n\n break;\n // Lookup\n\n case gd_sprest_1.SPTypes.FieldType.Lookup:\n // Default the lookup field props will determine the default type\n controlProps.type = props.field.AllowMultipleValues ? core_1.Components.FormControlTypes.MultiDropdown : core_1.Components.FormControlTypes.Dropdown; // See if this field is readonly and a value exists\n\n if (isReadonly) {\n // Update the value\n controlProps.type = core_1.Components.FormControlTypes.Readonly; // Ensure a value exists\n\n if (props.value) {\n // Set the rendered event\n onControlRendered = controlProps.onControlRendered;\n\n controlProps.onControlRendered = function (formControl) {\n // Set the class name\n control.el.classList.add(\"form-control\");\n control.el.style.backgroundColor = \"#e9ecef\"; // Override the html rendered\n\n control.el.innerHTML = props.listInfo.fieldValuesAsHtml[props.field.InternalName];\n };\n }\n } else {\n // Set the rendering event\n onControlRendering = controlProps.onControlRendering;\n\n controlProps.onControlRendering = function (newProps) {\n // Update the control properties\n controlProps = newProps; // Display a loading message\n\n controlProps.loadingMessage = \"Loading the Lookup Data\"; // Return a promise\n\n return new Promise(function (resolve, reject) {\n // Load the field information\n gd_sprest_1.Helper.ListFormField.create({\n field: props.field,\n listName: props.listInfo.list.Title,\n name: props.field.InternalName,\n webUrl: props.listInfo.webUrl\n }).then( // Success\n function (fieldInfo) {\n // Save the field information\n lookupFieldInfo = fieldInfo; // Set the lookup filter\n\n lookupFieldInfo.lookupFilter = controlProps.lookupFilter; // Update the multi property\n\n controlProps.multi = lookupFieldInfo.multi; // Get the drop down information\n\n gd_sprest_1.Helper.ListFormField.loadLookupData(lookupFieldInfo, 500).then( // Success\n function (items) {\n // Get the dropdown items\n var ddlItems = getLookupItems(props.field, items, props.value); // See if this is not a required field and not a multi-select\n\n if (!isRequired && !lookupFieldInfo.multi) {\n // Add a blank entry\n ddlItems = [{\n text: \"\",\n value: null\n }].concat(ddlItems);\n } // Set the items\n\n\n controlProps.items = ddlItems; // Clear the element\n\n controlProps.el ? controlProps.el.innerHTML = \"\" : null; // Clear the value, since the getLookupItems method takes care of this for us\n\n controlProps.value = null; // Call the event\n\n var returnVal = onControlRendering ? onControlRendering(controlProps) : null;\n\n if (returnVal && returnVal.then) {\n // Wait for the promise to complete\n returnVal.then(function (props) {\n // Resolve the promise\n resolve(props || controlProps);\n });\n } else {\n // Resolve the promise\n resolve(controlProps);\n }\n }, // Error\n function (msg) {\n // Set the error message\n var errorMessage = \"Error loading the lookup field values for '\" + props.field.InternalName + \"'.\"; // Display an error message\n\n core_1.Components.Alert({\n el: controlProps.el,\n content: errorMessage,\n type: core_1.Components.AlertTypes.Danger\n }); // Call the error event\n\n props.onError ? props.onError(errorMessage) : null;\n });\n }, // Error\n function (msg) {\n // Set the error message\n var errorMessage = \"Error loading the field information for field '\" + props.field.InternalName + \"'.\"; // Display an error message\n\n controlProps.el.innerHTML = \"\";\n core_1.Components.Alert({\n el: controlProps.el,\n content: \"Error loading the lookup field information.\",\n type: core_1.Components.AlertTypes.Danger\n }); // Call the error event\n\n props.onError ? props.onError(errorMessage) : null; // Reject the request\n\n reject(msg);\n });\n });\n };\n }\n\n break;\n // Multi-Choice\n\n case gd_sprest_1.SPTypes.FieldType.MultiChoice:\n var isChoice = props.field.SchemaXml.indexOf('Format=\"RadioButtons\"') > 0 ? true : false; // Set the type\n\n controlProps.type = isChoice ? core_1.Components.FormControlTypes.MultiSwitch : core_1.Components.FormControlTypes.MultiDropdown; // Update the value\n\n controlProps.value = (props.value ? props.value.results : null) || props.value; // Set the items\n\n controlProps.items = getChoiceItems(isChoice, props.field, props.value);\n break;\n // Note\n\n case gd_sprest_1.SPTypes.FieldType.Note:\n // Set the properties\n controlProps.type = core_1.Components.FormControlTypes.TextArea;\n controlProps.rows = props.field.NumberOfLines;\n break;\n // Number Field\n\n case gd_sprest_1.SPTypes.FieldType.Number:\n var numberField_1 = props.field;\n var numberProps = controlProps; // Set the default value\n\n numberProps.value = numberProps.value == null ? numberField_1.DefaultValue : numberProps.value; // See if this is a percentage\n\n var isPercent = numberField_1.ShowAsPercentage;\n\n if (isPercent == null) {\n // Set the value from the schema (2013 environments)\n isPercent = numberField_1.SchemaXml.toLowerCase().indexOf('percentage=\"true\"') > 0;\n }\n\n if (isPercent) {\n // Set the type\n numberProps.type = core_1.Components.FormControlTypes.Range; // Default the max\n\n numberProps.max = numberField_1.MaximumValue == 1 || numberField_1.MaximumValue == Number.MAX_VALUE ? 100 : numberField_1.MaximumValue; // Set the min value\n\n numberProps.min = numberField_1.MinimumValue == -1.7976931348623157e+308 ? 0 : numberField_1.MinimumValue; // Set the value\n\n numberProps.value = numberProps.value == null || numberProps.value == Number.MIN_VALUE ? 0 : numberProps.value;\n numberProps.value = numberProps.value * (numberProps.max == 100 && numberProps.value < 1 ? 100 : 1);\n } // Else, see if the min/max values are defined\n else if (typeof numberField_1.MaximumValue == \"number\" && numberField_1.MaximumValue != Number.MAX_VALUE && typeof numberField_1.MinimumValue == \"number\" && numberField_1.MinimumValue != Number.MIN_VALUE) {\n // Update the properties to display a range\n numberProps.type = core_1.Components.FormControlTypes.Range;\n numberProps.max = numberField_1.MaximumValue;\n numberProps.min = numberField_1.MinimumValue;\n numberProps.value = typeof numberProps.value == \"number\" ? numberProps.value : numberProps.min; // Set validation\n\n if (numberField_1.MinimumValue || numberField_1.MaximumValue) {\n // Add validation\n baseValidation = function baseValidation(control, result) {\n // Ensure the value is a number\n if (/^[0-9]*$/.test(result.value) == false) {\n // Update the validation and return it\n result.isValid = false;\n result.invalidMessage = \"The value must be a number.\";\n return result;\n } // Validate the min value\n\n\n if (numberField_1.MinimumValue && result.value < numberField_1.MinimumValue) {\n // Update the validation and return it\n result.isValid = false;\n result.invalidMessage = \"The value must be greater than or equal to \" + numberField_1.MinimumValue;\n return result;\n } // Validate the max value\n\n\n if (numberField_1.MaximumValue && result.value > numberField_1.MaximumValue) {\n // Update the validation and return it\n result.isValid = false;\n result.invalidMessage = \"The value must be less than or equal to \" + numberField_1.MaximumValue;\n return result;\n } // Valid\n\n\n result.isValid = true; // Return the result\n\n return result;\n };\n }\n } else {\n // Set the type\n numberProps.type = core_1.Components.FormControlTypes.TextField;\n }\n\n break;\n // URL\n\n case gd_sprest_1.SPTypes.FieldType.URL:\n var desc_1 = null;\n var url_1 = null;\n var value_1 = props.value; // See if a value exists\n\n if (props.value) {\n // Update the value\n controlProps.value = props.value.Url;\n } // Set the render event\n\n\n onControlRendered = controlProps.onControlRendered;\n\n controlProps.onControlRendered = function (formControl) {\n // Save the control\n control = formControl; // Clear the element\n\n control.el.innerHTML = \"\"; // See if we are rendering the description\n\n var showDesc = controlProps.showDescription;\n showDesc = typeof showDesc === \"boolean\" ? showDesc : true;\n\n if (showDesc) {\n // Render the description\n desc_1 = core_1.Components.FormControl({\n className: \"mb-1\",\n el: control.el,\n placeholder: \"Description\",\n type: core_1.Components.FormControlTypes.TextField,\n value: value_1 ? value_1.Description : null\n });\n } // Render the url\n\n\n url_1 = core_1.Components.FormControl({\n el: control.el,\n placeholder: \"Url\",\n type: core_1.Components.FormControlTypes.TextField,\n value: value_1 ? value_1.Url : null\n }); // Set the get value event\n\n control.props.onGetValue = function () {\n // Return the value\n return {\n Description: desc_1 ? desc_1.getValue() : url_1.getValue(),\n Url: url_1.getValue()\n };\n }; // Call the event\n\n\n onControlRendered ? onControlRendered(formControl) : null;\n }; // Set the validate event\n\n\n baseValidation = function baseValidation(control, result) {\n var descValid,\n urlValid = false; // Get the form control elements\n\n var elFormControl = control.el.querySelectorAll(\".form-control\");\n var elDesc = elFormControl[0];\n var elUrl = elFormControl[1]; // See if the description exists\n\n if (elDesc) {\n // Clear the classes\n elDesc.classList.remove(\"is-invalid\");\n elDesc.classList.remove(\"is-valid\"); // Set the flag\n\n descValid = control.props.required ? desc_1.getValue() ? true : false : true; // Set the class\n\n elDesc.classList.add(descValid ? \"is-valid\" : \"is-invalid\");\n } // See if the url exists\n\n\n if (elUrl) {\n // Clear the classes\n elUrl.classList.remove(\"is-invalid\");\n elUrl.classList.remove(\"is-valid\"); // Set the flag\n\n urlValid = control.props.required ? url_1.getValue() ? true : false : true; // Set the class\n\n elUrl.classList.add(urlValid ? \"is-valid\" : \"is-invalid\");\n } // Set the validation falg\n\n\n result.isValid = descValid && urlValid; // Return the result\n\n return result;\n };\n\n break;\n // User\n\n case gd_sprest_1.SPTypes.FieldType.User:\n // Set the type\n controlProps.type = isReadonly ? core_1.Components.FormControlTypes.Readonly : peoplePicker_1.PeoplePickerControlType; // Set the flag to allow multiple selections\n\n controlProps.multi = props.field.AllowMultipleValues; // Set the rendered event\n\n onControlRendered = controlProps.onControlRendered;\n\n controlProps.onControlRendered = function (formControl) {\n // Save the control\n control = formControl; // See if this field is readonly and a value exists\n\n if (props.value && isReadonly) {\n // Set the class name\n control.el.classList.add(\"form-control\");\n control.el.style.backgroundColor = \"#e9ecef\"; // Override the html rendered\n\n control.el.innerHTML = props.listInfo.fieldValuesAsHtml[props.field.InternalName];\n } // Call the event\n\n\n onControlRendered ? onControlRendered(formControl) : null;\n };\n\n break;\n } // See if this is the document name field\n\n\n if (props.field.InternalName == \"FileLeafRef\") {\n // Set base validation\n baseValidation = function baseValidation(control, result) {\n var value = result.value; // Ensure the value exists\n\n result.isValid = value ? true : false;\n\n if (result.isValid) {\n // See if it ends w/ a .\n if (value[value.length - 1] == '.') {\n // Update the validation\n result.isValid = false;\n result.invalidMessage = \"The value cannot end with a '.' character.\";\n } // Else, see if it contains invalid characters\n else if (/[~\"\\#\\%\\&\\*\\:\\<\\>\\?\\/\\\\\\{\\|\\}\"]/.test(value) || value.indexOf('\\\\') >= 0) {\n // Update the validation\n result.isValid = false;\n result.invalidMessage = \"The value cannot contain the following characters: ~ \\\" # % & * : < > ? / \\\\ { | }\";\n } // Else, see if we are changing the extension\n else if (control.props.value) {\n // Get the file extensions\n var origExtension = getFileExtension(control.props.value);\n var newExtension = getFileExtension(value); // Update the validation\n\n result.isValid = origExtension == newExtension;\n result.invalidMessage = \"The file extension cannot be changed. It must end with '.\" + origExtension + \"'\";\n }\n } // Return the validation result\n\n\n return result;\n };\n } // See if this is a taxonomy field\n\n\n if (/^TaxonomyFieldType/.test(props.field.TypeAsString)) {\n // Set the type\n controlProps.type = core_1.Components.FormControlTypes.Dropdown; // Set a render event\n\n onControlRendering = controlProps.onControlRendering;\n\n controlProps.onControlRendering = function (newProps) {\n // Update the control properties\n controlProps = newProps; // Return a promise\n\n return new Promise(function (resolve, reject) {\n // Display a loading message\n controlProps.loadingMessage = \"Loading the MMS Data\"; // Load the field information\n\n gd_sprest_1.Helper.ListFormField.create({\n field: props.field,\n listName: props.listInfo.list.Title,\n name: props.field.InternalName,\n webUrl: props.listInfo.webUrl\n }).then( // Success\n function (fieldInfo) {\n // Save the field information\n mmsFieldInfo = fieldInfo; // Set the type\n\n controlProps.type = mmsFieldInfo.multi ? core_1.Components.FormControlTypes.MultiDropdown : core_1.Components.FormControlTypes.Dropdown; // Load the value field\n\n gd_sprest_1.Helper.ListFormField.loadMMSValueField(mmsFieldInfo).then( // Success\n function (valueField) {\n // Set the value field\n mmsFieldInfo.valueField = valueField; // See if this is a new form\n\n if (props.controlMode == gd_sprest_1.SPTypes.ControlMode.New) {\n var fieldValue = []; // Get the default values\n\n var values = (props.field.DefaultValue || \"\").split(\";#\");\n\n for (var i = 0; i < values.length; i++) {\n var value = values[i].split(\"|\");\n\n if (value.length == 2) {\n // Add the term id\n fieldValue.push(value[1]);\n }\n } // Update the field value\n\n\n controlProps.value = fieldValue;\n } else {\n var fieldValue = props.value; // Get the field value\n\n var values = fieldValue && fieldValue.results ? fieldValue.results : [fieldValue]; // Clear the field values\n\n fieldValue = []; // Parse the values\n\n for (var i = 0; i < values.length; i++) {\n // Ensure the value exists\n if (values[i] && values[i].TermGuid) {\n // Add the value\n fieldValue.push(values[i].TermGuid);\n }\n } // Update the field value\n\n\n controlProps.value = fieldValue;\n } // Load the terms\n\n\n gd_sprest_1.Helper.ListFormField.loadMMSData(mmsFieldInfo).then( // Success\n function (terms) {\n // Get the items\n var items = getMMSItems(gd_sprest_1.Helper.Taxonomy.toObject(terms), controlProps.value); // See if this is not a required field and not a multi-select\n\n if (!isRequired && !mmsFieldInfo.multi) {\n // Add a blank entry\n items = [{\n text: \"\",\n value: null\n }].concat(items);\n } // Set the items\n\n\n controlProps.items = items; // Clear the element\n\n controlProps.el ? controlProps.el.innerHTML = \"\" : null; // Call the event\n\n var returnVal = onControlRendering ? onControlRendering(controlProps) : null;\n\n if (returnVal && returnVal.then) {\n // Wait for the promise to complete\n returnVal.then(function (props) {\n // Resolve the promise\n resolve(props || controlProps);\n });\n } else {\n // Resolve the promise\n resolve(controlProps);\n }\n }, // Error\n function (msg) {\n // Set the error message\n var errorMessage = \"Error loading the mms terms for '\" + props.field.InternalName + \"'.\"; // Display an error message\n\n core_1.Components.Alert({\n el: controlProps.el,\n content: errorMessage,\n type: core_1.Components.AlertTypes.Danger\n }); // Call the error event\n\n props.onError ? props.onError(errorMessage) : null;\n });\n }, // Error\n function (msg) {\n // Set the error message\n var errorMessage = \"Error loading the mms value field for '\" + props.field.InternalName + \"'.\"; // Display an error message\n\n core_1.Components.Alert({\n el: controlProps.el,\n content: errorMessage,\n type: core_1.Components.AlertTypes.Danger\n }); // Call the error event\n\n props.onError ? props.onError(errorMessage) : null; // Reject the request\n\n reject(msg);\n });\n }, function (msg) {\n // Display an error message\n core_1.Components.Alert({\n el: controlProps.el,\n content: msg,\n type: core_1.Components.AlertTypes.Danger\n }); // Call the error event\n\n props.onError ? props.onError(msg) : null;\n });\n });\n };\n } // Create the field\n\n\n var field = {\n control: control,\n controlProps: controlProps,\n getValue: function getValue() {\n var fieldValue = {\n name: props.field.InternalName,\n value: control ? control.getValue() : null\n }; // Update the field name/value, based on the type\n\n switch (props.field.FieldTypeKind) {\n // Boolean\n case gd_sprest_1.SPTypes.FieldType.Boolean:\n // Update the value\n fieldValue.value = fieldValue.value ? true : false;\n break;\n // Choice\n\n case gd_sprest_1.SPTypes.FieldType.Choice:\n // See if this is a dropdown\n if (controlProps.type == core_1.Components.FormControlTypes.Dropdown) {\n // See if there is a value\n var ddlValue = fieldValue.value;\n\n if (ddlValue) {\n // Update the field value\n fieldValue.value = ddlValue.value || ddlValue.text;\n }\n } else {\n // See if there is a value\n var cbValue = fieldValue.value;\n\n if (cbValue) {\n // Update the field value\n fieldValue.value = cbValue.label;\n }\n }\n\n break;\n // Number Field\n\n case gd_sprest_1.SPTypes.FieldType.Currency:\n // Ensure a value exists, otherwise null\n fieldValue.value = fieldValue.value || null;\n break;\n // Date/Time\n\n case gd_sprest_1.SPTypes.FieldType.DateTime:\n // Ensure a value exists, otherwise null\n fieldValue.value = fieldValue.value ? fieldValue.value.toISOString() : null;\n break;\n // Lookup\n\n case gd_sprest_1.SPTypes.FieldType.Lookup:\n // Append 'Id' to the field name\n fieldValue.name += fieldValue.name.lastIndexOf(\"Id\") == fieldValue.name.length - 2 ? \"\" : \"Id\"; // See if this is a multi-value field\n\n if (lookupFieldInfo.multi) {\n var values_1 = fieldValue.value || [];\n fieldValue.value = {\n results: []\n }; // Parse the values\n\n for (var j = 0; j < values_1.length; j++) {\n // Add the value\n fieldValue.value.results.push(values_1[j].value || values_1[j].text);\n }\n } else {\n // Update the field value\n fieldValue.value = fieldValue.value ? fieldValue.value.value || fieldValue.value.text : null; // Ensure a value exists, otherwise null\n\n fieldValue.value = fieldValue.value || null;\n }\n\n break;\n // Multi-Choice\n\n case gd_sprest_1.SPTypes.FieldType.MultiChoice:\n var values = fieldValue.value || [];\n fieldValue.value = {\n results: []\n }; // Parse the values\n\n for (var j = 0; j < values.length; j++) {\n // See if this is a dropdown\n if (controlProps.type == core_1.Components.FormControlTypes.MultiDropdown) {\n // See if there is a value\n var ddlValue = values[j]; // Add the values\n\n fieldValue.value.results.push(ddlValue.value || ddlValue.text);\n } else {\n // See if there is a value\n var cbValue = values[j]; // Add the values\n\n fieldValue.value.results.push(cbValue.label);\n }\n }\n\n break;\n // Number Field\n\n case gd_sprest_1.SPTypes.FieldType.Number:\n var numberField = props.field; // Ensure a field value exists\n\n if (fieldValue.value) {\n // See if this is a percentage\n if (numberField.ShowAsPercentage) {\n // Update the value\n fieldValue.value = fieldValue.value / 100;\n }\n } else {\n // Ensure the value is null\n fieldValue.value = null;\n }\n\n break;\n // URL\n\n case gd_sprest_1.SPTypes.FieldType.URL:\n // See if the field value exists\n if (fieldValue.value && fieldValue.value.Url) {\n // Set the url, and validate the format\n var url = fieldValue.value.Url;\n\n if (url && /^http/.test(url.toLowerCase()) == false) {\n // Update the url, otherwise the request will fail\n url = \"https://\" + url;\n } // Add the metadata\n\n\n fieldValue.value = {\n __metadata: {\n type: \"SP.FieldUrlValue\"\n },\n Description: fieldValue.value.Description || \"\",\n Url: url\n };\n } else {\n // Ensure the value is null\n fieldValue.value = null;\n }\n\n break;\n // User\n\n case gd_sprest_1.SPTypes.FieldType.User:\n // Append 'Id' to the field name\n fieldValue.name += fieldValue.name.lastIndexOf(\"Id\") == fieldValue.name.length - 2 ? \"\" : \"Id\"; // See if this is a multi-value field\n\n if (props.field.AllowMultipleValues) {\n var values_2 = fieldValue.value || []; // Default the value\n\n fieldValue.value = {\n results: []\n }; // Parse the options\n\n for (var j = 0; j < values_2.length; j++) {\n var userValue = values_2[j]; // Add the field value\n\n userValue.Id ? fieldValue.value.results.push(userValue.Id) : null;\n }\n } else {\n var userValue = fieldValue.value ? fieldValue.value[0] : null; // Set the field value\n\n fieldValue.value = userValue && userValue.Id ? userValue.Id : null;\n }\n\n break;\n // MMS\n\n default:\n // See if this is a MMS field\n if (mmsFieldInfo) {\n // Update the field name to the value field\n fieldValue.name = mmsFieldInfo ? mmsFieldInfo.valueField.InternalName : fieldValue.name + \"_0\"; // See if this is a multi field\n\n if (mmsFieldInfo.multi) {\n // Parse the field values\n var fieldValues = fieldValue.value || [];\n fieldValue.value = [];\n\n for (var j = 0; j < fieldValues.length; j++) {\n var termInfo = fieldValues[j]; // Add the field value\n\n fieldValue.value.push(-1 + \";#\" + termInfo.text + \"|\" + termInfo.value);\n } // Set the field value\n\n\n fieldValue.value = fieldValue.value.join(\";#\");\n } else {\n // Set the value\n fieldValue.value = fieldValue.value && fieldValue.value.value ? -1 + \";#\" + fieldValue.value.text + \"|\" + fieldValue.value.value : \"\";\n }\n }\n\n break;\n } // Return the field value\n\n\n return fieldValue;\n },\n isValid: function isValid() {\n // See if there is base validation\n if (baseValidation) {\n // Validate the field\n var baseResult = baseValidation(control, {\n isValid: false,\n value: control.getValue()\n }); // Validate the current control\n\n var result = controlProps.onValidate ? controlProps.onValidate(controlProps, baseResult) : baseResult; // Return the flag\n\n if (typeof result === \"boolean\") {\n // Update the validation\n baseResult.isValid = result;\n control.updateValidation(control.el, baseResult); // Return the result\n\n return result;\n } // Update the validation\n\n\n control.updateValidation(control.el, result); // Return the flag\n\n return result.isValid;\n } // Validate the control\n\n\n return control ? control.isValid : false;\n }\n }; // Execute the assign to event\n\n props.assignTo ? props.assignTo(field) : null; // Return the field\n\n return field;\n};\n\n//# sourceURL=webpack://gd-sprest-bs/./build/components/field/index.js?");
669
669
 
670
670
  /***/ }),
671
671
 
@@ -698,7 +698,7 @@ eval("\n\nObject.defineProperty(exports, \"__esModule\", ({\n value: true\n}));
698
698
  /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
699
699
 
700
700
  "use strict";
701
- eval("\n\nObject.defineProperty(exports, \"__esModule\", ({\n value: true\n}));\nexports.ListForm = void 0;\n\nvar gd_sprest_1 = __webpack_require__(/*! gd-sprest */ \"./node_modules/.pnpm/gd-sprest@6.8.4/node_modules/gd-sprest/build/index.js\");\n\nvar core_1 = __webpack_require__(/*! ../core */ \"./build/components/core.js\");\n\nvar datetime_1 = __webpack_require__(/*! ../datetime */ \"./build/components/datetime/index.js\");\n\nvar field_1 = __webpack_require__(/*! ../field */ \"./build/components/field/index.js\"); // Extend the list form\n\n\nexports.ListForm = gd_sprest_1.Helper.ListForm; // Method to get the fields to render\n\nvar getFieldsToRender = function getFieldsToRender(props) {\n var fieldNames = []; // See if the \"include\" fields property is defined\n\n if (props.includeFields) {\n // Set the field names\n fieldNames = props.includeFields;\n } else {\n // Parse the fields\n for (var fieldName in props.info.fields) {\n // See if the \"exclude\" property is set\n if (props.excludeFields) {\n var renderFl = true; // Parse the fields\n\n for (var i = 0; i < props.excludeFields.length; i++) {\n // See if we are excluding this field\n if (props.excludeFields[i] == fieldName) {\n // Set the flag\n renderFl = false;\n break;\n }\n } // Skip this field, if we are not rendering it\n\n\n if (!renderFl) {\n continue;\n }\n } // Add the field name\n\n\n fieldNames.push(fieldName);\n }\n } // Return the field names\n\n\n return fieldNames;\n}; // Method to render a display form for an item\n\n\nexports.ListForm.renderDisplayForm = function (props) {\n var form = null; // Render a loading message\n\n var progress = core_1.Components.Progress({\n el: props.el,\n isAnimated: true,\n isStriped: true,\n label: \"Loading the Form\",\n size: 100\n });\n var mapper = {};\n var rows = []; // See if we are rendering attachments\n\n if (props.info.attachments) {\n // Render the attachments\n rows.push({\n columns: [{\n control: {\n id: \"ListFormAttachments\",\n label: \"Attachments\",\n name: \"Attachments\",\n onControlRendered: function onControlRendered(control) {\n var items = []; // Parse the attachments\n\n for (var i = 0; i < props.info.attachments.length; i++) {\n var attachment = props.info.attachments[i]; // Add the item\n\n items.push({\n buttons: [{\n className: \"me-1\",\n href: attachment.ServerRelativeUrl,\n isSmall: true,\n text: attachment.FileName\n }]\n });\n } // Render a toolbar\n\n\n core_1.Components.Toolbar({\n el: control.el,\n items: items\n });\n }\n }\n }]\n });\n } // Parse the fields to render\n\n\n var fieldNames = getFieldsToRender(props);\n\n for (var i = 0; i < fieldNames.length; i++) {\n var fieldName = fieldNames[i];\n var field = props.info.fields[fieldName];\n var value = props.info.fieldValuesAsText[fieldName] || \"\";\n var html = props.info.fieldValuesAsHtml[fieldName] || props.info.fieldValuesAsHtml[fieldName.replace(/\\_/g, \"_x005f_\")] || \"\"; // Ensure the field exists\n\n if (field == null) {\n // Log\n console.error(\"[List Form] Field '\" + fieldName + \"' does not exist. Check the list or query.\");\n continue;\n } // See if we are hiding the field\n\n\n if (field.SchemaXml.indexOf('ShowInDisplayForm=\"FALSE\"') > 0) {\n continue;\n } // See if this is a note field\n\n\n if (field.FieldTypeKind == gd_sprest_1.SPTypes.FieldType.Note) {\n // Update the html\n html = html.replace(/\\r?\\n/g, '<br />');\n } // Else, see if this is a user field\n else if (field.FieldTypeKind == gd_sprest_1.SPTypes.FieldType.User) {\n // See if this is a multi-user selection\n if (field.AllowMultipleValues) {\n var userNames = []; // Parse the users\n\n var users = (props.info.item[fieldName] ? props.info.item[fieldName].results : null) || [];\n\n for (var j = 0; j < users.length; j++) {\n // Append the user name\n userNames.push(users[j].Title);\n } // Set the html value\n\n\n html = userNames.join('<br />\\n');\n } else {\n // Extract the text only for single selections\n var elUser = document.createElement(\"div\");\n elUser.innerHTML = html;\n html = elUser.innerText;\n }\n } // Else, see if this is a choice field\n else if (field.FieldTypeKind == gd_sprest_1.SPTypes.FieldType.Choice || field.FieldTypeKind == gd_sprest_1.SPTypes.FieldType.MultiChoice) {\n // Update the html\n html = value;\n } // Set the control\n\n\n mapper[fieldName] = {\n data: html,\n description: field.Description,\n isReadonly: true,\n label: field.Title,\n name: field.InternalName,\n type: core_1.Components.FormControlTypes.TextField,\n value: html\n }; // Update the type, based on the field\n\n switch (field.FieldTypeKind) {\n case gd_sprest_1.SPTypes.FieldType.DateTime:\n // Set the time flag\n mapper[fieldName].showTime = field.DisplayFormat == gd_sprest_1.SPTypes.DateFormat.DateTime ? true : false; // Set the type\n\n mapper[fieldName].type = datetime_1.DateTimeControlType;\n break;\n\n case gd_sprest_1.SPTypes.FieldType.Note:\n // Set the type\n mapper[fieldName].type = core_1.Components.FormControlTypes.TextArea;\n break;\n\n case gd_sprest_1.SPTypes.FieldType.User:\n // Set the type\n mapper[fieldName].type = field.AllowMultipleValues ? core_1.Components.FormControlTypes.TextArea : mapper[fieldName].type;\n break;\n } // Detect html\n\n\n if (/<*>/g.test(html)) {\n // Update the control to be read-only\n mapper[fieldName].type = core_1.Components.FormControlTypes.Readonly; // Set the rendered event\n\n mapper[fieldName].onControlRendered = function (control) {\n // Set the class name\n control.el.classList.add(\"form-control\");\n control.el.style.backgroundColor = \"#e9ecef\"; // Override the html rendered\n\n control.el.innerHTML = control.props.data;\n };\n } // Add the row\n\n\n rows.push({\n columns: [{\n control: mapper[fieldName]\n }]\n });\n } // See if there is a template\n\n\n if (props.template) {\n var updateControl = function updateControl(refControl) {\n // Get the control from the mapper\n var control = refControl ? mapper[refControl.name] : null; // Ensure the controls exists\n\n if (control && refControl) {\n // Parse the control keys\n for (var key in control) {\n // Skip if a value is already defined\n if (refControl[key]) {\n continue;\n } // Update the property\n\n\n refControl[key] = control[key];\n }\n }\n }; // Parse the template\n\n\n for (var i = 0; i < props.template.length; i++) {\n var row = props.template[i]; // Parse the columns if there are columns\n\n var columns = row.columns || [];\n\n for (var j = 0; j < columns.length; j++) {\n var column = columns[j]; // Update the control\n\n updateControl(column.control);\n }\n }\n } // Remove the progress bar\n\n\n progress.el.parentElement ? progress.el.parentElement.removeChild(progress.el) : null; // Counter for each control\n\n var ctrlCounter = 0; // Render the form\n\n form = core_1.Components.Form({\n el: props.el,\n className: props.className,\n groupClassName: props.groupClassName,\n rowClassName: props.rowClassName,\n onControlRendered: function onControlRendered(control) {\n // See if all of the controls have been rendered\n if (++ctrlCounter == rows.length) {\n // See if an event exists\n if (props.onFormRendered) {\n // Execute the form rendered event in another thread\n setTimeout(function () {\n props.onFormRendered(form);\n }, 10);\n }\n } // Return the control rendered event\n\n\n return props.onControlRendered ? props.onControlRendered(control, props.info.fields[control.props.name]) : null;\n },\n onControlRendering: function onControlRendering(control) {\n return props.onControlRendering ? props.onControlRendering(control, props.info.fields[control.name]) : null;\n },\n rows: props.template || rows\n }); // Execute the assign to event\n\n props.assignTo ? props.assignTo(form) : null; // Return the form informaiton\n\n return {\n get el() {\n return form ? form.el : null;\n }\n\n };\n}; // Render the edit form\n\n\nexports.ListForm.renderEditForm = function (props) {\n var mapper = {};\n var rows = [];\n var value = {};\n var attachments = {\n \"delete\": [],\n \"new\": []\n }; // Method to add a refresh alert\n\n var addRefreshLink = function addRefreshLink() {\n // Ensure the link doesn't already exist\n if (props.el.querySelector(\".refresh-btn\")) {\n return;\n } // Create the refresh button\n\n\n var alert = core_1.Components.ButtonGroup({\n className: \"refresh-btn\",\n buttonType: core_1.Components.ButtonTypes.Danger,\n buttons: [{\n text: \"Refresh Form\",\n onClick: function onClick() {\n // Clear the element and reload the form\n props.el.innerHTML = \"\"; // Render the form\n\n exports.ListForm.renderEditForm(props);\n }\n }, {\n text: \"Refresh Page\",\n onClick: function onClick() {\n // Refresh the page\n document.location.href = document.location.href;\n }\n }]\n }); // Add the element at the top\n\n props.el.insertBefore(alert.el, props.el.children[0]);\n }; // Method to remove the attachments\n\n\n var removeAttachments = function removeAttachments(info) {\n // Return a promise\n return new Promise(function (resolve, reject) {\n // Ensure attachments exists\n if (attachments[\"delete\"].length == 0) {\n resolve();\n return;\n } // Get the web\n\n\n props.info.list.ParentWeb().execute(function (web) {\n // Parse the attachments\n gd_sprest_1.Helper.Executor(attachments[\"delete\"], function (attachment) {\n // Get the attachment file\n web.getFileByServerRelativeUrl(attachment.ServerRelativeUrl)[\"delete\"]().execute(); // Parse the attachments\n\n for (var i = 0; i < props.info.attachments.length; i++) {\n // See if this is the target attachment\n if (props.info.attachments[i].ServerRelativeUrl == attachment.ServerRelativeUrl) {\n // Remove this item\n props.info.attachments.splice(i, 1);\n break;\n }\n }\n }).then(function () {\n // Wait for the files to be deleted\n web.done(function () {\n // Clear the attachments\n attachments[\"delete\"] = []; // Resolve the promise\n\n resolve();\n });\n });\n });\n });\n }; // Method to save the attachments\n\n\n var saveAttachments = function saveAttachments(info) {\n // Return a promise\n return new Promise(function (resolve, reject) {\n // Ensure attachments exists\n if (attachments[\"new\"].length == 0) {\n resolve();\n return;\n } // Parse the attachments\n\n\n gd_sprest_1.Helper.Executor(attachments[\"new\"], function (attachment) {\n // Get the item's attachments\n props.info.list.Items(info.item.Id).AttachmentFiles() // Add the file\n .add(attachment.name, attachment.data) // Execute the request\n .execute(function (attachment) {\n // Ensure attachments exist\n info.attachments = info.attachments || []; // Append the attachment\n\n info.attachments.push(attachment);\n });\n }).then(function () {\n // Wait for the files to upload\n props.info.list.done(function () {\n // Clear the attachments\n attachments[\"new\"] = []; // Resolve the promise\n\n resolve();\n });\n });\n });\n }; // Render a loading message\n\n\n var progress = core_1.Components.Progress({\n el: props.el,\n isAnimated: true,\n isStriped: true,\n label: \"Loading the Form\",\n size: 100\n }); // See if we are rendering attachments\n\n if (props.info.attachments) {\n // Render the attachments\n rows.push({\n columns: [{\n control: {\n id: \"ListFormAttachments\",\n label: \"Attachments\",\n name: \"Attachments\",\n onControlRendered: function onControlRendered(control) {\n // Render a toolbar\n var toolbar = core_1.Components.Toolbar({\n el: control.el,\n items: [{\n buttons: [{\n className: \"upload-btn me-1\",\n isSmall: true,\n text: \"Upload\",\n type: core_1.Components.ButtonTypes.Secondary,\n onClick: function onClick(btn, ev) {\n var elUpload = ev.currentTarget; // Display an upload dialog\n\n gd_sprest_1.Helper.ListForm.showFileDialog().then(function (fileInfo) {\n // Get the buttons and remove any duplicates\n var buttons = elUpload.parentElement.querySelectorAll(\".btn\");\n\n for (var i = 0; i < buttons.length; i++) {\n var button = buttons[i]; // See if this is the associated button\n\n if (button.innerText.replace(/X$/, '') == fileInfo.name) {\n // Get the badge\n var badge = button.querySelector(\".badge\");\n\n if (badge) {\n // Remove the button\n badge.click();\n }\n\n break;\n }\n } // Save the file information\n\n\n attachments[\"new\"].push(fileInfo); // Append the attachment\n\n elUpload.parentElement.appendChild(core_1.Components.Popover({\n isDismissible: true,\n type: core_1.Components.PopoverPlacements.Bottom,\n btnProps: {\n className: \"me-1\",\n isSmall: true,\n text: fileInfo.name\n },\n options: {\n content: core_1.Components.Button({\n data: fileInfo,\n isSmall: true,\n text: \"Remove\",\n type: core_1.Components.ButtonTypes.Danger,\n onClick: function onClick(btn, ev) {\n var fileName = btn.data.name; // Parse the array\n\n for (var i = 0; i < attachments[\"new\"].length; i++) {\n // See if this is the target attachment\n if (attachments[\"new\"][i].name == fileName) {\n // Remove this attachment\n attachments[\"new\"].splice(i, 1);\n break;\n }\n } // Get the files\n\n\n var files = btnGroup.querySelectorAll(\".btn[data-toggle='popover']\");\n\n for (var i = 0; i < files.length; i++) {\n var file = files[i]; // See if this is the target button\n\n if (file.innerText == fileName) {\n // Remove this popover\n file.parentElement.removeChild(file);\n break;\n }\n }\n }\n }).el\n }\n }).el);\n });\n }\n }]\n }]\n }); // Get the button group\n\n var btnGroup = toolbar.el.querySelector(\".btn-group\");\n\n if (btnGroup) {\n // Parse the attachments\n for (var i = 0; i < props.info.attachments.length; i++) {\n var attachment = props.info.attachments[i]; // Add the attachment\n\n btnGroup.appendChild(core_1.Components.Popover({\n isDismissible: true,\n type: core_1.Components.PopoverPlacements.Bottom,\n btnProps: {\n className: \"me-1\",\n isSmall: true,\n text: attachment.FileName\n },\n options: {\n content: core_1.Components.Button({\n data: attachment,\n isSmall: true,\n text: \"Remove\",\n type: core_1.Components.ButtonTypes.Danger,\n onClick: function onClick(btn, ev) {\n var attachment = btn.data; // Add this file for deletion\n\n attachments[\"delete\"].push(attachment); // Get the files\n\n var files = btnGroup.querySelectorAll(\".btn[data-toggle='popover']\");\n\n for (var i_1 = 0; i_1 < files.length; i_1++) {\n var file = files[i_1]; // See if this is the target button\n\n if (file.innerText == attachment.FileName) {\n // Remove this popover\n file.parentElement.removeChild(file);\n break;\n }\n }\n }\n }).el\n }\n }).el);\n }\n }\n }\n }\n }]\n });\n } // Parse the fields to render\n\n\n var fieldNames = getFieldsToRender(props);\n\n for (var i = 0; i < fieldNames.length; i++) {\n var fieldName = fieldNames[i];\n var field = props.info.fields[fieldName]; // Ensure the field exists\n\n if (field == null) {\n // Log\n console.error(\"[List Form] Field '\" + fieldName + \"' does not exist. Check the list or query.\");\n continue;\n } // See if the item exists\n\n\n value[fieldName] = null;\n\n if (props.info.item) {\n // Set the value\n value[fieldName] = props.info.item[fieldName]; // See if this is a lookup or user field\n\n if (field.FieldTypeKind == gd_sprest_1.SPTypes.FieldType.Lookup || field.FieldTypeKind == gd_sprest_1.SPTypes.FieldType.User) {\n // Update the value\n value[fieldName] = value[fieldName + \"Id\"] || (value[fieldName] ? value[fieldName].Id : null) || value[fieldName];\n } // See if this is a file leaf ref\n\n\n if (fieldName == \"FileLeafRef\") {\n // Update the value\n value[fieldName] = value[fieldName] || props.info.item.Title;\n }\n } // Determine the control mode\n\n\n var controlMode = props.controlMode || (props.info.item ? gd_sprest_1.SPTypes.ControlMode.Edit : gd_sprest_1.SPTypes.ControlMode.New); // See if this is an edit form and we are hiding this field\n\n if (controlMode == gd_sprest_1.SPTypes.ControlMode.Edit && field.SchemaXml.indexOf('ShowInEditForm=\"FALSE\"') > 0) {\n continue;\n } // See if this is a new form and we are hiding this field\n\n\n if (controlMode == gd_sprest_1.SPTypes.ControlMode.New && field.SchemaXml.indexOf('ShowInNewForm=\"FALSE\"') > 0) {\n continue;\n } // See if thi sis a new form and this is an associated lookup field\n\n\n if (controlMode == gd_sprest_1.SPTypes.ControlMode.New && field.IsDependentLookup) {\n continue;\n } // See if this is a display form and we are hiding this field\n\n\n if (controlMode == gd_sprest_1.SPTypes.ControlMode.Display && field.SchemaXml.indexOf('ShowInDisplayForm=\"FALSE\"') > 0) {\n continue;\n } // See if this is a read-only field\n\n\n if (field.ReadOnlyField) {\n // Do not render in the new form\n if (props.controlMode == gd_sprest_1.SPTypes.ControlMode.New) {\n continue;\n }\n } // Do not render a hidden taxonomy field\n\n\n if (field.Hidden && field.FieldTypeKind == gd_sprest_1.SPTypes.FieldType.Note && /_0$/.test(field.Title)) {\n continue;\n } // See if this is an invalid field type\n\n\n if (field.FieldTypeKind == gd_sprest_1.SPTypes.FieldType.Invalid) {\n // Ensure it's not a taxonomy field\n if (!/^TaxonomyFieldType/.test(field.TypeAsString)) {\n continue;\n }\n } // Else, see if this is a calculated column\n else if (field.FieldTypeKind == gd_sprest_1.SPTypes.FieldType.Calculated) {\n // Do not render in the new/edit forms\n if (props.controlMode != gd_sprest_1.SPTypes.ControlMode.Display) {\n continue;\n }\n } // See if this is a lookup field\n\n\n var lookupFilter = null;\n\n if (field.FieldTypeKind == gd_sprest_1.SPTypes.FieldType.Lookup) {\n // Call the filter event\n lookupFilter = props.onFilterLookupField ? props.onFilterLookupField(field) : null;\n } // Create the control\n\n\n var fieldControl = field_1.Field({\n controlMode: props.controlMode,\n field: field,\n listInfo: props.info,\n lookupFilter: lookupFilter,\n value: value[fieldName],\n onControlRendered: function onControlRendered(control, field) {\n // Update the mapper\n mapper[field.InternalName].control = control;\n },\n onValidate: props.onValidate,\n onError: function onError(msg) {\n // Add the refresh link\n addRefreshLink(); // Call the event\n\n props.onError ? props.onError(msg) : null;\n }\n }); // Update the mapper\n\n mapper[fieldName] = fieldControl; // Add the row\n\n rows.push({\n columns: [{\n control: fieldControl.controlProps\n }]\n });\n } // See if there is a template\n\n\n if (props.template) {\n var updateControl = function updateControl(refControl) {\n // Get the control from the mapper\n var control = refControl && mapper[refControl.name] ? mapper[refControl.name].controlProps : null; // Ensure the controls exists\n\n if (control && refControl) {\n // Parse the control keys\n for (var key in control) {\n // Skip if a value is already defined\n if (refControl[key]) {\n continue;\n } // Update the property\n\n\n refControl[key] = control[key];\n }\n }\n }; // Parse the template\n\n\n for (var i = 0; i < props.template.length; i++) {\n var row = props.template[i]; // Parse the columns if there are columns\n\n var columns = row.columns || [];\n\n for (var j = 0; j < columns.length; j++) {\n var column = columns[j]; // Update the control\n\n updateControl(column.control);\n }\n }\n } // Remove the progress bar\n\n\n progress.el.parentElement ? progress.el.parentElement.removeChild(progress.el) : null; // Counter for each control\n\n var ctrlCounter = 0; // Render the form\n\n var form = core_1.Components.Form({\n el: props.el,\n className: props.className,\n groupClassName: props.groupClassName,\n rowClassName: props.rowClassName,\n onControlRendered: function onControlRendered(control) {\n // See if all of the controls have been rendered\n if (++ctrlCounter == rows.length) {\n // See if an event exists\n if (props.onFormRendered) {\n // Execute the form rendered event in another thread\n setTimeout(function () {\n props.onFormRendered(form);\n }, 10);\n }\n } // Return the event\n\n\n return props.onControlRendered ? props.onControlRendered(control, props.info.fields[control.props.name]) : null;\n },\n onControlRendering: function onControlRendering(control) {\n var updateReadOnly = function updateReadOnly(control) {\n // See if this control is readonly\n if (control.isReadonly) {\n var html_1 = props.info.fieldValuesAsHtml && props.info.fieldValuesAsHtml[field.InternalName] || \"\"; // Update the control properties\n\n control.type = core_1.Components.FormControlTypes.Readonly; // Detect html\n\n if (/<*>/g.test(html_1)) {\n // Update the control properties\n control.data = html_1;\n } // Set the rendered event\n\n\n control.onControlRendered = function (control) {\n // Set the class name\n control.el.classList.add(\"form-control\");\n control.el.style.backgroundColor = \"#e9ecef\"; // Override the html rendered\n\n control.el.innerHTML = html_1 || control.props.value;\n }; // See if this is a user field\n\n\n if (field.FieldTypeKind == gd_sprest_1.SPTypes.FieldType.User) {\n // See if this is a multi-user selection\n if (field.AllowMultipleValues) {\n var userNames = []; // Parse the users\n\n var users = (props.info.item[field.InternalName] ? props.info.item[field.InternalName].results : null) || [];\n\n for (var j = 0; j < users.length; j++) {\n // Append the user name\n userNames.push(users[j].Title);\n } // Set the html value\n\n\n html_1 = userNames.join('<br />\\n');\n } else {\n // Extract the text only for single selections\n var elUser = document.createElement(\"div\");\n elUser.innerHTML = html_1;\n html_1 = elUser.innerText;\n }\n }\n }\n }; // Execute the rendering event\n\n\n var field = props.info.fields[control.name];\n var returnVal = props.onControlRendering ? props.onControlRendering(control, field) : null;\n\n if (returnVal && returnVal.then) {\n // Wait for the event to complete\n returnVal.then(function (ctrlProps) {\n // Update the properties\n updateReadOnly(ctrlProps || control);\n });\n } else {\n // Update the properties\n updateReadOnly(control);\n }\n },\n rows: props.template || rows,\n value: value\n }); // Method to get the values\n\n var getValues = function getValues() {\n var values = {}; // Parse the fields\n\n for (var fieldName in props.info.fields) {\n // Get the form field and skip readonly fields\n var formField = mapper[fieldName];\n\n if (formField == null || formField.controlProps.isReadonly) {\n continue;\n } // Get the field value\n\n\n var fieldValue = formField.getValue(); // Set the item value\n\n values[fieldValue.name] = fieldValue.value; // See if this is the file leaf ref\n\n if (fieldValue.name == \"FileLeafRef\") {\n // Update the 'Title'\n values[\"Title\"] = values[\"Title\"] || values[fieldValue.name];\n }\n } // Return the form values\n\n\n return values;\n }; // Create the form object\n\n\n var formObj = {\n appendControls: function appendControls(controls) {\n form.appendControls(controls);\n },\n appendRows: function appendRows(rows) {\n form.appendRows(rows);\n },\n el: form.el,\n getControl: function getControl(fieldName) {\n return mapper[fieldName] ? mapper[fieldName].control : null;\n },\n getValues: getValues,\n isValid: function isValid() {\n var isValid = true; // Parse the fields\n\n for (var fieldName in props.info.fields) {\n // Skip readonly fields\n var formField = mapper[fieldName];\n\n if (formField == null || formField.controlProps.isReadonly) {\n continue;\n } // Validate the form field and update the status flag\n\n\n var controlIsValid = formField.isValid();\n isValid = isValid && controlIsValid;\n } // Return the flag\n\n\n return isValid;\n },\n save: function save() {\n var onSaving = function onSaving(values) {\n return new Promise(function (resolve) {\n // See if a save event exists\n var returnVal = props.onSaving ? props.onSaving(values) : null;\n\n if (returnVal && returnVal.then) {\n // Wait for the promise to complete\n returnVal.then(function (newValues) {\n // Resolve the promise\n resolve(newValues || values);\n });\n } else {\n // Resolve the promise\n resolve(values);\n }\n });\n }; // Return a promise\n\n\n return new Promise(function (resolve, reject) {\n // Call the saving event\n onSaving(getValues()).then(function (values) {\n // Update the item\n exports.ListForm.saveItem(props.info, values).then(function (info) {\n // Remove the attachments\n removeAttachments(info).then(function () {\n // Save the attachments\n saveAttachments(info).then(function () {\n // Update the info\n props.info = info; // Resolve the promise\n\n resolve(props.info.item);\n });\n });\n }, reject);\n });\n });\n }\n }; // Execute the assign to event\n\n props.assignTo ? props.assignTo(formObj) : null; // Return the form\n\n return formObj;\n};\n\n//# sourceURL=webpack://gd-sprest-bs/./build/components/listForm/index.js?");
701
+ eval("\n\nObject.defineProperty(exports, \"__esModule\", ({\n value: true\n}));\nexports.ListForm = void 0;\n\nvar gd_sprest_1 = __webpack_require__(/*! gd-sprest */ \"./node_modules/.pnpm/gd-sprest@6.8.4/node_modules/gd-sprest/build/index.js\");\n\nvar core_1 = __webpack_require__(/*! ../core */ \"./build/components/core.js\");\n\nvar datetime_1 = __webpack_require__(/*! ../datetime */ \"./build/components/datetime/index.js\");\n\nvar field_1 = __webpack_require__(/*! ../field */ \"./build/components/field/index.js\"); // Extend the list form\n\n\nexports.ListForm = gd_sprest_1.Helper.ListForm; // Method to get the fields to render\n\nvar getFieldsToRender = function getFieldsToRender(props) {\n var fieldNames = []; // See if the \"include\" fields property is defined\n\n if (props.includeFields) {\n // Set the field names\n fieldNames = props.includeFields;\n } else {\n // Parse the fields\n for (var fieldName in props.info.fields) {\n // See if the \"exclude\" property is set\n if (props.excludeFields) {\n var renderFl = true; // Parse the fields\n\n for (var i = 0; i < props.excludeFields.length; i++) {\n // See if we are excluding this field\n if (props.excludeFields[i] == fieldName) {\n // Set the flag\n renderFl = false;\n break;\n }\n } // Skip this field, if we are not rendering it\n\n\n if (!renderFl) {\n continue;\n }\n } // Add the field name\n\n\n fieldNames.push(fieldName);\n }\n } // Return the field names\n\n\n return fieldNames;\n}; // Method to render a display form for an item\n\n\nexports.ListForm.renderDisplayForm = function (props) {\n var form = null; // Render a loading message\n\n var progress = core_1.Components.Progress({\n el: props.el,\n isAnimated: true,\n isStriped: true,\n label: \"Loading the Form\",\n size: 100\n });\n var mapper = {};\n var rows = []; // See if we are rendering attachments\n\n if (props.info.attachments) {\n // Render the attachments\n rows.push({\n columns: [{\n control: {\n id: \"ListFormAttachments\",\n label: \"Attachments\",\n name: \"Attachments\",\n onControlRendered: function onControlRendered(control) {\n var items = []; // Parse the attachments\n\n for (var i = 0; i < props.info.attachments.length; i++) {\n var attachment = props.info.attachments[i]; // Add the item\n\n items.push({\n buttons: [{\n className: \"me-1\",\n href: attachment.ServerRelativeUrl,\n isSmall: true,\n text: attachment.FileName\n }]\n });\n } // Render a toolbar\n\n\n core_1.Components.Toolbar({\n el: control.el,\n items: items\n });\n }\n }\n }]\n });\n } // Parse the fields to render\n\n\n var fieldNames = getFieldsToRender(props);\n\n for (var i = 0; i < fieldNames.length; i++) {\n var fieldName = fieldNames[i];\n var field = props.info.fields[fieldName];\n var value = props.info.fieldValuesAsText[fieldName] || \"\";\n var html = props.info.fieldValuesAsHtml[fieldName] || props.info.fieldValuesAsHtml[fieldName.replace(/\\_/g, \"_x005f_\")] || \"\"; // Ensure the field exists\n\n if (field == null) {\n // Log\n console.error(\"[List Form] Field '\" + fieldName + \"' does not exist. Check the list or query.\");\n continue;\n } // See if we are hiding the field\n\n\n if (field.SchemaXml.indexOf('ShowInDisplayForm=\"FALSE\"') > 0) {\n continue;\n } // See if this is a note field\n\n\n if (field.FieldTypeKind == gd_sprest_1.SPTypes.FieldType.Note) {\n // Update the html\n html = html.replace(/\\r?\\n/g, '<br />');\n } // Else, see if this is a user field\n else if (field.FieldTypeKind == gd_sprest_1.SPTypes.FieldType.User) {\n // See if this is a multi-user selection\n if (field.AllowMultipleValues) {\n var userNames = []; // Parse the users\n\n var users = (props.info.item[fieldName] ? props.info.item[fieldName].results : null) || [];\n\n for (var j = 0; j < users.length; j++) {\n // Append the user name\n userNames.push(users[j].Title);\n } // Set the html value\n\n\n html = userNames.join('<br />\\n');\n } else {\n // Extract the text only for single selections\n var elUser = document.createElement(\"div\");\n elUser.innerHTML = html;\n html = elUser.innerText;\n }\n } // Else, see if this is a choice field\n else if (field.FieldTypeKind == gd_sprest_1.SPTypes.FieldType.Choice || field.FieldTypeKind == gd_sprest_1.SPTypes.FieldType.MultiChoice) {\n // Update the html\n html = value;\n } // Set the control\n\n\n mapper[fieldName] = {\n data: html,\n description: field.Description,\n isReadonly: true,\n label: field.Title,\n name: field.InternalName,\n type: core_1.Components.FormControlTypes.TextField,\n value: html\n }; // Update the type, based on the field\n\n switch (field.FieldTypeKind) {\n case gd_sprest_1.SPTypes.FieldType.DateTime:\n // Set the time flag\n mapper[fieldName].showTime = field.DisplayFormat == gd_sprest_1.SPTypes.DateFormat.DateTime ? true : false; // Set the type\n\n mapper[fieldName].type = datetime_1.DateTimeControlType;\n break;\n\n case gd_sprest_1.SPTypes.FieldType.Note:\n // Set the type\n mapper[fieldName].type = core_1.Components.FormControlTypes.TextArea;\n break;\n\n case gd_sprest_1.SPTypes.FieldType.User:\n // Set the type\n mapper[fieldName].type = field.AllowMultipleValues ? core_1.Components.FormControlTypes.TextArea : mapper[fieldName].type;\n break;\n } // Detect html\n\n\n if (/<*>/g.test(html)) {\n // Update the control to be read-only\n mapper[fieldName].type = core_1.Components.FormControlTypes.Readonly; // Set the rendered event\n\n mapper[fieldName].onControlRendered = function (control) {\n // Set the class name\n control.el.classList.add(\"form-control\");\n control.el.style.backgroundColor = \"#e9ecef\"; // Override the html rendered\n\n control.el.innerHTML = control.props.data;\n };\n } // Add the row\n\n\n rows.push({\n columns: [{\n control: mapper[fieldName]\n }]\n });\n } // See if there is a template\n\n\n if (props.template) {\n var updateControl = function updateControl(refControl) {\n // Get the control from the mapper\n var control = refControl ? mapper[refControl.name] : null; // Ensure the controls exists\n\n if (control && refControl) {\n // Parse the control keys\n for (var key in control) {\n // Skip if a value is already defined\n if (refControl[key]) {\n continue;\n } // Update the property\n\n\n refControl[key] = control[key];\n }\n }\n }; // Parse the template\n\n\n for (var i = 0; i < props.template.length; i++) {\n var row = props.template[i]; // Parse the columns if there are columns\n\n var columns = row.columns || [];\n\n for (var j = 0; j < columns.length; j++) {\n var column = columns[j]; // Update the control\n\n updateControl(column.control);\n }\n }\n } // Remove the progress bar\n\n\n progress.el.parentElement ? progress.el.parentElement.removeChild(progress.el) : null; // Counter for each control\n\n var ctrlCounter = 0; // Render the form\n\n form = core_1.Components.Form({\n el: props.el,\n className: props.className,\n groupClassName: props.groupClassName,\n rowClassName: props.rowClassName,\n onControlRendered: function onControlRendered(control) {\n // See if all of the controls have been rendered\n if (++ctrlCounter == rows.length) {\n // See if an event exists\n if (props.onFormRendered) {\n // Execute the form rendered event in another thread\n setTimeout(function () {\n props.onFormRendered(form);\n }, 10);\n }\n } // Return the control rendered event\n\n\n return props.onControlRendered ? props.onControlRendered(control, props.info.fields[control.props.name]) : null;\n },\n onControlRendering: function onControlRendering(control) {\n return props.onControlRendering ? props.onControlRendering(control, props.info.fields[control.name]) : null;\n },\n rows: props.template || rows\n }); // Execute the assign to event\n\n props.assignTo ? props.assignTo(form) : null; // Return the form informaiton\n\n return {\n get el() {\n return form ? form.el : null;\n }\n\n };\n}; // Render the edit form\n\n\nexports.ListForm.renderEditForm = function (props) {\n var mapper = {};\n var rows = [];\n var value = {};\n var attachments = {\n \"delete\": [],\n \"new\": []\n }; // Method to add a refresh alert\n\n var addRefreshLink = function addRefreshLink() {\n // Ensure the link doesn't already exist\n if (props.el.querySelector(\".refresh-btn\")) {\n return;\n } // Create the refresh button\n\n\n var alert = core_1.Components.ButtonGroup({\n className: \"refresh-btn\",\n buttonType: core_1.Components.ButtonTypes.Danger,\n buttons: [{\n text: \"Refresh Form\",\n onClick: function onClick() {\n // Clear the element and reload the form\n props.el.innerHTML = \"\"; // Render the form\n\n exports.ListForm.renderEditForm(props);\n }\n }, {\n text: \"Refresh Page\",\n onClick: function onClick() {\n // Refresh the page\n document.location.href = document.location.href;\n }\n }]\n }); // Add the element at the top\n\n props.el.insertBefore(alert.el, props.el.children[0]);\n }; // Method to remove the attachments\n\n\n var removeAttachments = function removeAttachments(info) {\n // Return a promise\n return new Promise(function (resolve, reject) {\n // Ensure attachments exists\n if (attachments[\"delete\"].length == 0) {\n resolve();\n return;\n } // Get the web\n\n\n props.info.list.ParentWeb().execute(function (web) {\n // Parse the attachments\n gd_sprest_1.Helper.Executor(attachments[\"delete\"], function (attachment) {\n // Get the attachment file\n web.getFileByServerRelativeUrl(attachment.ServerRelativeUrl)[\"delete\"]().execute(); // Parse the attachments\n\n for (var i = 0; i < props.info.attachments.length; i++) {\n // See if this is the target attachment\n if (props.info.attachments[i].ServerRelativeUrl == attachment.ServerRelativeUrl) {\n // Remove this item\n props.info.attachments.splice(i, 1);\n break;\n }\n }\n }).then(function () {\n // Wait for the files to be deleted\n web.done(function () {\n // Clear the attachments\n attachments[\"delete\"] = []; // Resolve the promise\n\n resolve();\n });\n });\n });\n });\n }; // Method to save the attachments\n\n\n var saveAttachments = function saveAttachments(info) {\n // Return a promise\n return new Promise(function (resolve, reject) {\n // Ensure attachments exists\n if (attachments[\"new\"].length == 0) {\n resolve();\n return;\n } // Parse the attachments\n\n\n gd_sprest_1.Helper.Executor(attachments[\"new\"], function (attachment) {\n // Get the item's attachments\n props.info.list.Items(info.item.Id).AttachmentFiles() // Add the file\n .add(attachment.name, attachment.data) // Execute the request\n .execute(function (attachment) {\n // Ensure attachments exist\n info.attachments = info.attachments || []; // Append the attachment\n\n info.attachments.push(attachment);\n });\n }).then(function () {\n // Wait for the files to upload\n props.info.list.done(function () {\n // Clear the attachments\n attachments[\"new\"] = []; // Resolve the promise\n\n resolve();\n });\n });\n });\n }; // Render a loading message\n\n\n var progress = core_1.Components.Progress({\n el: props.el,\n isAnimated: true,\n isStriped: true,\n label: \"Loading the Form\",\n size: 100\n }); // See if we are rendering attachments\n\n if (props.info.attachments) {\n // Render the attachments\n rows.push({\n columns: [{\n control: {\n id: \"ListFormAttachments\",\n label: \"Attachments\",\n name: \"Attachments\",\n onControlRendered: function onControlRendered(control) {\n // Render a toolbar\n var toolbar = core_1.Components.Toolbar({\n el: control.el,\n items: [{\n buttons: [{\n className: \"upload-btn me-1\",\n isSmall: true,\n text: \"Upload\",\n type: core_1.Components.ButtonTypes.Secondary,\n onClick: function onClick(btn, ev) {\n var elUpload = ev.currentTarget; // Display an upload dialog\n\n gd_sprest_1.Helper.ListForm.showFileDialog().then(function (fileInfo) {\n // Get the buttons and remove any duplicates\n var buttons = elUpload.parentElement.querySelectorAll(\".btn\");\n\n for (var i = 0; i < buttons.length; i++) {\n var button = buttons[i]; // See if this is the associated button\n\n if (button.innerText.replace(/X$/, '') == fileInfo.name) {\n // Get the badge\n var badge = button.querySelector(\".badge\");\n\n if (badge) {\n // Remove the button\n badge.click();\n }\n\n break;\n }\n } // Save the file information\n\n\n attachments[\"new\"].push(fileInfo); // Append the attachment\n\n elUpload.parentElement.appendChild(core_1.Components.Popover({\n isDismissible: true,\n type: core_1.Components.PopoverPlacements.Bottom,\n btnProps: {\n className: \"me-1\",\n isSmall: true,\n text: fileInfo.name\n },\n options: {\n content: core_1.Components.Button({\n data: fileInfo,\n isSmall: true,\n text: \"Remove\",\n type: core_1.Components.ButtonTypes.Danger,\n onClick: function onClick(btn, ev) {\n var fileName = btn.data.name; // Parse the array\n\n for (var i = 0; i < attachments[\"new\"].length; i++) {\n // See if this is the target attachment\n if (attachments[\"new\"][i].name == fileName) {\n // Remove this attachment\n attachments[\"new\"].splice(i, 1);\n break;\n }\n } // Get the files\n\n\n var files = btnGroup.querySelectorAll(\".btn[data-toggle='popover']\");\n\n for (var i = 0; i < files.length; i++) {\n var file = files[i]; // See if this is the target button\n\n if (file.innerText == fileName) {\n // Remove this popover\n file.parentElement.removeChild(file);\n break;\n }\n }\n }\n }).el\n }\n }).el);\n });\n }\n }]\n }]\n }); // Get the button group\n\n var btnGroup = toolbar.el.querySelector(\".btn-group\");\n\n if (btnGroup) {\n // Parse the attachments\n for (var i = 0; i < props.info.attachments.length; i++) {\n var attachment = props.info.attachments[i]; // Add the attachment\n\n btnGroup.appendChild(core_1.Components.Popover({\n isDismissible: true,\n type: core_1.Components.PopoverPlacements.Bottom,\n btnProps: {\n className: \"me-1\",\n isSmall: true,\n text: attachment.FileName\n },\n options: {\n content: core_1.Components.Button({\n data: attachment,\n isSmall: true,\n text: \"Remove\",\n type: core_1.Components.ButtonTypes.Danger,\n onClick: function onClick(btn, ev) {\n var attachment = btn.data; // Add this file for deletion\n\n attachments[\"delete\"].push(attachment); // Get the files\n\n var files = btnGroup.querySelectorAll(\".btn[data-toggle='popover']\");\n\n for (var i_1 = 0; i_1 < files.length; i_1++) {\n var file = files[i_1]; // See if this is the target button\n\n if (file.innerText == attachment.FileName) {\n // Remove this popover\n file.parentElement.removeChild(file);\n break;\n }\n }\n }\n }).el\n }\n }).el);\n }\n }\n }\n }\n }]\n });\n } // Parse the fields to render\n\n\n var fieldNames = getFieldsToRender(props);\n\n var _loop_1 = function _loop_1(i) {\n var fieldName = fieldNames[i];\n var field = props.info.fields[fieldName]; // Ensure the field exists\n\n if (field == null) {\n // Log\n console.error(\"[List Form] Field '\" + fieldName + \"' does not exist. Check the list or query.\");\n return \"continue\";\n } // See if the item exists\n\n\n value[fieldName] = null;\n\n if (props.info.item) {\n // Set the value\n value[fieldName] = props.info.item[fieldName]; // See if this is a lookup or user field\n\n if (field.FieldTypeKind == gd_sprest_1.SPTypes.FieldType.Lookup || field.FieldTypeKind == gd_sprest_1.SPTypes.FieldType.User) {\n // Update the value\n value[fieldName] = value[fieldName + \"Id\"] || (value[fieldName] ? value[fieldName].Id : null) || value[fieldName];\n } // See if this is a file leaf ref\n\n\n if (fieldName == \"FileLeafRef\") {\n // Update the value\n value[fieldName] = value[fieldName] || props.info.item.Title;\n }\n } // Determine the control mode\n\n\n var controlMode = props.controlMode || (props.info.item ? gd_sprest_1.SPTypes.ControlMode.Edit : gd_sprest_1.SPTypes.ControlMode.New); // See if this is an edit form and we are hiding this field\n\n if (controlMode == gd_sprest_1.SPTypes.ControlMode.Edit && field.SchemaXml.indexOf('ShowInEditForm=\"FALSE\"') > 0) {\n return \"continue\";\n } // See if this is a new form and we are hiding this field\n\n\n if (controlMode == gd_sprest_1.SPTypes.ControlMode.New && field.SchemaXml.indexOf('ShowInNewForm=\"FALSE\"') > 0) {\n return \"continue\";\n } // See if thi sis a new form and this is an associated lookup field\n\n\n if (controlMode == gd_sprest_1.SPTypes.ControlMode.New && field.IsDependentLookup) {\n return \"continue\";\n } // See if this is a display form and we are hiding this field\n\n\n if (controlMode == gd_sprest_1.SPTypes.ControlMode.Display && field.SchemaXml.indexOf('ShowInDisplayForm=\"FALSE\"') > 0) {\n return \"continue\";\n } // See if this is a read-only field\n\n\n if (field.ReadOnlyField) {\n // Do not render in the new form\n if (props.controlMode == gd_sprest_1.SPTypes.ControlMode.New) {\n return \"continue\";\n }\n } // Do not render a hidden taxonomy field\n\n\n if (field.Hidden && field.FieldTypeKind == gd_sprest_1.SPTypes.FieldType.Note && /_0$/.test(field.Title)) {\n return \"continue\";\n } // See if this is an invalid field type\n\n\n if (field.FieldTypeKind == gd_sprest_1.SPTypes.FieldType.Invalid) {\n // Ensure it's not a taxonomy field\n if (!/^TaxonomyFieldType/.test(field.TypeAsString)) {\n return \"continue\";\n }\n } // Else, see if this is a calculated column\n else if (field.FieldTypeKind == gd_sprest_1.SPTypes.FieldType.Calculated) {\n // Do not render in the new/edit forms\n if (props.controlMode != gd_sprest_1.SPTypes.ControlMode.Display) {\n return \"continue\";\n }\n } // See if this is a lookup field\n\n\n var lookupFilter = null;\n\n if (field.FieldTypeKind == gd_sprest_1.SPTypes.FieldType.Lookup) {\n // Call the filter event\n lookupFilter = props.onFilterLookupField ? props.onFilterLookupField(field) : null;\n } // Create the control\n\n\n var fieldControl = field_1.Field({\n controlMode: props.controlMode,\n field: field,\n listInfo: props.info,\n value: value[fieldName],\n onControlRendering: function onControlRendering(control, field) {\n // Set the lookup field filter\n lookupFilter ? control.lookupFilter = lookupFilter : null;\n },\n onControlRendered: function onControlRendered(control, field) {\n // Update the mapper\n mapper[field.InternalName].control = control;\n },\n onValidate: props.onValidate,\n onError: function onError(msg) {\n // Add the refresh link\n addRefreshLink(); // Call the event\n\n props.onError ? props.onError(msg) : null;\n }\n }); // Update the mapper\n\n mapper[fieldName] = fieldControl; // Add the row\n\n rows.push({\n columns: [{\n control: fieldControl.controlProps\n }]\n });\n };\n\n for (var i = 0; i < fieldNames.length; i++) {\n _loop_1(i);\n } // See if there is a template\n\n\n if (props.template) {\n var updateControl = function updateControl(refControl) {\n // Get the control from the mapper\n var control = refControl && mapper[refControl.name] ? mapper[refControl.name].controlProps : null; // Ensure the controls exists\n\n if (control && refControl) {\n // Parse the control keys\n for (var key in control) {\n // Skip if a value is already defined\n if (refControl[key]) {\n continue;\n } // Update the property\n\n\n refControl[key] = control[key];\n }\n }\n }; // Parse the template\n\n\n for (var i = 0; i < props.template.length; i++) {\n var row = props.template[i]; // Parse the columns if there are columns\n\n var columns = row.columns || [];\n\n for (var j = 0; j < columns.length; j++) {\n var column = columns[j]; // Update the control\n\n updateControl(column.control);\n }\n }\n } // Remove the progress bar\n\n\n progress.el.parentElement ? progress.el.parentElement.removeChild(progress.el) : null; // Counter for each control\n\n var ctrlCounter = 0; // Render the form\n\n var form = core_1.Components.Form({\n el: props.el,\n className: props.className,\n groupClassName: props.groupClassName,\n rowClassName: props.rowClassName,\n onControlRendered: function onControlRendered(control) {\n // See if all of the controls have been rendered\n if (++ctrlCounter == rows.length) {\n // See if an event exists\n if (props.onFormRendered) {\n // Execute the form rendered event in another thread\n setTimeout(function () {\n props.onFormRendered(form);\n }, 10);\n }\n } // Return the event\n\n\n return props.onControlRendered ? props.onControlRendered(control, props.info.fields[control.props.name]) : null;\n },\n onControlRendering: function onControlRendering(control) {\n var updateReadOnly = function updateReadOnly(control) {\n // See if this control is readonly\n if (control.isReadonly) {\n var html_1 = props.info.fieldValuesAsHtml && props.info.fieldValuesAsHtml[field.InternalName] || \"\"; // Update the control properties\n\n control.type = core_1.Components.FormControlTypes.Readonly; // Detect html\n\n if (/<*>/g.test(html_1)) {\n // Update the control properties\n control.data = html_1;\n } // Set the rendered event\n\n\n control.onControlRendered = function (control) {\n // Set the class name\n control.el.classList.add(\"form-control\");\n control.el.style.backgroundColor = \"#e9ecef\"; // Override the html rendered\n\n control.el.innerHTML = html_1 || control.props.value;\n }; // See if this is a user field\n\n\n if (field.FieldTypeKind == gd_sprest_1.SPTypes.FieldType.User) {\n // See if this is a multi-user selection\n if (field.AllowMultipleValues) {\n var userNames = []; // Parse the users\n\n var users = (props.info.item[field.InternalName] ? props.info.item[field.InternalName].results : null) || [];\n\n for (var j = 0; j < users.length; j++) {\n // Append the user name\n userNames.push(users[j].Title);\n } // Set the html value\n\n\n html_1 = userNames.join('<br />\\n');\n } else {\n // Extract the text only for single selections\n var elUser = document.createElement(\"div\");\n elUser.innerHTML = html_1;\n html_1 = elUser.innerText;\n }\n }\n }\n }; // Execute the rendering event\n\n\n var field = props.info.fields[control.name];\n var returnVal = props.onControlRendering ? props.onControlRendering(control, field) : null;\n\n if (returnVal && returnVal.then) {\n // Wait for the event to complete\n returnVal.then(function (ctrlProps) {\n // Update the properties\n updateReadOnly(ctrlProps || control);\n });\n } else {\n // Update the properties\n updateReadOnly(control);\n }\n },\n rows: props.template || rows,\n value: value\n }); // Method to get the values\n\n var getValues = function getValues() {\n var values = {}; // Parse the fields\n\n for (var fieldName in props.info.fields) {\n // Get the form field and skip readonly fields\n var formField = mapper[fieldName];\n\n if (formField == null || formField.controlProps.isReadonly) {\n continue;\n } // Get the field value\n\n\n var fieldValue = formField.getValue(); // Set the item value\n\n values[fieldValue.name] = fieldValue.value; // See if this is the file leaf ref\n\n if (fieldValue.name == \"FileLeafRef\") {\n // Update the 'Title'\n values[\"Title\"] = values[\"Title\"] || values[fieldValue.name];\n }\n } // Return the form values\n\n\n return values;\n }; // Create the form object\n\n\n var formObj = {\n appendControls: function appendControls(controls) {\n form.appendControls(controls);\n },\n appendRows: function appendRows(rows) {\n form.appendRows(rows);\n },\n el: form.el,\n getControl: function getControl(fieldName) {\n return mapper[fieldName] ? mapper[fieldName].control : null;\n },\n getValues: getValues,\n isValid: function isValid() {\n var isValid = true; // Parse the fields\n\n for (var fieldName in props.info.fields) {\n // Skip readonly fields\n var formField = mapper[fieldName];\n\n if (formField == null || formField.controlProps.isReadonly) {\n continue;\n } // Validate the form field and update the status flag\n\n\n var controlIsValid = formField.isValid();\n isValid = isValid && controlIsValid;\n } // Return the flag\n\n\n return isValid;\n },\n save: function save() {\n var onSaving = function onSaving(values) {\n return new Promise(function (resolve) {\n // See if a save event exists\n var returnVal = props.onSaving ? props.onSaving(values) : null;\n\n if (returnVal && returnVal.then) {\n // Wait for the promise to complete\n returnVal.then(function (newValues) {\n // Resolve the promise\n resolve(newValues || values);\n });\n } else {\n // Resolve the promise\n resolve(values);\n }\n });\n }; // Return a promise\n\n\n return new Promise(function (resolve, reject) {\n // Call the saving event\n onSaving(getValues()).then(function (values) {\n // Update the item\n exports.ListForm.saveItem(props.info, values).then(function (info) {\n // Remove the attachments\n removeAttachments(info).then(function () {\n // Save the attachments\n saveAttachments(info).then(function () {\n // Update the info\n props.info = info; // Resolve the promise\n\n resolve(props.info.item);\n });\n });\n }, reject);\n });\n });\n }\n }; // Execute the assign to event\n\n props.assignTo ? props.assignTo(formObj) : null; // Return the form\n\n return formObj;\n};\n\n//# sourceURL=webpack://gd-sprest-bs/./build/components/listForm/index.js?");
702
702
 
703
703
  /***/ }),
704
704