gd-sprest 8.1.0 → 8.1.2
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.
|
@@ -14,20 +14,14 @@ exports.setContentTypeFields = function (ctInfo) {
|
|
|
14
14
|
// Get the links
|
|
15
15
|
getLinks().then(function (fieldLinks) {
|
|
16
16
|
var skipFields = [];
|
|
17
|
+
var ct = lib_1.Web(webContext.WebFullUrl).Lists(ctInfo.listName).ContentTypes(ctInfo.id);
|
|
17
18
|
// See if we need to remove any fields
|
|
18
19
|
if (fieldLinks.length > 0) {
|
|
19
20
|
var updateFl = false;
|
|
20
|
-
|
|
21
|
-
var ctx = ctInfo.webUrl ? new SP.ClientContext(ctInfo.webUrl) : new SP.ClientContext(lib_1.ContextInfo.webServerRelativeUrl);
|
|
22
|
-
// Get the source
|
|
23
|
-
var src = ctInfo.listName ? ctx.get_web().get_lists().getByTitle(ctInfo.listName) : ctx.get_web();
|
|
24
|
-
// Get the content type
|
|
25
|
-
var contentType = src.get_contentTypes().getById(ctInfo.id);
|
|
26
|
-
// Parse the content type field links
|
|
27
|
-
for (var i = 0; i < fieldLinks.length; i++) {
|
|
21
|
+
var _loop_1 = function (i) {
|
|
28
22
|
var fieldLink = fieldLinks[i];
|
|
29
23
|
var removeFl = true;
|
|
30
|
-
var
|
|
24
|
+
var _loop_2 = function (j) {
|
|
31
25
|
var field = ctInfo.fields[j];
|
|
32
26
|
var fieldName = typeof (field) === "string" ? field : field.Name || field.FieldInternalName;
|
|
33
27
|
// See if we are keeping this field
|
|
@@ -64,39 +58,44 @@ exports.setContentTypeFields = function (ctInfo) {
|
|
|
64
58
|
};
|
|
65
59
|
// Parse the fields to add
|
|
66
60
|
for (var j = 0; j < ctInfo.fields.length; j++) {
|
|
67
|
-
var state_1 =
|
|
61
|
+
var state_1 = _loop_2(j);
|
|
68
62
|
if (state_1 === "break")
|
|
69
63
|
break;
|
|
70
64
|
}
|
|
71
65
|
// See if we are removing the field
|
|
72
66
|
if (removeFl) {
|
|
67
|
+
// Log
|
|
68
|
+
console.log("[gd-sprest][Set Content Type Fields] Removing the field link: " + fieldLink.Name);
|
|
73
69
|
// Remove the field link
|
|
74
|
-
|
|
70
|
+
ct.Fields().getById(fieldLink.Id).delete().execute(
|
|
71
|
+
// Success
|
|
72
|
+
function () {
|
|
73
|
+
// Log
|
|
74
|
+
console.log("[gd-sprest][Set Content Type Fields] Field link '" + fieldLink.Name + "' was removed successfully.");
|
|
75
|
+
},
|
|
76
|
+
// Error
|
|
77
|
+
function () {
|
|
78
|
+
// Log
|
|
79
|
+
console.log("[gd-sprest][Set Content Type Fields] Error removing the field link: " + fieldLink.Name);
|
|
80
|
+
}, true);
|
|
75
81
|
// Set the flag
|
|
76
82
|
updateFl = true;
|
|
77
|
-
// Log
|
|
78
|
-
console.log("[gd-sprest][Set Content Type Fields] Removing the field link: " + fieldLink.Name);
|
|
79
83
|
}
|
|
84
|
+
};
|
|
85
|
+
// Parse the content type field links
|
|
86
|
+
for (var i = 0; i < fieldLinks.length; i++) {
|
|
87
|
+
_loop_1(i);
|
|
80
88
|
}
|
|
81
|
-
// See if
|
|
89
|
+
// See if we are updating the content type
|
|
82
90
|
if (updateFl) {
|
|
83
|
-
//
|
|
84
|
-
|
|
85
|
-
// Execute the request
|
|
86
|
-
ctx.executeQueryAsync(
|
|
91
|
+
// Wait for the requests to complete
|
|
92
|
+
ct.done(
|
|
87
93
|
// Success
|
|
88
94
|
function () {
|
|
89
95
|
// Log
|
|
90
96
|
console.log("[gd-sprest][Set Content Type Fields] Removed the field links successfully.");
|
|
91
97
|
// Resolve the request
|
|
92
98
|
resolve(skipFields);
|
|
93
|
-
},
|
|
94
|
-
// Error
|
|
95
|
-
function (sender, args) {
|
|
96
|
-
// Log
|
|
97
|
-
console.log("[gd-sprest][Set Content Type Fields] Error removing the field links.");
|
|
98
|
-
// Reject the request
|
|
99
|
-
reject();
|
|
100
99
|
});
|
|
101
100
|
}
|
|
102
101
|
else {
|
|
@@ -231,6 +230,20 @@ exports.setContentTypeFields = function (ctInfo) {
|
|
|
231
230
|
}, reject);
|
|
232
231
|
});
|
|
233
232
|
};
|
|
233
|
+
// Sets the context for the target site
|
|
234
|
+
var webContext = null;
|
|
235
|
+
var setContext = function () {
|
|
236
|
+
// Return a promise
|
|
237
|
+
return new Promise(function (resolve, reject) {
|
|
238
|
+
// Get the context information of the target web
|
|
239
|
+
lib_1.ContextInfo.getWeb(ctInfo.webUrl || lib_1.ContextInfo.webServerRelativeUrl).execute(function (context) {
|
|
240
|
+
// Set the web context info
|
|
241
|
+
webContext = context.GetContextWebInformation;
|
|
242
|
+
// Resolve the request
|
|
243
|
+
resolve();
|
|
244
|
+
}, reject);
|
|
245
|
+
});
|
|
246
|
+
};
|
|
234
247
|
// Set the order of the field references
|
|
235
248
|
var setOrder = function () {
|
|
236
249
|
// Return a promise
|
|
@@ -277,12 +290,15 @@ exports.setContentTypeFields = function (ctInfo) {
|
|
|
277
290
|
if (window["SP"]) {
|
|
278
291
|
// Ensure fields exist
|
|
279
292
|
if (ctInfo.fields) {
|
|
280
|
-
//
|
|
281
|
-
|
|
282
|
-
//
|
|
283
|
-
|
|
284
|
-
//
|
|
285
|
-
|
|
293
|
+
// Set the context
|
|
294
|
+
setContext().then(function () {
|
|
295
|
+
// Clear the links
|
|
296
|
+
clearLinks().then(function (skipFields) {
|
|
297
|
+
// Create the links
|
|
298
|
+
createLinks(skipFields).then(function () {
|
|
299
|
+
// Set the field order
|
|
300
|
+
setOrder().then(resolve, reject);
|
|
301
|
+
}, reject);
|
|
286
302
|
}, reject);
|
|
287
303
|
}, reject);
|
|
288
304
|
}
|
package/build/helper/spCfg.js
CHANGED
|
@@ -59,7 +59,7 @@ exports.SPConfig = function (cfg, webUrl) {
|
|
|
59
59
|
// Return a promise
|
|
60
60
|
return new Promise(function (resolve, reject) {
|
|
61
61
|
// Add the content type
|
|
62
|
-
var contentTypes = list ? lib_1.Web(webUrl).Lists(list.Title).ContentTypes() : lib_1.Web(webUrl).ContentTypes();
|
|
62
|
+
var contentTypes = list ? lib_1.Web(webUrl, { disableCache: true, requestDigest: _requestDigest }).Lists(list.Title).ContentTypes() : lib_1.Web(webUrl).ContentTypes();
|
|
63
63
|
contentTypes.add({
|
|
64
64
|
Description: cfg.Description,
|
|
65
65
|
Group: cfg.Group,
|
package/build/rest.js
CHANGED