UNPKG

@pnp/sp

Version:

pnp - provides a fluent api for working with SharePoint REST

424 lines • 16.8 kB
import { __decorate } from "tslib"; import { body } from "@pnp/queryable"; import { _SPCollection, _SPInstance, deleteable, spInvokableFactory, } from "../spqueryable.js"; import { defaultPath } from "../decorators.js"; import { spPost, spPostMerge } from "../operations.js"; let _Fields = class _Fields extends _SPCollection { /** * Creates a field based on the specified schema * * @param xml A string or XmlSchemaFieldCreationInformation instance descrbing the field to create */ async createFieldAsXml(xml) { if (typeof xml === "string") { xml = { SchemaXml: xml }; } const data = await spPost(Fields(this, "createfieldasxml"), body({ parameters: xml })); return { data, field: this.getById(data.Id), }; } /** * Gets a field from the collection by id * * @param id The Id of the list */ getById(id) { return Field(this).concat(`('${id}')`); } /** * Gets a field from the collection by title * * @param title The case-sensitive title of the field */ getByTitle(title) { return Field(this, `getByTitle('${title}')`); } /** * Gets a field from the collection by using internal name or title * * @param name The case-sensitive internal name or title of the field */ getByInternalNameOrTitle(name) { return Field(this, `getByInternalNameOrTitle('${name}')`); } /** * Adds a new field to the collection * * @param title The new field's title * @param properties Differ by type of field being created (see: https://msdn.microsoft.com/en-us/library/office/dn600182.aspx) */ async add(title, fieldTypeKind, properties) { const createData = await spPost(Fields(this, null), body({ Title: title, FieldTypeKind: fieldTypeKind, Required: (properties === null || properties === void 0 ? void 0 : properties.Required) || false, })); const field = this.getById(createData.Id); if (typeof properties !== "undefined") { await field.update(properties); } const data = await field(); return { data, field, }; } /** * Adds a new field to the collection * * @param title The new field's title * @param properties Differ by type of field being created (see: https://msdn.microsoft.com/en-us/library/office/dn600182.aspx) */ async addField(title, fieldTypeKind, properties) { const data = await spPost(Fields(this, "AddField"), body({ parameters: { Title: title, FieldTypeKind: fieldTypeKind, ...properties, }, })); return { data, field: this.getById(data.Id), }; } /** * Adds a new SP.FieldText to the collection * * @param title The field title * @param properties Differ by type of field being created (see: https://msdn.microsoft.com/en-us/library/office/dn600182.aspx) */ addText(title, properties) { return this.add(title, 2, { MaxLength: 255, ...properties, }); } /** * Adds a new SP.FieldCalculated to the collection * * @param title The field title. * @param properties Differ by type of field being created (see: https://msdn.microsoft.com/en-us/library/office/dn600182.aspx) */ addCalculated(title, properties) { return this.add(title, 17, { OutputType: 2 /* Text */, ...properties, }); } /** * Adds a new SP.FieldDateTime to the collection * * @param title The field title * @param properties Differ by type of field being created (see: https://msdn.microsoft.com/en-us/library/office/dn600182.aspx) */ addDateTime(title, properties) { return this.add(title, 4, { DateTimeCalendarType: 1 /* Gregorian */, DisplayFormat: DateTimeFieldFormatType.DateOnly, FriendlyDisplayFormat: DateTimeFieldFriendlyFormatType.Unspecified, ...properties, }); } /** * Adds a new SP.FieldNumber to the collection * * @param title The field title * @param properties Differ by type of field being created (see: https://msdn.microsoft.com/en-us/library/office/dn600182.aspx) */ addNumber(title, properties) { return this.add(title, 9, properties); } /** * Adds a new SP.FieldCurrency to the collection * * @param title The field title * @param properties Differ by type of field being created (see: https://msdn.microsoft.com/en-us/library/office/dn600182.aspx) */ addCurrency(title, properties) { return this.add(title, 10, { CurrencyLocaleId: 1033, ...properties, }); } /** * Adds a new SP.FieldMultiLineText to the collection * * @param title The field title * @param properties Differ by type of field being created (see: https://msdn.microsoft.com/en-us/library/office/dn600182.aspx) * */ addMultilineText(title, properties) { return this.add(title, 3, { AllowHyperlink: true, AppendOnly: false, NumberOfLines: 6, RestrictedMode: false, RichText: true, ...properties, }); } /** * Adds a new SP.FieldUrl to the collection * * @param title The field title */ addUrl(title, properties) { return this.add(title, 11, { DisplayFormat: UrlFieldFormatType.Hyperlink, ...properties, }); } /** Adds a user field to the colleciton * * @param title The new field's title * @param properties */ addUser(title, properties) { return this.add(title, 20, { SelectionMode: FieldUserSelectionMode.PeopleAndGroups, ...properties, }); } /** * Adds a SP.FieldLookup to the collection * * @param title The new field's title * @param properties Set of additional properties to set on the new field */ async addLookup(title, properties) { return this.addField(title, 7, properties); } /** * Adds a new SP.FieldChoice to the collection * * @param title The field title. * @param properties Differ by type of field being created (see: https://msdn.microsoft.com/en-us/library/office/dn600182.aspx) */ addChoice(title, properties) { return this.add(title, 6, { EditFormat: ChoiceFieldFormatType.Dropdown, FillInChoice: false, ...properties, }); } /** * Adds a new SP.FieldMultiChoice to the collection * * @param title The field title. * @param properties Differ by type of field being created (see: https://msdn.microsoft.com/en-us/library/office/dn600182.aspx) */ addMultiChoice(title, properties) { return this.add(title, 15, { FillInChoice: false, ...properties, }); } /** * Adds a new SP.FieldBoolean to the collection * * @param title The field title. * @param properties Differ by type of field being created (see: https://msdn.microsoft.com/en-us/library/office/dn600182.aspx) */ addBoolean(title, properties) { return this.add(title, 8, properties); } /** * Creates a secondary (dependent) lookup field, based on the Id of the primary lookup field. * * @param displayName The display name of the new field. * @param primaryLookupFieldId The guid of the primary Lookup Field. * @param showField Which field to show from the lookup list. */ async addDependentLookupField(displayName, primaryLookupFieldId, showField) { const path = `adddependentlookupfield(displayName='${displayName}', primarylookupfieldid='${primaryLookupFieldId}', showfield='${showField}')`; const data = await spPost(Fields(this, path)); return { data, field: this.getById(data.Id), }; } /** * Adds a new SP.FieldLocation to the collection * * @param title The field title. * @param properties Differ by type of field being created (see: https://msdn.microsoft.com/en-us/library/office/dn600182.aspx) */ addLocation(title, properties) { return this.add(title, 33, properties); } /** * Adds a new SP.FieldLocation to the collection * * @param title The field title. * @param properties Differ by type of field being created (see: https://msdn.microsoft.com/en-us/library/office/dn600182.aspx) */ addImageField(title, properties) { return this.add(title, 34, properties); } }; _Fields = __decorate([ defaultPath("fields") ], _Fields); export { _Fields }; export const Fields = spInvokableFactory(_Fields); export class _Field extends _SPInstance { constructor() { super(...arguments); this.delete = deleteable(); } /** * Updates this field instance with the supplied properties * * @param properties A plain object hash of values to update for the list * @param fieldType The type value such as SP.FieldLookup. Optional, looked up from the field if not provided */ async update(properties, fieldType) { if (typeof fieldType === "undefined" || fieldType === null) { const info = await Field(this).select("FieldTypeKind")(); fieldType = info["odata.type"]; } const data = await spPostMerge(this, body(properties)); return { data, field: this, }; } /** * Sets the value of the ShowInDisplayForm property for this field. */ setShowInDisplayForm(show) { return spPost(Field(this, `setshowindisplayform(${show})`)); } /** * Sets the value of the ShowInEditForm property for this field. */ setShowInEditForm(show) { return spPost(Field(this, `setshowineditform(${show})`)); } /** * Sets the value of the ShowInNewForm property for this field. */ setShowInNewForm(show) { return spPost(Field(this, `setshowinnewform(${show})`)); } } export const Field = spInvokableFactory(_Field); /** * Specifies the type of the field. */ export var FieldTypes; (function (FieldTypes) { FieldTypes[FieldTypes["Invalid"] = 0] = "Invalid"; FieldTypes[FieldTypes["Integer"] = 1] = "Integer"; FieldTypes[FieldTypes["Text"] = 2] = "Text"; FieldTypes[FieldTypes["Note"] = 3] = "Note"; FieldTypes[FieldTypes["DateTime"] = 4] = "DateTime"; FieldTypes[FieldTypes["Counter"] = 5] = "Counter"; FieldTypes[FieldTypes["Choice"] = 6] = "Choice"; FieldTypes[FieldTypes["Lookup"] = 7] = "Lookup"; FieldTypes[FieldTypes["Boolean"] = 8] = "Boolean"; FieldTypes[FieldTypes["Number"] = 9] = "Number"; FieldTypes[FieldTypes["Currency"] = 10] = "Currency"; FieldTypes[FieldTypes["URL"] = 11] = "URL"; FieldTypes[FieldTypes["Computed"] = 12] = "Computed"; FieldTypes[FieldTypes["Threading"] = 13] = "Threading"; FieldTypes[FieldTypes["Guid"] = 14] = "Guid"; FieldTypes[FieldTypes["MultiChoice"] = 15] = "MultiChoice"; FieldTypes[FieldTypes["GridChoice"] = 16] = "GridChoice"; FieldTypes[FieldTypes["Calculated"] = 17] = "Calculated"; FieldTypes[FieldTypes["File"] = 18] = "File"; FieldTypes[FieldTypes["Attachments"] = 19] = "Attachments"; FieldTypes[FieldTypes["User"] = 20] = "User"; FieldTypes[FieldTypes["Recurrence"] = 21] = "Recurrence"; FieldTypes[FieldTypes["CrossProjectLink"] = 22] = "CrossProjectLink"; FieldTypes[FieldTypes["ModStat"] = 23] = "ModStat"; FieldTypes[FieldTypes["Error"] = 24] = "Error"; FieldTypes[FieldTypes["ContentTypeId"] = 25] = "ContentTypeId"; FieldTypes[FieldTypes["PageSeparator"] = 26] = "PageSeparator"; FieldTypes[FieldTypes["ThreadIndex"] = 27] = "ThreadIndex"; FieldTypes[FieldTypes["WorkflowStatus"] = 28] = "WorkflowStatus"; FieldTypes[FieldTypes["AllDayEvent"] = 29] = "AllDayEvent"; FieldTypes[FieldTypes["WorkflowEventType"] = 30] = "WorkflowEventType"; })(FieldTypes || (FieldTypes = {})); export var DateTimeFieldFormatType; (function (DateTimeFieldFormatType) { DateTimeFieldFormatType[DateTimeFieldFormatType["DateOnly"] = 0] = "DateOnly"; DateTimeFieldFormatType[DateTimeFieldFormatType["DateTime"] = 1] = "DateTime"; })(DateTimeFieldFormatType || (DateTimeFieldFormatType = {})); export var DateTimeFieldFriendlyFormatType; (function (DateTimeFieldFriendlyFormatType) { DateTimeFieldFriendlyFormatType[DateTimeFieldFriendlyFormatType["Unspecified"] = 0] = "Unspecified"; DateTimeFieldFriendlyFormatType[DateTimeFieldFriendlyFormatType["Disabled"] = 1] = "Disabled"; DateTimeFieldFriendlyFormatType[DateTimeFieldFriendlyFormatType["Relative"] = 2] = "Relative"; })(DateTimeFieldFriendlyFormatType || (DateTimeFieldFriendlyFormatType = {})); /** * Specifies the control settings while adding a field. */ export var AddFieldOptions; (function (AddFieldOptions) { /** * Specify that a new field added to the list must also be added to the default content type in the site collection */ AddFieldOptions[AddFieldOptions["DefaultValue"] = 0] = "DefaultValue"; /** * Specify that a new field added to the list must also be added to the default content type in the site collection. */ AddFieldOptions[AddFieldOptions["AddToDefaultContentType"] = 1] = "AddToDefaultContentType"; /** * Specify that a new field must not be added to any other content type */ AddFieldOptions[AddFieldOptions["AddToNoContentType"] = 2] = "AddToNoContentType"; /** * Specify that a new field that is added to the specified list must also be added to all content types in the site collection */ AddFieldOptions[AddFieldOptions["AddToAllContentTypes"] = 4] = "AddToAllContentTypes"; /** * Specify adding an internal field name hint for the purpose of avoiding possible database locking or field renaming operations */ AddFieldOptions[AddFieldOptions["AddFieldInternalNameHint"] = 8] = "AddFieldInternalNameHint"; /** * Specify that a new field that is added to the specified list must also be added to the default list view */ AddFieldOptions[AddFieldOptions["AddFieldToDefaultView"] = 16] = "AddFieldToDefaultView"; /** * Specify to confirm that no other field has the same display name */ AddFieldOptions[AddFieldOptions["AddFieldCheckDisplayName"] = 32] = "AddFieldCheckDisplayName"; })(AddFieldOptions || (AddFieldOptions = {})); export var CalendarType; (function (CalendarType) { CalendarType[CalendarType["Gregorian"] = 1] = "Gregorian"; CalendarType[CalendarType["Japan"] = 3] = "Japan"; CalendarType[CalendarType["Taiwan"] = 4] = "Taiwan"; CalendarType[CalendarType["Korea"] = 5] = "Korea"; CalendarType[CalendarType["Hijri"] = 6] = "Hijri"; CalendarType[CalendarType["Thai"] = 7] = "Thai"; CalendarType[CalendarType["Hebrew"] = 8] = "Hebrew"; CalendarType[CalendarType["GregorianMEFrench"] = 9] = "GregorianMEFrench"; CalendarType[CalendarType["GregorianArabic"] = 10] = "GregorianArabic"; CalendarType[CalendarType["GregorianXLITEnglish"] = 11] = "GregorianXLITEnglish"; CalendarType[CalendarType["GregorianXLITFrench"] = 12] = "GregorianXLITFrench"; CalendarType[CalendarType["KoreaJapanLunar"] = 14] = "KoreaJapanLunar"; CalendarType[CalendarType["ChineseLunar"] = 15] = "ChineseLunar"; CalendarType[CalendarType["SakaEra"] = 16] = "SakaEra"; CalendarType[CalendarType["UmAlQura"] = 23] = "UmAlQura"; })(CalendarType || (CalendarType = {})); export var UrlFieldFormatType; (function (UrlFieldFormatType) { UrlFieldFormatType[UrlFieldFormatType["Hyperlink"] = 0] = "Hyperlink"; UrlFieldFormatType[UrlFieldFormatType["Image"] = 1] = "Image"; })(UrlFieldFormatType || (UrlFieldFormatType = {})); export var FieldUserSelectionMode; (function (FieldUserSelectionMode) { FieldUserSelectionMode[FieldUserSelectionMode["PeopleAndGroups"] = 1] = "PeopleAndGroups"; FieldUserSelectionMode[FieldUserSelectionMode["PeopleOnly"] = 0] = "PeopleOnly"; })(FieldUserSelectionMode || (FieldUserSelectionMode = {})); export var ChoiceFieldFormatType; (function (ChoiceFieldFormatType) { ChoiceFieldFormatType[ChoiceFieldFormatType["Dropdown"] = 0] = "Dropdown"; ChoiceFieldFormatType[ChoiceFieldFormatType["RadioButtons"] = 1] = "RadioButtons"; })(ChoiceFieldFormatType || (ChoiceFieldFormatType = {})); //# sourceMappingURL=types.js.map