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
|
@@ -1,40 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.setContentTypeFields = void 0;
|
|
4
|
-
var lib_1 = require("../../lib");
|
|
1
|
+
import { ContextInfo, Web } from "../../lib";
|
|
5
2
|
/**
|
|
6
3
|
* Sets the field links associated with a content type.
|
|
7
4
|
* @param ctInfo - The content type information
|
|
8
5
|
*/
|
|
9
|
-
|
|
6
|
+
export const setContentTypeFields = (ctInfo) => {
|
|
10
7
|
// Clears the content type field links
|
|
11
|
-
|
|
8
|
+
let clearLinks = () => {
|
|
12
9
|
// Return a promise
|
|
13
|
-
return new Promise(
|
|
10
|
+
return new Promise((resolve, reject) => {
|
|
14
11
|
// Get the links
|
|
15
|
-
getLinks().then(
|
|
16
|
-
|
|
12
|
+
getLinks().then(fieldLinks => {
|
|
13
|
+
let skipFields = [];
|
|
17
14
|
// See if we need to remove any fields
|
|
18
15
|
if (fieldLinks.length > 0) {
|
|
19
|
-
|
|
16
|
+
let updateFl = false;
|
|
20
17
|
// Set the context
|
|
21
|
-
|
|
18
|
+
let ctx = ctInfo.webUrl ? new SP.ClientContext(ctInfo.webUrl) : new SP.ClientContext(ContextInfo.webServerRelativeUrl);
|
|
22
19
|
// Get the source
|
|
23
|
-
|
|
20
|
+
let src = ctInfo.listName ? ctx.get_web().get_lists().getByTitle(ctInfo.listName) : ctx.get_web();
|
|
24
21
|
// Get the content type
|
|
25
|
-
|
|
22
|
+
let contentType = src.get_contentTypes().getById(ctInfo.id);
|
|
26
23
|
// Parse the content type field links
|
|
27
|
-
for (
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
24
|
+
for (let i = 0; i < fieldLinks.length; i++) {
|
|
25
|
+
let fieldLink = fieldLinks[i];
|
|
26
|
+
let removeFl = true;
|
|
27
|
+
// Parse the fields to add
|
|
28
|
+
for (let j = 0; j < ctInfo.fields.length; j++) {
|
|
29
|
+
let field = ctInfo.fields[j];
|
|
30
|
+
let fieldName = typeof (field) === "string" ? field : field.Name || field.FieldInternalName;
|
|
33
31
|
// See if we are keeping this field
|
|
34
32
|
if (fieldName == fieldLink.Name) {
|
|
35
|
-
|
|
33
|
+
let propUpdateFl = false;
|
|
36
34
|
// Checks if an update is needed
|
|
37
|
-
|
|
35
|
+
let updateField = (oldValue, newValue) => {
|
|
38
36
|
// Ensure a value exists
|
|
39
37
|
if (newValue == null) {
|
|
40
38
|
return;
|
|
@@ -44,7 +42,7 @@ var setContentTypeFields = function (ctInfo) {
|
|
|
44
42
|
return;
|
|
45
43
|
}
|
|
46
44
|
// Set the flag
|
|
47
|
-
|
|
45
|
+
propUpdateFl = true;
|
|
48
46
|
};
|
|
49
47
|
// Update the properties
|
|
50
48
|
updateField(fieldLink.DisplayName, field.DisplayName);
|
|
@@ -53,20 +51,15 @@ var setContentTypeFields = function (ctInfo) {
|
|
|
53
51
|
updateField(fieldLink.Required, field.Required);
|
|
54
52
|
updateField(fieldLink.ShowInDisplayForm, field.ShowInDisplayForm);
|
|
55
53
|
// See if an update to the property is needed
|
|
56
|
-
if (!
|
|
54
|
+
if (!propUpdateFl) {
|
|
57
55
|
// Set the flag to not remove this field reference
|
|
58
56
|
removeFl = false;
|
|
59
57
|
// Add the field to skip
|
|
60
58
|
skipFields.push(fieldLink);
|
|
61
59
|
}
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
// Parse the fields to add
|
|
66
|
-
for (var j = 0; j < ctInfo.fields.length; j++) {
|
|
67
|
-
var state_1 = _loop_1(j);
|
|
68
|
-
if (state_1 === "break")
|
|
60
|
+
// Break from the loop
|
|
69
61
|
break;
|
|
62
|
+
}
|
|
70
63
|
}
|
|
71
64
|
// See if we are removing the field
|
|
72
65
|
if (removeFl) {
|
|
@@ -85,14 +78,14 @@ var setContentTypeFields = function (ctInfo) {
|
|
|
85
78
|
// Execute the request
|
|
86
79
|
ctx.executeQueryAsync(
|
|
87
80
|
// Success
|
|
88
|
-
|
|
81
|
+
() => {
|
|
89
82
|
// Log
|
|
90
83
|
console.log("[gd-sprest][Set Content Type Fields] Removed the field links successfully.");
|
|
91
84
|
// Resolve the request
|
|
92
85
|
resolve(skipFields);
|
|
93
86
|
},
|
|
94
87
|
// Error
|
|
95
|
-
|
|
88
|
+
(sender, args) => {
|
|
96
89
|
// Log
|
|
97
90
|
console.log("[gd-sprest][Set Content Type Fields] Error removing the field links.");
|
|
98
91
|
// Reject the request
|
|
@@ -114,15 +107,15 @@ var setContentTypeFields = function (ctInfo) {
|
|
|
114
107
|
});
|
|
115
108
|
};
|
|
116
109
|
// Creates the field links
|
|
117
|
-
|
|
110
|
+
let createLinks = (skipFields) => {
|
|
118
111
|
// Return a promise
|
|
119
|
-
return new Promise(
|
|
112
|
+
return new Promise((resolve, reject) => {
|
|
120
113
|
// Set the context
|
|
121
|
-
|
|
114
|
+
let ctx = ctInfo.webUrl ? new SP.ClientContext(ctInfo.webUrl) : new SP.ClientContext(ContextInfo.webServerRelativeUrl);
|
|
122
115
|
// Get the source
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
for (
|
|
116
|
+
let src = ctInfo.listName ? ctx.get_web().get_lists().getByTitle(ctInfo.listName) : ctx.get_web();
|
|
117
|
+
let skipField = (fieldName, fields) => {
|
|
118
|
+
for (let i = 0; i < fields.length; i++) {
|
|
126
119
|
// See if we are skipping this field
|
|
127
120
|
if (fields[i].Name == fieldName) {
|
|
128
121
|
return true;
|
|
@@ -130,16 +123,16 @@ var setContentTypeFields = function (ctInfo) {
|
|
|
130
123
|
}
|
|
131
124
|
};
|
|
132
125
|
// Parse the fields to add
|
|
133
|
-
|
|
134
|
-
for (
|
|
135
|
-
|
|
136
|
-
|
|
126
|
+
let fields = [];
|
|
127
|
+
for (let i = 0; i < ctInfo.fields.length; i++) {
|
|
128
|
+
let fieldInfo = ctInfo.fields[i];
|
|
129
|
+
let fieldName = typeof (fieldInfo) === "string" ? fieldInfo : fieldInfo.Name || fieldInfo.FieldInternalName;
|
|
137
130
|
// See if we are skipping this field
|
|
138
131
|
if (skipField(fieldName, skipFields)) {
|
|
139
132
|
continue;
|
|
140
133
|
}
|
|
141
134
|
// Load the field
|
|
142
|
-
|
|
135
|
+
let field = src.get_fields().getByInternalNameOrTitle(fieldName);
|
|
143
136
|
ctx.load(field);
|
|
144
137
|
// Log
|
|
145
138
|
console.log("[gd-sprest][Set Content Type Fields] Adding the field link: " + fieldName);
|
|
@@ -149,13 +142,13 @@ var setContentTypeFields = function (ctInfo) {
|
|
|
149
142
|
// See if an update is needed
|
|
150
143
|
if (fields.length > 0) {
|
|
151
144
|
// Execute the request
|
|
152
|
-
ctx.executeQueryAsync(
|
|
145
|
+
ctx.executeQueryAsync(() => {
|
|
153
146
|
// Get the content type
|
|
154
|
-
|
|
147
|
+
let contentType = src.get_contentTypes().getById(ctInfo.id);
|
|
155
148
|
ctx.load(contentType);
|
|
156
149
|
// Parse the fields
|
|
157
|
-
for (
|
|
158
|
-
|
|
150
|
+
for (let i = 0; i < fields.length; i++) {
|
|
151
|
+
let field = fields[i];
|
|
159
152
|
/**
|
|
160
153
|
* The field link set_[property] methods don't seem to work. Setting the field information seems to be the only way.
|
|
161
154
|
* The read only property is the only one that doesn't seem to work.
|
|
@@ -170,7 +163,7 @@ var setContentTypeFields = function (ctInfo) {
|
|
|
170
163
|
field.info.ShowInDisplayForm != null ? field.ref.setShowInDisplayForm(field.info.ShowInDisplayForm) : null;
|
|
171
164
|
}
|
|
172
165
|
// Create the field link
|
|
173
|
-
|
|
166
|
+
let fieldLink = new SP.FieldLinkCreationInformation();
|
|
174
167
|
fieldLink.set_field(field.ref);
|
|
175
168
|
// Add the field link to the content type
|
|
176
169
|
contentType.get_fieldLinks().add(fieldLink);
|
|
@@ -180,20 +173,20 @@ var setContentTypeFields = function (ctInfo) {
|
|
|
180
173
|
// Execute the request
|
|
181
174
|
ctx.executeQueryAsync(
|
|
182
175
|
// Success
|
|
183
|
-
|
|
176
|
+
() => {
|
|
184
177
|
// Log
|
|
185
178
|
console.log("[gd-sprest][Set Content Type Fields] Added the field links successfully.");
|
|
186
179
|
// Resolve the request
|
|
187
180
|
resolve();
|
|
188
181
|
},
|
|
189
182
|
// Error
|
|
190
|
-
|
|
183
|
+
(sender, args) => {
|
|
191
184
|
// Log
|
|
192
185
|
console.log("[gd-sprest][Set Content Type Fields] Error adding field references.", args.get_message());
|
|
193
186
|
// Reject the request
|
|
194
187
|
reject();
|
|
195
188
|
});
|
|
196
|
-
},
|
|
189
|
+
}, (sender, args) => {
|
|
197
190
|
// Log
|
|
198
191
|
console.log("[gd-sprest][Set Content Type Fields] Error getting field references.", args.get_message());
|
|
199
192
|
// Resolve the request
|
|
@@ -209,18 +202,18 @@ var setContentTypeFields = function (ctInfo) {
|
|
|
209
202
|
});
|
|
210
203
|
};
|
|
211
204
|
// Gets the content type field links
|
|
212
|
-
|
|
205
|
+
let getLinks = () => {
|
|
213
206
|
// Return a promise
|
|
214
|
-
return new Promise(
|
|
215
|
-
|
|
207
|
+
return new Promise((resolve, reject) => {
|
|
208
|
+
let ct = null;
|
|
216
209
|
// See if list name exists
|
|
217
210
|
if (ctInfo.listName) {
|
|
218
211
|
// Get the list content type
|
|
219
|
-
ct =
|
|
212
|
+
ct = Web(ctInfo.webUrl).Lists(ctInfo.listName).ContentTypes(ctInfo.id);
|
|
220
213
|
}
|
|
221
214
|
else {
|
|
222
215
|
// Get the content type
|
|
223
|
-
ct =
|
|
216
|
+
ct = Web(ctInfo.webUrl).ContentTypes(ctInfo.id);
|
|
224
217
|
}
|
|
225
218
|
// Query the fields
|
|
226
219
|
ct.query({
|
|
@@ -230,17 +223,17 @@ var setContentTypeFields = function (ctInfo) {
|
|
|
230
223
|
"FieldLinks/Required", "FieldLinks/ReadOnly", "FieldLinks/ShowInDisplayForm",
|
|
231
224
|
"Fields/InternalName", "Fields/IsDependentLookup"
|
|
232
225
|
]
|
|
233
|
-
}).execute(
|
|
234
|
-
|
|
226
|
+
}).execute(ct => {
|
|
227
|
+
let fieldRefs = [];
|
|
235
228
|
// Associated lookup fields error when removing from content types
|
|
236
229
|
// They may get removed when removing the main lookup field
|
|
237
230
|
// Parse the field links
|
|
238
|
-
for (
|
|
239
|
-
|
|
240
|
-
|
|
231
|
+
for (let i = 0; i < ct.FieldLinks.results.length; i++) {
|
|
232
|
+
let addField = true;
|
|
233
|
+
let fieldLink = ct.FieldLinks.results[i];
|
|
241
234
|
// Find the field
|
|
242
|
-
for (
|
|
243
|
-
|
|
235
|
+
for (let j = 0; j < ct.Fields.results.length; j++) {
|
|
236
|
+
let field = ct.Fields.results[j];
|
|
244
237
|
// See if this is the target field
|
|
245
238
|
if (field.InternalName == fieldLink.Name) {
|
|
246
239
|
// See if this is an associated lookup field
|
|
@@ -262,25 +255,25 @@ var setContentTypeFields = function (ctInfo) {
|
|
|
262
255
|
}, reject);
|
|
263
256
|
ct.FieldLinks().query({
|
|
264
257
|
Select: ["DisplayName", "Id", "Name", "Required", "ReadOnly", "ShowInDisplayForm"]
|
|
265
|
-
}).execute(
|
|
258
|
+
}).execute(fieldLinks => {
|
|
266
259
|
}, reject);
|
|
267
260
|
});
|
|
268
261
|
};
|
|
269
262
|
// Set the order of the field references
|
|
270
|
-
|
|
263
|
+
let setOrder = () => {
|
|
271
264
|
// Return a promise
|
|
272
|
-
return new Promise(
|
|
265
|
+
return new Promise((resolve, reject) => {
|
|
273
266
|
// Set the context
|
|
274
|
-
|
|
267
|
+
let ctx = ctInfo.webUrl ? new SP.ClientContext(ctInfo.webUrl) : new SP.ClientContext(ContextInfo.webServerRelativeUrl);
|
|
275
268
|
// Get the source
|
|
276
|
-
|
|
269
|
+
let src = ctInfo.listName ? ctx.get_web().get_lists().getByTitle(ctInfo.listName) : ctx.get_web();
|
|
277
270
|
// Get the content type
|
|
278
|
-
|
|
271
|
+
let contentType = src.get_contentTypes().getById(ctInfo.id);
|
|
279
272
|
// Parse the fields to add
|
|
280
|
-
|
|
281
|
-
for (
|
|
282
|
-
|
|
283
|
-
|
|
273
|
+
let fieldNames = [];
|
|
274
|
+
for (let i = 0; i < ctInfo.fields.length; i++) {
|
|
275
|
+
let fieldInfo = ctInfo.fields[i];
|
|
276
|
+
let fieldName = typeof (fieldInfo) === "string" ? fieldInfo : fieldInfo.Name || fieldInfo.FieldInternalName;
|
|
284
277
|
// Add the field name
|
|
285
278
|
fieldNames.push(fieldName);
|
|
286
279
|
}
|
|
@@ -291,14 +284,14 @@ var setContentTypeFields = function (ctInfo) {
|
|
|
291
284
|
// Execute the request
|
|
292
285
|
ctx.executeQueryAsync(
|
|
293
286
|
// Success
|
|
294
|
-
|
|
287
|
+
() => {
|
|
295
288
|
// Log
|
|
296
289
|
console.log("[gd-sprest][Set Content Type Fields] Updated the field order successfully.");
|
|
297
290
|
// Resolve the request
|
|
298
291
|
resolve();
|
|
299
292
|
},
|
|
300
293
|
// Error
|
|
301
|
-
|
|
294
|
+
(sender, args) => {
|
|
302
295
|
// Log
|
|
303
296
|
console.log("[gd-sprest][Set Content Type Fields] Error updating the field order.", args.get_message());
|
|
304
297
|
// Reject the request
|
|
@@ -307,15 +300,15 @@ var setContentTypeFields = function (ctInfo) {
|
|
|
307
300
|
});
|
|
308
301
|
};
|
|
309
302
|
// Return a promise
|
|
310
|
-
return new Promise(
|
|
303
|
+
return new Promise((resolve, reject) => {
|
|
311
304
|
// Ensure the SP object exists
|
|
312
305
|
if (window["SP"]) {
|
|
313
306
|
// Ensure fields exist
|
|
314
307
|
if (ctInfo.fields) {
|
|
315
308
|
// Clear the links
|
|
316
|
-
clearLinks().then(
|
|
309
|
+
clearLinks().then(skipFields => {
|
|
317
310
|
// Create the links
|
|
318
|
-
createLinks(skipFields).then(
|
|
311
|
+
createLinks(skipFields).then(() => {
|
|
319
312
|
// Set the field order
|
|
320
313
|
setOrder().then(resolve, reject);
|
|
321
314
|
}, reject);
|
|
@@ -333,4 +326,3 @@ var setContentTypeFields = function (ctInfo) {
|
|
|
333
326
|
}
|
|
334
327
|
});
|
|
335
328
|
};
|
|
336
|
-
exports.setContentTypeFields = setContentTypeFields;
|
|
@@ -1,19 +1,16 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.setGroupOwner = void 0;
|
|
4
1
|
/**
|
|
5
2
|
* Sets the group owner
|
|
6
3
|
* This uses JSOM to set a site group owner's property to another group. You can only set the owner to a user, using the REST API.
|
|
7
4
|
*/
|
|
8
|
-
|
|
5
|
+
export const setGroupOwner = (groupName, ownerName, siteUrl) => {
|
|
9
6
|
// Return a promise
|
|
10
|
-
return new Promise(
|
|
7
|
+
return new Promise((resolve, reject) => {
|
|
11
8
|
// Get the site groups
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
let context = siteUrl ? new SP.ClientContext(siteUrl) : SP.ClientContext.get_current();
|
|
10
|
+
let siteGroups = context.get_web().get_siteGroups();
|
|
14
11
|
// Get the groups
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
let group = siteGroups.getByName(groupName);
|
|
13
|
+
let owner = siteGroups.getByName(ownerName);
|
|
17
14
|
// Set the owner
|
|
18
15
|
group.set_owner(owner);
|
|
19
16
|
// Save the changes
|
|
@@ -22,4 +19,3 @@ var setGroupOwner = function (groupName, ownerName, siteUrl) {
|
|
|
22
19
|
context.executeQueryAsync(resolve, reject);
|
|
23
20
|
});
|
|
24
21
|
};
|
|
25
|
-
exports.setGroupOwner = setGroupOwner;
|
|
@@ -1,58 +1,55 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.setWebProperty = void 0;
|
|
4
|
-
var contextInfo_1 = require("../../lib/contextInfo");
|
|
5
|
-
var web_1 = require("../../lib/web");
|
|
1
|
+
import { ContextInfo } from "../../lib/contextInfo";
|
|
2
|
+
import { Web } from "../../lib/web";
|
|
6
3
|
/**
|
|
7
4
|
* Adds or updates a key/value pair for a web's property bag
|
|
8
5
|
* This uses JSOM to set a web's property. The REST API doesn't support this at the moment.
|
|
9
6
|
*/
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
export const setWebProperty = (key, value, indexed, siteUrl) => {
|
|
8
|
+
let encodedKey = "vti_x005f_indexedpropertykeys";
|
|
9
|
+
let decodedKey = "vti_indexedpropertykeys";
|
|
13
10
|
// Return a promise
|
|
14
|
-
return new Promise(
|
|
11
|
+
return new Promise((resolve, reject) => {
|
|
15
12
|
// Gets the request digest value of the web
|
|
16
|
-
|
|
13
|
+
let getRequestDigest = () => {
|
|
17
14
|
// Return a promise
|
|
18
|
-
return new Promise(
|
|
15
|
+
return new Promise((resolve, reject) => {
|
|
19
16
|
// See if the site url exists
|
|
20
17
|
if (siteUrl) {
|
|
21
|
-
|
|
18
|
+
ContextInfo.getWeb(siteUrl).execute(context => {
|
|
22
19
|
// Resolve the request
|
|
23
20
|
resolve(context.GetContextWebInformation.FormDigestValue);
|
|
24
21
|
}, reject);
|
|
25
22
|
}
|
|
26
23
|
else {
|
|
27
24
|
// Resolve the request w/ the default digest value
|
|
28
|
-
resolve(
|
|
25
|
+
resolve(ContextInfo.formDigestValue);
|
|
29
26
|
}
|
|
30
27
|
});
|
|
31
28
|
};
|
|
32
29
|
// Get the request digest for the web
|
|
33
|
-
getRequestDigest().then(
|
|
30
|
+
getRequestDigest().then(requestDigest => {
|
|
34
31
|
// Convert the key to a base64 string
|
|
35
|
-
|
|
36
|
-
for (
|
|
32
|
+
let idxKeyValue = "";
|
|
33
|
+
for (let i = 0; i < key.length; i++) {
|
|
37
34
|
idxKeyValue += key[i] + "\x00";
|
|
38
35
|
}
|
|
39
36
|
idxKeyValue = btoa(idxKeyValue);
|
|
40
37
|
// See if a value exists
|
|
41
38
|
if (value) {
|
|
42
39
|
// Add the property
|
|
43
|
-
|
|
40
|
+
Web(siteUrl, { requestDigest }).AllProperties().add(key, value).execute(() => {
|
|
44
41
|
// See if we are indexing the property
|
|
45
42
|
if (indexed) {
|
|
46
43
|
// Get the properties
|
|
47
|
-
|
|
44
|
+
Web(siteUrl, { requestDigest }).AllProperties().execute(propBag => {
|
|
48
45
|
// See if the indexed keys doesn't contain this value
|
|
49
|
-
|
|
46
|
+
let idxKeys = propBag[encodedKey] || "";
|
|
50
47
|
if (idxKeys.indexOf(idxKeyValue) < 0) {
|
|
51
48
|
// Append the value
|
|
52
|
-
|
|
49
|
+
Web(siteUrl, { requestDigest }).AllProperties().add(decodedKey, idxKeys + idxKeyValue + "|").execute(() => {
|
|
53
50
|
// Resolve the request
|
|
54
51
|
resolve();
|
|
55
|
-
},
|
|
52
|
+
}, () => {
|
|
56
53
|
// Reject the request
|
|
57
54
|
reject("Error setting the indexed keys property.");
|
|
58
55
|
});
|
|
@@ -67,26 +64,26 @@ var setWebProperty = function (key, value, indexed, siteUrl) {
|
|
|
67
64
|
// Resolve the request
|
|
68
65
|
resolve();
|
|
69
66
|
}
|
|
70
|
-
},
|
|
67
|
+
}, () => {
|
|
71
68
|
// Reject the request
|
|
72
69
|
reject("Error adding the web property.");
|
|
73
70
|
});
|
|
74
71
|
}
|
|
75
72
|
else {
|
|
76
73
|
// Remove the property
|
|
77
|
-
|
|
74
|
+
Web(siteUrl, { requestDigest }).AllProperties().remove(key).execute(() => {
|
|
78
75
|
// See if we are indexing the property
|
|
79
76
|
if (indexed) {
|
|
80
77
|
// Get the properties
|
|
81
|
-
|
|
78
|
+
Web(siteUrl, { requestDigest }).AllProperties().execute(propBag => {
|
|
82
79
|
// See if the indexed keys contains the value
|
|
83
|
-
|
|
80
|
+
let idxKeys = propBag[encodedKey] || "";
|
|
84
81
|
if (idxKeys.indexOf(idxKeyValue) >= 0) {
|
|
85
82
|
// Remove the value
|
|
86
|
-
|
|
83
|
+
Web(siteUrl, { requestDigest }).AllProperties().add(decodedKey, idxKeys.replace(idxKeyValue + "|", "")).execute(() => {
|
|
87
84
|
// Resolve the request
|
|
88
85
|
resolve();
|
|
89
|
-
},
|
|
86
|
+
}, () => {
|
|
90
87
|
// Reject the request
|
|
91
88
|
reject("Error setting the indexed keys property.");
|
|
92
89
|
});
|
|
@@ -101,15 +98,14 @@ var setWebProperty = function (key, value, indexed, siteUrl) {
|
|
|
101
98
|
// Resolve the request
|
|
102
99
|
resolve();
|
|
103
100
|
}
|
|
104
|
-
},
|
|
101
|
+
}, () => {
|
|
105
102
|
// Reject the request
|
|
106
103
|
reject("Error removing the web property.");
|
|
107
104
|
});
|
|
108
105
|
}
|
|
109
|
-
},
|
|
106
|
+
}, () => {
|
|
110
107
|
// Reject the request
|
|
111
108
|
reject("Unable to get the context of this web.");
|
|
112
109
|
});
|
|
113
110
|
});
|
|
114
111
|
};
|
|
115
|
-
exports.setWebProperty = setWebProperty;
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.stringify = void 0;
|
|
4
1
|
/**
|
|
5
2
|
* Convert an object to a string
|
|
6
3
|
*/
|
|
7
|
-
|
|
4
|
+
export const stringify = (obj) => {
|
|
8
5
|
// Return the string
|
|
9
|
-
return JSON.stringify(obj,
|
|
6
|
+
return JSON.stringify(obj, (key, value) => {
|
|
10
7
|
// Ensure a key exists
|
|
11
8
|
if (key) {
|
|
12
9
|
// See if this is a string or number, and return it
|
|
13
|
-
|
|
10
|
+
let valueType = typeof (value);
|
|
14
11
|
if (valueType === "string" || valueType === "number") {
|
|
15
12
|
return value;
|
|
16
13
|
}
|
|
@@ -29,4 +26,3 @@ var stringify = function (obj) {
|
|
|
29
26
|
return value;
|
|
30
27
|
});
|
|
31
28
|
};
|
|
32
|
-
exports.stringify = stringify;
|
|
@@ -1,39 +1,59 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.WebWorker = WebWorker;
|
|
4
1
|
// Web Worker
|
|
5
|
-
|
|
2
|
+
class _WebWorker {
|
|
6
3
|
// Constructor
|
|
7
|
-
|
|
8
|
-
if (interval === void 0) { interval = 1000; }
|
|
9
|
-
var _this = this;
|
|
4
|
+
constructor(callback, interval = 1000) {
|
|
10
5
|
this._worker = null;
|
|
11
6
|
// Create the worker process
|
|
12
|
-
|
|
7
|
+
let blob = new Blob([WorkerCode(interval)], { type: "application/javascript" });
|
|
13
8
|
this._worker = new Worker(URL.createObjectURL(blob));
|
|
14
9
|
// Set the callback method
|
|
15
|
-
this._worker.onmessage =
|
|
10
|
+
this._worker.onmessage = () => {
|
|
16
11
|
// Call the callback method
|
|
17
12
|
callback();
|
|
18
13
|
};
|
|
19
14
|
// Watch the unload event to stop the loop
|
|
20
|
-
window.addEventListener("beforeunload",
|
|
15
|
+
window.addEventListener("beforeunload", () => {
|
|
21
16
|
// Stop the loop
|
|
22
|
-
|
|
23
|
-
|
|
17
|
+
this.stop();
|
|
18
|
+
this._worker.terminate();
|
|
24
19
|
});
|
|
25
20
|
}
|
|
26
21
|
// Starts the loop
|
|
27
|
-
|
|
22
|
+
start() { this._worker.postMessage("start"); }
|
|
28
23
|
// Stops the loop
|
|
29
|
-
|
|
30
|
-
return _WebWorker;
|
|
31
|
-
}());
|
|
32
|
-
function WebWorker(callback, interval) {
|
|
33
|
-
if (interval === void 0) { interval = 1000; }
|
|
34
|
-
return new _WebWorker(callback, interval);
|
|
24
|
+
stop() { this._worker.postMessage("stop"); }
|
|
35
25
|
}
|
|
26
|
+
export function WebWorker(callback, interval = 1000) { return new _WebWorker(callback, interval); }
|
|
36
27
|
// The worker code
|
|
37
28
|
function WorkerCode(interval) {
|
|
38
|
-
return
|
|
29
|
+
return `
|
|
30
|
+
let interval = [Default Interval];
|
|
31
|
+
let loopId = null;
|
|
32
|
+
self.onmessage = (e) => {
|
|
33
|
+
// See if the input is a number
|
|
34
|
+
if (typeof (e.data) === "number") {
|
|
35
|
+
// Set the interval value
|
|
36
|
+
interval = e.data;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// See if we are stopping the loop
|
|
40
|
+
if (e.data == "stop") {
|
|
41
|
+
// Stop the interval and loop id
|
|
42
|
+
clearInterval(loopId);
|
|
43
|
+
loopId = null;
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// See if we are starting the loop
|
|
48
|
+
if (e.data == "start") {
|
|
49
|
+
// Ensure it's not already started
|
|
50
|
+
if (loopId != null) { return; }
|
|
51
|
+
|
|
52
|
+
// Start the loop
|
|
53
|
+
loopId = setInterval(() => {
|
|
54
|
+
// Trigger the callback
|
|
55
|
+
self.postMessage(null);
|
|
56
|
+
}, interval || 1000);
|
|
57
|
+
}
|
|
58
|
+
}`.replace('[Default Interval]', interval.toString());
|
|
39
59
|
}
|