UNPKG

18.1 kBJavaScriptView Raw
1import { __decorate } from "tslib";
2import { body, headers } from "@pnp/queryable";
3import { _SPCollection, _SPInstance, deleteable, spInvokableFactory, } from "../spqueryable.js";
4import { defaultPath } from "../decorators.js";
5import { spPost, spPostMerge } from "../operations.js";
6import { metadata } from "../utils/metadata.js";
7let _Fields = class _Fields extends _SPCollection {
8 /**
9 * Creates a field based on the specified schema
10 *
11 * @param xml A string or XmlSchemaFieldCreationInformation instance descrbing the field to create
12 */
13 async createFieldAsXml(xml) {
14 if (typeof xml === "string") {
15 xml = { SchemaXml: xml };
16 }
17 const data = await spPost(Fields(this, "createfieldasxml"), body({ parameters: xml }));
18 return {
19 data,
20 field: this.getById(data.Id),
21 };
22 }
23 /**
24 * Gets a field from the collection by id
25 *
26 * @param id The Id of the list
27 */
28 getById(id) {
29 return Field(this).concat(`('${id}')`);
30 }
31 /**
32 * Gets a field from the collection by title
33 *
34 * @param title The case-sensitive title of the field
35 */
36 getByTitle(title) {
37 return Field(this, `getByTitle('${title}')`);
38 }
39 /**
40 * Gets a field from the collection by using internal name or title
41 *
42 * @param name The case-sensitive internal name or title of the field
43 */
44 getByInternalNameOrTitle(name) {
45 return Field(this, `getByInternalNameOrTitle('${name}')`);
46 }
47 /**
48 * Adds a new field to the collection
49 *
50 * @param title The new field's title
51 * @param properties Differ by type of field being created (see: https://msdn.microsoft.com/en-us/library/office/dn600182.aspx)
52 */
53 async add(title, fieldTypeKind, properties) {
54 const data = await spPost(Fields(this, null), body(Object.assign(metadata(mapFieldTypeEnumToString(fieldTypeKind)), {
55 Title: title,
56 FieldTypeKind: fieldTypeKind,
57 ...properties,
58 }), headers({
59 "Accept": "application/json;odata=verbose",
60 "Content-Type": "application/json;odata=verbose",
61 })));
62 return {
63 data,
64 field: this.getById(data.Id),
65 };
66 }
67 /**
68 * Adds a new field to the collection
69 *
70 * @param title The new field's title
71 * @param properties Differ by type of field being created (see: https://msdn.microsoft.com/en-us/library/office/dn600182.aspx)
72 */
73 async addField(title, fieldTypeKind, properties) {
74 const data = await spPost(Fields(this, "AddField"), body({
75 parameters: {
76 Title: title,
77 FieldTypeKind: fieldTypeKind,
78 ...properties,
79 },
80 }));
81 return {
82 data,
83 field: this.getById(data.Id),
84 };
85 }
86 /**
87 * Adds a new SP.FieldText to the collection
88 *
89 * @param title The field title
90 * @param properties Differ by type of field being created (see: https://msdn.microsoft.com/en-us/library/office/dn600182.aspx)
91 */
92 addText(title, properties) {
93 return this.add(title, 2, {
94 MaxLength: 255,
95 ...properties,
96 });
97 }
98 /**
99 * Adds a new SP.FieldCalculated to the collection
100 *
101 * @param title The field title.
102 * @param properties Differ by type of field being created (see: https://msdn.microsoft.com/en-us/library/office/dn600182.aspx)
103 */
104 addCalculated(title, properties) {
105 return this.add(title, 17, {
106 OutputType: 2 /* Text */,
107 ...properties,
108 });
109 }
110 /**
111 * Adds a new SP.FieldDateTime to the collection
112 *
113 * @param title The field title
114 * @param properties Differ by type of field being created (see: https://msdn.microsoft.com/en-us/library/office/dn600182.aspx)
115 */
116 addDateTime(title, properties) {
117 return this.add(title, 4, {
118 DateTimeCalendarType: 1 /* Gregorian */,
119 DisplayFormat: DateTimeFieldFormatType.DateOnly,
120 FriendlyDisplayFormat: DateTimeFieldFriendlyFormatType.Unspecified,
121 ...properties,
122 });
123 }
124 /**
125 * Adds a new SP.FieldNumber to the collection
126 *
127 * @param title The field title
128 * @param properties Differ by type of field being created (see: https://msdn.microsoft.com/en-us/library/office/dn600182.aspx)
129 */
130 addNumber(title, properties) {
131 return this.add(title, 9, properties);
132 }
133 /**
134 * Adds a new SP.FieldCurrency to the collection
135 *
136 * @param title The field title
137 * @param properties Differ by type of field being created (see: https://msdn.microsoft.com/en-us/library/office/dn600182.aspx)
138 */
139 addCurrency(title, properties) {
140 return this.add(title, 10, {
141 CurrencyLocaleId: 1033,
142 ...properties,
143 });
144 }
145 /**
146 * Adds a new SP.FieldMultiLineText to the collection
147 *
148 * @param title The field title
149 * @param properties Differ by type of field being created (see: https://msdn.microsoft.com/en-us/library/office/dn600182.aspx)
150 *
151 */
152 addMultilineText(title, properties) {
153 return this.add(title, 3, {
154 AllowHyperlink: true,
155 AppendOnly: false,
156 NumberOfLines: 6,
157 RestrictedMode: false,
158 RichText: true,
159 ...properties,
160 });
161 }
162 /**
163 * Adds a new SP.FieldUrl to the collection
164 *
165 * @param title The field title
166 */
167 addUrl(title, properties) {
168 return this.add(title, 11, {
169 DisplayFormat: UrlFieldFormatType.Hyperlink,
170 ...properties,
171 });
172 }
173 /** Adds a user field to the colleciton
174 *
175 * @param title The new field's title
176 * @param properties
177 */
178 addUser(title, properties) {
179 return this.add(title, 20, {
180 SelectionMode: FieldUserSelectionMode.PeopleAndGroups,
181 ...properties,
182 });
183 }
184 /**
185 * Adds a SP.FieldLookup to the collection
186 *
187 * @param title The new field's title
188 * @param properties Set of additional properties to set on the new field
189 */
190 async addLookup(title, properties) {
191 return this.addField(title, 7, properties);
192 }
193 /**
194 * Adds a new SP.FieldChoice to the collection
195 *
196 * @param title The field title.
197 * @param properties Differ by type of field being created (see: https://msdn.microsoft.com/en-us/library/office/dn600182.aspx)
198 */
199 addChoice(title, properties) {
200 const props = {
201 ...properties,
202 Choices: {
203 results: properties.Choices,
204 },
205 };
206 return this.add(title, 6, props);
207 }
208 /**
209 * Adds a new SP.FieldMultiChoice to the collection
210 *
211 * @param title The field title.
212 * @param properties Differ by type of field being created (see: https://msdn.microsoft.com/en-us/library/office/dn600182.aspx)
213 */
214 addMultiChoice(title, properties) {
215 const props = {
216 ...properties,
217 Choices: {
218 results: properties.Choices,
219 },
220 };
221 return this.add(title, 15, props);
222 }
223 /**
224 * Adds a new SP.FieldBoolean to the collection
225 *
226 * @param title The field title.
227 * @param properties Differ by type of field being created (see: https://msdn.microsoft.com/en-us/library/office/dn600182.aspx)
228 */
229 addBoolean(title, properties) {
230 return this.add(title, 8, properties);
231 }
232 /**
233 * Creates a secondary (dependent) lookup field, based on the Id of the primary lookup field.
234 *
235 * @param displayName The display name of the new field.
236 * @param primaryLookupFieldId The guid of the primary Lookup Field.
237 * @param showField Which field to show from the lookup list.
238 */
239 async addDependentLookupField(displayName, primaryLookupFieldId, showField) {
240 const path = `adddependentlookupfield(displayName='${displayName}', primarylookupfieldid='${primaryLookupFieldId}', showfield='${showField}')`;
241 const data = await spPost(Fields(this, path));
242 return {
243 data,
244 field: this.getById(data.Id),
245 };
246 }
247 /**
248 * Adds a new SP.FieldLocation to the collection
249 *
250 * @param title The field title.
251 * @param properties Differ by type of field being created (see: https://msdn.microsoft.com/en-us/library/office/dn600182.aspx)
252 */
253 addLocation(title, properties) {
254 return this.add(title, 33, properties);
255 }
256 /**
257 * Adds a new SP.FieldLocation to the collection
258 *
259 * @param title The field title.
260 * @param properties Differ by type of field being created (see: https://msdn.microsoft.com/en-us/library/office/dn600182.aspx)
261 */
262 addImageField(title, properties) {
263 return this.add(title, 34, properties);
264 }
265};
266_Fields = __decorate([
267 defaultPath("fields")
268], _Fields);
269export { _Fields };
270export const Fields = spInvokableFactory(_Fields);
271export class _Field extends _SPInstance {
272 constructor() {
273 super(...arguments);
274 this.delete = deleteable();
275 }
276 /**
277 * Updates this field instance with the supplied properties
278 *
279 * @param properties A plain object hash of values to update for the list
280 * @param fieldType The type value such as SP.FieldLookup. Optional, looked up from the field if not provided
281 */
282 async update(properties, fieldType) {
283 if (typeof fieldType === "undefined" || fieldType === null) {
284 const info = await Field(this).select("FieldTypeKind")();
285 fieldType = info["odata.type"];
286 }
287 const data = await spPostMerge(this, body(properties));
288 return {
289 data,
290 field: this,
291 };
292 }
293 /**
294 * Sets the value of the ShowInDisplayForm property for this field.
295 */
296 setShowInDisplayForm(show) {
297 return spPost(Field(this, `setshowindisplayform(${show})`));
298 }
299 /**
300 * Sets the value of the ShowInEditForm property for this field.
301 */
302 setShowInEditForm(show) {
303 return spPost(Field(this, `setshowineditform(${show})`));
304 }
305 /**
306 * Sets the value of the ShowInNewForm property for this field.
307 */
308 setShowInNewForm(show) {
309 return spPost(Field(this, `setshowinnewform(${show})`));
310 }
311}
312export const Field = spInvokableFactory(_Field);
313/**
314 * Specifies the type of the field.
315 */
316export var FieldTypes;
317(function (FieldTypes) {
318 FieldTypes[FieldTypes["Invalid"] = 0] = "Invalid";
319 FieldTypes[FieldTypes["Integer"] = 1] = "Integer";
320 FieldTypes[FieldTypes["Text"] = 2] = "Text";
321 FieldTypes[FieldTypes["Note"] = 3] = "Note";
322 FieldTypes[FieldTypes["DateTime"] = 4] = "DateTime";
323 FieldTypes[FieldTypes["Counter"] = 5] = "Counter";
324 FieldTypes[FieldTypes["Choice"] = 6] = "Choice";
325 FieldTypes[FieldTypes["Lookup"] = 7] = "Lookup";
326 FieldTypes[FieldTypes["Boolean"] = 8] = "Boolean";
327 FieldTypes[FieldTypes["Number"] = 9] = "Number";
328 FieldTypes[FieldTypes["Currency"] = 10] = "Currency";
329 FieldTypes[FieldTypes["URL"] = 11] = "URL";
330 FieldTypes[FieldTypes["Computed"] = 12] = "Computed";
331 FieldTypes[FieldTypes["Threading"] = 13] = "Threading";
332 FieldTypes[FieldTypes["Guid"] = 14] = "Guid";
333 FieldTypes[FieldTypes["MultiChoice"] = 15] = "MultiChoice";
334 FieldTypes[FieldTypes["GridChoice"] = 16] = "GridChoice";
335 FieldTypes[FieldTypes["Calculated"] = 17] = "Calculated";
336 FieldTypes[FieldTypes["File"] = 18] = "File";
337 FieldTypes[FieldTypes["Attachments"] = 19] = "Attachments";
338 FieldTypes[FieldTypes["User"] = 20] = "User";
339 FieldTypes[FieldTypes["Recurrence"] = 21] = "Recurrence";
340 FieldTypes[FieldTypes["CrossProjectLink"] = 22] = "CrossProjectLink";
341 FieldTypes[FieldTypes["ModStat"] = 23] = "ModStat";
342 FieldTypes[FieldTypes["Error"] = 24] = "Error";
343 FieldTypes[FieldTypes["ContentTypeId"] = 25] = "ContentTypeId";
344 FieldTypes[FieldTypes["PageSeparator"] = 26] = "PageSeparator";
345 FieldTypes[FieldTypes["ThreadIndex"] = 27] = "ThreadIndex";
346 FieldTypes[FieldTypes["WorkflowStatus"] = 28] = "WorkflowStatus";
347 FieldTypes[FieldTypes["AllDayEvent"] = 29] = "AllDayEvent";
348 FieldTypes[FieldTypes["WorkflowEventType"] = 30] = "WorkflowEventType";
349 FieldTypes[FieldTypes["Location"] = 33] = "Location";
350 FieldTypes[FieldTypes["Image"] = 34] = "Image";
351})(FieldTypes || (FieldTypes = {}));
352const FieldTypeClassMapping = {
353 [17 /* Calculated */]: "SP.FieldCalculated",
354 [6 /* Choice */]: "SP.FieldChoice",
355 [12 /* Computed */]: "SP.FieldComputed",
356 [10 /* Currency */]: "SP.FieldCurrency",
357 [4 /* DateTime */]: "SP.FieldDateTime",
358 [16 /* GridChoice */]: "SP.FieldRatingScale",
359 [14 /* Guid */]: "SP.FieldGuid",
360 [34 /* Image */]: "FieldMultiLineText",
361 [1 /* Integer */]: "SP.FieldNumber",
362 [33 /* Location */]: "SP.FieldLocation",
363 [7 /* Lookup */]: "SP.FieldLookup",
364 [23 /* ModStat */]: "SP.FieldChoice",
365 [15 /* MultiChoice */]: "SP.FieldMultiChoice",
366 [3 /* Note */]: "SP.FieldMultiLineText",
367 [9 /* Number */]: "SP.FieldNumber",
368 [2 /* Text */]: "SP.FieldText",
369 [11 /* URL */]: "SP.FieldUrl",
370 [20 /* User */]: "SP.FieldUser",
371 [28 /* WorkflowStatus */]: "SP.FieldChoice",
372 [30 /* WorkflowEventType */]: "SP.FieldNumber",
373};
374function mapFieldTypeEnumToString(enumValue) {
375 var _a;
376 return (_a = FieldTypeClassMapping[enumValue]) !== null && _a !== void 0 ? _a : "SP.Field";
377}
378export var DateTimeFieldFormatType;
379(function (DateTimeFieldFormatType) {
380 DateTimeFieldFormatType[DateTimeFieldFormatType["DateOnly"] = 0] = "DateOnly";
381 DateTimeFieldFormatType[DateTimeFieldFormatType["DateTime"] = 1] = "DateTime";
382})(DateTimeFieldFormatType || (DateTimeFieldFormatType = {}));
383export var DateTimeFieldFriendlyFormatType;
384(function (DateTimeFieldFriendlyFormatType) {
385 DateTimeFieldFriendlyFormatType[DateTimeFieldFriendlyFormatType["Unspecified"] = 0] = "Unspecified";
386 DateTimeFieldFriendlyFormatType[DateTimeFieldFriendlyFormatType["Disabled"] = 1] = "Disabled";
387 DateTimeFieldFriendlyFormatType[DateTimeFieldFriendlyFormatType["Relative"] = 2] = "Relative";
388})(DateTimeFieldFriendlyFormatType || (DateTimeFieldFriendlyFormatType = {}));
389/**
390 * Specifies the control settings while adding a field.
391 */
392export var AddFieldOptions;
393(function (AddFieldOptions) {
394 /**
395 * Specify that a new field added to the list must also be added to the default content type in the site collection
396 */
397 AddFieldOptions[AddFieldOptions["DefaultValue"] = 0] = "DefaultValue";
398 /**
399 * Specify that a new field added to the list must also be added to the default content type in the site collection.
400 */
401 AddFieldOptions[AddFieldOptions["AddToDefaultContentType"] = 1] = "AddToDefaultContentType";
402 /**
403 * Specify that a new field must not be added to any other content type
404 */
405 AddFieldOptions[AddFieldOptions["AddToNoContentType"] = 2] = "AddToNoContentType";
406 /**
407 * Specify that a new field that is added to the specified list must also be added to all content types in the site collection
408 */
409 AddFieldOptions[AddFieldOptions["AddToAllContentTypes"] = 4] = "AddToAllContentTypes";
410 /**
411 * Specify adding an internal field name hint for the purpose of avoiding possible database locking or field renaming operations
412 */
413 AddFieldOptions[AddFieldOptions["AddFieldInternalNameHint"] = 8] = "AddFieldInternalNameHint";
414 /**
415 * Specify that a new field that is added to the specified list must also be added to the default list view
416 */
417 AddFieldOptions[AddFieldOptions["AddFieldToDefaultView"] = 16] = "AddFieldToDefaultView";
418 /**
419 * Specify to confirm that no other field has the same display name
420 */
421 AddFieldOptions[AddFieldOptions["AddFieldCheckDisplayName"] = 32] = "AddFieldCheckDisplayName";
422})(AddFieldOptions || (AddFieldOptions = {}));
423export var CalendarType;
424(function (CalendarType) {
425 CalendarType[CalendarType["Gregorian"] = 1] = "Gregorian";
426 CalendarType[CalendarType["Japan"] = 3] = "Japan";
427 CalendarType[CalendarType["Taiwan"] = 4] = "Taiwan";
428 CalendarType[CalendarType["Korea"] = 5] = "Korea";
429 CalendarType[CalendarType["Hijri"] = 6] = "Hijri";
430 CalendarType[CalendarType["Thai"] = 7] = "Thai";
431 CalendarType[CalendarType["Hebrew"] = 8] = "Hebrew";
432 CalendarType[CalendarType["GregorianMEFrench"] = 9] = "GregorianMEFrench";
433 CalendarType[CalendarType["GregorianArabic"] = 10] = "GregorianArabic";
434 CalendarType[CalendarType["GregorianXLITEnglish"] = 11] = "GregorianXLITEnglish";
435 CalendarType[CalendarType["GregorianXLITFrench"] = 12] = "GregorianXLITFrench";
436 CalendarType[CalendarType["KoreaJapanLunar"] = 14] = "KoreaJapanLunar";
437 CalendarType[CalendarType["ChineseLunar"] = 15] = "ChineseLunar";
438 CalendarType[CalendarType["SakaEra"] = 16] = "SakaEra";
439 CalendarType[CalendarType["UmAlQura"] = 23] = "UmAlQura";
440})(CalendarType || (CalendarType = {}));
441export var UrlFieldFormatType;
442(function (UrlFieldFormatType) {
443 UrlFieldFormatType[UrlFieldFormatType["Hyperlink"] = 0] = "Hyperlink";
444 UrlFieldFormatType[UrlFieldFormatType["Image"] = 1] = "Image";
445})(UrlFieldFormatType || (UrlFieldFormatType = {}));
446export var FieldUserSelectionMode;
447(function (FieldUserSelectionMode) {
448 FieldUserSelectionMode[FieldUserSelectionMode["PeopleAndGroups"] = 1] = "PeopleAndGroups";
449 FieldUserSelectionMode[FieldUserSelectionMode["PeopleOnly"] = 0] = "PeopleOnly";
450})(FieldUserSelectionMode || (FieldUserSelectionMode = {}));
451export var ChoiceFieldFormatType;
452(function (ChoiceFieldFormatType) {
453 ChoiceFieldFormatType[ChoiceFieldFormatType["Dropdown"] = 0] = "Dropdown";
454 ChoiceFieldFormatType[ChoiceFieldFormatType["RadioButtons"] = 1] = "RadioButtons";
455})(ChoiceFieldFormatType || (ChoiceFieldFormatType = {}));
456//# sourceMappingURL=types.js.map
\No newline at end of file