diff options
Diffstat (limited to 'web/react/utils')
-rw-r--r-- | web/react/utils/async_client.jsx | 2 | ||||
-rw-r--r-- | web/react/utils/client.jsx | 24 | ||||
-rw-r--r-- | web/react/utils/utils.jsx | 21 |
3 files changed, 32 insertions, 15 deletions
diff --git a/web/react/utils/async_client.jsx b/web/react/utils/async_client.jsx index dc4fc1096..f35b0f6cc 100644 --- a/web/react/utils/async_client.jsx +++ b/web/react/utils/async_client.jsx @@ -322,7 +322,7 @@ module.exports.getMe = function() { if (isCallInProgress("getMe")) return; callTracker["getMe"] = utils.getTimestamp(); - client.getMeSynchronous( + client.getMe( function(data, textStatus, xhr) { callTracker["getMe"] = 0; diff --git a/web/react/utils/client.jsx b/web/react/utils/client.jsx index b8eda0075..6a1f7c820 100644 --- a/web/react/utils/client.jsx +++ b/web/react/utils/client.jsx @@ -279,32 +279,24 @@ module.exports.getAudits = function(userId, success, error) { }); }; -module.exports.getMeSynchronous = function(success, error) { - - var current_user = null; +module.exports.getMe = function(success, error) { $.ajax({ - async: false, url: "/api/v1/users/me", dataType: 'json', contentType: 'application/json', type: 'GET', - success: function(data, textStatus, xhr) { - current_user = data; - if (success) success(data, textStatus, xhr); - }, + success: success, error: function(xhr, status, err) { var ieChecker = window.navigator.userAgent; // This and the condition below is used to check specifically for browsers IE10 & 11 to suppress a 200 'OK' error from appearing on login if (xhr.status != 200 || !(ieChecker.indexOf("Trident/7.0") > 0 || ieChecker.indexOf("Trident/6.0") > 0)) { if (error) { - e = handleError("getMeSynchronous", xhr, status, err); + e = handleError("getMe", xhr, status, err); error(e); }; }; } }); - - return current_user; }; module.exports.inviteMembers = function(data, success, error) { @@ -762,7 +754,7 @@ module.exports.getProfiles = function(success, error) { }; module.exports.uploadFile = function(formData, success, error) { - $.ajax({ + var request = $.ajax({ url: "/api/v1/files/upload", type: 'POST', data: formData, @@ -771,12 +763,16 @@ module.exports.uploadFile = function(formData, success, error) { processData: false, success: success, error: function(xhr, status, err) { - e = handleError("uploadFile", xhr, status, err); - error(e); + if (err !== 'abort') { + e = handleError("uploadFile", xhr, status, err); + error(e); + } } }); module.exports.track('api', 'api_files_upload'); + + return request; }; module.exports.getPublicLink = function(data, success, error) { diff --git a/web/react/utils/utils.jsx b/web/react/utils/utils.jsx index a759cc579..2214b6239 100644 --- a/web/react/utils/utils.jsx +++ b/web/react/utils/utils.jsx @@ -913,3 +913,24 @@ module.exports.getFileName = function(path) { var split = path.split('/'); return split[split.length - 1]; }; + +// Generates a RFC-4122 version 4 compliant globally unique identifier. +module.exports.generateId = function() { + // implementation taken from http://stackoverflow.com/a/2117523 + var id = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'; + + id = id.replace(/[xy]/g, function(c) { + var r = Math.floor(Math.random() * 16); + + var v; + if (c === 'x') { + v = r; + } else { + v = r & 0x3 | 0x8; + } + + return v.toString(16); + }); + + return id; +}; |