gd-sprest-bs 9.3.1 → 9.3.2
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.
|
@@ -137,6 +137,8 @@ var renderDisplay = function (fieldName, props) {
|
|
|
137
137
|
.replace(/&/g, '&')
|
|
138
138
|
.replace(/"/g, '"');
|
|
139
139
|
}
|
|
140
|
+
// Return the control
|
|
141
|
+
return control;
|
|
140
142
|
};
|
|
141
143
|
// Method to render a display form for an item
|
|
142
144
|
exports.ListForm.renderDisplayForm = function (props) {
|
|
@@ -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.9.0/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 the display control\n\n\nvar renderDisplay = function renderDisplay(fieldName, props) {\n var control = null;\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 return control;\n } // See if we are hiding the field\n\n\n if (field.SchemaXml.indexOf('ShowInDisplayForm=\"FALSE\"') > 0) {\n return control;\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 control = {\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 control.showTime = field.DisplayFormat == gd_sprest_1.SPTypes.DateFormat.DateTime ? true : false; // Set the type\n\n control.type = datetime_1.DateTimeControlType;\n break;\n\n case gd_sprest_1.SPTypes.FieldType.Note:\n // Set the type\n control.type = core_1.Components.FormControlTypes.TextArea;\n break;\n\n case gd_sprest_1.SPTypes.FieldType.User:\n // Set the type\n control.type = field.AllowMultipleValues ? core_1.Components.FormControlTypes.TextArea : control.type;\n break;\n } // Detect html\n\n\n if (/<*>/g.test(html)) {\n // Update the control to be read-only\n control.type = core_1.Components.FormControlTypes.Readonly; // Set the rendered event\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 = control.props.data;\n };\n } // Else, detect xml\n else if (/</g.test(html)) {\n // Update the value\n control.value = html.replace(/</g, '<').replace(/>/g, '>').replace(/&/g, '&').replace(/"/g, '\"');\n }\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]; // Generate the control\n\n var control = renderDisplay(fieldName, props);\n\n if (control) {\n // Update the mapper\n mapper[fieldName] = control; // Add the row\n\n rows.push({\n columns: [{\n control: control\n }]\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 = (0, 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 // Get the control display properties\n var dispControl = renderDisplay(control.name, props); // Update the properties\n\n control.data = dispControl.data;\n control.label = dispControl.label;\n control.showTime = dispControl.showTime;\n control.type = dispControl.type;\n control.value = dispControl.value;\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 = {}; // See if the content type was set\n\n if (props.info.contentType) {\n // Set the content type id\n values[\"ContentTypeId\"] = props.info.contentType.Id.StringValue;\n } // Parse the fields\n\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 getItem: function getItem() {\n return props.info.item;\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.9.0/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 the display control\n\n\nvar renderDisplay = function renderDisplay(fieldName, props) {\n var control = null;\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 return control;\n } // See if we are hiding the field\n\n\n if (field.SchemaXml.indexOf('ShowInDisplayForm=\"FALSE\"') > 0) {\n return control;\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 control = {\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 control.showTime = field.DisplayFormat == gd_sprest_1.SPTypes.DateFormat.DateTime ? true : false; // Set the type\n\n control.type = datetime_1.DateTimeControlType;\n break;\n\n case gd_sprest_1.SPTypes.FieldType.Note:\n // Set the type\n control.type = core_1.Components.FormControlTypes.TextArea;\n break;\n\n case gd_sprest_1.SPTypes.FieldType.User:\n // Set the type\n control.type = field.AllowMultipleValues ? core_1.Components.FormControlTypes.TextArea : control.type;\n break;\n } // Detect html\n\n\n if (/<*>/g.test(html)) {\n // Update the control to be read-only\n control.type = core_1.Components.FormControlTypes.Readonly; // Set the rendered event\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 = control.props.data;\n };\n } // Else, detect xml\n else if (/</g.test(html)) {\n // Update the value\n control.value = html.replace(/</g, '<').replace(/>/g, '>').replace(/&/g, '&').replace(/"/g, '\"');\n } // Return the control\n\n\n return control;\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]; // Generate the control\n\n var control = renderDisplay(fieldName, props);\n\n if (control) {\n // Update the mapper\n mapper[fieldName] = control; // Add the row\n\n rows.push({\n columns: [{\n control: control\n }]\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 = (0, 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 // Get the control display properties\n var dispControl = renderDisplay(control.name, props); // Update the properties\n\n control.data = dispControl.data;\n control.label = dispControl.label;\n control.showTime = dispControl.showTime;\n control.type = dispControl.type;\n control.value = dispControl.value;\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 = {}; // See if the content type was set\n\n if (props.info.contentType) {\n // Set the content type id\n values[\"ContentTypeId\"] = props.info.contentType.Id.StringValue;\n } // Parse the fields\n\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 getItem: function getItem() {\n return props.info.item;\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
|
|