gd-sprest
Advanced tools
Comparing version 8.1.1 to 8.1.2
@@ -17,16 +17,10 @@ "use strict"; | ||
var skipFields = []; | ||
var ct = lib_1.Web(webContext.WebFullUrl).Lists(ctInfo.listName).ContentTypes(ctInfo.id); | ||
// See if we need to remove any fields | ||
if (fieldLinks.length > 0) { | ||
var updateFl = false; | ||
// Set the context | ||
var ctx = ctInfo.webUrl ? new SP.ClientContext(ctInfo.webUrl) : new SP.ClientContext(lib_1.ContextInfo.webServerRelativeUrl); | ||
// Get the source | ||
var src = ctInfo.listName ? ctx.get_web().get_lists().getByTitle(ctInfo.listName) : ctx.get_web(); | ||
// Get the content type | ||
var contentType = src.get_contentTypes().getById(ctInfo.id); | ||
// Parse the content type field links | ||
for (var i = 0; i < fieldLinks.length; i++) { | ||
var _loop_1 = function (i) { | ||
var fieldLink = fieldLinks[i]; | ||
var removeFl = true; | ||
var _loop_1 = function (j) { | ||
var _loop_2 = function (j) { | ||
var field = ctInfo.fields[j]; | ||
@@ -68,3 +62,3 @@ var fieldName = typeof (field) === "string" ? field : field.Name || field.FieldInternalName; | ||
for (var j = 0; j < ctInfo.fields.length; j++) { | ||
var state_1 = _loop_1(j); | ||
var state_1 = _loop_2(j); | ||
if (state_1 === "break") | ||
@@ -75,16 +69,28 @@ break; | ||
if (removeFl) { | ||
// Log | ||
console.log("[gd-sprest][Set Content Type Fields] Removing the field link: " + fieldLink.Name); | ||
// Remove the field link | ||
contentType.get_fieldLinks().getById(fieldLink.Id).deleteObject(); | ||
ct.Fields().getById(fieldLink.Id).delete().execute( | ||
// Success | ||
function () { | ||
// Log | ||
console.log("[gd-sprest][Set Content Type Fields] Field link '" + fieldLink.Name + "' was removed successfully."); | ||
}, | ||
// Error | ||
function () { | ||
// Log | ||
console.log("[gd-sprest][Set Content Type Fields] Error removing the field link: " + fieldLink.Name); | ||
}, true); | ||
// Set the flag | ||
updateFl = true; | ||
// Log | ||
console.log("[gd-sprest][Set Content Type Fields] Removing the field link: " + fieldLink.Name); | ||
} | ||
}; | ||
// Parse the content type field links | ||
for (var i = 0; i < fieldLinks.length; i++) { | ||
_loop_1(i); | ||
} | ||
// See if an update is required | ||
// See if we are updating the content type | ||
if (updateFl) { | ||
// Update the content type | ||
contentType.update(false); | ||
// Execute the request | ||
ctx.executeQueryAsync( | ||
// Wait for the requests to complete | ||
ct.done( | ||
// Success | ||
@@ -96,9 +102,2 @@ function () { | ||
resolve(skipFields); | ||
}, | ||
// Error | ||
function (sender, args) { | ||
// Log | ||
console.log("[gd-sprest][Set Content Type Fields] Error removing the field links."); | ||
// Reject the request | ||
reject(); | ||
}); | ||
@@ -238,2 +237,16 @@ } | ||
}; | ||
// Sets the context for the target site | ||
var webContext = null; | ||
var setContext = function () { | ||
// Return a promise | ||
return new Promise(function (resolve, reject) { | ||
// Get the context information of the target web | ||
lib_1.ContextInfo.getWeb(ctInfo.webUrl || lib_1.ContextInfo.webServerRelativeUrl).execute(function (context) { | ||
// Set the web context info | ||
webContext = context.GetContextWebInformation; | ||
// Resolve the request | ||
resolve(); | ||
}, reject); | ||
}); | ||
}; | ||
// Set the order of the field references | ||
@@ -285,8 +298,11 @@ var setOrder = function () { | ||
if (ctInfo.fields) { | ||
// Clear the links | ||
clearLinks().then(function (skipFields) { | ||
// Create the links | ||
createLinks(skipFields).then(function () { | ||
// Set the field order | ||
setOrder().then(resolve, reject); | ||
// Set the context | ||
setContext().then(function () { | ||
// Clear the links | ||
clearLinks().then(function (skipFields) { | ||
// Create the links | ||
createLinks(skipFields).then(function () { | ||
// Set the field order | ||
setOrder().then(resolve, reject); | ||
}, reject); | ||
}, reject); | ||
@@ -293,0 +309,0 @@ }, reject); |
@@ -12,3 +12,3 @@ "use strict"; | ||
exports.$REST = { | ||
__ver: 8.11, | ||
__ver: 8.12, | ||
AppContext: function (siteUrl) { return Lib.Site.getAppContext(siteUrl); }, | ||
@@ -15,0 +15,0 @@ Apps: Lib.Apps, |
{ | ||
"name": "gd-sprest", | ||
"version": "8.1.1", | ||
"version": "8.1.2", | ||
"description": "An easy way to develop against the SharePoint REST API.", | ||
@@ -5,0 +5,0 @@ "author": "Gunjan Datta <me@dattabase.com> (https://gunjandatta.github.io)", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2575112
31376