gd-sprest 6.9.4 → 6.9.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/helper/listForm.js +3 -0
- package/build/rest.js +1 -1
- package/dist/gd-sprest.js +2 -2
- package/dist/gd-sprest.min.js +1 -1
- package/package.json +1 -1
package/build/helper/listForm.js
CHANGED
|
@@ -216,7 +216,10 @@ exports.ListForm = {
|
|
|
216
216
|
}, _reject);
|
|
217
217
|
}, _reject);
|
|
218
218
|
}
|
|
219
|
+
// Else, this is a new item
|
|
219
220
|
else {
|
|
221
|
+
// Default the attachments
|
|
222
|
+
_info.attachments = _props.loadAttachments ? [] : _info.attachments;
|
|
220
223
|
// Resolve the promise
|
|
221
224
|
_resolve(_info);
|
|
222
225
|
}
|
package/build/rest.js
CHANGED
package/dist/gd-sprest.js
CHANGED
|
@@ -60,7 +60,7 @@ eval("\n\nObject.defineProperty(exports, \"__esModule\", ({\n value: true\n}));
|
|
|
60
60
|
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
|
|
61
61
|
|
|
62
62
|
"use strict";
|
|
63
|
-
eval("\n\nObject.defineProperty(exports, \"__esModule\", ({\n value: true\n}));\nexports.ListForm = void 0;\n\nvar __1 = __webpack_require__(/*! .. */ \"./build/index.js\");\n/**\r\n * List Form\r\n */\n\n\nexports.ListForm = {\n // Method to create an instance of the list form\n create: function create(props) {\n var _info = null;\n var _props = null;\n var _reject = null;\n var _resolve = null; // Save the properties\n\n _props = props || {};\n _props.fields = _props.fields; // Method to load the list data\n\n var load = function load() {\n // Clear the information\n _info = {\n item: _props.item,\n query: _props.query || {}\n }; // Load the list data\n\n loadListData().then( // Success\n function () {\n // See if the fields have been defined\n if (_props.fields) {\n // Process the fields\n processFields(); // Load the item data\n\n loadItem();\n } else {\n // Load the content type\n loadContentType();\n }\n }, // Reject\n _reject);\n }; // Method to load a content type for the associated fields\n\n\n var loadContentType = function loadContentType() {\n // Load the content types\n _info.list.ContentTypes() // Query for the default content type and expand the field links\n .query({\n Filter: _props.contentType ? \"Name eq '\" + _props.contentType + \"'\" : null,\n Expand: [\"FieldLinks\"],\n Select: [\"*\", \"FieldLinks/DisplayName\", \"FieldLinks/Hidden\", \"FieldLinks/Name\", \"FieldLinks/ReadOnly\", \"FieldLinks/Required\"],\n Top: 1\n }) // Execute the request, but wait for the previous one to be completed\n .execute(function (ct) {\n // Resolve the promise\n loadDefaultFields(ct.results[0]);\n }, _reject);\n }; // Method to load the default fields\n\n\n var loadDefaultFields = function loadDefaultFields(ct) {\n var fields = ct ? ct.FieldLinks.results : [];\n var formFields = {};\n var formLinks = {}; // Parse the field links\n\n for (var i = 0; i < fields.length; i++) {\n var fieldLink = fields[i]; // Get the field\n\n var field = _info.fields[fieldLink.Name];\n\n if (field) {\n // Skip the content type field\n if (field.InternalName == \"ContentType\") {\n continue;\n } // Skip hidden fields\n\n\n if (field.Hidden || fieldLink.Hidden) {\n continue;\n } // Save the form field and link\n\n\n formFields[field.InternalName] = field;\n formLinks[field.InternalName] = fieldLink;\n }\n } // Update the fields\n\n\n _info.contentType = ct;\n _info.fields = formFields;\n _info.fieldLinks = formLinks; // Load the item data\n\n loadItem();\n }; // Method to load the field data\n\n\n var loadFieldData = function loadFieldData(fields) {\n // Clear the fields\n _info.fields = {}; // Parse the fields\n\n for (var i = 0; i < fields.results.length; i++) {\n var field = fields.results[i]; // See if the exclude fields is defined\n\n if (_props.excludeFields) {\n var excludeField = false; // Parse the fields to exclude\n\n for (var j = 0; j < _props.excludeFields.length; j++) {\n // See if we are excluding this field\n if (_props.excludeFields[j] == field.InternalName) {\n // Set the flag\n excludeField = true;\n break;\n }\n } // See if we are excluding the field\n\n\n if (excludeField) {\n continue;\n }\n } // Save the field\n\n\n _info.fields[field.InternalName] = field;\n }\n }; // Method to load the item\n\n\n var loadItem = function loadItem() {\n var reloadItem = false; // See if the item already exist\n\n if (_info.item) {\n // Parse the fields\n for (var fieldName in _info.fields) {\n var field = _info.fields[fieldName]; // See what type of field this is\n\n switch (field.FieldTypeKind) {\n // Lookup or User Field\n case __1.SPTypes.FieldType.Lookup:\n case __1.SPTypes.FieldType.User:\n var fieldValue = _info.item[fieldName + \"Id\"]; // Ensure the value exists\n\n if (fieldValue) {\n // See if a value exists\n if (fieldValue.results ? fieldValue.results.length > 0 : fieldValue > 0) {\n // Ensure the field data has been loaded\n if (_info.item[fieldName] == null) {\n // Set the flag\n reloadItem = true;\n }\n }\n }\n\n break;\n // Default\n\n default:\n // See if this is an taxonomy field\n if (field.TypeAsString.indexOf(\"TaxonomyFieldType\") == 0) {\n var fieldValue_1 = _info.item[fieldName + \"Id\"]; // Ensure the value exists\n\n if (fieldValue_1) {\n // See if a field value exists\n if (fieldValue_1.results ? fieldValue_1.results.length > 0 : fieldValue_1 != null) {\n // Parse the fields\n for (var fieldName_1 in _info.fields) {\n var valueField = _info.fields[fieldName_1]; // See if this is the value field\n\n if (valueField.InternalName == field.InternalName + \"_0\" || valueField.Title == field.InternalName + \"_0\") {\n // Ensure the value field is loaded\n if (_info.item[valueField.InternalName] == null) {\n // Set the flag\n reloadItem = true;\n }\n\n break;\n }\n }\n }\n }\n }\n\n break;\n } // See if we are reloading the item\n\n\n if (reloadItem) {\n break;\n }\n }\n } // See if the item exists\n\n\n if (_info.item && !reloadItem) {\n // See if we are loading attachments\n if (_props.loadAttachments && _info.attachments == null) {\n // Load the attachments\n exports.ListForm.loadAttachments(_props).then(function (attachments) {\n // Set the attachments\n _info.attachments = attachments; // Resolve the promise\n\n _resolve(_info);\n }, _reject);\n } else {\n // Resolve the promise\n _resolve(_info);\n }\n } // Else, see if we are loading the list item\n else if (reloadItem || _props.itemId > 0) {\n // Update the item query\n _info.query = exports.ListForm.generateODataQuery(_info, _props.loadAttachments); // Get the list item\n\n _info.list.Items(reloadItem ? _props.item.Id : _props.itemId) // Set the query\n .query(_info.query) // Execute the request\n .execute(function (item) {\n // Save the attachments\n _info.attachments = item.AttachmentFiles.results; // Save the item\n\n _info.item = item; // Refresh the item\n\n exports.ListForm.refreshItem(_info).then(function (info) {\n // Update the info\n _info = info; // Resolve the promise\n\n _resolve(_info);\n }, _reject);\n }, _reject);\n } else {\n // Resolve the promise\n _resolve(_info);\n }\n }; // Method to load the list data\n\n\n var loadListData = function loadListData() {\n // Return a promise\n return new Promise(function (resolve, reject) {\n // See if the list & fields already exist\n if (_info.list && _info.fields) {\n // Resolve the promise\n resolve();\n return;\n } // Get the web\n\n\n __1.Web(_props.webUrl, {\n disableCache: true\n }) // Get the list\n .Lists(_props.listName) // Execute the request\n .execute(function (list) {\n // Save the list and web url\n _info.list = list;\n _info.webUrl = _props.webUrl;\n }, reject) // Load the fields\n .Fields() // Execute the request\n .execute(function (fields) {\n // Load the field data\n loadFieldData(fields); // Resolve the promise\n\n resolve();\n }, reject, true);\n });\n }; // Method to process the fields\n\n\n var processFields = function processFields() {\n var formFields = {}; // Parse the fields provided\n\n for (var i = 0; i < _props.fields.length; i++) {\n var field = _info.fields[_props.fields[i]]; // Ensure the field exists\n\n if (field) {\n // Save the field\n formFields[field.InternalName] = field; // See if this is a taxonomy field\n\n if (field.TypeAsString.indexOf(\"TaxonomyFieldType\") == 0) {\n // Parse the list fields\n for (var fieldName in _info.fields) {\n var valueField = _info.fields[fieldName]; // See if this is a value field\n\n if (valueField.InternalName == field.InternalName + \"_0\" || valueField.Title == field.InternalName + \"_0\") {\n // Include this field\n formFields[valueField.InternalName] = valueField;\n break;\n }\n }\n }\n }\n } // Update the fields\n\n\n _info.fields = formFields;\n }; // Return a promise\n\n\n return new Promise(function (resolve, reject) {\n // Save the methods\n _reject = reject;\n _resolve = resolve; // Load the list data\n\n load();\n });\n },\n // Method to generate the odata query\n generateODataQuery: function generateODataQuery(info, loadAttachments) {\n if (loadAttachments === void 0) {\n loadAttachments = false;\n }\n\n var query = info.query || {}; // Default the select query to get all the fields by default\n\n query.Select = query.Select || [\"*\"];\n query.Expand = query.Expand || []; // See if we are loading the attachments\n\n if (loadAttachments) {\n // Expand the attachment files collection\n query.Expand.push(\"AttachmentFiles\"); // Select the attachment files\n\n query.Select.push(\"Attachments\");\n query.Select.push(\"AttachmentFiles\");\n } // Parse the fields\n\n\n for (var fieldName in info.fields) {\n var field = info.fields[fieldName]; // See if this is the file leaf ref\n\n if (field.InternalName == \"FileLeafRef\") {\n // Ensure the field is included\n query.Select.push(\"FileLeafRef\");\n continue;\n } // Update the query, based on the type\n\n\n switch (field.FieldTypeKind) {\n // Lookup Field\n case __1.SPTypes.FieldType.Lookup:\n var lookupField = field; // See if this is an associated lookup field\n\n if (lookupField.PrimaryFieldId) {\n // Parse the form fields to find the parent field\n for (var parentFieldName in info.fields) {\n var parentField = info.fields[parentFieldName]; // See if the parent field is being loaded\n\n if (parentField.Id == lookupField.PrimaryFieldId) {\n // Select the field\n query.Select.push(parentField.InternalName + \"/\" + lookupField.LookupField);\n break;\n }\n }\n } else {\n // Expand the field\n query.Expand.push(field.InternalName); // Select the fields\n\n query.Select.push(field.InternalName + \"/Id\");\n query.Select.push(field.InternalName + \"/\" + field.LookupField);\n }\n\n break;\n // User Field\n\n case __1.SPTypes.FieldType.User:\n // Expand the field\n query.Expand.push(field.InternalName); // Select the fields\n\n query.Select.push(field.InternalName + \"/Id\");\n query.Select.push(field.InternalName + \"/Title\");\n break;\n // Default\n\n default:\n // See if this is an taxonomy field\n if (field.TypeAsString.indexOf(\"TaxonomyFieldType\") == 0) {\n // Parse the fields\n for (var fieldName_2 in info.fields) {\n var valueField = info.fields[fieldName_2]; // See if this is the value field\n\n if (valueField.InternalName == field.InternalName + \"_0\" || valueField.Title == field.InternalName + \"_0\") {\n // Include the value field\n query.Select.push(valueField.InternalName);\n break;\n }\n }\n }\n\n break;\n }\n } // Return the query\n\n\n return query;\n },\n // Method to load the item attachments\n loadAttachments: function loadAttachments(info) {\n // Return a promise\n return new Promise(function (resolve, reject) {\n // Ensure the item id exists\n var itemId = info.item ? info.item.Id : info.itemId;\n\n if (itemId > 0) {\n // Get the web\n __1.Web(info.webUrl) // Get the list\n .Lists(info.listName) // Get the item\n .Items(itemId) // Get the attachment files\n .AttachmentFiles() // Execute the request\n .execute(function (attachments) {\n // Ensure the attachments exist\n if (!attachments.existsFl) {\n // Reject the promise\n reject(attachments.response);\n return;\n } // Resolve the promise\n\n\n resolve(attachments.results || []);\n }, reject);\n } else {\n // Resolve the promise\n resolve([]);\n }\n });\n },\n // Method to refresh an item\n refreshItem: function refreshItem(info) {\n // Return a promise\n return new Promise(function (resolve, reject) {\n // Update the query\n info.query = exports.ListForm.generateODataQuery(info, info.attachments ? true : false); // Get the item\n\n info.list.Items(info.item.Id).query(info.query).execute(function (item) {\n // Update the item\n info.item = item; // Get the item values\n\n info.list.Items(item.Id).query({\n Expand: [\"FieldValuesAsText\", \"Folder\"]\n }).execute(function (item) {\n // Set the values\n info.itemFolder = item.Folder;\n info.fieldValuesAsText = item.FieldValuesAsText;\n }); // Get the html values for this item\n // This is needed for complex field values\n\n info.list.Items(item.Id).FieldValuesAsHtml().execute(function (values) {\n // Set the values\n info.fieldValuesAsHtml = values; // Resolve the promise\n\n resolve(info);\n }, true);\n }, reject);\n });\n },\n // Method to remove attachments from an item\n removeAttachment: function removeAttachment(info, fileName) {\n // Return a promise\n return new Promise(function (resolve, reject) {\n // Ensure attachments exist\n if (info.attachments) {\n // Parse the attachments\n for (var i = 0; i < info.attachments.length; i++) {\n // See if this is the target attachment\n var attachment = info.attachments[i];\n\n if (attachment.FileName == fileName) {\n // Get the web\n __1.Web(info.webUrl) // Get the file\n .getFileByServerRelativeUrl(attachment.ServerRelativeUrl) // Delete the file\n [\"delete\"]() // Execute the request\n .execute(function () {\n // Resolve the promise\n resolve(info);\n }, reject); // Attachment found\n\n\n return;\n } // Attachment not found\n\n\n reject(\"Attachment '\" + fileName + \"' was not found.\");\n }\n } else {\n // Attachments not loaded\n reject(\"Attachment '\" + fileName + \"' was not found.\");\n }\n });\n },\n // Method to save attachments to an existing item\n saveAttachments: function saveAttachments(info, attachmentInfo) {\n // Return a promise\n return new Promise(function (resolve, reject) {\n var itemId = info.item ? info.item.Id : info.itemId;\n\n if (itemId > 0) {\n // Get the web\n var attachments = __1.Web(info.webUrl) // Get the lists\n .Lists(info.listName) // Get the item\n .Items(itemId) // Get the attachment files\n .AttachmentFiles(); // Parse the attachment information\n\n\n for (var i = 0; i < attachmentInfo.length; i++) {\n var attachment = attachmentInfo[i]; // Add the attachment\n\n attachments.add(attachment.name, attachment.data).execute(true);\n } // Wait for the requests to complete\n\n\n attachments.done(function () {\n var args = [];\n\n for (var _i = 0; _i < arguments.length; _i++) {\n args[_i] = arguments[_i];\n } // Resolve the promise\n\n\n resolve.apply(args);\n });\n } else {\n // Resolve the promise\n resolve(null);\n }\n });\n },\n // Method to save a new or existing item\n saveItem: function saveItem(info, formValues) {\n if (formValues === void 0) {\n formValues = {};\n } // Return a promise\n\n\n return new Promise(function (resolve, reject) {\n // See if this is an existing item\n if (info.item && info.item.update) {\n // Update the item\n info.item.update(formValues).execute(function (response) {\n // Refresh the item\n exports.ListForm.refreshItem(info).then(function (info) {\n // Resolve the promise\n resolve(info);\n }, reject);\n });\n } else {\n // Set the metadata type\n formValues[\"__metadata\"] = {\n type: info.list.ListItemEntityTypeFullName\n }; // Add the item\n\n info.list.Items().add(formValues) // Execute the request\n .execute(function (item) {\n // Update the info\n info.item = item; // Refresh the item\n\n exports.ListForm.refreshItem(info).then(function (info) {\n // Resolve the promise\n resolve(info);\n });\n }, reject);\n }\n });\n },\n // Method to show a file dialog\n showFileDialog: function showFileDialog(info, onSave) {\n // Return a promise\n return new Promise(function (resolve, reject) {\n // Method to add an attachment\n var addAttachment = function addAttachment(name, data) {\n // Call the save event\n onSave ? onSave({\n name: name,\n data: data\n }) : null; // Get the list\n\n info.list // Get the item\n .Items(info.item.Id) // Get the attachments\n .AttachmentFiles() // Add the file\n .add(name, data) // Execute the request\n .execute(function () {\n // Refresh the item\n exports.ListForm.refreshItem(info).then(function (info) {\n // Remove the element\n document.body.removeChild(el); // Resolve the promise\n\n resolve(info);\n });\n }, reject);\n }; // Method to read the file\n\n\n var readFile = function readFile(ev) {\n // Get the source file\n var srcFile = ev.target[\"files\"][0];\n\n if (srcFile) {\n var reader = new FileReader(); // Set the file loaded event\n\n reader.onloadend = function (ev) {\n var attachment = null;\n var ext = srcFile.name.split(\".\");\n ext = ext[ext.length - 1].toLowerCase(); // See if the info exists\n\n if (info) {\n // Add the attachment\n addAttachment(srcFile.name, ev.target.result);\n } else {\n // Remove the element\n document.body.removeChild(el); // Resolve the promise with the file information\n\n resolve({\n data: ev.target.result,\n name: srcFile.name\n });\n }\n }; // Set the error\n\n\n reader.onerror = function (ev) {\n // Remove the element\n document.body.removeChild(el); // Reject the promise\n\n reject(ev.target.error);\n }; // Read the file\n\n\n reader.readAsArrayBuffer(srcFile);\n }\n }; // Create the file element\n\n\n var el = document.body.querySelector(\"#listform-attachment\");\n\n if (el == null) {\n el = document.createElement(\"input\"); // Set the properties\n\n el.id = \"listform-attachment\";\n el.type = \"file\";\n el.hidden = true;\n el.onchange = readFile; // Add the element to the body\n\n document.body.appendChild(el);\n } // Show the dialog\n\n\n el.click();\n });\n }\n};\n\n//# sourceURL=webpack://gd-sprest/./build/helper/listForm.js?");
|
|
63
|
+
eval("\n\nObject.defineProperty(exports, \"__esModule\", ({\n value: true\n}));\nexports.ListForm = void 0;\n\nvar __1 = __webpack_require__(/*! .. */ \"./build/index.js\");\n/**\r\n * List Form\r\n */\n\n\nexports.ListForm = {\n // Method to create an instance of the list form\n create: function create(props) {\n var _info = null;\n var _props = null;\n var _reject = null;\n var _resolve = null; // Save the properties\n\n _props = props || {};\n _props.fields = _props.fields; // Method to load the list data\n\n var load = function load() {\n // Clear the information\n _info = {\n item: _props.item,\n query: _props.query || {}\n }; // Load the list data\n\n loadListData().then( // Success\n function () {\n // See if the fields have been defined\n if (_props.fields) {\n // Process the fields\n processFields(); // Load the item data\n\n loadItem();\n } else {\n // Load the content type\n loadContentType();\n }\n }, // Reject\n _reject);\n }; // Method to load a content type for the associated fields\n\n\n var loadContentType = function loadContentType() {\n // Load the content types\n _info.list.ContentTypes() // Query for the default content type and expand the field links\n .query({\n Filter: _props.contentType ? \"Name eq '\" + _props.contentType + \"'\" : null,\n Expand: [\"FieldLinks\"],\n Select: [\"*\", \"FieldLinks/DisplayName\", \"FieldLinks/Hidden\", \"FieldLinks/Name\", \"FieldLinks/ReadOnly\", \"FieldLinks/Required\"],\n Top: 1\n }) // Execute the request, but wait for the previous one to be completed\n .execute(function (ct) {\n // Resolve the promise\n loadDefaultFields(ct.results[0]);\n }, _reject);\n }; // Method to load the default fields\n\n\n var loadDefaultFields = function loadDefaultFields(ct) {\n var fields = ct ? ct.FieldLinks.results : [];\n var formFields = {};\n var formLinks = {}; // Parse the field links\n\n for (var i = 0; i < fields.length; i++) {\n var fieldLink = fields[i]; // Get the field\n\n var field = _info.fields[fieldLink.Name];\n\n if (field) {\n // Skip the content type field\n if (field.InternalName == \"ContentType\") {\n continue;\n } // Skip hidden fields\n\n\n if (field.Hidden || fieldLink.Hidden) {\n continue;\n } // Save the form field and link\n\n\n formFields[field.InternalName] = field;\n formLinks[field.InternalName] = fieldLink;\n }\n } // Update the fields\n\n\n _info.contentType = ct;\n _info.fields = formFields;\n _info.fieldLinks = formLinks; // Load the item data\n\n loadItem();\n }; // Method to load the field data\n\n\n var loadFieldData = function loadFieldData(fields) {\n // Clear the fields\n _info.fields = {}; // Parse the fields\n\n for (var i = 0; i < fields.results.length; i++) {\n var field = fields.results[i]; // See if the exclude fields is defined\n\n if (_props.excludeFields) {\n var excludeField = false; // Parse the fields to exclude\n\n for (var j = 0; j < _props.excludeFields.length; j++) {\n // See if we are excluding this field\n if (_props.excludeFields[j] == field.InternalName) {\n // Set the flag\n excludeField = true;\n break;\n }\n } // See if we are excluding the field\n\n\n if (excludeField) {\n continue;\n }\n } // Save the field\n\n\n _info.fields[field.InternalName] = field;\n }\n }; // Method to load the item\n\n\n var loadItem = function loadItem() {\n var reloadItem = false; // See if the item already exist\n\n if (_info.item) {\n // Parse the fields\n for (var fieldName in _info.fields) {\n var field = _info.fields[fieldName]; // See what type of field this is\n\n switch (field.FieldTypeKind) {\n // Lookup or User Field\n case __1.SPTypes.FieldType.Lookup:\n case __1.SPTypes.FieldType.User:\n var fieldValue = _info.item[fieldName + \"Id\"]; // Ensure the value exists\n\n if (fieldValue) {\n // See if a value exists\n if (fieldValue.results ? fieldValue.results.length > 0 : fieldValue > 0) {\n // Ensure the field data has been loaded\n if (_info.item[fieldName] == null) {\n // Set the flag\n reloadItem = true;\n }\n }\n }\n\n break;\n // Default\n\n default:\n // See if this is an taxonomy field\n if (field.TypeAsString.indexOf(\"TaxonomyFieldType\") == 0) {\n var fieldValue_1 = _info.item[fieldName + \"Id\"]; // Ensure the value exists\n\n if (fieldValue_1) {\n // See if a field value exists\n if (fieldValue_1.results ? fieldValue_1.results.length > 0 : fieldValue_1 != null) {\n // Parse the fields\n for (var fieldName_1 in _info.fields) {\n var valueField = _info.fields[fieldName_1]; // See if this is the value field\n\n if (valueField.InternalName == field.InternalName + \"_0\" || valueField.Title == field.InternalName + \"_0\") {\n // Ensure the value field is loaded\n if (_info.item[valueField.InternalName] == null) {\n // Set the flag\n reloadItem = true;\n }\n\n break;\n }\n }\n }\n }\n }\n\n break;\n } // See if we are reloading the item\n\n\n if (reloadItem) {\n break;\n }\n }\n } // See if the item exists\n\n\n if (_info.item && !reloadItem) {\n // See if we are loading attachments\n if (_props.loadAttachments && _info.attachments == null) {\n // Load the attachments\n exports.ListForm.loadAttachments(_props).then(function (attachments) {\n // Set the attachments\n _info.attachments = attachments; // Resolve the promise\n\n _resolve(_info);\n }, _reject);\n } else {\n // Resolve the promise\n _resolve(_info);\n }\n } // Else, see if we are loading the list item\n else if (reloadItem || _props.itemId > 0) {\n // Update the item query\n _info.query = exports.ListForm.generateODataQuery(_info, _props.loadAttachments); // Get the list item\n\n _info.list.Items(reloadItem ? _props.item.Id : _props.itemId) // Set the query\n .query(_info.query) // Execute the request\n .execute(function (item) {\n // Save the attachments\n _info.attachments = item.AttachmentFiles.results; // Save the item\n\n _info.item = item; // Refresh the item\n\n exports.ListForm.refreshItem(_info).then(function (info) {\n // Update the info\n _info = info; // Resolve the promise\n\n _resolve(_info);\n }, _reject);\n }, _reject);\n } // Else, this is a new item\n else {\n // Default the attachments\n _info.attachments = _props.loadAttachments ? [] : _info.attachments; // Resolve the promise\n\n _resolve(_info);\n }\n }; // Method to load the list data\n\n\n var loadListData = function loadListData() {\n // Return a promise\n return new Promise(function (resolve, reject) {\n // See if the list & fields already exist\n if (_info.list && _info.fields) {\n // Resolve the promise\n resolve();\n return;\n } // Get the web\n\n\n __1.Web(_props.webUrl, {\n disableCache: true\n }) // Get the list\n .Lists(_props.listName) // Execute the request\n .execute(function (list) {\n // Save the list and web url\n _info.list = list;\n _info.webUrl = _props.webUrl;\n }, reject) // Load the fields\n .Fields() // Execute the request\n .execute(function (fields) {\n // Load the field data\n loadFieldData(fields); // Resolve the promise\n\n resolve();\n }, reject, true);\n });\n }; // Method to process the fields\n\n\n var processFields = function processFields() {\n var formFields = {}; // Parse the fields provided\n\n for (var i = 0; i < _props.fields.length; i++) {\n var field = _info.fields[_props.fields[i]]; // Ensure the field exists\n\n if (field) {\n // Save the field\n formFields[field.InternalName] = field; // See if this is a taxonomy field\n\n if (field.TypeAsString.indexOf(\"TaxonomyFieldType\") == 0) {\n // Parse the list fields\n for (var fieldName in _info.fields) {\n var valueField = _info.fields[fieldName]; // See if this is a value field\n\n if (valueField.InternalName == field.InternalName + \"_0\" || valueField.Title == field.InternalName + \"_0\") {\n // Include this field\n formFields[valueField.InternalName] = valueField;\n break;\n }\n }\n }\n }\n } // Update the fields\n\n\n _info.fields = formFields;\n }; // Return a promise\n\n\n return new Promise(function (resolve, reject) {\n // Save the methods\n _reject = reject;\n _resolve = resolve; // Load the list data\n\n load();\n });\n },\n // Method to generate the odata query\n generateODataQuery: function generateODataQuery(info, loadAttachments) {\n if (loadAttachments === void 0) {\n loadAttachments = false;\n }\n\n var query = info.query || {}; // Default the select query to get all the fields by default\n\n query.Select = query.Select || [\"*\"];\n query.Expand = query.Expand || []; // See if we are loading the attachments\n\n if (loadAttachments) {\n // Expand the attachment files collection\n query.Expand.push(\"AttachmentFiles\"); // Select the attachment files\n\n query.Select.push(\"Attachments\");\n query.Select.push(\"AttachmentFiles\");\n } // Parse the fields\n\n\n for (var fieldName in info.fields) {\n var field = info.fields[fieldName]; // See if this is the file leaf ref\n\n if (field.InternalName == \"FileLeafRef\") {\n // Ensure the field is included\n query.Select.push(\"FileLeafRef\");\n continue;\n } // Update the query, based on the type\n\n\n switch (field.FieldTypeKind) {\n // Lookup Field\n case __1.SPTypes.FieldType.Lookup:\n var lookupField = field; // See if this is an associated lookup field\n\n if (lookupField.PrimaryFieldId) {\n // Parse the form fields to find the parent field\n for (var parentFieldName in info.fields) {\n var parentField = info.fields[parentFieldName]; // See if the parent field is being loaded\n\n if (parentField.Id == lookupField.PrimaryFieldId) {\n // Select the field\n query.Select.push(parentField.InternalName + \"/\" + lookupField.LookupField);\n break;\n }\n }\n } else {\n // Expand the field\n query.Expand.push(field.InternalName); // Select the fields\n\n query.Select.push(field.InternalName + \"/Id\");\n query.Select.push(field.InternalName + \"/\" + field.LookupField);\n }\n\n break;\n // User Field\n\n case __1.SPTypes.FieldType.User:\n // Expand the field\n query.Expand.push(field.InternalName); // Select the fields\n\n query.Select.push(field.InternalName + \"/Id\");\n query.Select.push(field.InternalName + \"/Title\");\n break;\n // Default\n\n default:\n // See if this is an taxonomy field\n if (field.TypeAsString.indexOf(\"TaxonomyFieldType\") == 0) {\n // Parse the fields\n for (var fieldName_2 in info.fields) {\n var valueField = info.fields[fieldName_2]; // See if this is the value field\n\n if (valueField.InternalName == field.InternalName + \"_0\" || valueField.Title == field.InternalName + \"_0\") {\n // Include the value field\n query.Select.push(valueField.InternalName);\n break;\n }\n }\n }\n\n break;\n }\n } // Return the query\n\n\n return query;\n },\n // Method to load the item attachments\n loadAttachments: function loadAttachments(info) {\n // Return a promise\n return new Promise(function (resolve, reject) {\n // Ensure the item id exists\n var itemId = info.item ? info.item.Id : info.itemId;\n\n if (itemId > 0) {\n // Get the web\n __1.Web(info.webUrl) // Get the list\n .Lists(info.listName) // Get the item\n .Items(itemId) // Get the attachment files\n .AttachmentFiles() // Execute the request\n .execute(function (attachments) {\n // Ensure the attachments exist\n if (!attachments.existsFl) {\n // Reject the promise\n reject(attachments.response);\n return;\n } // Resolve the promise\n\n\n resolve(attachments.results || []);\n }, reject);\n } else {\n // Resolve the promise\n resolve([]);\n }\n });\n },\n // Method to refresh an item\n refreshItem: function refreshItem(info) {\n // Return a promise\n return new Promise(function (resolve, reject) {\n // Update the query\n info.query = exports.ListForm.generateODataQuery(info, info.attachments ? true : false); // Get the item\n\n info.list.Items(info.item.Id).query(info.query).execute(function (item) {\n // Update the item\n info.item = item; // Get the item values\n\n info.list.Items(item.Id).query({\n Expand: [\"FieldValuesAsText\", \"Folder\"]\n }).execute(function (item) {\n // Set the values\n info.itemFolder = item.Folder;\n info.fieldValuesAsText = item.FieldValuesAsText;\n }); // Get the html values for this item\n // This is needed for complex field values\n\n info.list.Items(item.Id).FieldValuesAsHtml().execute(function (values) {\n // Set the values\n info.fieldValuesAsHtml = values; // Resolve the promise\n\n resolve(info);\n }, true);\n }, reject);\n });\n },\n // Method to remove attachments from an item\n removeAttachment: function removeAttachment(info, fileName) {\n // Return a promise\n return new Promise(function (resolve, reject) {\n // Ensure attachments exist\n if (info.attachments) {\n // Parse the attachments\n for (var i = 0; i < info.attachments.length; i++) {\n // See if this is the target attachment\n var attachment = info.attachments[i];\n\n if (attachment.FileName == fileName) {\n // Get the web\n __1.Web(info.webUrl) // Get the file\n .getFileByServerRelativeUrl(attachment.ServerRelativeUrl) // Delete the file\n [\"delete\"]() // Execute the request\n .execute(function () {\n // Resolve the promise\n resolve(info);\n }, reject); // Attachment found\n\n\n return;\n } // Attachment not found\n\n\n reject(\"Attachment '\" + fileName + \"' was not found.\");\n }\n } else {\n // Attachments not loaded\n reject(\"Attachment '\" + fileName + \"' was not found.\");\n }\n });\n },\n // Method to save attachments to an existing item\n saveAttachments: function saveAttachments(info, attachmentInfo) {\n // Return a promise\n return new Promise(function (resolve, reject) {\n var itemId = info.item ? info.item.Id : info.itemId;\n\n if (itemId > 0) {\n // Get the web\n var attachments = __1.Web(info.webUrl) // Get the lists\n .Lists(info.listName) // Get the item\n .Items(itemId) // Get the attachment files\n .AttachmentFiles(); // Parse the attachment information\n\n\n for (var i = 0; i < attachmentInfo.length; i++) {\n var attachment = attachmentInfo[i]; // Add the attachment\n\n attachments.add(attachment.name, attachment.data).execute(true);\n } // Wait for the requests to complete\n\n\n attachments.done(function () {\n var args = [];\n\n for (var _i = 0; _i < arguments.length; _i++) {\n args[_i] = arguments[_i];\n } // Resolve the promise\n\n\n resolve.apply(args);\n });\n } else {\n // Resolve the promise\n resolve(null);\n }\n });\n },\n // Method to save a new or existing item\n saveItem: function saveItem(info, formValues) {\n if (formValues === void 0) {\n formValues = {};\n } // Return a promise\n\n\n return new Promise(function (resolve, reject) {\n // See if this is an existing item\n if (info.item && info.item.update) {\n // Update the item\n info.item.update(formValues).execute(function (response) {\n // Refresh the item\n exports.ListForm.refreshItem(info).then(function (info) {\n // Resolve the promise\n resolve(info);\n }, reject);\n });\n } else {\n // Set the metadata type\n formValues[\"__metadata\"] = {\n type: info.list.ListItemEntityTypeFullName\n }; // Add the item\n\n info.list.Items().add(formValues) // Execute the request\n .execute(function (item) {\n // Update the info\n info.item = item; // Refresh the item\n\n exports.ListForm.refreshItem(info).then(function (info) {\n // Resolve the promise\n resolve(info);\n });\n }, reject);\n }\n });\n },\n // Method to show a file dialog\n showFileDialog: function showFileDialog(info, onSave) {\n // Return a promise\n return new Promise(function (resolve, reject) {\n // Method to add an attachment\n var addAttachment = function addAttachment(name, data) {\n // Call the save event\n onSave ? onSave({\n name: name,\n data: data\n }) : null; // Get the list\n\n info.list // Get the item\n .Items(info.item.Id) // Get the attachments\n .AttachmentFiles() // Add the file\n .add(name, data) // Execute the request\n .execute(function () {\n // Refresh the item\n exports.ListForm.refreshItem(info).then(function (info) {\n // Remove the element\n document.body.removeChild(el); // Resolve the promise\n\n resolve(info);\n });\n }, reject);\n }; // Method to read the file\n\n\n var readFile = function readFile(ev) {\n // Get the source file\n var srcFile = ev.target[\"files\"][0];\n\n if (srcFile) {\n var reader = new FileReader(); // Set the file loaded event\n\n reader.onloadend = function (ev) {\n var attachment = null;\n var ext = srcFile.name.split(\".\");\n ext = ext[ext.length - 1].toLowerCase(); // See if the info exists\n\n if (info) {\n // Add the attachment\n addAttachment(srcFile.name, ev.target.result);\n } else {\n // Remove the element\n document.body.removeChild(el); // Resolve the promise with the file information\n\n resolve({\n data: ev.target.result,\n name: srcFile.name\n });\n }\n }; // Set the error\n\n\n reader.onerror = function (ev) {\n // Remove the element\n document.body.removeChild(el); // Reject the promise\n\n reject(ev.target.error);\n }; // Read the file\n\n\n reader.readAsArrayBuffer(srcFile);\n }\n }; // Create the file element\n\n\n var el = document.body.querySelector(\"#listform-attachment\");\n\n if (el == null) {\n el = document.createElement(\"input\"); // Set the properties\n\n el.id = \"listform-attachment\";\n el.type = \"file\";\n el.hidden = true;\n el.onchange = readFile; // Add the element to the body\n\n document.body.appendChild(el);\n } // Show the dialog\n\n\n el.click();\n });\n }\n};\n\n//# sourceURL=webpack://gd-sprest/./build/helper/listForm.js?");
|
|
64
64
|
|
|
65
65
|
/***/ }),
|
|
66
66
|
|
|
@@ -742,7 +742,7 @@ eval("\n\nObject.defineProperty(exports, \"__esModule\", ({\n value: true\n}));
|
|
|
742
742
|
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
|
|
743
743
|
|
|
744
744
|
"use strict";
|
|
745
|
-
eval("\n\nObject.defineProperty(exports, \"__esModule\", ({\n value: true\n}));\nexports.$REST = void 0;\n\nvar Helper = __webpack_require__(/*! ./helper */ \"./build/helper/index.js\");\n\nvar Lib = __webpack_require__(/*! ./lib */ \"./build/lib/index.js\");\n\nvar sptypes_1 = __webpack_require__(/*! ./sptypes */ \"./build/sptypes/index.js\");\n/**\r\n * SharePoint REST Library\r\n */\n\n\nexports.$REST = {\n __ver: 6.
|
|
745
|
+
eval("\n\nObject.defineProperty(exports, \"__esModule\", ({\n value: true\n}));\nexports.$REST = void 0;\n\nvar Helper = __webpack_require__(/*! ./helper */ \"./build/helper/index.js\");\n\nvar Lib = __webpack_require__(/*! ./lib */ \"./build/lib/index.js\");\n\nvar sptypes_1 = __webpack_require__(/*! ./sptypes */ \"./build/sptypes/index.js\");\n/**\r\n * SharePoint REST Library\r\n */\n\n\nexports.$REST = {\n __ver: 6.95,\n AppContext: function AppContext(siteUrl) {\n return Lib.Site.getAppContext(siteUrl);\n },\n Apps: Lib.Apps,\n ContextInfo: Lib.ContextInfo,\n DefaultRequestToHostFl: false,\n Graph: Lib.Graph,\n GroupService: Lib.GroupService,\n GroupSiteManager: Lib.GroupSiteManager,\n Helper: Helper,\n HubSites: Lib.HubSites,\n HubSitesUtility: Lib.HubSitesUtility,\n List: Lib.List,\n ListByEntityName: Lib.List.getByEntityName,\n ListDataAsStream: Lib.List.getDataAsStream,\n Navigation: Lib.Navigation,\n PeopleManager: Lib.PeopleManager,\n PeoplePicker: Lib.PeoplePicker,\n ProfileLoader: Lib.ProfileLoader,\n RemoteWeb: function RemoteWeb(requestUrl) {\n return Lib.Web.getRemoteWeb(requestUrl);\n },\n Search: Lib.Search,\n Site: Lib.Site,\n SiteManager: Lib.SiteManager,\n SiteExists: function SiteExists(url) {\n return Lib.Site.exists(url);\n },\n SiteUrl: function SiteUrl(id) {\n return Lib.Site.getUrlById(id);\n },\n SPTypes: sptypes_1.SPTypes,\n SocialFeed: Lib.SocialFeed,\n ThemeManager: Lib.ThemeManager,\n UserProfile: Lib.UserProfile,\n Utility: Lib.Utility,\n Web: Lib.Web,\n WebTemplateExtensions: Lib.WebTemplateExtensions,\n WorkflowInstanceService: Lib.WorkflowInstanceService,\n WorkflowSubscriptionService: Lib.WorkflowSubscriptionService\n}; // See if the library doesn't exist, or is an older version\n\nvar global = Lib.ContextInfo.window.$REST;\n\nif (global == null || global.__ver == null || global.__ver < exports.$REST.__ver) {\n // Set the global variable\n Lib.ContextInfo.window.$REST = exports.$REST; // Ensure the SP lib exists\n\n if (Lib.ContextInfo.window.SP) {\n // If MDS is turned on in a SP2013 environment, it may throw an error\n try {\n // Alert other scripts this library is loaded\n Lib.ContextInfo.window.SP.SOD.notifyScriptLoadedAndExecuteWaitingJobs(\"gd-sprest\");\n Lib.ContextInfo.window.SP.SOD.notifyScriptLoadedAndExecuteWaitingJobs(\"gd-sprest.js\");\n } catch (_a) {\n // Log\n console.error(\"[gd-sprest] Error notifying scripts using the SP SOD library.\");\n }\n }\n}\n\n//# sourceURL=webpack://gd-sprest/./build/rest.js?");
|
|
746
746
|
|
|
747
747
|
/***/ }),
|
|
748
748
|
|