UNPKG

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