New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

gd-sprest-react

Package Overview
Dependencies
Maintainers
1
Versions
309
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gd-sprest-react - npm Package Compare versions

Comparing version 2.5.0 to 2.5.1

88

build/components/itemForm.d.ts

@@ -5,9 +5,11 @@ /// <reference types="react" />

import { IItemFormProps, IItemFormState } from "../definitions";
import { Fields } from "..";
import { Field } from ".";
/**
* Item Form WebPart
* Item Form
*/
export declare class ItemForm extends React.Component<IItemFormProps, IItemFormState> {
/**
* Constructor
*/
constructor(props: IItemFormProps);
/**
* Reference to the attachments field

@@ -19,51 +21,12 @@ */

*/
private _fields;
private _formFields;
/**
* Reference to the query used to refresh the item
* Form Control Mode
*/
private _query;
/**
* Get the attachment field
*/
/**
* Set the attachment field
*/
AttachmentField: Fields.FieldAttachments;
/**
* Get the control mode
*/
readonly ControlMode: number;
/**
* Get the form fields
* Get the form information
*/
readonly FormInfo: Types.Helper.ListForm.IListFormResult;
/**
* Set the form fields
*/
FormFields: {
[key: string]: Field;
};
/**
* Get the list
*/
readonly List: Types.IListResult;
/**
* Get the item query
*/
/**
* Set the item query
*/
ItemQuery: Types.ODataQuery;
/**
* Constructor
*/
constructor(props: IItemFormProps);
/**
* Method to get the form values
*/
getFormValues<T>(): any;
/**
* Method to refresh the item
*/
refresh(): void;
/**
* Render the component

@@ -73,29 +36,20 @@ */

/**
* Method to save the item form
*/
save<IItem = any>(): PromiseLike<IItem>;
/**
* Method to update the item.
*/
updateItem<IItem = any>(fieldValues: any): PromiseLike<IItem>;
/**
* Methods
*/
/**
* Method to get the item
* @param itemId - The item id.
* Method to get the form values
*/
private getItem;
getFormValues<IItem = any>(): any;
/**
* Method to get the form values
* Method to load the list information
*/
private getValues<IItem>();
private loadformInfo;
/**
* Method to load the fields
* Method to refresh the item
*/
private loadDefaultFields;
refresh(): void;
/**
* Method to load the list
* Method to render the attachments field
*/
private loadList;
private renderAttachmentsField;
/**

@@ -106,2 +60,6 @@ * Method to render the fields

/**
* Method to save the item form
*/
save<IItem = any>(): PromiseLike<IItem>;
/**
* Method to save the item attachments

@@ -112,5 +70,5 @@ * @param itemId - The item id.

/**
* Method to save the item
* Method to update the item.
*/
private saveItem;
updateItem<IItem = any>(fieldValues: any): PromiseLike<IItem>;
}

@@ -19,3 +19,3 @@ "use strict";

/**
* Item Form WebPart
* Item Form
*/

