diff options
Diffstat (limited to 'web/react/utils/client.jsx')
-rw-r--r-- | web/react/utils/client.jsx | 297 |
1 files changed, 147 insertions, 150 deletions
diff --git a/web/react/utils/client.jsx b/web/react/utils/client.jsx index 082f82a08..10f9c0b37 100644 --- a/web/react/utils/client.jsx +++ b/web/react/utils/client.jsx @@ -3,15 +3,15 @@ var BrowserStore = require('../stores/browser_store.jsx'); var TeamStore = require('../stores/team_store.jsx'); -module.exports.track = function(category, action, label, prop, val) { +export function track(category, action, label, prop, val) { global.window.snowplow('trackStructEvent', category, action, label, prop, val); global.window.analytics.track(action, {category: category, label: label, property: prop, value: val}); -}; +} -module.exports.trackPage = function() { +export function trackPage() { global.window.snowplow('trackPageView'); global.window.analytics.page(); -}; +} function handleError(methodName, xhr, status, err) { var LTracker = global.window.LTracker || []; @@ -41,7 +41,7 @@ function handleError(methodName, xhr, status, err) { console.error(e); //eslint-disable-line no-console LTracker.push(msg); - module.exports.track('api', 'api_weberror', methodName, 'message', msg); + track('api', 'api_weberror', methodName, 'message', msg); if (xhr.status === 401) { if (window.location.href.indexOf('/channels') === 0) { @@ -55,7 +55,7 @@ function handleError(methodName, xhr, status, err) { return e; } -module.exports.createTeamFromSignup = function(teamSignup, success, error) { +export function createTeamFromSignup(teamSignup, success, error) { $.ajax({ url: '/api/v1/teams/create_from_signup', dataType: 'json', @@ -68,9 +68,9 @@ module.exports.createTeamFromSignup = function(teamSignup, success, error) { error(e); } }); -}; +} -module.exports.createTeamWithSSO = function(team, service, success, error) { +export function createTeamWithSSO(team, service, success, error) { $.ajax({ url: '/api/v1/teams/create_with_sso/' + service, dataType: 'json', @@ -83,9 +83,9 @@ module.exports.createTeamWithSSO = function(team, service, success, error) { error(e); } }); -}; +} -module.exports.createUser = function(user, data, emailHash, success, error) { +export function createUser(user, data, emailHash, success, error) { $.ajax({ url: '/api/v1/users/create?d=' + encodeURIComponent(data) + '&h=' + encodeURIComponent(emailHash), dataType: 'json', @@ -99,10 +99,10 @@ module.exports.createUser = function(user, data, emailHash, success, error) { } }); - module.exports.track('api', 'api_users_create', user.team_id, 'email', user.email); -}; + track('api', 'api_users_create', user.team_id, 'email', user.email); +} -module.exports.updateUser = function(user, success, error) { +export function updateUser(user, success, error) { $.ajax({ url: '/api/v1/users/update', dataType: 'json', @@ -116,10 +116,10 @@ module.exports.updateUser = function(user, success, error) { } }); - module.exports.track('api', 'api_users_update'); -}; + track('api', 'api_users_update'); +} -module.exports.updatePassword = function(data, success, error) { +export function updatePassword(data, success, error) { $.ajax({ url: '/api/v1/users/newpassword', dataType: 'json', @@ -133,10 +133,10 @@ module.exports.updatePassword = function(data, success, error) { } }); - module.exports.track('api', 'api_users_newpassword'); -}; + track('api', 'api_users_newpassword'); +} -module.exports.updateUserNotifyProps = function(data, success, error) { +export function updateUserNotifyProps(data, success, error) { $.ajax({ url: '/api/v1/users/update_notify', dataType: 'json', @@ -149,9 +149,9 @@ module.exports.updateUserNotifyProps = function(data, success, error) { error(e); } }); -}; +} -module.exports.updateRoles = function(data, success, error) { +export function updateRoles(data, success, error) { $.ajax({ url: '/api/v1/users/update_roles', dataType: 'json', @@ -165,10 +165,10 @@ module.exports.updateRoles = function(data, success, error) { } }); - module.exports.track('api', 'api_users_update_roles'); -}; + track('api', 'api_users_update_roles'); +} -module.exports.updateActive = function(userId, active, success, error) { +export function updateActive(userId, active, success, error) { var data = {}; data.user_id = userId; data.active = '' + active; @@ -186,10 +186,10 @@ module.exports.updateActive = function(userId, active, success, error) { } }); - module.exports.track('api', 'api_users_update_roles'); -}; + track('api', 'api_users_update_roles'); +} -module.exports.sendPasswordReset = function(data, success, error) { +export function sendPasswordReset(data, success, error) { $.ajax({ url: '/api/v1/users/send_password_reset', dataType: 'json', @@ -203,10 +203,10 @@ module.exports.sendPasswordReset = function(data, success, error) { } }); - module.exports.track('api', 'api_users_send_password_reset'); -}; + track('api', 'api_users_send_password_reset'); +} -module.exports.resetPassword = function(data, success, error) { +export function resetPassword(data, success, error) { $.ajax({ url: '/api/v1/users/reset_password', dataType: 'json', @@ -220,17 +220,17 @@ module.exports.resetPassword = function(data, success, error) { } }); - module.exports.track('api', 'api_users_reset_password'); -}; + track('api', 'api_users_reset_password'); +} -module.exports.logout = function() { - module.exports.track('api', 'api_users_logout'); +export function logout() { + track('api', 'api_users_logout'); var currentTeamUrl = TeamStore.getCurrentTeamUrl(); BrowserStore.clear(); window.location.href = currentTeamUrl + '/logout'; -}; +} -module.exports.loginByEmail = function(name, email, password, success, error) { +export function loginByEmail(name, email, password, success, error) { $.ajax({ url: '/api/v1/users/login', dataType: 'json', @@ -238,19 +238,19 @@ module.exports.loginByEmail = function(name, email, password, success, error) { type: 'POST', data: JSON.stringify({name: name, email: email, password: password}), success: function onSuccess(data, textStatus, xhr) { - module.exports.track('api', 'api_users_login_success', data.team_id, 'email', data.email); + track('api', 'api_users_login_success', data.team_id, 'email', data.email); success(data, textStatus, xhr); }, error: function onError(xhr, status, err) { - module.exports.track('api', 'api_users_login_fail', window.getSubDomain(), 'email', email); + track('api', 'api_users_login_fail', name, 'email', email); var e = handleError('loginByEmail', xhr, status, err); error(e); } }); -}; +} -module.exports.revokeSession = function(altId, success, error) { +export function revokeSession(altId, success, error) { $.ajax({ url: '/api/v1/users/revoke_session', dataType: 'json', @@ -263,9 +263,9 @@ module.exports.revokeSession = function(altId, success, error) { error(e); } }); -}; +} -module.exports.getSessions = function(userId, success, error) { +export function getSessions(userId, success, error) { $.ajax({ cache: false, url: '/api/v1/users/' + userId + '/sessions', @@ -278,9 +278,9 @@ module.exports.getSessions = function(userId, success, error) { error(e); } }); -}; +} -module.exports.getAudits = function(userId, success, error) { +export function getAudits(userId, success, error) { $.ajax({ url: '/api/v1/users/' + userId + '/audits', dataType: 'json', @@ -292,9 +292,9 @@ module.exports.getAudits = function(userId, success, error) { error(e); } }); -}; +} -module.exports.getMeSynchronous = function(success, error) { +export function getMeSynchronous(success, error) { var currentUser = null; $.ajax({ async: false, @@ -318,9 +318,9 @@ module.exports.getMeSynchronous = function(success, error) { }); return currentUser; -}; +} -module.exports.inviteMembers = function(data, success, error) { +export function inviteMembers(data, success, error) { $.ajax({ url: '/api/v1/teams/invite_members', dataType: 'json', @@ -334,10 +334,10 @@ module.exports.inviteMembers = function(data, success, error) { } }); - module.exports.track('api', 'api_teams_invite_members'); -}; + track('api', 'api_teams_invite_members'); +} -module.exports.updateTeamDisplayName = function(data, success, error) { +export function updateTeamDisplayName(data, success, error) { $.ajax({ url: '/api/v1/teams/update_name', dataType: 'json', @@ -351,10 +351,10 @@ module.exports.updateTeamDisplayName = function(data, success, error) { } }); - module.exports.track('api', 'api_teams_update_name'); -}; + track('api', 'api_teams_update_name'); +} -module.exports.signupTeam = function(email, success, error) { +export function signupTeam(email, success, error) { $.ajax({ url: '/api/v1/teams/signup', dataType: 'json', @@ -368,10 +368,10 @@ module.exports.signupTeam = function(email, success, error) { } }); - module.exports.track('api', 'api_teams_signup'); -}; + track('api', 'api_teams_signup'); +} -module.exports.createTeam = function(team, success, error) { +export function createTeam(team, success, error) { $.ajax({ url: '/api/v1/teams/create', dataType: 'json', @@ -384,9 +384,9 @@ module.exports.createTeam = function(team, success, error) { error(e); } }); -}; +} -module.exports.findTeamByName = function(teamName, success, error) { +export function findTeamByName(teamName, success, error) { $.ajax({ url: '/api/v1/teams/find_team_by_name', dataType: 'json', @@ -399,9 +399,9 @@ module.exports.findTeamByName = function(teamName, success, error) { error(e); } }); -}; +} -module.exports.findTeamsSendEmail = function(email, success, error) { +export function findTeamsSendEmail(email, success, error) { $.ajax({ url: '/api/v1/teams/email_teams', dataType: 'json', @@ -415,10 +415,10 @@ module.exports.findTeamsSendEmail = function(email, success, error) { } }); - module.exports.track('api', 'api_teams_email_teams'); -}; + track('api', 'api_teams_email_teams'); +} -module.exports.findTeams = function(email, success, error) { +export function findTeams(email, success, error) { $.ajax({ url: '/api/v1/teams/find_teams', dataType: 'json', @@ -431,9 +431,9 @@ module.exports.findTeams = function(email, success, error) { error(e); } }); -}; +} -module.exports.createChannel = function(channel, success, error) { +export function createChannel(channel, success, error) { $.ajax({ url: '/api/v1/channels/create', dataType: 'json', @@ -447,10 +447,10 @@ module.exports.createChannel = function(channel, success, error) { } }); - module.exports.track('api', 'api_channels_create', channel.type, 'name', channel.name); -}; + track('api', 'api_channels_create', channel.type, 'name', channel.name); +} -module.exports.createDirectChannel = function(channel, userId, success, error) { +export function createDirectChannel(channel, userId, success, error) { $.ajax({ url: '/api/v1/channels/create_direct', dataType: 'json', @@ -458,16 +458,16 @@ module.exports.createDirectChannel = function(channel, userId, success, error) { type: 'POST', data: JSON.stringify({user_id: userId}), success: success, - error: function(xhr, status, err) { + error: function onError(xhr, status, err) { var e = handleError('createDirectChannel', xhr, status, err); error(e); } }); - module.exports.track('api', 'api_channels_create_direct', channel.type, 'name', channel.name); -}; + track('api', 'api_channels_create_direct', channel.type, 'name', channel.name); +} -module.exports.updateChannel = function(channel, success, error) { +export function updateChannel(channel, success, error) { $.ajax({ url: '/api/v1/channels/update', dataType: 'json', @@ -481,10 +481,10 @@ module.exports.updateChannel = function(channel, success, error) { } }); - module.exports.track('api', 'api_channels_update'); -}; + track('api', 'api_channels_update'); +} -module.exports.updateChannelDesc = function(data, success, error) { +export function updateChannelDesc(data, success, error) { $.ajax({ url: '/api/v1/channels/update_desc', dataType: 'json', @@ -498,10 +498,10 @@ module.exports.updateChannelDesc = function(data, success, error) { } }); - module.exports.track('api', 'api_channels_desc'); -}; + track('api', 'api_channels_desc'); +} -module.exports.updateNotifyLevel = function(data, success, error) { +export function updateNotifyLevel(data, success, error) { $.ajax({ url: '/api/v1/channels/update_notify_level', dataType: 'json', @@ -514,9 +514,9 @@ module.exports.updateNotifyLevel = function(data, success, error) { error(e); } }); -}; +} -module.exports.joinChannel = function(id, success, error) { +export function joinChannel(id, success, error) { $.ajax({ url: '/api/v1/channels/' + id + '/join', dataType: 'json', @@ -529,10 +529,10 @@ module.exports.joinChannel = function(id, success, error) { } }); - module.exports.track('api', 'api_channels_join'); -}; + track('api', 'api_channels_join'); +} -module.exports.leaveChannel = function(id, success, error) { +export function leaveChannel(id, success, error) { $.ajax({ url: '/api/v1/channels/' + id + '/leave', dataType: 'json', @@ -545,10 +545,10 @@ module.exports.leaveChannel = function(id, success, error) { } }); - module.exports.track('api', 'api_channels_leave'); -}; + track('api', 'api_channels_leave'); +} -module.exports.deleteChannel = function(id, success, error) { +export function deleteChannel(id, success, error) { $.ajax({ url: '/api/v1/channels/' + id + '/delete', dataType: 'json', @@ -561,10 +561,10 @@ module.exports.deleteChannel = function(id, success, error) { } }); - module.exports.track('api', 'api_channels_delete'); -}; + track('api', 'api_channels_delete'); +} -module.exports.updateLastViewedAt = function(channelId, success, error) { +export function updateLastViewedAt(channelId, success, error) { $.ajax({ url: '/api/v1/channels/' + channelId + '/update_last_viewed_at', dataType: 'json', @@ -576,9 +576,9 @@ module.exports.updateLastViewedAt = function(channelId, success, error) { error(e); } }); -}; +} -function getChannels(success, error) { +export function getChannels(success, error) { $.ajax({ cache: false, url: '/api/v1/channels/', @@ -592,9 +592,8 @@ function getChannels(success, error) { } }); } -module.exports.getChannels = getChannels; -module.exports.getChannel = function(id, success, error) { +export function getChannel(id, success, error) { $.ajax({ cache: false, url: '/api/v1/channels/' + id + '/', @@ -607,10 +606,10 @@ module.exports.getChannel = function(id, success, error) { } }); - module.exports.track('api', 'api_channel_get'); -}; + track('api', 'api_channel_get'); +} -module.exports.getMoreChannels = function(success, error) { +export function getMoreChannels(success, error) { $.ajax({ url: '/api/v1/channels/more', dataType: 'json', @@ -622,9 +621,9 @@ module.exports.getMoreChannels = function(success, error) { error(e); } }); -}; +} -function getChannelCounts(success, error) { +export function getChannelCounts(success, error) { $.ajax({ cache: false, url: '/api/v1/channels/counts', @@ -638,9 +637,8 @@ function getChannelCounts(success, error) { } }); } -module.exports.getChannelCounts = getChannelCounts; -module.exports.getChannelExtraInfo = function(id, success, error) { +export function getChannelExtraInfo(id, success, error) { $.ajax({ url: '/api/v1/channels/' + id + '/extra_info', dataType: 'json', @@ -651,9 +649,9 @@ module.exports.getChannelExtraInfo = function(id, success, error) { error(e); } }); -}; +} -module.exports.executeCommand = function(channelId, command, suggest, success, error) { +export function executeCommand(channelId, command, suggest, success, error) { $.ajax({ url: '/api/v1/command', dataType: 'json', @@ -666,9 +664,9 @@ module.exports.executeCommand = function(channelId, command, suggest, success, e error(e); } }); -}; +} -module.exports.getPostsPage = function(channelId, offset, limit, success, error, complete) { +export function getPostsPage(channelId, offset, limit, success, error, complete) { $.ajax({ cache: false, url: '/api/v1/channels/' + channelId + '/posts/' + offset + '/' + limit, @@ -682,9 +680,9 @@ module.exports.getPostsPage = function(channelId, offset, limit, success, error, }, complete: complete }); -}; +} -module.exports.getPosts = function(channelId, since, success, error, complete) { +export function getPosts(channelId, since, success, error, complete) { $.ajax({ url: '/api/v1/channels/' + channelId + '/posts/' + since, dataType: 'json', @@ -697,9 +695,9 @@ module.exports.getPosts = function(channelId, since, success, error, complete) { }, complete: complete }); -}; +} -module.exports.getPost = function(channelId, postId, success, error) { +export function getPost(channelId, postId, success, error) { $.ajax({ cache: false, url: '/api/v1/channels/' + channelId + '/post/' + postId, @@ -712,9 +710,9 @@ module.exports.getPost = function(channelId, postId, success, error) { error(e); } }); -}; +} -module.exports.search = function(terms, success, error) { +export function search(terms, success, error) { $.ajax({ url: '/api/v1/posts/search', dataType: 'json', @@ -727,10 +725,10 @@ module.exports.search = function(terms, success, error) { } }); - module.exports.track('api', 'api_posts_search'); -}; + track('api', 'api_posts_search'); +} -module.exports.deletePost = function(channelId, id, success, error) { +export function deletePost(channelId, id, success, error) { $.ajax({ url: '/api/v1/channels/' + channelId + '/post/' + id + '/delete', dataType: 'json', @@ -743,10 +741,10 @@ module.exports.deletePost = function(channelId, id, success, error) { } }); - module.exports.track('api', 'api_posts_delete'); -}; + track('api', 'api_posts_delete'); +} -module.exports.createPost = function(post, channel, success, error) { +export function createPost(post, channel, success, error) { $.ajax({ url: '/api/v1/channels/' + post.channel_id + '/create', dataType: 'json', @@ -760,7 +758,7 @@ module.exports.createPost = function(post, channel, success, error) { } }); - module.exports.track('api', 'api_posts_create', channel.name, 'length', post.message.length); + track('api', 'api_posts_create', channel.name, 'length', post.message.length); // global.window.analytics.track('api_posts_create', { // category: 'api', @@ -770,9 +768,9 @@ module.exports.createPost = function(post, channel, success, error) { // files: (post.filenames || []).length, // mentions: (post.message.match('/<mention>/g') || []).length // }); -}; +} -module.exports.updatePost = function(post, success, error) { +export function updatePost(post, success, error) { $.ajax({ url: '/api/v1/channels/' + post.channel_id + '/update', dataType: 'json', @@ -786,10 +784,10 @@ module.exports.updatePost = function(post, success, error) { } }); - module.exports.track('api', 'api_posts_update'); -}; + track('api', 'api_posts_update'); +} -module.exports.addChannelMember = function(id, data, success, error) { +export function addChannelMember(id, data, success, error) { $.ajax({ url: '/api/v1/channels/' + id + '/add', dataType: 'json', @@ -803,10 +801,10 @@ module.exports.addChannelMember = function(id, data, success, error) { } }); - module.exports.track('api', 'api_channels_add_member'); -}; + track('api', 'api_channels_add_member'); +} -module.exports.removeChannelMember = function(id, data, success, error) { +export function removeChannelMember(id, data, success, error) { $.ajax({ url: '/api/v1/channels/' + id + '/remove', dataType: 'json', @@ -820,10 +818,10 @@ module.exports.removeChannelMember = function(id, data, success, error) { } }); - module.exports.track('api', 'api_channels_remove_member'); -}; + track('api', 'api_channels_remove_member'); +} -module.exports.getProfiles = function(success, error) { +export function getProfiles(success, error) { $.ajax({ cache: false, url: '/api/v1/users/profiles', @@ -837,9 +835,9 @@ module.exports.getProfiles = function(success, error) { error(e); } }); -}; +} -module.exports.uploadFile = function(formData, success, error) { +export function uploadFile(formData, success, error) { var request = $.ajax({ url: '/api/v1/files/upload', type: 'POST', @@ -856,12 +854,12 @@ module.exports.uploadFile = function(formData, success, error) { } }); - module.exports.track('api', 'api_files_upload'); + track('api', 'api_files_upload'); return request; -}; +} -module.exports.getFileInfo = function(filename, success, error) { +export function getFileInfo(filename, success, error) { $.ajax({ url: '/api/v1/files/get_info' + filename, dataType: 'json', @@ -873,9 +871,9 @@ module.exports.getFileInfo = function(filename, success, error) { error(e); } }); -}; +} -module.exports.getPublicLink = function(data, success, error) { +export function getPublicLink(data, success, error) { $.ajax({ url: '/api/v1/files/get_public_link', dataType: 'json', @@ -887,9 +885,9 @@ module.exports.getPublicLink = function(data, success, error) { error(e); } }); -}; +} -module.exports.uploadProfileImage = function(imageData, success, error) { +export function uploadProfileImage(imageData, success, error) { $.ajax({ url: '/api/v1/users/newimage', type: 'POST', @@ -903,9 +901,9 @@ module.exports.uploadProfileImage = function(imageData, success, error) { error(e); } }); -}; +} -module.exports.importSlack = function(fileData, success, error) { +export function importSlack(fileData, success, error) { $.ajax({ url: '/api/v1/teams/import_team', type: 'POST', @@ -919,9 +917,9 @@ module.exports.importSlack = function(fileData, success, error) { error(e); } }); -}; +} -module.exports.getStatuses = function(success, error) { +export function getStatuses(success, error) { $.ajax({ url: '/api/v1/users/status', dataType: 'json', @@ -933,9 +931,9 @@ module.exports.getStatuses = function(success, error) { error(e); } }); -}; +} -module.exports.getMyTeam = function(success, error) { +export function getMyTeam(success, error) { $.ajax({ url: '/api/v1/teams/me', dataType: 'json', @@ -947,9 +945,9 @@ module.exports.getMyTeam = function(success, error) { error(e); } }); -}; +} -module.exports.updateValetFeature = function(data, success, error) { +export function updateValetFeature(data, success, error) { $.ajax({ url: '/api/v1/teams/update_valet_feature', dataType: 'json', @@ -963,10 +961,10 @@ module.exports.updateValetFeature = function(data, success, error) { } }); - module.exports.track('api', 'api_teams_update_valet_feature'); -}; + track('api', 'api_teams_update_valet_feature'); +} -function getConfig(success, error) { +export function getConfig(success, error) { $.ajax({ url: '/api/v1/config/get_all', dataType: 'json', @@ -979,4 +977,3 @@ function getConfig(success, error) { } }); } -module.exports.getConfig = getConfig; |