Skip to content

Commit

Permalink
v6.2.0
Browse files Browse the repository at this point in the history
  - Added option `modify` to `$SP().getManager()`
  - Added `$SP().isSPO()`
  - Changed `$SP().ajax()` to better managed 401 error for the REST API calls
  - Changed `$SP().cleanResult()` when dealing with a date (`$SP().cleanResult("2022-01-19 00:00:00")` will now return "2022-01-19" instead of "2022-01-19 00:00:00")
  - Changed `$SP().toDate()` to ignore the timezone (e.g. `$SP().toDate("2022-01-19")` used to return different result based on the user's timezone, but now it returns the correct date at 00:00:00 in the current timezone)
  - /!\ Changed `$SP().getVersions()`: only compatible with REST API, and it returns a different result/outcome than before
  - /!\ Changed `$SP().hasREST()`: it will always return TRUE (it's possible to override the value) because REST API is around for a while now and I assume everyone is using at least SP2013 (see issue #180)
  - Fixed `$SP().isMember()` for the `url` option (see issue #175)
  - Removed support for IE10 in the bundle for browsers
  • Loading branch information
Aymkdn committed Jun 9, 2022
1 parent 63f2930 commit 281c2ca
Show file tree
Hide file tree
Showing 64 changed files with 539 additions and 6,184 deletions.
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
generate_docs.bat
inch.json
node_modules
package-lock.json
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ SharepointPlus ($SP) is a JavaScript library which offers some extended features

## Documentation

Browse the [online documentation here](http://aymkdn.github.com/SharepointPlus/).
Browse the [online documentation here](https://aymkdn.github.io/SharepointPlus/).

## Quick Start

Expand All @@ -23,7 +23,7 @@ Then:
import $SP from 'sharepointplus'
```

Please, make sure to read [the documentation](http://aymkdn.github.com/SharepointPlus/) to optimize your bundle size.
Please, make sure to read [the documentation](https://aymkdn.github.io/SharepointPlus/) to optimize your bundle size.

### Browser Only

Expand Down Expand Up @@ -65,4 +65,4 @@ $SP().list('ListName').get({
## More information
Please visit the [online documentation](http://aymkdn.github.com/SharepointPlus/) to know more.
Please visit the [online documentation](https://aymkdn.github.io/SharepointPlus/) to know more.
2 changes: 1 addition & 1 deletion browser/sharepointplus.js

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Changelog

**Change Log v6.2.0 (June 8, 2022)**

- Added option `modify` to `$SP().getManager()`
- Added `$SP().isSPO()`
- Changed `$SP().ajax()` to better managed 401 error for the REST API calls
- Changed `$SP().cleanResult()` when dealing with a date (`$SP().cleanResult("2022-01-19 00:00:00")` will now return "2022-01-19" instead of "2022-01-19 00:00:00")
- Changed `$SP().toDate()` to ignore the timezone (e.g. `$SP().toDate("2022-01-19")` used to return different result based on the user's timezone, but now it returns the correct date at 00:00:00 in the current timezone)
- /!\ Changed `$SP().getVersions()`: only compatible with REST API, and it returns a different result/outcome than before
- /!\ Changed `$SP().hasREST()`: it will always return TRUE (it's possible to override the value) because REST API is around for a while now and I assume everyone is using at least SP2013 (see issue https://github.com/Aymkdn/SharepointPlus/issues/180)
- Fixed `$SP().isMember()` for the `url` option (see issue https://github.com/Aymkdn/SharepointPlus/issues/175)
- Removed support for IE10 in the bundle for browsers

**Change Log v6.1.5 (March 5, 2021)**

- Fixed `$SP().list().get()` when using `join` option and when there is no data in the left-list
Expand Down
3 changes: 3 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ var _getURL = _interopRequireDefault(require("./utils/getURL.js"));

var _hasREST = _interopRequireDefault(require("./utils/hasREST.js"));

var _isSPO = _interopRequireDefault(require("./utils/isSPO.js"));

var _newGuid = _interopRequireDefault(require("./utils/newGuid.js"));

var _regionalDateFormat = _interopRequireDefault(require("./utils/regionalDateFormat.js"));
Expand Down Expand Up @@ -213,6 +215,7 @@ var _default = spInit({
getTimeZoneInfo: _getTimeZoneInfo.default,
getURL: _getURL.default,
hasREST: _hasREST.default,
isSPO: _isSPO.default,
newGuid: _newGuid.default,
regionalDateFormat: _regionalDateFormat.default,
regionalSettings: _regionalSettings.default,
Expand Down
2 changes: 1 addition & 1 deletion dist/lists/addAttachment.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ var _restoreVersion = _interopRequireDefault(require("./restoreVersion.js"));
});
// to read a file and send it
// with something like: <input type="file" onchange="addAttachment(event)">
// with something like: &lt;input type="file" onchange="addAttachment(event)"&gt;
function addAttachment(event) {
let files = event.target.files;
let fileReader = new FileReader();
Expand Down
3 changes: 2 additions & 1 deletion dist/lists/cleanResult.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ exports.default = cleanResult;
$SP().cleanResult("string;#"); // -> ""
$SP().cleanResult(";#Paul;#Jacques;#Aymeric;#"); // -> "Paul;Jacques;Aymeric"
$SP().cleanResult(";#Paul;#Jacques;#Aymeric;#", ", "); // -> "Paul, Jacques, Aymeric"
$SP().cleanResult("2022-01-19 00:00:00"); // -> "2022-01-19"
*/
function cleanResult(str, separator) {
if (str === null || typeof str === "undefined") return "";
separator = separator || ";";
return typeof str === "string" ? str.replace(/^(string;|float;|datetime;)#?/, "").replace(/;#-?[0-9]+;#/g, separator).replace(/^-?[0-9]+;#/, "").replace(/^;#|;#$/g, "").replace(/;#/g, separator) : str;
return typeof str === "string" ? str.replace(/^(string;|float;|datetime;)#?/, "").replace(/^(\d{4}-\d{2}-\d{2}) 00:00:00$/, "$1").replace(/;#-?[0-9]+;#/g, separator).replace(/^-?[0-9]+;#/, "").replace(/^;#|;#$/g, "").replace(/;#/g, separator) : str;
}

module.exports = exports.default;
5 changes: 2 additions & 3 deletions dist/lists/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ function () {
@param {String} on The ON clause
@return {Array} array of {ListName1:FieldName1, ListName2:FieldName2}
@example
$SP()._parseOn("'List1'.field1 = 'List2'.field2 AND 'List1'.Other_x0020_Field = 'List2'.Some_x0020_Field")
_parseOn("'List1'.field1 = 'List2'.field2 AND 'List1'.Other_x0020_Field = 'List2'.Some_x0020_Field")
*/


Expand Down Expand Up @@ -1143,8 +1143,7 @@ function _get() {

if (joinLookupField) {
if (joinWhereLookup.length > 0) {
// SP2013 limits to 60 items per IN
wh = (0, _arrayChunk.default)(joinWhereLookup, 60);
wh = (0, _arrayChunk.default)(joinWhereLookup, global._SP_MAXWHERE_ONLOOKUP);

for (j = 0; j < wh.length; j++) {
wh[j] = joinLookupField + ' IN ["' + wh[j].join('","') + '"]';
Expand Down
67 changes: 13 additions & 54 deletions dist/lists/getVersions.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,22 @@ exports.default = getVersions;

var _regenerator = _interopRequireDefault(require("@babel/runtime-corejs3/regenerator"));

var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/map"));

var _isArray = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/array/is-array"));

var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/asyncToGenerator"));

var _info = _interopRequireDefault(require("./info.js"));

var _ajax = _interopRequireDefault(require("../utils/ajax.js"));

/**
@name $SP().list.getVersions
@function
@description When versionning is activated on a list, you can use this function to get the different version label/number for a list item
@description When versionning is activated on a list, you can use this function to get the different versions of a list item
@param {Number} ID The item ID
@return {Promise} resolve(arrayOflistOfVersions)
@return {Promise} resolve(arrayOfVersions)
@example
$SP().list("My List").getVersions({
ID:1
}).then(function(versions) {
$SP().list("My List").getVersions(1234).then(function(versions) {
versions.forEach(function(version) {
console.log(version);
// returns:
// - CheckInComment
// - Created
// - VersionID
// - IsCurrentVersion (boolean)
// - VersionLabel (e.g. "1.0", "2.0", …)
})
});
*/
Expand All @@ -53,70 +39,43 @@ function _getVersions() {
_getVersions = (0, _asyncToGenerator2.default)(
/*#__PURE__*/
_regenerator.default.mark(function _callee(itemID) {
var infos, rootFolder;
return _regenerator.default.wrap(function _callee$(_context2) {
return _regenerator.default.wrap(function _callee$(_context) {
while (1) {
switch (_context2.prev = _context2.next) {
switch (_context.prev = _context.next) {
case 0:
if (this.listID) {
_context2.next = 2;
_context.next = 2;
break;
}

throw "[SharepointPlus 'getVersions'] the list ID/Name is required.";

case 2:
if (this.url) {
_context2.next = 4;
_context.next = 4;
break;
}

throw "[SharepointPlus 'getVersions'] not able to find the URL!";

case 4:
if (itemID) {
_context2.next = 6;
_context.next = 6;
break;
}

throw "[SharepointPlus 'getVersions'] the item ID is required.";

case 6:
_context2.next = 8;
return _info.default.call(this);

case 8:
infos = _context2.sent;
rootFolder = infos._List.RootFolder; // if no versionning

if (!(infos._List.EnableVersioning !== "True")) {
_context2.next = 12;
break;
}

return _context2.abrupt("return", []);

case 12:
return _context2.abrupt("return", _ajax.default.call(this, {
url: this.url + "/_api/web/GetFileByServerRelativeUrl('" + encodeURIComponent(rootFolder + "/" + itemID + "_.000") + "')/Versions"
return _context.abrupt("return", _ajax.default.call(this, {
url: this.url + "/_api/lists/getbytitle('" + this.listID + "')/Items(" + itemID + ")/Versions"
}).then(function (res) {
var _context;

if (!res || !res.d || !(0, _isArray.default)(res.d.results)) return [];
return (0, _map.default)(_context = res.d.results).call(_context, function (item) {
return {
CheckInComment: item.CheckInComment,
Created: item.Created,
VersionID: item.ID,
IsCurrentVersion: item.IsCurrentVersion,
VersionLabel: item.VersionLabel
};
});
return (res.d ? res.d.results : res.value) || [];
}));

case 13:
case 7:
case "end":
return _context2.stop();
return _context.stop();
}
}
}, _callee, this);
Expand Down
2 changes: 1 addition & 1 deletion dist/lists/hasPermission.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var _ajax = _interopRequireDefault(require("../utils/ajax.js"));
@function
@description This function permits to check if the current user has a specific permission for a list/library
@param {String|Array} perm Can be one of the values listed on https://docs.microsoft.com/en-us/previous-versions/office/developer/sharepoint-2010/ee556747(v%3Doffice.14)
return {Promise} A promise with a boolean (TRUE/FALSE) if the requested perm was a string, or an object ({perm1:BOOLEAN, perm2:BOOLEAN}) if it was an array
@return {Promise} A promise with a boolean (TRUE/FALSE) if the requested perm was a string, or an object ({perm1:BOOLEAN, perm2:BOOLEAN}) if it was an array
@example
// check permissions for list 'Travels'
Expand Down
2 changes: 1 addition & 1 deletion dist/lists/removeAttachment.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var _restoreVersion = _interopRequireDefault(require("./restoreVersion.js"));
@example
$SP().list("My List").removeAttachment({
ID:1,
filename:"https://mysite.share.point.com/Toolbox/Lists/Tasks/Attachments/2305/image1.png"
fileURL:"https://mysite.share.point.com/Toolbox/Lists/Tasks/Attachments/2305/image1.png"
})
*/
function removeAttachment(setup) {
Expand Down
2 changes: 1 addition & 1 deletion dist/lists/restoreVersion.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var _getRequestDigest = _interopRequireDefault(require("../utils/getRequestDiges
@param {Object} [setup] Options (see below)
@param {Number} setup.ID The item ID
@param {Number} setup.VersionID The version ID from $SP().list().getVersions()
@return {Promise} resolve(htmlPage), reject(errorMessage)
@return {Promise} resolve(true), reject(errorMessage)
@example
$SP().list("My List").restoreVersion({
Expand Down
3 changes: 2 additions & 1 deletion dist/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ global._SP_PLUGINS = {};
global._SP_MODALDIALOG_LOADED = false;
global._SP_MAXWHERE_ONLOOKUP = 30;
global._SP_ISBROWSER = new Function("try {return this===window;}catch(e){ return false;}")();
global._SP_ISSPO = {};
global._SP_JSON_ACCEPT = "verbose"; // other options are "minimalmetadata" and "nometadata"

var SharepointPlus =
Expand Down Expand Up @@ -76,7 +77,7 @@ function () {
(0, _createClass2.default)(SharepointPlus, [{
key: "getVersion",
value: function getVersion() {
return "6.1.5";
return "6.2.0";
}
/**
@name $SP().auth
Expand Down
2 changes: 1 addition & 1 deletion dist/modals/closeModalDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function closeModalDialog(dialogResult, returnValue) {
var fct = function fct() {
var md;

if ((0, _typeof2.default)(dialogResult) === "object" && typeof dialogResult.type !== "undefined" && dialogResult.type === "modalDialog") {
if ((0, _typeof2.default)(dialogResult) === "object" && dialogResult.type === "modalDialog") {
md = {
id: dialogResult.id,
dialogResult: returnValue,
Expand Down
24 changes: 16 additions & 8 deletions dist/people/getManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ var _regenerator = _interopRequireDefault(require("@babel/runtime-corejs3/regene

var _promise = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/promise"));

var _startsWith = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/starts-with"));

var _typeof2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/typeof"));

var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/asyncToGenerator"));
Expand All @@ -32,13 +30,14 @@ var _people = _interopRequireDefault(require("./people.js"));
@category people
@description Return the manager for the provided user, as a People string
@param {String} [username] With or without the domain, and you can also use an email address, and if you leave it empty it's the current user by default
@param {String} [username] Username with the domain, and if you leave it empty it's the current user by default
@param {Object} [setup] Options (see below)
@param {String} [setup.url='current website'] The website url
@param {Function} [setup.modify] Permits to modify the manager's username returned by the service
@return {Function} resolve(manager), reject(error)
@example
$SP().getManager("john_doe",{url:"http://my.si.te/subdir/"})
$SP().getManager("domain\\john_doe",{url:"http://my.si.te/subdir/"})
.then(function(manager) {
console.log(manager); // 42;#Smith,, Jane,#i:0#.w|domain\Jane_Smith,#[email protected],#[email protected],#Smith,, Jane
manager = $SP().getPeopleLookup(manager);
Expand All @@ -47,6 +46,12 @@ var _people = _interopRequireDefault(require("./people.js"));
.catch(function(err) {
console.log("Err => ",err)
});
$SP().getManager("domain\\john_doe",{
modify:function(managerUserName) {
return (managerUserName.startsWith('i:0') ? managerUserName : "i:0#.w|" + managerUserName);
}
})
*/
function getManager(_x, _x2) {
return _getManager.apply(this, arguments);
Expand Down Expand Up @@ -88,13 +93,16 @@ function _getManager() {
setup.url = _context.sent;

case 8:
_context.next = 10;
setup.modify = setup.modify || function (val) {
return val;
};

_context.next = 11;
return _people.default.call(this, username, setup);

case 10:
case 11:
pres = _context.sent;
managerUserName = pres.Manager;
if (!(0, _startsWith.default)(managerUserName).call(managerUserName, 'i:0')) managerUserName = "i:0#.w|" + managerUserName;
managerUserName = setup.modify(pres.Manager);
_context.next = 15;
return _getUserInfo.default.call(this, managerUserName, setup);

Expand Down
9 changes: 6 additions & 3 deletions dist/people/isMember.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ function _isMember() {

_context.next = 15;
return _usergroups.default.call(this, setup.user, {
cache: setup.cache
cache: setup.cache,
url: setup.url
});

case 15:
Expand All @@ -123,7 +124,8 @@ function _isMember() {
case 22:
_context.next = 24;
return _groupMembers.default.call(this, setup.group, {
cache: setup.cache
cache: setup.cache,
url: setup.url
});

case 24:
Expand All @@ -136,7 +138,8 @@ function _isMember() {

_context.next = 28;
return _distributionLists.default.call(this, setup.user, {
cache: setup.cache
cache: setup.cache,
url: setup.url
});

case 28:
Expand Down
Loading

0 comments on commit 281c2ca

Please sign in to comment.