1 | import { __decorate } from "tslib";
|
2 | import { body } from "@pnp/queryable";
|
3 | import { _SPCollection, _SPInstance, deleteable, spInvokableFactory, } from "../spqueryable.js";
|
4 | import { defaultPath } from "../decorators.js";
|
5 | import { spPost, spPostMerge } from "../operations.js";
|
6 | let _Fields = class _Fields extends _SPCollection {
|
7 | |
8 |
|
9 |
|
10 |
|
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 |
|
24 |
|
25 |
|
26 |
|
27 | getById(id) {
|
28 | return Field(this).concat(`('${id}')`);
|
29 | }
|
30 | |
31 |
|
32 |
|
33 |
|
34 |
|
35 | getByTitle(title) {
|
36 | return Field(this, `getByTitle('${title}')`);
|
37 | }
|
38 | |
39 |
|
40 |
|
41 |
|
42 |
|
43 | getByInternalNameOrTitle(name) {
|
44 | return Field(this, `getByInternalNameOrTitle('${name}')`);
|
45 | }
|
46 | |
47 |
|
48 |
|
49 |
|
50 |
|
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 === null || properties === void 0 ? void 0 : 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 |
|
70 |
|
71 |
|
72 |
|
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 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 | addText(title, properties) {
|
94 | return this.add(title, 2, {
|
95 | MaxLength: 255,
|
96 | ...properties,
|
97 | });
|
98 | }
|
99 | |
100 |
|
101 |
|
102 |
|
103 |
|
104 |
|
105 | addCalculated(title, properties) {
|
106 | return this.add(title, 17, {
|
107 | OutputType: 2 ,
|
108 | ...properties,
|
109 | });
|
110 | }
|
111 | |
112 |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 | addDateTime(title, properties) {
|
118 | return this.add(title, 4, {
|
119 | DateTimeCalendarType: 1 ,
|
120 | DisplayFormat: DateTimeFieldFormatType.DateOnly,
|
121 | FriendlyDisplayFormat: DateTimeFieldFriendlyFormatType.Unspecified,
|
122 | ...properties,
|
123 | });
|
124 | }
|
125 | |
126 |
|
127 |
|
128 |
|
129 |
|
130 |
|
131 | addNumber(title, properties) {
|
132 | return this.add(title, 9, properties);
|
133 | }
|
134 | |
135 |
|
136 |
|
137 |
|
138 |
|
139 |
|
140 | addCurrency(title, properties) {
|
141 | return this.add(title, 10, {
|
142 | CurrencyLocaleId: 1033,
|
143 | ...properties,
|
144 | });
|
145 | }
|
146 | |
147 |
|
148 |
|
149 |
|
150 |
|
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 |
|
165 |
|
166 |
|
167 |
|
168 | addUrl(title, properties) {
|
169 | return this.add(title, 11, {
|
170 | DisplayFormat: UrlFieldFormatType.Hyperlink,
|
171 | ...properties,
|
172 | });
|
173 | }
|
174 | |
175 |
|
176 |
|
177 |
|
178 |
|
179 | addUser(title, properties) {
|
180 | return this.add(title, 20, {
|
181 | SelectionMode: FieldUserSelectionMode.PeopleAndGroups,
|
182 | ...properties,
|
183 | });
|
184 | }
|
185 | |
186 |
|
187 |
|
188 |
|
189 |
|
190 |
|
191 | async addLookup(title, properties) {
|
192 | return this.addField(title, 7, properties);
|
193 | }
|
194 | |
195 |
|
196 |
|
197 |
|
198 |
|
199 |
|
200 | addChoice(title, properties) {
|
201 | return this.add(title, 6, {
|
202 | EditFormat: ChoiceFieldFormatType.Dropdown,
|
203 | FillInChoice: false,
|
204 | ...properties,
|
205 | });
|
206 | }
|
207 | |
208 |
|
209 |
|
210 |
|
211 |
|
212 |
|
213 | addMultiChoice(title, properties) {
|
214 | return this.add(title, 15, {
|
215 | FillInChoice: false,
|
216 | ...properties,
|
217 | });
|
218 | }
|
219 | |
220 |
|
221 |
|
222 |
|
223 |
|
224 |
|
225 | addBoolean(title, properties) {
|
226 | return this.add(title, 8, properties);
|
227 | }
|
228 | |
229 |
|
230 |
|
231 |
|
232 |
|
233 |
|
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 |
|
245 |
|
246 |
|
247 |
|
248 |
|
249 | addLocation(title, properties) {
|
250 | return this.add(title, 33, properties);
|
251 | }
|
252 | |
253 |
|
254 |
|
255 |
|
256 |
|
257 |
|
258 | addImageField(title, properties) {
|
259 | return this.add(title, 34, properties);
|
260 | }
|
261 | };
|
262 | _Fields = __decorate([
|
263 | defaultPath("fields")
|
264 | ], _Fields);
|
265 | export { _Fields };
|
266 | export const Fields = spInvokableFactory(_Fields);
|
267 | export class _Field extends _SPInstance {
|
268 | constructor() {
|
269 | super(...arguments);
|
270 | this.delete = deleteable();
|
271 | }
|
272 | |
273 |
|
274 |
|
275 |
|
276 |
|
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 |
|
291 |
|
292 | setShowInDisplayForm(show) {
|
293 | return spPost(Field(this, `setshowindisplayform(${show})`));
|
294 | }
|
295 | |
296 |
|
297 |
|
298 | setShowInEditForm(show) {
|
299 | return spPost(Field(this, `setshowineditform(${show})`));
|
300 | }
|
301 | |
302 |
|
303 |
|
304 | setShowInNewForm(show) {
|
305 | return spPost(Field(this, `setshowinnewform(${show})`));
|
306 | }
|
307 | }
|
308 | export const Field = spInvokableFactory(_Field);
|
309 |
|
310 |
|
311 |
|
312 | export 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 = {}));
|
346 | export var DateTimeFieldFormatType;
|
347 | (function (DateTimeFieldFormatType) {
|
348 | DateTimeFieldFormatType[DateTimeFieldFormatType["DateOnly"] = 0] = "DateOnly";
|
349 | DateTimeFieldFormatType[DateTimeFieldFormatType["DateTime"] = 1] = "DateTime";
|
350 | })(DateTimeFieldFormatType || (DateTimeFieldFormatType = {}));
|
351 | export 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 |
|
359 |
|
360 | export var AddFieldOptions;
|
361 | (function (AddFieldOptions) {
|
362 | |
363 |
|
364 |
|
365 | AddFieldOptions[AddFieldOptions["DefaultValue"] = 0] = "DefaultValue";
|
366 | |
367 |
|
368 |
|
369 | AddFieldOptions[AddFieldOptions["AddToDefaultContentType"] = 1] = "AddToDefaultContentType";
|
370 | |
371 |
|
372 |
|
373 | AddFieldOptions[AddFieldOptions["AddToNoContentType"] = 2] = "AddToNoContentType";
|
374 | |
375 |
|
376 |
|
377 | AddFieldOptions[AddFieldOptions["AddToAllContentTypes"] = 4] = "AddToAllContentTypes";
|
378 | |
379 |
|
380 |
|
381 | AddFieldOptions[AddFieldOptions["AddFieldInternalNameHint"] = 8] = "AddFieldInternalNameHint";
|
382 | |
383 |
|
384 |
|
385 | AddFieldOptions[AddFieldOptions["AddFieldToDefaultView"] = 16] = "AddFieldToDefaultView";
|
386 | |
387 |
|
388 |
|
389 | AddFieldOptions[AddFieldOptions["AddFieldCheckDisplayName"] = 32] = "AddFieldCheckDisplayName";
|
390 | })(AddFieldOptions || (AddFieldOptions = {}));
|
391 | export 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 = {}));
|
409 | export var UrlFieldFormatType;
|
410 | (function (UrlFieldFormatType) {
|
411 | UrlFieldFormatType[UrlFieldFormatType["Hyperlink"] = 0] = "Hyperlink";
|
412 | UrlFieldFormatType[UrlFieldFormatType["Image"] = 1] = "Image";
|
413 | })(UrlFieldFormatType || (UrlFieldFormatType = {}));
|
414 | export var FieldUserSelectionMode;
|
415 | (function (FieldUserSelectionMode) {
|
416 | FieldUserSelectionMode[FieldUserSelectionMode["PeopleAndGroups"] = 1] = "PeopleAndGroups";
|
417 | FieldUserSelectionMode[FieldUserSelectionMode["PeopleOnly"] = 0] = "PeopleOnly";
|
418 | })(FieldUserSelectionMode || (FieldUserSelectionMode = {}));
|
419 | export var ChoiceFieldFormatType;
|
420 | (function (ChoiceFieldFormatType) {
|
421 | ChoiceFieldFormatType[ChoiceFieldFormatType["Dropdown"] = 0] = "Dropdown";
|
422 | ChoiceFieldFormatType[ChoiceFieldFormatType["RadioButtons"] = 1] = "RadioButtons";
|
423 | })(ChoiceFieldFormatType || (ChoiceFieldFormatType = {}));
|
424 |
|
\ | No newline at end of file |