@@ -36,127 +36,74 @@ var ItemForm = /** @class */ (function (_super) {

*/
_this._fields = {};
_this._formFields = {};
/**
* Reference to the query used to refresh the item
* Method to load the list information
*/
_this._query = null;
/**
* Methods
*/
/**
* Method to get the item
* @param itemId - The item id.
*/
_this.getItem = function (itemId) {
// Return a promise
return new Promise(function (resolve, reject) {
// Set the filter
_this._query.Filter = "ID eq " + itemId;
// Get the item
_this.state.list.Items().query(_this._query)
.execute(function (items) {
// Resolve the promise
resolve(items.results ? items.results[0] : null);
});
});
};
/**
* Method to load the fields
*/
_this.loadDefaultFields = function () {
// Get the default content type
_this.state.list.ContentTypes()
.query({
Expand: ["FieldLinks"],
Top: 1
})
.execute(function (contentTypes) {
// Ensure the content types exist
if (contentTypes.results) {
var fields = [];
// Parse the default content type
for (var i = 0; i < contentTypes.results[0].FieldLinks.results.length; i++) {
var fieldLink = contentTypes.results[0].FieldLinks.results[i];
var field = _this.state.listFields[fieldLink.Name];
// Skip the content type field
if (field.InternalName == "ContentType") {
continue;
}
// Skip hidden fields
if (field.Hidden || fieldLink.Hidden) {
continue;
}
// Add the field name
fields.push({ name: field.InternalName });
}
// Update the state
_this.setState({ fields: fields });
}
else {
console.log("[gd-sprest] Error getting default fields.");
console.log("[gd-sprest] " + contentTypes["response"]);
}
}, true);
};
/**
* Method to load the list
*/
_this.loadList = function () {
// Get the web
(new gd_sprest_1.Web(_this.props.webUrl))
.Lists(_this.props.listName)
.execute(function (list) {
// Update the state
_this.setState({ list: list }, function () {
// See if the item id was passed in
if (typeof (_this.state.item) === "number") {
// Get the item
_this.getItem(_this.state.item).then(function (item) {
// Update the state
_this.setState({ item: item });
});
}
});
})
.Fields()
.execute(function (fields) {
var listFields = {};
_this.loadformInfo = function () {
var fields = null;
var formFields = _this.props.fields;
// Ensure the fields exist
if (formFields) {
fields = [];
// Parse the fields
for (var i = 0; i < fields.results.length; i++) {
var field = fields.results[i];
// Add the list field
listFields[field.InternalName] = field;
for (var i = 0; i < formFields.length; i++) {
// Add the field
fields.push(formFields[i].name);
}
}
// Create an instance of the list form
new gd_sprest_1.Helper.ListForm({
cacheKey: _this.props.cacheKey,
fields: fields,
itemId: _this.props.item ? _this.props.item.Id : _this.props.itemId,
listName: _this.props.listName,
webUrl: _this.props.webUrl
}).then(function (formInfo) {
// Update the state
_this.setState({ listFields: listFields });
_this.setState({ formInfo: formInfo });
});
};
/**
* Method to render the fields
* Method to render the attachments field
*/
_this.renderFields = function () {
var formFields = [];
var item = _this.state.item;
_this.renderAttachmentsField = function () {
var item = _this.state.formInfo.item;
// See if we are displaying attachments
if (_this.props.showAttachments) {
formFields.push(React.createElement("div", { className: "ms-Grid-row", key: "row_Attachments" },
return (React.createElement("div", { className: "ms-Grid-row", key: "row_Attachments" },
React.createElement("div", { className: "ms-Grid-col-md12" },
React.createElement(__1.Fields.FieldAttachments, { controlMode: _this.ControlMode, files: item.AttachmentFiles, key: "Attachments", itemId: item.Id, listName: _this.props.listName, onAttachmentsRender: _this.props.onFieldRender == null ? null : function (attachments) { return _this.props.onFieldRender({ listName: _this.props.listName, name: "Attachments" }, attachments); }, onFileAdded: _this.props.onAttachmentAdded, onFileClick: _this.props.onAttachmentClick == null ? null : function (file) { return _this.props.onAttachmentClick(file, _this.ControlMode); }, onFileRender: _this.props.onAttachmentRender == null ? null : function (file) { return _this.props.onAttachmentRender(file, _this.ControlMode); }, onRender: _this.props.onRenderAttachments == null ? null : function (files) { return _this.props.onRenderAttachments(files, _this.ControlMode); }, ref: function (field) { _this._attachmentField = field; }, webUrl: _this.props.webUrl }))));
React.createElement(__1.Fields.FieldAttachments, { controlMode: _this.ControlMode, files: item ? item.AttachmentFiles : null, key: "Attachments", itemId: item.Id, listName: _this.props.listName, onAttachmentsRender: _this.props.onFieldRender == null ? null : function (attachments) { return _this.props.onFieldRender({ listName: _this.props.listName, name: "Attachments" }, attachments); }, onFileAdded: _this.props.onAttachmentAdded, onFileClick: _this.props.onAttachmentClick == null ? null : function (file) { return _this.props.onAttachmentClick(file, _this.ControlMode); }, onFileRender: _this.props.onAttachmentRender == null ? null : function (file) { return _this.props.onAttachmentRender(file, _this.ControlMode); }, onRender: _this.props.onRenderAttachments == null ? null : function (files) { return _this.props.onRenderAttachments(files, _this.ControlMode); }, ref: function (field) { _this._attachmentField = field; }, webUrl: _this.props.webUrl }))));
}
// Parse the fields
for (var i = 0; i < _this.state.fields.length; i++) {
var fieldInfo = _this.state.fields[i];
// Render nothing
return null;
};
/**
* Method to render the fields
*/
_this.renderFields = function () {
var formFields = [];
var item = _this.state.formInfo.item;
var _loop_1 = function (fieldName) {
var field = _this.state.formInfo.fields[fieldName];
var readOnly = false;
// See if we are excluding this field
if (_this.props.excludeFields && _this.props.excludeFields.indexOf(fieldInfo.name) >= 0) {
continue;
if (_this.props.excludeFields && _this.props.excludeFields.indexOf(fieldName) >= 0) {
return "continue";
}
// See if this is a read-only field
if (_this.props.readOnlyFields && _this.props.readOnlyFields.indexOf(fieldInfo.name) >= 0) {
if (_this.props.readOnlyFields && _this.props.readOnlyFields.indexOf(fieldName) >= 0) {
// Set the flag
readOnly = true;
}
// Find the field information
var fieldInfo = (_this.props.fields || []).find(function (fieldInfo) {
return fieldInfo.name == fieldName;
});
// Add the form field
formFields.push(React.createElement("div", { className: "ms-Grid-row", key: "row_" + fieldInfo.name },
formFields.push(React.createElement("div", { className: "ms-Grid-row", key: "row_" + fieldName },
React.createElement("div", { className: "ms-Grid-col ms-md12" },
React.createElement(_1.Field, { controlMode: readOnly ? gd_sprest_1.SPTypes.ControlMode.Display : _this.ControlMode, defaultValue: item[fieldInfo.name], field: _this.state.listFields && _this.state.listFields[fieldInfo.name], item: item, listName: _this.props.listName, key: fieldInfo.name, name: fieldInfo.name, onChange: fieldInfo.onChange, onFieldRender: _this.props.onFieldRender, onRender: fieldInfo.onRender, queryTop: _this.props.queryTop, ref: function (field) { field ? _this._fields[field.props.name] = field : null; }, webUrl: _this.props.webUrl }))));
React.createElement(_1.Field, { controlMode: readOnly ? gd_sprest_1.SPTypes.ControlMode.Display : _this.ControlMode, defaultValue: item[field.InternalName], field: field, item: item, listName: _this.props.listName, key: field.InternalName, name: field.InternalName, onChange: fieldInfo ? fieldInfo.onChange : null, onFieldRender: _this.props.onFieldRender, onRender: fieldInfo ? fieldInfo.onRender : null, queryTop: _this.props.queryTop, ref: function (field) { field ? _this._formFields[field.props.name] = field : null; }, webUrl: _this.props.webUrl }))));
};
// Parse the form fields
for (var fieldName in _this.state.formInfo.fields) {
_loop_1(fieldName);
}

@@ -178,3 +125,3 @@ // Return the form fields

// Resolve the promise
resolve(itemId);
resolve();
});

@@ -184,40 +131,11 @@ }

// Resolve the promise
resolve(itemId);
resolve();
}
});
};
/**
* Method to save the item
*/
_this.saveItem = function () {
// Return a promise
return new Promise(function (resolve, reject) {
var item = _this.state.item;
// Get the item
var formValues = _this.getValues();
// See if this is an existing item
if (item && item.update) {
// Update the item
item.update(formValues).execute(function (response) {
// Resolve the request
resolve(item.Id);
});
}
else {
// Set the metadata type
formValues["__metadata"] = { type: _this.state.list.ListItemEntityTypeFullName };
// Get the items
_this.state.list.Items()
.add(formValues)
.execute(function (item) {
// Resolve the request
resolve(item.Id);
});
}
});
};
// Set the state
_this.state = {
fields: props.fields,
item: props.item || {},
fields: null,
itemId: null,
formInfo: null,
refreshFl: false,

@@ -227,33 +145,7 @@ saveFl: false,

};
// Default the query
_this._query = props.query || {
Select: ["*"]
};
// See if we are showing attachments
if (props.showAttachments) {
// Expand the attachment files
_this._query.Expand = _this._query.Expand || [];
_this._query.Expand.push("AttachmentFiles");
// Get the attachment files
_this._query.Select = _this._query.Select || [];
_this._query.Select.push("Attachments");
_this._query.Select.push("AttachmentFiles");
}
return _this;
}
Object.defineProperty(ItemForm.prototype, "AttachmentField", {
/**
* Get the attachment field
*/
get: function () { return this._attachmentField; },
/**
* Set the attachment field
*/
set: function (field) { this._attachmentField = field; },
enumerable: true,
configurable: true
});
Object.defineProperty(ItemForm.prototype, "ControlMode", {
/**
* Get the control mode
* Form Control Mode
*/

@@ -269,3 +161,3 @@ get: function () {

// Ensure the item exists
controlMode = this.state.item && this.state.item.Id > 0 ? gd_sprest_1.SPTypes.ControlMode.Edit : gd_sprest_1.SPTypes.ControlMode.New;
controlMode = this.state.formInfo.item && this.state.formInfo.item.Id > 0 ? gd_sprest_1.SPTypes.ControlMode.Edit : gd_sprest_1.SPTypes.ControlMode.New;
}

@@ -278,76 +170,44 @@ // Return the control mode

});
Object.defineProperty(ItemForm.prototype, "FormFields", {
Object.defineProperty(ItemForm.prototype, "FormInfo", {
/**
* Get the form fields
* Get the form information
*/
get: function () { return this._fields; },
/**
* Set the form fields
*/
set: function (fields) { this._fields = fields; },
get: function () { return this.state.formInfo; },
enumerable: true,
configurable: true
});
Object.defineProperty(ItemForm.prototype, "List", {
/**
* Get the list
*/
get: function () { return this.state.list; },
enumerable: true,
configurable: true
});
Object.defineProperty(ItemForm.prototype, "ItemQuery", {
/**
* Get the item query
*/
get: function () { return this._query; },
/**
* Set the item query
*/
set: function (query) { this._query = query; },
enumerable: true,
configurable: true
});
/**
* Method to get the form values
*/
ItemForm.prototype.getFormValues = function () { return this.getValues(); };
/**
* Method to refresh the item
*/
ItemForm.prototype.refresh = function () {
// Update the state
this.setState({ item: this.state.item.Id });
};
/**
* Render the component
*/
ItemForm.prototype.render = function () {
// See if the list exists
if (this.state.list == null) {
// Load the list
this.loadList();
var _this = this;
var spinner = null;
// See if the list has been loaded
if (this.state.formInfo == null) {
// Load the list information
this.loadformInfo();
// Return a spinner
return (React.createElement(office_ui_fabric_react_1.Spinner, { label: "Loading the list..." }));
return (React.createElement(office_ui_fabric_react_1.Spinner, { label: "Loading the list information..." }));
}
// Ensure the fields are loaded
if (this.state.listFields == null) {
// Return a spinner
return (React.createElement(office_ui_fabric_react_1.Spinner, { label: "Loading the list fields..." }));
}
// Ensure the item is loaded
if (typeof (this.state.item) === "number") {
// Return a spinner
return (React.createElement(office_ui_fabric_react_1.Spinner, { label: "Loading the item..." }));
}
// See if we are refreshing the item
if (this.state.refreshFl) {
// Return a spinner
return (React.createElement(office_ui_fabric_react_1.Spinner, { label: "Refreshing the Item", size: office_ui_fabric_react_1.SpinnerSize.large }));
// Reload the item
gd_sprest_1.Helper.ListForm.refreshItem(this.state.formInfo).then(function (formInfo) {
// Update the state
_this.setState({
formInfo: formInfo,
refreshFl: false
});
});
// Set the spinner
spinner = (React.createElement(office_ui_fabric_react_1.Spinner, { label: "Refreshing the Item", size: office_ui_fabric_react_1.SpinnerSize.large }));
}
// See if we are updating the item
if (this.state.updateFl) {
// Return a spinner
return (React.createElement(office_ui_fabric_react_1.Spinner, { label: "Updating the Item", size: office_ui_fabric_react_1.SpinnerSize.large }));
else if (this.state.saveFl) {
// Set the spinner
spinner = (React.createElement(office_ui_fabric_react_1.Spinner, { label: "Saving the item", size: office_ui_fabric_react_1.SpinnerSize.large }));
}
else if (this.state.updateFl) {
// Set the spinner
spinner = (React.createElement(office_ui_fabric_react_1.Spinner, { label: "Updating the Item", size: office_ui_fabric_react_1.SpinnerSize.large }));
}
// See if there is a custom renderer

@@ -357,13 +217,5 @@ if (this.props.onRender) {

return (React.createElement("div", null,
!this.state.saveFl ? null :
React.createElement(office_ui_fabric_react_1.Spinner, { label: "Saving the Item", size: office_ui_fabric_react_1.SpinnerSize.large }),
React.createElement("div", { hidden: this.state.saveFl }, this.props.onRender(this.ControlMode))));
spinner,
React.createElement("div", { hidden: spinner ? true : false }, this.props.onRender(this.ControlMode))));
}
// See if the fields have been defined
if (this.state.fields == null) {
// Load the default fields
this.loadDefaultFields();
// Return a spinner
return (React.createElement(office_ui_fabric_react_1.Spinner, { label: "Loading the fields..." }));
}
// Render the fields

@@ -373,58 +225,17 @@ return (React.createElement("div", { className: "ms-Grid " + (this.props.className || "") },

React.createElement(office_ui_fabric_react_1.Spinner, { label: "Saving the Item", size: office_ui_fabric_react_1.SpinnerSize.large }),
React.createElement("div", { hidden: this.state.saveFl }, this.renderFields())));
React.createElement("div", { hidden: this.state.saveFl },
this.renderAttachmentsField(),
this.renderFields())));
};
/**
* Method to save the item form
* Methods
*/
ItemForm.prototype.save = function () {
var _this = this;
return new Promise(function (resolve, reject) {
// Set the state
_this.setState({ saveFl: true }, function () {
// Save the item
_this.saveItem()
.then(_this.saveAttachments)
.then(_this.getItem)
.then(function (item) {
// Update the state
_this.setState({ item: item, saveFl: false }, function () {
// Resolve the promise
resolve(item);
});
});
});
});
};
/**
* Method to update the item.
*/
ItemForm.prototype.updateItem = function (fieldValues) {
var _this = this;
// Return a promise
return new Promise(function (resolve, reject) {
// Set the state
_this.setState({ updateFl: true }, function () {
var item = _this.state.item;
// Update the item
item.update(fieldValues).execute(function (response) {
// Get the item
_this.getItem(item.Id).then(function (item) {
// Update the state
_this.setState({ item: item, updateFl: false }, function () {
// Resolve the promise
resolve(item);
});
});
});
});
});
};
/**
* Method to get the form values
*/
ItemForm.prototype.getValues = function () {
ItemForm.prototype.getFormValues = function () {
var formValues = {};
// Parse the fields
for (var fieldName in this._fields) {
var field = this._fields[fieldName];
for (var fieldName in this._formFields) {
var field = this._formFields[fieldName];
// Ensure the field exists

@@ -487,2 +298,57 @@ if (field == null) {

};
/**
* Method to refresh the item
*/
ItemForm.prototype.refresh = function () {
// Update the state
this.setState({ refreshFl: true });
};
/**
* Method to save the item form
*/
ItemForm.prototype.save = function () {
var _this = this;
// Return a promise
return new Promise(function (resolve, reject) {
// Set the state
_this.setState({ saveFl: true }, function () {
// Save the item
gd_sprest_1.Helper.ListForm.saveItem(_this.state.formInfo, _this.getFormValues())
.then(function (formInfo) {
// Save the attachments
_this.saveAttachments(formInfo.item.Id).then(function () {
// Refresh the item
gd_sprest_1.Helper.ListForm.refreshItem(formInfo).then(function (formInfo) {
// Update the state
_this.setState({ formInfo: formInfo, saveFl: false }, function () {
// Resolve the promise
resolve(formInfo.item);
});
});
});
});
});
});
};
/**
* Method to update the item.
*/
ItemForm.prototype.updateItem = function (fieldValues) {
var _this = this;
// Return a promise
return new Promise(function (resolve, reject) {
// Set the state
_this.setState({ updateFl: true }, function () {
var formInfo = _this.state.formInfo;
// Update the item
gd_sprest_1.Helper.ListForm.saveItem(formInfo, fieldValues).then(function (formInfo) {
// Update the state
_this.setState({ formInfo: formInfo, updateFl: false }, function () {
// Resolve the promise
resolve(formInfo.item);
});
});
});
});
};
return ItemForm;

@@ -489,0 +355,0 @@ }(React.Component));

@@ -10,3 +10,3 @@ /// <reference types="react" />

controlMode?: number;
/** The internal field name. */
/** The field name. */
name: string;

@@ -22,2 +22,4 @@ /** The on change event */

export interface IItemFormProps {
/** If defined, the form data will be cached to the session storage. */
cacheKey?: string;
/** The class name to apply to the item form element. */

@@ -33,2 +35,4 @@ className?: string;

item?: any;
/** The item id */
itemId?: number;
/** The list display name. */

@@ -63,12 +67,8 @@ listName: string;

export interface IItemFormState {
/** The form information */
formInfo?: Types.Helper.ListForm.IListFormResult;
/** The item id. */
itemId?: number;
/** The form fields. */
fields?: Array<IItemFormField>;
/** The existing item. */
item?: any;
/** The list. */
list?: Types.IListResult;
/** The list fields. */
listFields?: {
[key: string]: Types.IFieldResult | Types.IFieldQueryResult;
};
/** The refresh flag. */

@@ -75,0 +75,0 @@ refreshFl?: boolean;

@@ -18,6 +18,6 @@ /// <reference types="react" />

helpUrl?: string;
onPostRender?: (targetInfo?: Types.Helper.WebPart.IWebPart) => void;
onRenderDisplayElement?: (targetInfo: Types.Helper.WebPart.IWebPart) => any;
onRenderEditElement?: (targetInfo: Types.Helper.WebPart.IWebPart) => any;
onPostRender?: (targetInfo?: Types.Helper.WebPart.IWebPartInfo) => void;
onRenderDisplayElement?: (targetInfo: Types.Helper.WebPart.IWebPartInfo) => any;
onRenderEditElement?: (targetInfo: Types.Helper.WebPart.IWebPartInfo) => any;
targetElementId: string;
}
{
"name": "gd-sprest-react",
"version": "2.5.0",
"version": "2.5.1",
"description": "SharePoint react components.",

@@ -41,5 +41,5 @@ "main": "build/index.js",

"css-loader": "^0.28.8",
"gd-sprest": "^2.6.4",
"gd-sprest": "^2.9.6",
"node-sass": "^4.7.2",
"office-ui-fabric-react": "^5.39.0",
"office-ui-fabric-react": "^5.39.1",
"react": "^16.2.0",

@@ -46,0 +46,0 @@ "react-dom": "^16.2.0",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc