gd-sprest 9.7.2 → 9.7.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/@types/utils/base.d.ts +0 -3
- package/build/helper/executor.js +10 -20
- package/build/helper/fieldSchemaXML.js +85 -89
- package/build/helper/index.js +12 -28
- package/build/helper/jslink.js +124 -128
- package/build/helper/listForm.js +109 -118
- package/build/helper/listFormField.js +62 -65
- package/build/helper/methods/addContentEditorWebPart.js +9 -17
- package/build/helper/methods/addPermissionLevel.js +12 -16
- package/build/helper/methods/addScriptEditorWebPart.js +9 -17
- package/build/helper/methods/copyPermissionLevel.js +22 -26
- package/build/helper/methods/createContentType.js +96 -19
- package/build/helper/methods/createDocSet.js +10 -14
- package/build/helper/methods/getCurrentTheme.js +26 -31
- package/build/helper/methods/hasPermissions.js +8 -13
- package/build/helper/methods/index.js +16 -32
- package/build/helper/methods/loadSPCore.js +13 -17
- package/build/helper/methods/parse.js +5 -9
- package/build/helper/methods/request.js +4 -8
- package/build/helper/methods/setContentTypeFields.js +71 -79
- package/build/helper/methods/setGroupOwner.js +6 -10
- package/build/helper/methods/setWebProperty.js +26 -30
- package/build/helper/methods/stringify.js +3 -7
- package/build/helper/methods/webWorker.js +40 -20
- package/build/helper/ribbonLink.js +10 -14
- package/build/helper/sbLink.js +11 -15
- package/build/helper/sp/calloutManager.js +22 -25
- package/build/helper/sp/index.js +13 -16
- package/build/helper/sp/modalDialog.js +32 -35
- package/build/helper/sp/notify.js +9 -12
- package/build/helper/sp/ribbon.js +1 -4
- package/build/helper/sp/sod.js +9 -18
- package/build/helper/sp/status.js +18 -21
- package/build/helper/spCfg.js +232 -259
- package/build/helper/spCfgTypes.js +2 -5
- package/build/helper/taxonomy.js +144 -182
- package/build/helper/webpart.js +110 -94
- package/build/index.js +6 -23
- package/build/lib/apps.js +4 -7
- package/build/lib/contextInfo.js +217 -781
- package/build/lib/directorySession.js +4 -7
- package/build/lib/graph.js +16 -19
- package/build/lib/groupService.js +4 -7
- package/build/lib/groupSiteManager.js +4 -7
- package/build/lib/hubSites.js +11 -25
- package/build/lib/hubSitesUtility.js +4 -7
- package/build/lib/index.js +27 -43
- package/build/lib/list.js +49 -53
- package/build/lib/navigation.js +4 -7
- package/build/lib/peopleManager.js +4 -7
- package/build/lib/peoplePicker.js +4 -7
- package/build/lib/profileLoader.js +4 -7
- package/build/lib/search.js +30 -33
- package/build/lib/sensitivityLabels.js +6 -9
- package/build/lib/site.js +20 -35
- package/build/lib/siteIconManager.js +4 -7
- package/build/lib/siteManager.js +4 -7
- package/build/lib/sitePages.js +37 -51
- package/build/lib/socialFeed.js +13 -16
- package/build/lib/themeManager.js +4 -7
- package/build/lib/userProfile.js +4 -7
- package/build/lib/utility.js +12 -17
- package/build/lib/web.js +34 -49
- package/build/lib/webTemplateExtensions.js +4 -7
- package/build/lib/wfInstanceService.js +4 -7
- package/build/lib/wfSubscriptionService.js +4 -7
- package/build/mapper/custom/audit.js +3 -6
- package/build/mapper/custom/graph.js +13 -16
- package/build/mapper/custom/index.js +8 -24
- package/build/mapper/custom/odata.js +3 -6
- package/build/mapper/custom/old.js +42 -45
- package/build/mapper/custom/peoplePicker.js +4 -7
- package/build/mapper/custom/propertyValues.js +3 -6
- package/build/mapper/custom/utility.js +17 -20
- package/build/mapper/custom/webTemplateExtensions.js +19 -22
- package/build/mapper/def.js +1032 -989
- package/build/mapper/index.js +4 -9
- package/build/mapper/v2.js +2629 -2632
- package/build/rest.js +16 -19
- package/build/sptypes/graphtypes.js +694 -710
- package/build/sptypes/index.js +3 -7
- package/build/sptypes/sptypes.js +49 -52
- package/build/utils/base.js +20 -37
- package/build/utils/batch.js +53 -63
- package/build/utils/helper.js +79 -83
- package/build/utils/index.js +9 -25
- package/build/utils/methodInfo.js +88 -141
- package/build/utils/oData.js +62 -112
- package/build/utils/request.js +137 -155
- package/build/utils/requestType.js +1 -4
- package/build/utils/targetInfo.js +39 -52
- package/build/utils/xhrRequest.js +59 -107
- package/build/v2/drive.js +9 -13
- package/build/v2/drives.js +8 -12
- package/build/v2/index.js +3 -19
- package/build/v2/sites.js +61 -65
- package/dist/gd-sprest.d.ts +0 -3
- package/dist/gd-sprest.js +1 -1
- package/dist/gd-sprest.min.js +1 -1
- package/package.json +2 -2
package/build/helper/listForm.js
CHANGED
|
@@ -1,22 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ListForm = void 0;
|
|
4
|
-
var __1 = require("..");
|
|
1
|
+
import { ContextInfo, SPTypes, Web } from "..";
|
|
5
2
|
/**
|
|
6
3
|
* List Form
|
|
7
4
|
*/
|
|
8
|
-
|
|
5
|
+
export const ListForm = {
|
|
9
6
|
// Method to create an instance of the list form
|
|
10
|
-
create:
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
7
|
+
create: (props) => {
|
|
8
|
+
let _info = null;
|
|
9
|
+
let _props = null;
|
|
10
|
+
let _reject = null;
|
|
11
|
+
let _resolve = null;
|
|
15
12
|
// Save the properties
|
|
16
13
|
_props = props || {};
|
|
17
14
|
_props.fields = _props.fields;
|
|
18
15
|
// Method to load the list data
|
|
19
|
-
|
|
16
|
+
let load = () => {
|
|
20
17
|
// Clear the information
|
|
21
18
|
_info = {
|
|
22
19
|
item: _props.item,
|
|
@@ -26,7 +23,7 @@ exports.ListForm = {
|
|
|
26
23
|
// Load the list data
|
|
27
24
|
loadListData().then(
|
|
28
25
|
// Success
|
|
29
|
-
|
|
26
|
+
() => {
|
|
30
27
|
// See if the fields have been defined
|
|
31
28
|
if (_props.fields) {
|
|
32
29
|
// Process the fields
|
|
@@ -43,7 +40,7 @@ exports.ListForm = {
|
|
|
43
40
|
_reject);
|
|
44
41
|
};
|
|
45
42
|
// Method to load a content type for the associated fields
|
|
46
|
-
|
|
43
|
+
let loadContentType = () => {
|
|
47
44
|
// Load the content types
|
|
48
45
|
_info.list.ContentTypes()
|
|
49
46
|
// Query for the default content type and expand the field links
|
|
@@ -54,21 +51,21 @@ exports.ListForm = {
|
|
|
54
51
|
Top: 1
|
|
55
52
|
})
|
|
56
53
|
// Execute the request, but wait for the previous one to be completed
|
|
57
|
-
.execute(
|
|
54
|
+
.execute(ct => {
|
|
58
55
|
// Resolve the promise
|
|
59
56
|
loadDefaultFields(ct.results[0]);
|
|
60
57
|
}, _reject);
|
|
61
58
|
};
|
|
62
59
|
// Method to load the default fields
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
60
|
+
let loadDefaultFields = (ct) => {
|
|
61
|
+
let fields = ct ? ct.FieldLinks.results : [];
|
|
62
|
+
let formFields = {};
|
|
63
|
+
let formLinks = {};
|
|
67
64
|
// Parse the field links
|
|
68
|
-
for (
|
|
69
|
-
|
|
65
|
+
for (let i = 0; i < fields.length; i++) {
|
|
66
|
+
let fieldLink = fields[i];
|
|
70
67
|
// Get the field
|
|
71
|
-
|
|
68
|
+
let field = _info.fields[fieldLink.Name];
|
|
72
69
|
if (field) {
|
|
73
70
|
// Skip the content type field
|
|
74
71
|
if (field.InternalName == "ContentType") {
|
|
@@ -91,17 +88,17 @@ exports.ListForm = {
|
|
|
91
88
|
loadItem();
|
|
92
89
|
};
|
|
93
90
|
// Method to load the field data
|
|
94
|
-
|
|
91
|
+
let loadFieldData = (fields) => {
|
|
95
92
|
// Clear the fields
|
|
96
93
|
_info.fields = {};
|
|
97
94
|
// Parse the fields
|
|
98
|
-
for (
|
|
99
|
-
|
|
95
|
+
for (let i = 0; i < fields.results.length; i++) {
|
|
96
|
+
let field = fields.results[i];
|
|
100
97
|
// See if the exclude fields is defined
|
|
101
98
|
if (_props.excludeFields) {
|
|
102
|
-
|
|
99
|
+
let excludeField = false;
|
|
103
100
|
// Parse the fields to exclude
|
|
104
|
-
for (
|
|
101
|
+
for (let j = 0; j < _props.excludeFields.length; j++) {
|
|
105
102
|
// See if we are excluding this field
|
|
106
103
|
if (_props.excludeFields[j] == field.InternalName) {
|
|
107
104
|
// Set the flag
|
|
@@ -119,19 +116,19 @@ exports.ListForm = {
|
|
|
119
116
|
}
|
|
120
117
|
};
|
|
121
118
|
// Method to load the item
|
|
122
|
-
|
|
123
|
-
|
|
119
|
+
let loadItem = () => {
|
|
120
|
+
let reloadItem = false;
|
|
124
121
|
// See if the item already exist
|
|
125
122
|
if (_info.item) {
|
|
126
123
|
// Parse the fields
|
|
127
|
-
for (
|
|
128
|
-
|
|
124
|
+
for (let fieldName in _info.fields) {
|
|
125
|
+
let field = _info.fields[fieldName];
|
|
129
126
|
// See what type of field this is
|
|
130
127
|
switch (field.FieldTypeKind) {
|
|
131
128
|
// Lookup or User Field
|
|
132
|
-
case
|
|
133
|
-
case
|
|
134
|
-
|
|
129
|
+
case SPTypes.FieldType.Lookup:
|
|
130
|
+
case SPTypes.FieldType.User:
|
|
131
|
+
let fieldValue = _info.item[fieldName + "Id"];
|
|
135
132
|
// Ensure the value exists
|
|
136
133
|
if (fieldValue) {
|
|
137
134
|
// See if a value exists
|
|
@@ -148,14 +145,14 @@ exports.ListForm = {
|
|
|
148
145
|
default:
|
|
149
146
|
// See if this is an taxonomy field
|
|
150
147
|
if (field.TypeAsString.indexOf("TaxonomyFieldType") == 0) {
|
|
151
|
-
|
|
148
|
+
let fieldValue = _info.item[fieldName + "Id"];
|
|
152
149
|
// Ensure the value exists
|
|
153
|
-
if (
|
|
150
|
+
if (fieldValue) {
|
|
154
151
|
// See if a field value exists
|
|
155
|
-
if (
|
|
152
|
+
if (fieldValue.results ? fieldValue.results.length > 0 : fieldValue != null) {
|
|
156
153
|
// Parse the fields
|
|
157
|
-
for (
|
|
158
|
-
|
|
154
|
+
for (let fieldName in _info.fields) {
|
|
155
|
+
let valueField = _info.fields[fieldName];
|
|
159
156
|
// See if this is the value field
|
|
160
157
|
if (valueField.InternalName == field.InternalName + "_0" || valueField.Title == field.InternalName + "_0") {
|
|
161
158
|
// Ensure the value field is loaded
|
|
@@ -182,7 +179,7 @@ exports.ListForm = {
|
|
|
182
179
|
// See if we are loading attachments
|
|
183
180
|
if (_props.loadAttachments && _info.attachments == null) {
|
|
184
181
|
// Load the attachments
|
|
185
|
-
|
|
182
|
+
ListForm.loadAttachments(_props).then(attachments => {
|
|
186
183
|
// Set the attachments
|
|
187
184
|
_info.attachments = attachments;
|
|
188
185
|
// Resolve the promise
|
|
@@ -197,19 +194,19 @@ exports.ListForm = {
|
|
|
197
194
|
// Else, see if we are loading the list item
|
|
198
195
|
else if (reloadItem || _props.itemId > 0) {
|
|
199
196
|
// Update the item query
|
|
200
|
-
_info.query =
|
|
197
|
+
_info.query = ListForm.generateODataQuery(_info, _props.loadAttachments);
|
|
201
198
|
// Get the list item
|
|
202
199
|
_info.list.Items(reloadItem ? _props.item.Id : _props.itemId)
|
|
203
200
|
// Set the query
|
|
204
201
|
.query(_info.query)
|
|
205
202
|
// Execute the request
|
|
206
|
-
.execute(
|
|
203
|
+
.execute(item => {
|
|
207
204
|
// Save the attachments
|
|
208
205
|
_info.attachments = item.AttachmentFiles.results;
|
|
209
206
|
// Save the item
|
|
210
207
|
_info.item = item;
|
|
211
208
|
// Refresh the item
|
|
212
|
-
|
|
209
|
+
ListForm.refreshItem(_info).then(info => {
|
|
213
210
|
// Update the info
|
|
214
211
|
_info = info;
|
|
215
212
|
// Resolve the promise
|
|
@@ -226,9 +223,9 @@ exports.ListForm = {
|
|
|
226
223
|
}
|
|
227
224
|
};
|
|
228
225
|
// Method to load the list data
|
|
229
|
-
|
|
226
|
+
let loadListData = () => {
|
|
230
227
|
// Return a promise
|
|
231
|
-
return new Promise(
|
|
228
|
+
return new Promise((resolve, reject) => {
|
|
232
229
|
// See if the list & fields already exist
|
|
233
230
|
if (_info.list && _info.fields) {
|
|
234
231
|
// Resolve the promise
|
|
@@ -236,11 +233,11 @@ exports.ListForm = {
|
|
|
236
233
|
return;
|
|
237
234
|
}
|
|
238
235
|
// Get the web
|
|
239
|
-
|
|
236
|
+
Web(_props.webUrl, { disableCache: true, requestDigest: _props.requestDigest })
|
|
240
237
|
// Get the list
|
|
241
238
|
.Lists(_props.listName)
|
|
242
239
|
// Execute the request
|
|
243
|
-
.execute(
|
|
240
|
+
.execute(list => {
|
|
244
241
|
// Save the list and web url
|
|
245
242
|
_info.list = list;
|
|
246
243
|
_info.webUrl = _props.webUrl;
|
|
@@ -248,7 +245,7 @@ exports.ListForm = {
|
|
|
248
245
|
// Load the fields
|
|
249
246
|
.Fields()
|
|
250
247
|
// Execute the request
|
|
251
|
-
.execute(
|
|
248
|
+
.execute(fields => {
|
|
252
249
|
// Load the field data
|
|
253
250
|
loadFieldData(fields);
|
|
254
251
|
// Resolve the promise
|
|
@@ -257,11 +254,11 @@ exports.ListForm = {
|
|
|
257
254
|
});
|
|
258
255
|
};
|
|
259
256
|
// Method to process the fields
|
|
260
|
-
|
|
261
|
-
|
|
257
|
+
let processFields = () => {
|
|
258
|
+
let formFields = {};
|
|
262
259
|
// Parse the fields provided
|
|
263
|
-
for (
|
|
264
|
-
|
|
260
|
+
for (let i = 0; i < _props.fields.length; i++) {
|
|
261
|
+
let field = _info.fields[_props.fields[i]];
|
|
265
262
|
// Ensure the field exists
|
|
266
263
|
if (field) {
|
|
267
264
|
// Save the field
|
|
@@ -269,8 +266,8 @@ exports.ListForm = {
|
|
|
269
266
|
// See if this is a taxonomy field
|
|
270
267
|
if (field.TypeAsString.indexOf("TaxonomyFieldType") == 0) {
|
|
271
268
|
// Parse the list fields
|
|
272
|
-
for (
|
|
273
|
-
|
|
269
|
+
for (let fieldName in _info.fields) {
|
|
270
|
+
let valueField = _info.fields[fieldName];
|
|
274
271
|
// See if this is a value field
|
|
275
272
|
if (valueField.InternalName == field.InternalName + "_0" || valueField.Title == field.InternalName + "_0") {
|
|
276
273
|
// Include this field
|
|
@@ -285,7 +282,7 @@ exports.ListForm = {
|
|
|
285
282
|
_info.fields = formFields;
|
|
286
283
|
};
|
|
287
284
|
// Return a promise
|
|
288
|
-
return new Promise(
|
|
285
|
+
return new Promise((resolve, reject) => {
|
|
289
286
|
// Save the methods
|
|
290
287
|
_reject = reject;
|
|
291
288
|
_resolve = resolve;
|
|
@@ -294,9 +291,8 @@ exports.ListForm = {
|
|
|
294
291
|
});
|
|
295
292
|
},
|
|
296
293
|
// Method to generate the odata query
|
|
297
|
-
generateODataQuery:
|
|
298
|
-
|
|
299
|
-
var query = info.query || {};
|
|
294
|
+
generateODataQuery: (info, loadAttachments = false) => {
|
|
295
|
+
let query = info.query || {};
|
|
300
296
|
// Default the select query to get all the fields by default
|
|
301
297
|
query.Select = query.Select || ["*"];
|
|
302
298
|
query.Expand = query.Expand || [];
|
|
@@ -309,8 +305,8 @@ exports.ListForm = {
|
|
|
309
305
|
query.Select.push("AttachmentFiles");
|
|
310
306
|
}
|
|
311
307
|
// Parse the fields
|
|
312
|
-
for (
|
|
313
|
-
|
|
308
|
+
for (let fieldName in info.fields) {
|
|
309
|
+
let field = info.fields[fieldName];
|
|
314
310
|
// Skip the attachments field
|
|
315
311
|
if (fieldName == "Attachments") {
|
|
316
312
|
continue;
|
|
@@ -324,13 +320,13 @@ exports.ListForm = {
|
|
|
324
320
|
// Update the query, based on the type
|
|
325
321
|
switch (field.FieldTypeKind) {
|
|
326
322
|
// Lookup Field
|
|
327
|
-
case
|
|
328
|
-
|
|
323
|
+
case SPTypes.FieldType.Lookup:
|
|
324
|
+
let lookupField = field;
|
|
329
325
|
// See if this is an associated lookup field
|
|
330
326
|
if (lookupField.PrimaryFieldId) {
|
|
331
327
|
// Parse the form fields to find the parent field
|
|
332
|
-
for (
|
|
333
|
-
|
|
328
|
+
for (let parentFieldName in info.fields) {
|
|
329
|
+
let parentField = info.fields[parentFieldName];
|
|
334
330
|
// See if the parent field is being loaded
|
|
335
331
|
if (parentField.Id == lookupField.PrimaryFieldId) {
|
|
336
332
|
// Select the field
|
|
@@ -348,7 +344,7 @@ exports.ListForm = {
|
|
|
348
344
|
}
|
|
349
345
|
break;
|
|
350
346
|
// User Field
|
|
351
|
-
case
|
|
347
|
+
case SPTypes.FieldType.User:
|
|
352
348
|
// Expand the field
|
|
353
349
|
query.Expand.push(field.InternalName);
|
|
354
350
|
// Select the fields
|
|
@@ -360,8 +356,8 @@ exports.ListForm = {
|
|
|
360
356
|
// See if this is an taxonomy field
|
|
361
357
|
if (field.TypeAsString.indexOf("TaxonomyFieldType") == 0) {
|
|
362
358
|
// Parse the fields
|
|
363
|
-
for (
|
|
364
|
-
|
|
359
|
+
for (let fieldName in info.fields) {
|
|
360
|
+
let valueField = info.fields[fieldName];
|
|
365
361
|
// See if this is the value field
|
|
366
362
|
if (valueField.InternalName == field.InternalName + "_0" || valueField.Title == field.InternalName + "_0") {
|
|
367
363
|
// Include the value field
|
|
@@ -377,14 +373,14 @@ exports.ListForm = {
|
|
|
377
373
|
return query;
|
|
378
374
|
},
|
|
379
375
|
// Method to load the item attachments
|
|
380
|
-
loadAttachments:
|
|
376
|
+
loadAttachments: (info) => {
|
|
381
377
|
// Return a promise
|
|
382
|
-
return new Promise(
|
|
378
|
+
return new Promise((resolve, reject) => {
|
|
383
379
|
// Ensure the item id exists
|
|
384
|
-
|
|
380
|
+
let itemId = info.item ? info.item.Id : info.itemId;
|
|
385
381
|
if (itemId > 0) {
|
|
386
382
|
// Get the web
|
|
387
|
-
|
|
383
|
+
Web(info.webUrl, { requestDigest: info.requestDigest })
|
|
388
384
|
// Get the list
|
|
389
385
|
.Lists(info.listName)
|
|
390
386
|
// Get the item
|
|
@@ -392,7 +388,7 @@ exports.ListForm = {
|
|
|
392
388
|
// Get the attachment files
|
|
393
389
|
.AttachmentFiles()
|
|
394
390
|
// Execute the request
|
|
395
|
-
.execute(
|
|
391
|
+
.execute(attachments => {
|
|
396
392
|
// Ensure the attachments exist
|
|
397
393
|
if (!attachments.existsFl) {
|
|
398
394
|
// Reject the promise
|
|
@@ -410,26 +406,26 @@ exports.ListForm = {
|
|
|
410
406
|
});
|
|
411
407
|
},
|
|
412
408
|
// Method to refresh an item
|
|
413
|
-
refreshItem:
|
|
409
|
+
refreshItem: (info) => {
|
|
414
410
|
// Return a promise
|
|
415
|
-
return new Promise(
|
|
411
|
+
return new Promise((resolve, reject) => {
|
|
416
412
|
// Update the query
|
|
417
|
-
info.query =
|
|
413
|
+
info.query = ListForm.generateODataQuery(info, info.attachments ? true : false);
|
|
418
414
|
// Get the item
|
|
419
|
-
info.list.Items(info.item.Id).query(info.query).execute(
|
|
415
|
+
info.list.Items(info.item.Id).query(info.query).execute(item => {
|
|
420
416
|
// Update the item
|
|
421
417
|
info.item = item;
|
|
422
418
|
// Get the item values
|
|
423
419
|
info.list.Items(item.Id).query({
|
|
424
420
|
Expand: ["FieldValuesAsText", "Folder"]
|
|
425
|
-
}).execute(
|
|
421
|
+
}).execute(item => {
|
|
426
422
|
// Set the values
|
|
427
423
|
info.itemFolder = item.Folder;
|
|
428
424
|
info.fieldValuesAsText = item.FieldValuesAsText;
|
|
429
425
|
});
|
|
430
426
|
// Get the html values for this item
|
|
431
427
|
// This is needed for complex field values
|
|
432
|
-
info.list.Items(item.Id).FieldValuesAsHtml().execute(
|
|
428
|
+
info.list.Items(item.Id).FieldValuesAsHtml().execute(values => {
|
|
433
429
|
// Set the values
|
|
434
430
|
info.fieldValuesAsHtml = values;
|
|
435
431
|
// Resolve the promise
|
|
@@ -439,11 +435,11 @@ exports.ListForm = {
|
|
|
439
435
|
});
|
|
440
436
|
},
|
|
441
437
|
// Method to refresh the request digest value
|
|
442
|
-
refreshRequestDigest:
|
|
438
|
+
refreshRequestDigest: (info) => {
|
|
443
439
|
// Return a promise
|
|
444
|
-
return new Promise(
|
|
440
|
+
return new Promise((resolve, reject) => {
|
|
445
441
|
// Get the context info
|
|
446
|
-
|
|
442
|
+
ContextInfo.getWeb(info.webUrl).execute(context => {
|
|
447
443
|
// Update the request digest value
|
|
448
444
|
info.item.updateRequestDigest(context.GetContextWebInformation.FormDigestValue);
|
|
449
445
|
info.list.updateRequestDigest(context.GetContextWebInformation.FormDigestValue);
|
|
@@ -453,24 +449,24 @@ exports.ListForm = {
|
|
|
453
449
|
});
|
|
454
450
|
},
|
|
455
451
|
// Method to remove attachments from an item
|
|
456
|
-
removeAttachment:
|
|
452
|
+
removeAttachment: (info, fileName) => {
|
|
457
453
|
// Return a promise
|
|
458
|
-
return new Promise(
|
|
454
|
+
return new Promise((resolve, reject) => {
|
|
459
455
|
// Ensure attachments exist
|
|
460
456
|
if (info.attachments) {
|
|
461
457
|
// Parse the attachments
|
|
462
|
-
for (
|
|
458
|
+
for (let i = 0; i < info.attachments.length; i++) {
|
|
463
459
|
// See if this is the target attachment
|
|
464
|
-
|
|
460
|
+
let attachment = info.attachments[i];
|
|
465
461
|
if (attachment.FileName == fileName) {
|
|
466
462
|
// Get the web
|
|
467
|
-
|
|
463
|
+
Web(info.webUrl, { requestDigest: info.requestDigest })
|
|
468
464
|
// Get the file
|
|
469
465
|
.getFileByServerRelativeUrl(attachment.ServerRelativeUrl)
|
|
470
466
|
// Delete the file
|
|
471
467
|
.delete()
|
|
472
468
|
// Execute the request
|
|
473
|
-
.execute(
|
|
469
|
+
.execute(() => {
|
|
474
470
|
// Resolve the promise
|
|
475
471
|
resolve(info);
|
|
476
472
|
}, reject);
|
|
@@ -488,13 +484,13 @@ exports.ListForm = {
|
|
|
488
484
|
});
|
|
489
485
|
},
|
|
490
486
|
// Method to save attachments to an existing item
|
|
491
|
-
saveAttachments:
|
|
487
|
+
saveAttachments: (info, attachmentInfo) => {
|
|
492
488
|
// Return a promise
|
|
493
|
-
return new Promise(
|
|
494
|
-
|
|
489
|
+
return new Promise((resolve, reject) => {
|
|
490
|
+
let itemId = info.item ? info.item.Id : info.itemId;
|
|
495
491
|
if (itemId > 0) {
|
|
496
492
|
// Get the web
|
|
497
|
-
|
|
493
|
+
let attachments = Web(info.webUrl, { requestDigest: info.requestDigest })
|
|
498
494
|
// Get the lists
|
|
499
495
|
.Lists(info.listName)
|
|
500
496
|
// Get the item
|
|
@@ -502,17 +498,13 @@ exports.ListForm = {
|
|
|
502
498
|
// Get the attachment files
|
|
503
499
|
.AttachmentFiles();
|
|
504
500
|
// Parse the attachment information
|
|
505
|
-
for (
|
|
506
|
-
|
|
501
|
+
for (let i = 0; i < attachmentInfo.length; i++) {
|
|
502
|
+
let attachment = attachmentInfo[i];
|
|
507
503
|
// Add the attachment
|
|
508
504
|
attachments.add(attachment.name, attachment.data).execute(true);
|
|
509
505
|
}
|
|
510
506
|
// Wait for the requests to complete
|
|
511
|
-
attachments.done(
|
|
512
|
-
var args = [];
|
|
513
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
514
|
-
args[_i] = arguments[_i];
|
|
515
|
-
}
|
|
507
|
+
attachments.done((...args) => {
|
|
516
508
|
// Resolve the promise
|
|
517
509
|
resolve.apply(args);
|
|
518
510
|
});
|
|
@@ -524,16 +516,15 @@ exports.ListForm = {
|
|
|
524
516
|
});
|
|
525
517
|
},
|
|
526
518
|
// Method to save a new or existing item
|
|
527
|
-
saveItem:
|
|
528
|
-
if (formValues === void 0) { formValues = {}; }
|
|
519
|
+
saveItem: (info, formValues = {}, checkItemVersion) => {
|
|
529
520
|
// Return a promise
|
|
530
|
-
return new Promise(
|
|
521
|
+
return new Promise((resolve, reject) => {
|
|
531
522
|
// Set the metadata type
|
|
532
523
|
formValues["__metadata"] = formValues["__metadata"] || { type: info.list.ListItemEntityTypeFullName };
|
|
533
524
|
// See if this is an existing item
|
|
534
525
|
if (info.item && info.item.update) {
|
|
535
526
|
// Set the request properties if we are checking the item version
|
|
536
|
-
|
|
527
|
+
let requestProps = {
|
|
537
528
|
requestDigest: info.item.getRequestDigest()
|
|
538
529
|
};
|
|
539
530
|
// See if we are checking the item versions
|
|
@@ -542,9 +533,9 @@ exports.ListForm = {
|
|
|
542
533
|
requestProps.requestHeader = { "IF-MATCH": info.item.etag };
|
|
543
534
|
}
|
|
544
535
|
// Update the item
|
|
545
|
-
|
|
536
|
+
Web(info.webUrl, requestProps).Lists(info.list.Title).Items(info.item.Id).update(formValues).execute(response => {
|
|
546
537
|
// Refresh the item
|
|
547
|
-
|
|
538
|
+
ListForm.refreshItem(info).then(info => {
|
|
548
539
|
// Resolve the promise
|
|
549
540
|
resolve(info);
|
|
550
541
|
}, reject);
|
|
@@ -552,11 +543,11 @@ exports.ListForm = {
|
|
|
552
543
|
}
|
|
553
544
|
else {
|
|
554
545
|
// Add the item
|
|
555
|
-
info.list.Items().add(formValues).execute(
|
|
546
|
+
info.list.Items().add(formValues).execute(item => {
|
|
556
547
|
// Update the info
|
|
557
548
|
info.item = item;
|
|
558
549
|
// Refresh the item
|
|
559
|
-
|
|
550
|
+
ListForm.refreshItem(info).then(info => {
|
|
560
551
|
// Resolve the promise
|
|
561
552
|
resolve(info);
|
|
562
553
|
}, reject);
|
|
@@ -565,13 +556,13 @@ exports.ListForm = {
|
|
|
565
556
|
});
|
|
566
557
|
},
|
|
567
558
|
// Method to show a file dialog
|
|
568
|
-
showFileDialog:
|
|
559
|
+
showFileDialog: (accept, info, onSave) => {
|
|
569
560
|
// Return a promise
|
|
570
|
-
return new Promise(
|
|
561
|
+
return new Promise((resolve, reject) => {
|
|
571
562
|
// Method to add an attachment
|
|
572
|
-
|
|
563
|
+
let addAttachment = (name, data, src) => {
|
|
573
564
|
// Call the save event
|
|
574
|
-
onSave ? onSave({ name
|
|
565
|
+
onSave ? onSave({ name, data, src }) : null;
|
|
575
566
|
// Get the list
|
|
576
567
|
info.list
|
|
577
568
|
// Get the item
|
|
@@ -581,9 +572,9 @@ exports.ListForm = {
|
|
|
581
572
|
// Add the file
|
|
582
573
|
.add(name, data)
|
|
583
574
|
// Execute the request
|
|
584
|
-
.execute(
|
|
575
|
+
.execute(() => {
|
|
585
576
|
// Refresh the item
|
|
586
|
-
|
|
577
|
+
ListForm.refreshItem(info).then(info => {
|
|
587
578
|
// Remove the element
|
|
588
579
|
document.body.removeChild(el);
|
|
589
580
|
// Resolve the promise
|
|
@@ -592,14 +583,14 @@ exports.ListForm = {
|
|
|
592
583
|
}, reject);
|
|
593
584
|
};
|
|
594
585
|
// Method to read the file
|
|
595
|
-
|
|
586
|
+
let readFile = (ev) => {
|
|
596
587
|
// Get the source file
|
|
597
|
-
|
|
588
|
+
let srcFile = ev.target["files"][0];
|
|
598
589
|
if (srcFile) {
|
|
599
|
-
|
|
590
|
+
let reader = new FileReader();
|
|
600
591
|
// Set the file loaded event
|
|
601
|
-
reader.onloadend =
|
|
602
|
-
|
|
592
|
+
reader.onloadend = (ev) => {
|
|
593
|
+
let ext = srcFile.name.split(".");
|
|
603
594
|
ext = ext[ext.length - 1].toLowerCase();
|
|
604
595
|
// See if the info exists
|
|
605
596
|
if (info) {
|
|
@@ -618,7 +609,7 @@ exports.ListForm = {
|
|
|
618
609
|
}
|
|
619
610
|
};
|
|
620
611
|
// Set the error
|
|
621
|
-
reader.onerror =
|
|
612
|
+
reader.onerror = (ev) => {
|
|
622
613
|
// Remove the element
|
|
623
614
|
document.body.removeChild(el);
|
|
624
615
|
// Reject the promise
|
|
@@ -629,7 +620,7 @@ exports.ListForm = {
|
|
|
629
620
|
}
|
|
630
621
|
};
|
|
631
622
|
// Create the file element
|
|
632
|
-
|
|
623
|
+
let el = document.body.querySelector("#listform-attachment");
|
|
633
624
|
if (el == null) {
|
|
634
625
|
el = document.createElement("input");
|
|
635
626
|
// Set the properties
|