Files
mattermost/web/react/utils/client.jsx

1564 lines
43 KiB
React
Raw Normal View History

2015-06-14 23:53:32 -08:00
// See License.txt for license information.
import BrowserStore from '../stores/browser_store.jsx';
import TeamStore from '../stores/team_store.jsx';
import ErrorStore from '../stores/error_store.jsx';
2015-06-14 23:53:32 -08:00
2015-10-22 10:17:25 -07:00
export function track(category, action, label, property, value) {
global.window.analytics.track(action, {category, label, property, value});
2015-09-02 10:42:26 -04:00
}
2015-06-14 23:53:32 -08:00
2015-09-02 10:42:26 -04:00
export function trackPage() {
global.window.analytics.page();
2015-09-02 10:42:26 -04:00
}
2015-06-14 23:53:32 -08:00
2015-08-18 09:43:22 -04:00
function handleError(methodName, xhr, status, err) {
2015-06-14 23:53:32 -08:00
var e = null;
try {
e = JSON.parse(xhr.responseText);
} catch (parseError) {
2015-08-18 09:43:22 -04:00
e = null;
2015-06-14 23:53:32 -08:00
}
2015-08-18 09:43:22 -04:00
var msg = '';
2015-06-14 23:53:32 -08:00
if (e) {
2015-08-18 09:43:22 -04:00
msg = 'error in ' + methodName + ' msg=' + e.message + ' detail=' + e.detailed_error + ' rid=' + e.request_id;
} else {
msg = 'error in ' + methodName + ' status=' + status + ' statusCode=' + xhr.status + ' err=' + err;
2015-06-14 23:53:32 -08:00
2015-08-18 09:43:22 -04:00
if (xhr.status === 0) {
2015-10-06 16:17:27 -07:00
let errorCount = 1;
const oldError = ErrorStore.getLastError();
let connectError = 'There appears to be a problem with your internet connection';
if (oldError && oldError.connErrorCount) {
errorCount += oldError.connErrorCount;
connectError = 'Please check connection, Mattermost unreachable. If issue persists, ask administrator to check WebSocket port.';
2015-10-06 16:17:27 -07:00
}
e = {message: connectError, connErrorCount: errorCount};
2015-08-18 09:43:22 -04:00
} else {
e = {message: 'We received an unexpected status code from the server (' + xhr.status + ')'};
}
2015-06-14 23:53:32 -08:00
}
2015-08-18 09:43:22 -04:00
console.error(msg); //eslint-disable-line no-console
console.error(e); //eslint-disable-line no-console
2015-06-14 23:53:32 -08:00
2015-09-02 10:42:26 -04:00
track('api', 'api_weberror', methodName, 'message', msg);
2015-06-14 23:53:32 -08:00
2015-08-18 09:43:22 -04:00
if (xhr.status === 401) {
if (window.location.href.indexOf('/channels') === 0) {
window.location.pathname = '/login?redirect=' + encodeURIComponent(window.location.pathname + window.location.search);
} else {
var teamURL = window.location.href.split('/channels')[0];
2015-08-18 09:43:22 -04:00
window.location.href = teamURL + '/login?redirect=' + encodeURIComponent(window.location.pathname + window.location.search);
}
2015-06-14 23:53:32 -08:00
}
return e;
}
2016-01-21 13:54:21 -06:00
export function getTranslations(locale, success, error) {
$.ajax({
url: '/static/i18n/' + locale + '.json',
dataType: 'json',
success,
error: function onError(xhr, status, err) {
var e = handleError('getTranslations', xhr, status, err);
error(e);
}
});
}
2015-09-02 10:42:26 -04:00
export function createTeamFromSignup(teamSignup, success, error) {
2015-06-14 23:53:32 -08:00
$.ajax({
2015-08-18 09:43:22 -04:00
url: '/api/v1/teams/create_from_signup',
2015-06-14 23:53:32 -08:00
dataType: 'json',
contentType: 'application/json',
type: 'POST',
2015-08-18 09:43:22 -04:00
data: JSON.stringify(teamSignup),
2015-09-21 14:22:23 -04:00
success,
2015-08-18 09:43:22 -04:00
error: function onError(xhr, status, err) {
var e = handleError('createTeamFromSignup', xhr, status, err);
2015-06-14 23:53:32 -08:00
error(e);
}
});
2015-09-02 10:42:26 -04:00
}
2015-06-14 23:53:32 -08:00
2015-09-02 10:42:26 -04:00
export function createTeamWithSSO(team, service, success, error) {
$.ajax({
url: '/api/v1/teams/create_with_sso/' + service,
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify(team),
2015-09-21 14:22:23 -04:00
success,
error: function onError(xhr, status, err) {
var e = handleError('createTeamWithSSO', xhr, status, err);
error(e);
}
});
2015-09-02 10:42:26 -04:00
}
2015-09-02 10:42:26 -04:00
export function createUser(user, data, emailHash, success, error) {
2015-06-14 23:53:32 -08:00
$.ajax({
2015-08-18 09:43:22 -04:00
url: '/api/v1/users/create?d=' + encodeURIComponent(data) + '&h=' + encodeURIComponent(emailHash),
2015-06-14 23:53:32 -08:00
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify(user),
2015-09-21 14:22:23 -04:00
success,
2015-08-18 09:43:22 -04:00
error: function onError(xhr, status, err) {
var e = handleError('createUser', xhr, status, err);
2015-06-14 23:53:32 -08:00
error(e);
}
});
2015-09-02 10:42:26 -04:00
track('api', 'api_users_create', user.team_id, 'email', user.email);
}
2015-06-14 23:53:32 -08:00
2015-09-02 10:42:26 -04:00
export function updateUser(user, success, error) {
2015-06-14 23:53:32 -08:00
$.ajax({
2015-08-18 09:43:22 -04:00
url: '/api/v1/users/update',
2015-06-14 23:53:32 -08:00
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify(user),
2015-09-21 14:22:23 -04:00
success,
2015-08-18 09:43:22 -04:00
error: function onError(xhr, status, err) {
var e = handleError('updateUser', xhr, status, err);
2015-06-14 23:53:32 -08:00
error(e);
}
});
2015-09-02 10:42:26 -04:00
track('api', 'api_users_update');
}
2015-06-14 23:53:32 -08:00
2015-09-02 10:42:26 -04:00
export function updatePassword(data, success, error) {
2015-06-14 23:53:32 -08:00
$.ajax({
2015-08-18 09:43:22 -04:00
url: '/api/v1/users/newpassword',
2015-06-14 23:53:32 -08:00
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify(data),
2015-09-21 14:22:23 -04:00
success,
2015-08-18 09:43:22 -04:00
error: function onError(xhr, status, err) {
var e = handleError('newPassword', xhr, status, err);
2015-06-14 23:53:32 -08:00
error(e);
}
});
2015-09-02 10:42:26 -04:00
track('api', 'api_users_newpassword');
}
2015-06-14 23:53:32 -08:00
2015-09-02 10:42:26 -04:00
export function updateUserNotifyProps(data, success, error) {
2015-06-14 23:53:32 -08:00
$.ajax({
2015-08-18 09:43:22 -04:00
url: '/api/v1/users/update_notify',
2015-06-14 23:53:32 -08:00
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify(data),
2015-09-21 14:22:23 -04:00
success,
2015-08-18 09:43:22 -04:00
error: function onError(xhr, status, err) {
var e = handleError('updateUserNotifyProps', xhr, status, err);
2015-06-14 23:53:32 -08:00
error(e);
}
});
2015-09-02 10:42:26 -04:00
}
2015-06-14 23:53:32 -08:00
2015-09-02 10:42:26 -04:00
export function updateRoles(data, success, error) {
2015-06-14 23:53:32 -08:00
$.ajax({
2015-08-18 09:43:22 -04:00
url: '/api/v1/users/update_roles',
2015-06-14 23:53:32 -08:00
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify(data),
2015-09-21 14:22:23 -04:00
success,
2015-08-18 09:43:22 -04:00
error: function onError(xhr, status, err) {
var e = handleError('updateRoles', xhr, status, err);
2015-06-14 23:53:32 -08:00
error(e);
}
});
2015-09-02 10:42:26 -04:00
track('api', 'api_users_update_roles');
}
2015-06-14 23:53:32 -08:00
2015-09-02 10:42:26 -04:00
export function updateActive(userId, active, success, error) {
2015-08-18 09:43:22 -04:00
var data = {};
data.user_id = userId;
data.active = '' + active;
2015-06-14 23:53:32 -08:00
$.ajax({
2015-08-18 09:43:22 -04:00
url: '/api/v1/users/update_active',
2015-06-14 23:53:32 -08:00
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify(data),
2015-09-21 14:22:23 -04:00
success,
2015-08-18 09:43:22 -04:00
error: function onError(xhr, status, err) {
var e = handleError('updateActive', xhr, status, err);
2015-06-14 23:53:32 -08:00
error(e);
}
});
2015-09-02 10:42:26 -04:00
track('api', 'api_users_update_roles');
}
2015-06-14 23:53:32 -08:00
2015-09-02 10:42:26 -04:00
export function sendPasswordReset(data, success, error) {
2015-06-14 23:53:32 -08:00
$.ajax({
2015-08-18 09:43:22 -04:00
url: '/api/v1/users/send_password_reset',
2015-06-14 23:53:32 -08:00
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify(data),
2015-09-21 14:22:23 -04:00
success,
2015-08-18 09:43:22 -04:00
error: function onError(xhr, status, err) {
var e = handleError('sendPasswordReset', xhr, status, err);
2015-06-14 23:53:32 -08:00
error(e);
}
});
2015-09-02 10:42:26 -04:00
track('api', 'api_users_send_password_reset');
}
2015-06-14 23:53:32 -08:00
2015-09-02 10:42:26 -04:00
export function resetPassword(data, success, error) {
2015-06-14 23:53:32 -08:00
$.ajax({
2015-08-18 09:43:22 -04:00
url: '/api/v1/users/reset_password',
2015-06-14 23:53:32 -08:00
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify(data),
2015-09-21 14:22:23 -04:00
success,
2015-08-18 09:43:22 -04:00
error: function onError(xhr, status, err) {
var e = handleError('resetPassword', xhr, status, err);
2015-06-14 23:53:32 -08:00
error(e);
}
});
2015-09-02 10:42:26 -04:00
track('api', 'api_users_reset_password');
}
2015-06-14 23:53:32 -08:00
export function switchToSSO(data, success, error) {
$.ajax({
url: '/api/v1/users/switch_to_sso',
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify(data),
success,
error: function onError(xhr, status, err) {
var e = handleError('switchToSSO', xhr, status, err);
error(e);
}
});
track('api', 'api_users_switch_to_sso');
}
export function switchToEmail(data, success, error) {
$.ajax({
url: '/api/v1/users/switch_to_email',
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify(data),
success,
error: function onError(xhr, status, err) {
var e = handleError('switchToEmail', xhr, status, err);
error(e);
}
});
track('api', 'api_users_switch_to_email');
}
2015-09-02 10:42:26 -04:00
export function logout() {
track('api', 'api_users_logout');
var currentTeamUrl = TeamStore.getCurrentTeamUrl();
BrowserStore.signalLogout();
BrowserStore.clear();
2015-10-16 09:10:54 -07:00
ErrorStore.storeLastError(null);
2015-08-18 09:43:22 -04:00
window.location.href = currentTeamUrl + '/logout';
2015-09-02 10:42:26 -04:00
}
2015-06-14 23:53:32 -08:00
2015-09-02 10:42:26 -04:00
export function loginByEmail(name, email, password, success, error) {
2015-06-14 23:53:32 -08:00
$.ajax({
2015-08-18 09:43:22 -04:00
url: '/api/v1/users/login',
2015-06-14 23:53:32 -08:00
dataType: 'json',
contentType: 'application/json',
type: 'POST',
2015-12-08 13:38:43 -05:00
data: JSON.stringify({name, email, password}),
2015-08-18 09:43:22 -04:00
success: function onSuccess(data, textStatus, xhr) {
2015-09-02 10:42:26 -04:00
track('api', 'api_users_login_success', data.team_id, 'email', data.email);
sessionStorage.removeItem(data.id + '_last_error');
2015-12-14 15:21:22 -08:00
BrowserStore.signalLogin();
2015-06-14 23:53:32 -08:00
success(data, textStatus, xhr);
},
2015-08-18 09:43:22 -04:00
error: function onError(xhr, status, err) {
2015-09-02 10:42:26 -04:00
track('api', 'api_users_login_fail', name, 'email', email);
2015-06-14 23:53:32 -08:00
2015-08-18 09:43:22 -04:00
var e = handleError('loginByEmail', xhr, status, err);
2015-06-14 23:53:32 -08:00
error(e);
}
});
2015-09-02 10:42:26 -04:00
}
2015-06-14 23:53:32 -08:00
export function loginByUsername(name, username, password, success, error) {
$.ajax({
url: '/api/v1/users/login',
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify({name, username, password}),
success: function onSuccess(data, textStatus, xhr) {
track('api', 'api_users_login_success', data.team_id, 'username', data.username);
sessionStorage.removeItem(data.id + '_last_error');
BrowserStore.signalLogin();
success(data, textStatus, xhr);
},
error: function onError(xhr, status, err) {
track('api', 'api_users_login_fail', name, 'username', username);
var e = handleError('loginByUsername', xhr, status, err);
error(e);
}
});
}
2015-12-08 13:38:43 -05:00
export function loginByLdap(teamName, id, password, success, error) {
$.ajax({
url: '/api/v1/users/login_ldap',
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify({teamName, id, password}),
success: function onSuccess(data, textStatus, xhr) {
track('api', 'api_users_loginLdap_success', data.team_id, 'id', id);
sessionStorage.removeItem(data.id + '_last_error');
BrowserStore.signalLogin();
2015-12-08 13:38:43 -05:00
success(data, textStatus, xhr);
},
error: function onError(xhr, status, err) {
track('api', 'api_users_loginLdap_fail', teamName, 'id', id);
var e = handleError('loginByLdap', xhr, status, err);
error(e);
}
});
}
2015-09-02 10:42:26 -04:00
export function revokeSession(altId, success, error) {
2015-06-14 23:53:32 -08:00
$.ajax({
2015-08-18 09:43:22 -04:00
url: '/api/v1/users/revoke_session',
2015-06-14 23:53:32 -08:00
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify({id: altId}),
2015-09-21 14:22:23 -04:00
success,
2015-08-18 09:43:22 -04:00
error: function onError(xhr, status, err) {
var e = handleError('revokeSession', xhr, status, err);
2015-06-14 23:53:32 -08:00
error(e);
}
});
2015-09-02 10:42:26 -04:00
}
2015-06-14 23:53:32 -08:00
2015-09-02 10:42:26 -04:00
export function getSessions(userId, success, error) {
2015-06-14 23:53:32 -08:00
$.ajax({
cache: false,
2015-08-18 09:43:22 -04:00
url: '/api/v1/users/' + userId + '/sessions',
2015-06-14 23:53:32 -08:00
dataType: 'json',
contentType: 'application/json',
type: 'GET',
2015-09-21 14:22:23 -04:00
success,
2015-08-18 09:43:22 -04:00
error: function onError(xhr, status, err) {
var e = handleError('getSessions', xhr, status, err);
2015-06-14 23:53:32 -08:00
error(e);
}
});
2015-09-02 10:42:26 -04:00
}
2015-06-14 23:53:32 -08:00
2015-09-02 10:42:26 -04:00
export function getAudits(userId, success, error) {
2015-06-14 23:53:32 -08:00
$.ajax({
2015-08-18 09:43:22 -04:00
url: '/api/v1/users/' + userId + '/audits',
2015-06-14 23:53:32 -08:00
dataType: 'json',
contentType: 'application/json',
type: 'GET',
2015-09-21 14:22:23 -04:00
success,
2015-08-18 09:43:22 -04:00
error: function onError(xhr, status, err) {
var e = handleError('getAudits', xhr, status, err);
2015-06-14 23:53:32 -08:00
error(e);
}
});
2015-09-02 10:42:26 -04:00
}
2015-06-14 23:53:32 -08:00
2015-09-10 18:32:22 -07:00
export function getLogs(success, error) {
$.ajax({
url: '/api/v1/admin/logs',
dataType: 'json',
contentType: 'application/json',
type: 'GET',
success,
2015-09-10 18:32:22 -07:00
error: function onError(xhr, status, err) {
var e = handleError('getLogs', xhr, status, err);
error(e);
}
});
}
export function getServerAudits(success, error) {
$.ajax({
url: '/api/v1/admin/audits',
dataType: 'json',
contentType: 'application/json',
type: 'GET',
success,
error: function onError(xhr, status, err) {
var e = handleError('getServerAudits', xhr, status, err);
error(e);
}
});
}
export function getConfig(success, error) {
$.ajax({
url: '/api/v1/admin/config',
dataType: 'json',
contentType: 'application/json',
type: 'GET',
success,
error: function onError(xhr, status, err) {
var e = handleError('getConfig', xhr, status, err);
error(e);
}
});
}
export function getTeamAnalytics(teamId, name, success, error) {
2015-10-22 18:04:06 -07:00
$.ajax({
url: '/api/v1/admin/analytics/' + teamId + '/' + name,
dataType: 'json',
contentType: 'application/json',
type: 'GET',
success,
2015-10-26 22:13:40 -07:00
error: (xhr, status, err) => {
var e = handleError('getTeamAnalytics', xhr, status, err);
error(e);
}
});
}
2016-01-21 12:59:32 -05:00
export function getSystemAnalytics(name, success, error) {
$.ajax({
url: '/api/v1/admin/analytics/' + name,
dataType: 'json',
contentType: 'application/json',
type: 'GET',
success,
error: (xhr, status, err) => {
2016-01-21 12:59:32 -05:00
var e = handleError('getSystemAnalytics', xhr, status, err);
2015-10-22 18:04:06 -07:00
error(e);
}
});
}
export function saveConfig(config, success, error) {
$.ajax({
url: '/api/v1/admin/save_config',
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify(config),
success,
error: function onError(xhr, status, err) {
var e = handleError('saveConfig', xhr, status, err);
error(e);
}
});
}
2015-09-29 15:55:19 -07:00
export function logClientError(msg) {
var l = {};
l.level = 'ERROR';
l.message = msg;
$.ajax({
url: '/api/v1/admin/log_client',
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify(l)
});
}
2015-09-21 15:11:56 -07:00
export function testEmail(config, success, error) {
$.ajax({
url: '/api/v1/admin/test_email',
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify(config),
success,
error: function onError(xhr, status, err) {
var e = handleError('testEmail', xhr, status, err);
error(e);
}
});
}
export function getAllTeams(success, error) {
$.ajax({
url: '/api/v1/teams/all',
dataType: 'json',
contentType: 'application/json',
type: 'GET',
success,
error: function onError(xhr, status, err) {
var e = handleError('getAllTeams', xhr, status, err);
error(e);
}
});
}
2015-10-16 09:10:54 -07:00
export function getMe(success, error) {
var currentUser = null;
2015-06-14 23:53:32 -08:00
$.ajax({
cache: false,
2015-08-18 09:43:22 -04:00
url: '/api/v1/users/me',
2015-06-14 23:53:32 -08:00
dataType: 'json',
contentType: 'application/json',
type: 'GET',
success: function gotUser(data, textStatus, xhr) {
currentUser = data;
if (success) {
success(data, textStatus, xhr);
}
},
2015-08-18 09:43:22 -04:00
error: function onError(xhr, status, err) {
if (error) {
2015-10-16 09:10:54 -07:00
var e = handleError('getMe', xhr, status, err);
error(e);
2015-08-18 09:43:22 -04:00
}
2015-06-14 23:53:32 -08:00
}
});
return currentUser;
2015-09-02 10:42:26 -04:00
}
2015-06-14 23:53:32 -08:00
2015-09-02 10:42:26 -04:00
export function inviteMembers(data, success, error) {
2015-06-14 23:53:32 -08:00
$.ajax({
2015-08-18 09:43:22 -04:00
url: '/api/v1/teams/invite_members',
2015-06-14 23:53:32 -08:00
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify(data),
2015-09-21 14:22:23 -04:00
success,
2015-08-18 09:43:22 -04:00
error: function onError(xhr, status, err) {
var e = handleError('inviteMembers', xhr, status, err);
2015-06-14 23:53:32 -08:00
error(e);
}
});
2015-09-02 10:42:26 -04:00
track('api', 'api_teams_invite_members');
}
2015-06-14 23:53:32 -08:00
2015-10-27 22:18:52 -07:00
export function updateTeam(team, success, error) {
2015-06-14 23:53:32 -08:00
$.ajax({
2015-10-27 22:18:52 -07:00
url: '/api/v1/teams/update',
2015-06-14 23:53:32 -08:00
dataType: 'json',
contentType: 'application/json',
type: 'POST',
2015-10-27 22:18:52 -07:00
data: JSON.stringify(team),
2015-09-21 14:22:23 -04:00
success,
2015-10-27 22:18:52 -07:00
error: (xhr, status, err) => {
var e = handleError('updateTeam', xhr, status, err);
2015-06-14 23:53:32 -08:00
error(e);
}
});
2015-09-02 10:42:26 -04:00
track('api', 'api_teams_update_name');
}
2015-06-14 23:53:32 -08:00
2015-09-02 10:42:26 -04:00
export function signupTeam(email, success, error) {
2015-06-14 23:53:32 -08:00
$.ajax({
2015-08-18 09:43:22 -04:00
url: '/api/v1/teams/signup',
2015-06-14 23:53:32 -08:00
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify({email: email}),
2015-09-21 14:22:23 -04:00
success,
2015-08-18 09:43:22 -04:00
error: function onError(xhr, status, err) {
var e = handleError('singupTeam', xhr, status, err);
2015-06-14 23:53:32 -08:00
error(e);
}
});
2015-09-02 10:42:26 -04:00
track('api', 'api_teams_signup');
}
2015-06-14 23:53:32 -08:00
2015-09-02 10:42:26 -04:00
export function createTeam(team, success, error) {
2015-06-14 23:53:32 -08:00
$.ajax({
2015-08-18 09:43:22 -04:00
url: '/api/v1/teams/create',
2015-06-14 23:53:32 -08:00
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify(team),
2015-09-21 14:22:23 -04:00
success,
2015-08-18 09:43:22 -04:00
error: function onError(xhr, status, err) {
var e = handleError('createTeam', xhr, status, err);
2015-06-14 23:53:32 -08:00
error(e);
}
});
2015-09-02 10:42:26 -04:00
}
2015-06-14 23:53:32 -08:00
2015-09-02 10:42:26 -04:00
export function findTeamByName(teamName, success, error) {
2015-06-14 23:53:32 -08:00
$.ajax({
2015-08-18 09:43:22 -04:00
url: '/api/v1/teams/find_team_by_name',
2015-06-14 23:53:32 -08:00
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify({name: teamName}),
2015-09-21 14:22:23 -04:00
success,
2015-08-18 09:43:22 -04:00
error: function onError(xhr, status, err) {
var e = handleError('findTeamByName', xhr, status, err);
2015-06-14 23:53:32 -08:00
error(e);
}
});
2015-09-02 10:42:26 -04:00
}
2015-06-14 23:53:32 -08:00
2015-09-02 10:42:26 -04:00
export function findTeamsSendEmail(email, success, error) {
2015-06-14 23:53:32 -08:00
$.ajax({
2015-08-18 09:43:22 -04:00
url: '/api/v1/teams/email_teams',
2015-06-14 23:53:32 -08:00
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify({email: email}),
2015-09-21 14:22:23 -04:00
success,
2015-08-18 09:43:22 -04:00
error: function onError(xhr, status, err) {
var e = handleError('findTeamsSendEmail', xhr, status, err);
2015-06-14 23:53:32 -08:00
error(e);
}
});
2015-09-02 10:42:26 -04:00
track('api', 'api_teams_email_teams');
}
2015-06-14 23:53:32 -08:00
2015-09-02 10:42:26 -04:00
export function findTeams(email, success, error) {
2015-06-14 23:53:32 -08:00
$.ajax({
2015-08-18 09:43:22 -04:00
url: '/api/v1/teams/find_teams',
2015-06-14 23:53:32 -08:00
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify({email: email}),
2015-09-21 14:22:23 -04:00
success,
2015-08-18 09:43:22 -04:00
error: function onError(xhr, status, err) {
var e = handleError('findTeams', xhr, status, err);
2015-06-14 23:53:32 -08:00
error(e);
}
});
2015-09-02 10:42:26 -04:00
}
2015-06-14 23:53:32 -08:00
2015-09-02 10:42:26 -04:00
export function createChannel(channel, success, error) {
2015-06-14 23:53:32 -08:00
$.ajax({
2015-08-18 09:43:22 -04:00
url: '/api/v1/channels/create',
2015-06-14 23:53:32 -08:00
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify(channel),
2015-09-21 14:22:23 -04:00
success,
2015-08-18 09:43:22 -04:00
error: function onError(xhr, status, err) {
var e = handleError('createChannel', xhr, status, err);
2015-06-14 23:53:32 -08:00
error(e);
}
});
2015-09-02 10:42:26 -04:00
track('api', 'api_channels_create', channel.type, 'name', channel.name);
}
2015-06-14 23:53:32 -08:00
2015-09-02 10:42:26 -04:00
export function createDirectChannel(channel, userId, success, error) {
$.ajax({
url: '/api/v1/channels/create_direct',
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify({user_id: userId}),
2015-09-21 14:22:23 -04:00
success,
2015-09-02 10:42:26 -04:00
error: function onError(xhr, status, err) {
var e = handleError('createDirectChannel', xhr, status, err);
error(e);
}
});
2015-09-02 10:42:26 -04:00
track('api', 'api_channels_create_direct', channel.type, 'name', channel.name);
}
2015-09-02 10:42:26 -04:00
export function updateChannel(channel, success, error) {
2015-06-14 23:53:32 -08:00
$.ajax({
2015-08-18 09:43:22 -04:00
url: '/api/v1/channels/update',
2015-06-14 23:53:32 -08:00
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify(channel),
2015-09-21 14:22:23 -04:00
success,
2015-08-18 09:43:22 -04:00
error: function onError(xhr, status, err) {
var e = handleError('updateChannel', xhr, status, err);
2015-06-14 23:53:32 -08:00
error(e);
}
});
2015-09-02 10:42:26 -04:00
track('api', 'api_channels_update');
}
2015-06-14 23:53:32 -08:00
export function updateChannelHeader(channelId, header, success, error) {
const data = {
channel_id: channelId,
channel_header: header
};
2015-06-14 23:53:32 -08:00
$.ajax({
url: '/api/v1/channels/update_header',
2015-06-14 23:53:32 -08:00
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify(data),
2015-09-21 14:22:23 -04:00
success,
2015-08-18 09:43:22 -04:00
error: function onError(xhr, status, err) {
var e = handleError('updateChannelHeader', xhr, status, err);
2015-06-14 23:53:32 -08:00
error(e);
}
});
track('api', 'api_channels_header');
2015-09-02 10:42:26 -04:00
}
2015-06-14 23:53:32 -08:00
export function updateChannelPurpose(data, success, error) {
$.ajax({
url: '/api/v1/channels/update_purpose',
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify(data),
success,
error: function onError(xhr, status, err) {
var e = handleError('updateChannelPurpose', xhr, status, err);
error(e);
}
});
track('api', 'api_channels_purpose');
2015-09-02 10:42:26 -04:00
}
2015-06-14 23:53:32 -08:00
export function updateNotifyProps(data, success, error) {
2015-06-14 23:53:32 -08:00
$.ajax({
url: '/api/v1/channels/update_notify_props',
2015-06-14 23:53:32 -08:00
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify(data),
2015-09-21 14:22:23 -04:00
success,
2015-08-18 09:43:22 -04:00
error: function onError(xhr, status, err) {
var e = handleError('updateNotifyProps', xhr, status, err);
2015-06-14 23:53:32 -08:00
error(e);
}
});
2015-09-02 10:42:26 -04:00
}
2015-06-14 23:53:32 -08:00
2015-09-02 10:42:26 -04:00
export function joinChannel(id, success, error) {
2015-06-14 23:53:32 -08:00
$.ajax({
2015-08-18 09:43:22 -04:00
url: '/api/v1/channels/' + id + '/join',
2015-06-14 23:53:32 -08:00
dataType: 'json',
contentType: 'application/json',
type: 'POST',
2015-09-21 14:22:23 -04:00
success,
2015-08-18 09:43:22 -04:00
error: function onError(xhr, status, err) {
var e = handleError('joinChannel', xhr, status, err);
2015-06-14 23:53:32 -08:00
error(e);
}
});
2015-09-02 10:42:26 -04:00
track('api', 'api_channels_join');
}
2015-06-14 23:53:32 -08:00
2015-09-02 10:42:26 -04:00
export function leaveChannel(id, success, error) {
2015-06-14 23:53:32 -08:00
$.ajax({
2015-08-18 09:43:22 -04:00
url: '/api/v1/channels/' + id + '/leave',
2015-06-14 23:53:32 -08:00
dataType: 'json',
contentType: 'application/json',
type: 'POST',
2015-09-21 14:22:23 -04:00
success,
2015-08-18 09:43:22 -04:00
error: function onError(xhr, status, err) {
var e = handleError('leaveChannel', xhr, status, err);
2015-06-14 23:53:32 -08:00
error(e);
}
});
2015-09-02 10:42:26 -04:00
track('api', 'api_channels_leave');
}
2015-06-14 23:53:32 -08:00
2015-09-02 10:42:26 -04:00
export function deleteChannel(id, success, error) {
2015-06-14 23:53:32 -08:00
$.ajax({
2015-08-18 09:43:22 -04:00
url: '/api/v1/channels/' + id + '/delete',
2015-06-14 23:53:32 -08:00
dataType: 'json',
contentType: 'application/json',
type: 'POST',
2015-09-21 14:22:23 -04:00
success,
2015-08-18 09:43:22 -04:00
error: function onError(xhr, status, err) {
var e = handleError('deleteChannel', xhr, status, err);
2015-06-14 23:53:32 -08:00
error(e);
}
});
2015-09-02 10:42:26 -04:00
track('api', 'api_channels_delete');
}
2015-06-14 23:53:32 -08:00
2015-09-02 10:42:26 -04:00
export function updateLastViewedAt(channelId, success, error) {
2015-06-14 23:53:32 -08:00
$.ajax({
2015-08-18 09:43:22 -04:00
url: '/api/v1/channels/' + channelId + '/update_last_viewed_at',
2015-06-14 23:53:32 -08:00
dataType: 'json',
contentType: 'application/json',
type: 'POST',
2015-09-21 14:22:23 -04:00
success,
2015-08-18 09:43:22 -04:00
error: function onError(xhr, status, err) {
var e = handleError('updateLastViewedAt', xhr, status, err);
2015-06-14 23:53:32 -08:00
error(e);
}
});
2015-09-02 10:42:26 -04:00
}
2015-06-14 23:53:32 -08:00
2015-09-02 10:42:26 -04:00
export function getChannels(success, error) {
2015-06-14 23:53:32 -08:00
$.ajax({
cache: false,
url: '/api/v1/channels/',
2015-06-14 23:53:32 -08:00
dataType: 'json',
type: 'GET',
2015-09-21 14:22:23 -04:00
success,
2015-06-14 23:53:32 -08:00
ifModified: true,
2015-08-18 09:43:22 -04:00
error: function onError(xhr, status, err) {
var e = handleError('getChannels', xhr, status, err);
2015-06-14 23:53:32 -08:00
error(e);
}
});
}
2015-06-14 23:53:32 -08:00
2015-09-02 10:42:26 -04:00
export function getChannel(id, success, error) {
$.ajax({
cache: false,
2015-08-18 09:43:22 -04:00
url: '/api/v1/channels/' + id + '/',
dataType: 'json',
type: 'GET',
2015-09-21 14:22:23 -04:00
success,
2015-08-18 09:43:22 -04:00
error: function onError(xhr, status, err) {
var e = handleError('getChannel', xhr, status, err);
error(e);
}
});
2015-09-02 10:42:26 -04:00
track('api', 'api_channel_get');
}
2015-09-02 10:42:26 -04:00
export function getMoreChannels(success, error) {
2015-06-14 23:53:32 -08:00
$.ajax({
2015-08-18 09:43:22 -04:00
url: '/api/v1/channels/more',
2015-06-14 23:53:32 -08:00
dataType: 'json',
type: 'GET',
2015-09-21 14:22:23 -04:00
success,
2015-06-14 23:53:32 -08:00
ifModified: true,
2015-08-18 09:43:22 -04:00
error: function onError(xhr, status, err) {
var e = handleError('getMoreChannels', xhr, status, err);
2015-06-14 23:53:32 -08:00
error(e);
}
});
2015-09-02 10:42:26 -04:00
}
2015-06-14 23:53:32 -08:00
2015-09-02 10:42:26 -04:00
export function getChannelCounts(success, error) {
$.ajax({
cache: false,
url: '/api/v1/channels/counts',
dataType: 'json',
type: 'GET',
2015-09-21 14:22:23 -04:00
success,
ifModified: true,
2015-08-18 09:43:22 -04:00
error: function onError(xhr, status, err) {
var e = handleError('getChannelCounts', xhr, status, err);
error(e);
}
});
}
export function getChannelExtraInfo(id, memberLimit, success, error) {
let url = '/api/v1/channels/' + id + '/extra_info';
if (memberLimit) {
url += '/' + memberLimit;
}
2015-06-14 23:53:32 -08:00
$.ajax({
url,
2015-06-14 23:53:32 -08:00
dataType: 'json',
contentType: 'application/json',
2015-06-14 23:53:32 -08:00
type: 'GET',
2015-09-21 14:22:23 -04:00
success,
2015-08-18 09:43:22 -04:00
error: function onError(xhr, status, err) {
var e = handleError('getChannelExtraInfo', xhr, status, err);
2015-06-14 23:53:32 -08:00
error(e);
}
});
2015-09-02 10:42:26 -04:00
}
2015-06-14 23:53:32 -08:00
2015-09-02 10:42:26 -04:00
export function executeCommand(channelId, command, suggest, success, error) {
2015-06-14 23:53:32 -08:00
$.ajax({
2016-01-08 12:41:26 -06:00
url: '/api/v1/commands/execute',
2015-06-14 23:53:32 -08:00
dataType: 'json',
contentType: 'application/json',
type: 'POST',
2016-01-14 10:52:14 -06:00
data: JSON.stringify({channelId, command, suggest: '' + suggest}),
2015-09-21 14:22:23 -04:00
success,
2015-08-18 09:43:22 -04:00
error: function onError(xhr, status, err) {
var e = handleError('executeCommand', xhr, status, err);
2015-06-14 23:53:32 -08:00
error(e);
}
});
2015-09-02 10:42:26 -04:00
}
2015-06-14 23:53:32 -08:00
2016-01-14 10:52:14 -06:00
export function addCommand(cmd, success, error) {
$.ajax({
url: '/api/v1/commands/create',
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify(cmd),
success,
error: (xhr, status, err) => {
var e = handleError('addCommand', xhr, status, err);
error(e);
}
});
}
export function deleteCommand(data, success, error) {
$.ajax({
url: '/api/v1/commands/delete',
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify(data),
success,
error: (xhr, status, err) => {
var e = handleError('deleteCommand', xhr, status, err);
error(e);
}
});
}
export function listTeamCommands(success, error) {
$.ajax({
url: '/api/v1/commands/list_team_commands',
dataType: 'json',
type: 'GET',
success,
error: (xhr, status, err) => {
var e = handleError('listTeamCommands', xhr, status, err);
error(e);
}
});
}
export function regenCommandToken(data, success, error) {
$.ajax({
url: '/api/v1/commands/regen_token',
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify(data),
success,
error: (xhr, status, err) => {
var e = handleError('regenCommandToken', xhr, status, err);
error(e);
}
});
}
2016-01-08 12:41:26 -06:00
export function listCommands(success, error) {
$.ajax({
url: '/api/v1/commands/list',
dataType: 'json',
contentType: 'application/json',
2016-01-09 09:22:14 -06:00
type: 'GET',
2016-01-08 12:41:26 -06:00
success,
error: function onError(xhr, status, err) {
var e = handleError('listCommands', xhr, status, err);
error(e);
}
});
}
2015-09-02 10:42:26 -04:00
export function getPostsPage(channelId, offset, limit, success, error, complete) {
2015-06-14 23:53:32 -08:00
$.ajax({
cache: false,
2015-08-18 09:43:22 -04:00
url: '/api/v1/channels/' + channelId + '/posts/' + offset + '/' + limit,
2015-06-14 23:53:32 -08:00
dataType: 'json',
type: 'GET',
ifModified: true,
2015-09-21 14:22:23 -04:00
success,
2015-08-18 09:43:22 -04:00
error: function onError(xhr, status, err) {
var e = handleError('getPosts', xhr, status, err);
error(e);
},
complete: complete
});
2015-09-02 10:42:26 -04:00
}
2015-09-02 10:42:26 -04:00
export function getPosts(channelId, since, success, error, complete) {
$.ajax({
url: '/api/v1/channels/' + channelId + '/posts/' + since,
dataType: 'json',
type: 'GET',
ifModified: true,
2015-09-21 14:22:23 -04:00
success,
error: function onError(xhr, status, err) {
var e = handleError('getPosts', xhr, status, err);
2015-08-18 09:43:22 -04:00
error(e);
2015-06-14 23:53:32 -08:00
},
complete: complete
});
2015-09-02 10:42:26 -04:00
}
2015-06-14 23:53:32 -08:00
export function getPostsBefore(channelId, post, offset, numPost, success, error, complete) {
$.ajax({
url: '/api/v1/channels/' + channelId + '/post/' + post + '/before/' + offset + '/' + numPost,
dataType: 'json',
type: 'GET',
ifModified: false,
success,
error: function onError(xhr, status, err) {
var e = handleError('getPostsBefore', xhr, status, err);
error(e);
},
complete: complete
});
}
export function getPostsAfter(channelId, post, offset, numPost, success, error, complete) {
$.ajax({
url: '/api/v1/channels/' + channelId + '/post/' + post + '/after/' + offset + '/' + numPost,
dataType: 'json',
type: 'GET',
ifModified: false,
success,
error: function onError(xhr, status, err) {
var e = handleError('getPostsAfter', xhr, status, err);
error(e);
},
complete: complete
});
}
export function getPost(channelId, postId, success, error, complete) {
2015-06-14 23:53:32 -08:00
$.ajax({
cache: false,
2015-08-18 09:43:22 -04:00
url: '/api/v1/channels/' + channelId + '/post/' + postId,
2015-06-14 23:53:32 -08:00
dataType: 'json',
type: 'GET',
ifModified: false,
2015-09-21 14:22:23 -04:00
success,
2015-08-18 09:43:22 -04:00
error: function onError(xhr, status, err) {
var e = handleError('getPost', xhr, status, err);
2015-06-14 23:53:32 -08:00
error(e);
},
complete
});
}
export function getPostById(postId, success, error, complete) {
$.ajax({
cache: false,
url: '/api/v1/posts/' + postId,
dataType: 'json',
type: 'GET',
ifModified: false,
success,
error: function onError(xhr, status, err) {
var e = handleError('getPostById', xhr, status, err);
error(e);
},
complete
2015-06-14 23:53:32 -08:00
});
2015-09-02 10:42:26 -04:00
}
2015-06-14 23:53:32 -08:00
2015-09-02 10:42:26 -04:00
export function search(terms, success, error) {
2015-06-14 23:53:32 -08:00
$.ajax({
2015-08-18 09:43:22 -04:00
url: '/api/v1/posts/search',
2015-06-14 23:53:32 -08:00
dataType: 'json',
type: 'GET',
2015-08-18 09:43:22 -04:00
data: {terms: terms},
2015-09-21 14:22:23 -04:00
success,
2015-08-18 09:43:22 -04:00
error: function onError(xhr, status, err) {
var e = handleError('search', xhr, status, err);
2015-06-14 23:53:32 -08:00
error(e);
}
});
2015-09-02 10:42:26 -04:00
track('api', 'api_posts_search');
}
2015-06-14 23:53:32 -08:00
2015-09-02 10:42:26 -04:00
export function deletePost(channelId, id, success, error) {
2015-06-14 23:53:32 -08:00
$.ajax({
2015-08-18 09:43:22 -04:00
url: '/api/v1/channels/' + channelId + '/post/' + id + '/delete',
2015-06-14 23:53:32 -08:00
dataType: 'json',
contentType: 'application/json',
type: 'POST',
2015-09-21 14:22:23 -04:00
success,
2015-08-18 09:43:22 -04:00
error: function onError(xhr, status, err) {
var e = handleError('deletePost', xhr, status, err);
2015-06-14 23:53:32 -08:00
error(e);
}
});
2015-09-02 10:42:26 -04:00
track('api', 'api_posts_delete');
}
2015-06-14 23:53:32 -08:00
2015-09-02 10:42:26 -04:00
export function createPost(post, channel, success, error) {
2015-06-14 23:53:32 -08:00
$.ajax({
2015-08-18 09:43:22 -04:00
url: '/api/v1/channels/' + post.channel_id + '/create',
2015-06-14 23:53:32 -08:00
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify(post),
2015-09-21 14:22:23 -04:00
success,
2015-08-18 09:43:22 -04:00
error: function onError(xhr, status, err) {
var e = handleError('createPost', xhr, status, err);
2015-06-14 23:53:32 -08:00
error(e);
}
});
2015-09-02 10:42:26 -04:00
track('api', 'api_posts_create', channel.name, 'length', post.message.length);
2015-06-14 23:53:32 -08:00
// global.window.analytics.track('api_posts_create', {
// category: 'api',
// channel_name: channel.name,
// channel_type: channel.type,
// length: post.message.length,
// files: (post.filenames || []).length,
2015-08-18 09:43:22 -04:00
// mentions: (post.message.match('/<mention>/g') || []).length
2015-06-14 23:53:32 -08:00
// });
2015-09-02 10:42:26 -04:00
}
2015-06-14 23:53:32 -08:00
2015-09-02 10:42:26 -04:00
export function updatePost(post, success, error) {
2015-06-14 23:53:32 -08:00
$.ajax({
2015-08-18 09:43:22 -04:00
url: '/api/v1/channels/' + post.channel_id + '/update',
2015-06-14 23:53:32 -08:00
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify(post),
2015-09-21 14:22:23 -04:00
success,
2015-08-18 09:43:22 -04:00
error: function onError(xhr, status, err) {
var e = handleError('updatePost', xhr, status, err);
2015-06-14 23:53:32 -08:00
error(e);
}
});
2015-09-02 10:42:26 -04:00
track('api', 'api_posts_update');
}
2015-06-14 23:53:32 -08:00
2015-09-02 10:42:26 -04:00
export function addChannelMember(id, data, success, error) {
2015-06-14 23:53:32 -08:00
$.ajax({
2015-08-18 09:43:22 -04:00
url: '/api/v1/channels/' + id + '/add',
2015-06-14 23:53:32 -08:00
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify(data),
2015-09-21 14:22:23 -04:00
success,
2015-08-18 09:43:22 -04:00
error: function onError(xhr, status, err) {
var e = handleError('addChannelMember', xhr, status, err);
2015-06-14 23:53:32 -08:00
error(e);
}
});
2015-09-02 10:42:26 -04:00
track('api', 'api_channels_add_member');
}
2015-06-14 23:53:32 -08:00
2015-09-02 10:42:26 -04:00
export function removeChannelMember(id, data, success, error) {
2015-06-14 23:53:32 -08:00
$.ajax({
2015-08-18 09:43:22 -04:00
url: '/api/v1/channels/' + id + '/remove',
2015-06-14 23:53:32 -08:00
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify(data),
2015-09-21 14:22:23 -04:00
success,
2015-08-18 09:43:22 -04:00
error: function onError(xhr, status, err) {
var e = handleError('removeChannelMember', xhr, status, err);
2015-06-14 23:53:32 -08:00
error(e);
}
});
2015-09-02 10:42:26 -04:00
track('api', 'api_channels_remove_member');
}
2015-06-14 23:53:32 -08:00
2015-09-02 10:42:26 -04:00
export function getProfiles(success, error) {
2015-06-14 23:53:32 -08:00
$.ajax({
cache: false,
2015-08-18 09:43:22 -04:00
url: '/api/v1/users/profiles',
2015-06-14 23:53:32 -08:00
dataType: 'json',
contentType: 'application/json',
type: 'GET',
2015-09-21 14:22:23 -04:00
success,
2015-06-14 23:53:32 -08:00
ifModified: true,
2015-08-18 09:43:22 -04:00
error: function onError(xhr, status, err) {
var e = handleError('getProfiles', xhr, status, err);
2015-06-14 23:53:32 -08:00
error(e);
}
});
2015-09-02 10:42:26 -04:00
}
2015-06-14 23:53:32 -08:00
export function getProfilesForTeam(teamId, success, error) {
$.ajax({
cache: false,
url: '/api/v1/users/profiles/' + teamId,
dataType: 'json',
contentType: 'application/json',
type: 'GET',
success,
error: function onError(xhr, status, err) {
var e = handleError('getProfilesForTeam', xhr, status, err);
error(e);
}
});
}
2015-09-02 10:42:26 -04:00
export function uploadFile(formData, success, error) {
var request = $.ajax({
2015-08-18 09:43:22 -04:00
url: '/api/v1/files/upload',
2015-06-14 23:53:32 -08:00
type: 'POST',
data: formData,
cache: false,
contentType: false,
processData: false,
2015-09-21 14:22:23 -04:00
success,
2015-08-18 09:43:22 -04:00
error: function onError(xhr, status, err) {
if (err !== 'abort') {
2015-08-18 09:43:22 -04:00
var e = handleError('uploadFile', xhr, status, err);
error(e);
}
2015-06-14 23:53:32 -08:00
}
});
2015-09-02 10:42:26 -04:00
track('api', 'api_files_upload');
return request;
2015-09-02 10:42:26 -04:00
}
2015-06-14 23:53:32 -08:00
2015-09-02 10:42:26 -04:00
export function getFileInfo(filename, success, error) {
$.ajax({
url: '/api/v1/files/get_info' + filename,
dataType: 'json',
contentType: 'application/json',
type: 'GET',
success: (data) => {
success(data);
},
error: function onError(xhr, status, err) {
var e = handleError('getFileInfo', xhr, status, err);
error(e);
}
});
2015-09-02 10:42:26 -04:00
}
2015-09-02 10:42:26 -04:00
export function getPublicLink(data, success, error) {
2015-06-14 23:53:32 -08:00
$.ajax({
2015-08-18 09:43:22 -04:00
url: '/api/v1/files/get_public_link',
2015-06-14 23:53:32 -08:00
dataType: 'json',
type: 'POST',
data: JSON.stringify(data),
2015-09-21 14:22:23 -04:00
success,
2015-08-18 09:43:22 -04:00
error: function onError(xhr, status, err) {
var e = handleError('getPublicLink', xhr, status, err);
2015-06-14 23:53:32 -08:00
error(e);
}
});
2015-09-02 10:42:26 -04:00
}
2015-06-14 23:53:32 -08:00
2015-09-02 10:42:26 -04:00
export function uploadProfileImage(imageData, success, error) {
2015-06-14 23:53:32 -08:00
$.ajax({
2015-08-18 09:43:22 -04:00
url: '/api/v1/users/newimage',
2015-06-14 23:53:32 -08:00
type: 'POST',
data: imageData,
cache: false,
contentType: false,
processData: false,
2015-09-21 14:22:23 -04:00
success,
2015-08-18 09:43:22 -04:00
error: function onError(xhr, status, err) {
var e = handleError('uploadProfileImage', xhr, status, err);
2015-06-14 23:53:32 -08:00
error(e);
}
});
2015-09-02 10:42:26 -04:00
}
2015-06-14 23:53:32 -08:00
2015-09-02 10:42:26 -04:00
export function importSlack(fileData, success, error) {
2015-07-07 09:16:13 -04:00
$.ajax({
url: '/api/v1/teams/import_team',
2015-07-07 09:16:13 -04:00
type: 'POST',
data: fileData,
cache: false,
contentType: false,
processData: false,
2015-09-21 14:22:23 -04:00
success,
2015-08-18 09:43:22 -04:00
error: function onError(xhr, status, err) {
var e = handleError('importTeam', xhr, status, err);
2015-07-07 09:16:13 -04:00
error(e);
}
});
2015-09-02 10:42:26 -04:00
}
2015-07-07 09:16:13 -04:00
export function exportTeam(success, error) {
$.ajax({
url: '/api/v1/teams/export_team',
type: 'GET',
dataType: 'json',
2015-09-21 14:22:23 -04:00
success,
error: function onError(xhr, status, err) {
var e = handleError('exportTeam', xhr, status, err);
error(e);
}
});
}
export function getStatuses(ids, success, error) {
2015-06-14 23:53:32 -08:00
$.ajax({
2015-08-18 09:43:22 -04:00
url: '/api/v1/users/status',
2015-06-14 23:53:32 -08:00
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify(ids),
2015-09-21 14:22:23 -04:00
success,
2015-08-18 09:43:22 -04:00
error: function onError(xhr, status, err) {
var e = handleError('getStatuses', xhr, status, err);
2015-06-14 23:53:32 -08:00
error(e);
}
});
2015-09-02 10:42:26 -04:00
}
2015-09-02 10:42:26 -04:00
export function getMyTeam(success, error) {
$.ajax({
2015-08-18 09:43:22 -04:00
url: '/api/v1/teams/me',
dataType: 'json',
type: 'GET',
2015-09-21 14:22:23 -04:00
success,
ifModified: true,
2015-08-18 09:43:22 -04:00
error: function onError(xhr, status, err) {
var e = handleError('getMyTeam', xhr, status, err);
error(e);
}
});
2015-09-02 10:42:26 -04:00
}
export function registerOAuthApp(app, success, error) {
$.ajax({
url: '/api/v1/oauth/register',
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify(app),
success: success,
error: (xhr, status, err) => {
const e = handleError('registerApp', xhr, status, err);
error(e);
}
});
module.exports.track('api', 'api_apps_register');
}
export function allowOAuth2(responseType, clientId, redirectUri, state, scope, success, error) {
$.ajax({
url: '/api/v1/oauth/allow?response_type=' + responseType + '&client_id=' + clientId + '&redirect_uri=' + redirectUri + '&scope=' + scope + '&state=' + state,
dataType: 'json',
contentType: 'application/json',
type: 'GET',
2015-09-21 14:22:23 -04:00
success,
error: (xhr, status, err) => {
const e = handleError('allowOAuth2', xhr, status, err);
error(e);
}
});
module.exports.track('api', 'api_users_allow_oauth2');
}
2015-09-21 14:22:23 -04:00
export function addIncomingHook(hook, success, error) {
$.ajax({
url: '/api/v1/hooks/incoming/create',
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify(hook),
success,
error: (xhr, status, err) => {
var e = handleError('addIncomingHook', xhr, status, err);
error(e);
}
});
}
export function deleteIncomingHook(data, success, error) {
$.ajax({
url: '/api/v1/hooks/incoming/delete',
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify(data),
success,
error: (xhr, status, err) => {
var e = handleError('deleteIncomingHook', xhr, status, err);
error(e);
}
});
}
export function listIncomingHooks(success, error) {
$.ajax({
url: '/api/v1/hooks/incoming/list',
dataType: 'json',
type: 'GET',
success,
error: (xhr, status, err) => {
var e = handleError('listIncomingHooks', xhr, status, err);
error(e);
}
});
}
export function getAllPreferences(success, error) {
$.ajax({
url: `/api/v1/preferences/`,
dataType: 'json',
type: 'GET',
success,
error: (xhr, status, err) => {
var e = handleError('getAllPreferences', xhr, status, err);
error(e);
}
});
}
2015-10-13 11:52:17 -04:00
export function getPreferenceCategory(category, success, error) {
$.ajax({
2015-10-13 11:52:17 -04:00
url: `/api/v1/preferences/${category}`,
dataType: 'json',
type: 'GET',
success,
error: (xhr, status, err) => {
2015-10-13 11:52:17 -04:00
var e = handleError('getPreferenceCategory', xhr, status, err);
error(e);
}
});
}
2015-10-13 11:52:17 -04:00
export function savePreferences(preferences, success, error) {
$.ajax({
2015-10-13 11:52:17 -04:00
url: '/api/v1/preferences/save',
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify(preferences),
success,
error: (xhr, status, err) => {
2015-10-13 11:52:17 -04:00
var e = handleError('savePreferences', xhr, status, err);
error(e);
}
});
}
2015-10-01 14:07:20 -04:00
export function addOutgoingHook(hook, success, error) {
$.ajax({
url: '/api/v1/hooks/outgoing/create',
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify(hook),
success,
error: (xhr, status, err) => {
var e = handleError('addOutgoingHook', xhr, status, err);
error(e);
}
});
}
export function deleteOutgoingHook(data, success, error) {
$.ajax({
url: '/api/v1/hooks/outgoing/delete',
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify(data),
success,
error: (xhr, status, err) => {
var e = handleError('deleteOutgoingHook', xhr, status, err);
error(e);
}
});
}
export function listOutgoingHooks(success, error) {
$.ajax({
url: '/api/v1/hooks/outgoing/list',
dataType: 'json',
type: 'GET',
success,
error: (xhr, status, err) => {
var e = handleError('listOutgoingHooks', xhr, status, err);
error(e);
}
});
}
export function regenOutgoingHookToken(data, success, error) {
$.ajax({
url: '/api/v1/hooks/outgoing/regen_token',
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify(data),
success,
error: (xhr, status, err) => {
var e = handleError('regenOutgoingHookToken', xhr, status, err);
error(e);
}
});
}
2016-01-04 12:44:22 -05:00
export function uploadLicenseFile(formData, success, error) {
$.ajax({
url: '/api/v1/license/add',
type: 'POST',
data: formData,
cache: false,
contentType: false,
processData: false,
success,
error: function onError(xhr, status, err) {
var e = handleError('uploadLicenseFile', xhr, status, err);
error(e);
}
});
track('api', 'api_license_upload');
}
export function removeLicenseFile(success, error) {
$.ajax({
url: '/api/v1/license/remove',
type: 'POST',
cache: false,
contentType: false,
processData: false,
success,
error: function onError(xhr, status, err) {
var e = handleError('removeLicenseFile', xhr, status, err);
error(e);
}
});
track('api', 'api_license_upload');
}