refactor: use alerts.error/success

isekai-main
Barış Soner Uşaklı 3 years ago
parent 4f4236101b
commit cba78aee16

@ -1,6 +1,6 @@
'use strict';
define('admin/advanced/cache', function () {
define('admin/advanced/cache', ['alerts'], function (alerts) {
const Cache = {};
Cache.init = function () {
require(['admin/settings'], function (Settings) {
@ -11,7 +11,7 @@ define('admin/advanced/cache', function () {
const name = $(this).attr('data-name');
socket.emit('admin.cache.clear', { name: name }, function (err) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
ajaxify.refresh();
});
@ -23,7 +23,7 @@ define('admin/advanced/cache', function () {
const name = $(this).attr('data-name');
socket.emit('admin.cache.toggle', { name: name, enabled: flag }, function (err) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
});
});

@ -1,7 +1,7 @@
'use strict';
define('admin/advanced/errors', ['bootbox', 'Chart'], function (bootbox, Chart) {
define('admin/advanced/errors', ['bootbox', 'alerts', 'Chart'], function (bootbox, alerts, Chart) {
const Errors = {};
Errors.init = function () {
@ -15,11 +15,11 @@ define('admin/advanced/errors', ['bootbox', 'Chart'], function (bootbox, Chart)
if (ok) {
socket.emit('admin.errors.clear', {}, function (err) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
ajaxify.refresh();
app.alertSuccess('[[admin/advanced/errors:clear404-success]]');
alerts.success('[[admin/advanced/errors:clear404-success]]');
});
}
});

@ -1,7 +1,7 @@
'use strict';
define('admin/advanced/events', ['bootbox'], function (bootbox) {
define('admin/advanced/events', ['bootbox', 'alerts'], function (bootbox, alerts) {
const Events = {};
Events.init = function () {
@ -10,7 +10,7 @@ define('admin/advanced/events', ['bootbox'], function (bootbox) {
if (confirm) {
socket.emit('admin.deleteAllEvents', function (err) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
$('.events-list').empty();
});
@ -23,7 +23,7 @@ define('admin/advanced/events', ['bootbox'], function (bootbox) {
const eid = $parentEl.attr('data-eid');
socket.emit('admin.deleteEvents', [eid], function (err) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
$parentEl.remove();
});

@ -1,7 +1,7 @@
'use strict';
define('admin/advanced/logs', function () {
define('admin/advanced/logs', ['alerts'], function (alerts) {
const Logs = {};
Logs.init = function () {
@ -21,7 +21,7 @@ define('admin/advanced/logs', function () {
logsEl.text(logs);
logsEl.scrollTop(logsEl.prop('scrollHeight'));
} else {
app.alertError(err.message);
alerts.error(err);
}
});
break;
@ -29,8 +29,10 @@ define('admin/advanced/logs', function () {
case 'clear':
socket.emit('admin.logs.clear', function (err) {
if (!err) {
app.alertSuccess('[[admin/advanced/logs:clear-success]]');
alerts.success('[[admin/advanced/logs:clear-success]]');
btnEl.prev().click();
} else {
alerts.error(err);
}
});
break;

@ -1,7 +1,9 @@
'use strict';
define('admin/dashboard', ['Chart', 'translator', 'benchpress', 'bootbox'], function (Chart, translator, Benchpress, bootbox) {
define('admin/dashboard', [
'Chart', 'translator', 'benchpress', 'bootbox', 'alerts',
], function (Chart, translator, Benchpress, bootbox, alerts) {
const Admin = {};
const intervals = {
rooms: false,
@ -53,7 +55,7 @@ define('admin/dashboard', ['Chart', 'translator', 'benchpress', 'bootbox'], func
Admin.updateRoomUsage = function (err, data) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
if (JSON.stringify(graphData.rooms) === JSON.stringify(data)) {
@ -425,7 +427,7 @@ define('admin/dashboard', ['Chart', 'translator', 'benchpress', 'bootbox'], func
amount: amount,
}, function (err, data) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
if (JSON.stringify(graphData.traffic) === JSON.stringify(data)) {
return;

@ -169,7 +169,7 @@ define('admin/extend/plugins', [
submitPluginUsage: $(this).prop('checked') ? '1' : '0',
}, function (err) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
});
});
@ -178,7 +178,7 @@ define('admin/extend/plugins', [
$('#order-active-plugins-modal').modal('show');
socket.emit('admin.plugins.getActive', function (err, activePlugins) {
if (err) {
return app.alertError(err);
return alerts.error(err);
}
let html = '';
activePlugins.forEach(function (plugin) {

@ -1,7 +1,7 @@
'use strict';
define('admin/extend/rewards', [], function () {
define('admin/extend/rewards', ['alerts'], function (alerts) {
const rewards = {};
@ -30,9 +30,9 @@ define('admin/extend/rewards', [], function () {
socket.emit('admin.rewards.delete', { id: id }, function (err) {
if (err) {
app.alertError(err.message);
alerts.error(err);
} else {
app.alertSuccess('[[admin/extend/rewards:alert.delete-success]]');
alerts.success('[[admin/extend/rewards:alert.delete-success]]');
}
});
@ -88,7 +88,7 @@ define('admin/extend/rewards', [], function () {
}
if (!inputs) {
return app.alertError('[[admin/extend/rewards:alert.no-inputs-found]] ' + el.attr('data-selected'));
return alerts.error('[[admin/extend/rewards:alert.no-inputs-found]] ' + el.attr('data-selected'));
}
inputs.forEach(function (input) {
@ -169,9 +169,9 @@ define('admin/extend/rewards', [], function () {
socket.emit('admin.rewards.save', activeRewards, function (err, result) {
if (err) {
app.alertError(err.message);
alerts.error(err);
} else {
app.alertSuccess('[[admin/extend/rewards:alert.save-success]]');
alerts.success('[[admin/extend/rewards:alert.save-success]]');
// newly added rewards are missing data-id, update to prevent rewards getting duplicated
$('#active li').each(function (index) {
if (!$(this).attr('data-id')) {

@ -245,7 +245,7 @@ define('admin/extend/widgets', [
cloneBtn.on('click', function () {
const template = cloneBtn.attr('data-template');
if (!template) {
return app.alertError('[[admin/extend/widgets:error.select-clone]]');
return alerts.error('[[admin/extend/widgets:error.select-clone]]');
}
const currentTemplate = $('#active-widgets .active.tab-pane[data-template] .area');
@ -274,7 +274,7 @@ define('admin/extend/widgets', [
clone(location);
}
app.alertSuccess('[[admin/extend/widgets:alert.clone-success]]');
alerts.success('[[admin/extend/widgets:alert.clone-success]]');
});
}

@ -1,17 +1,17 @@
'use strict';
define('admin/manage/admins-mods', [
'autocomplete', 'api', 'bootbox', 'categorySelector',
], function (autocomplete, api, bootbox, categorySelector) {
'autocomplete', 'api', 'bootbox', 'alerts', 'categorySelector',
], function (autocomplete, api, bootbox, alerts, categorySelector) {
const AdminsMods = {};
AdminsMods.init = function () {
autocomplete.user($('#admin-search'), function (ev, ui) {
socket.emit('admin.user.makeAdmins', [ui.item.user.uid], function (err) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
app.alertSuccess('[[admin/manage/users:alerts.make-admin-success]]');
alerts.success('[[admin/manage/users:alerts.make-admin-success]]');
$('#admin-search').val('');
if ($('.administrator-area [data-uid="' + ui.item.user.uid + '"]').length) {
@ -28,15 +28,15 @@ define('admin/manage/admins-mods', [
const userCard = $(this).parents('[data-uid]');
const uid = userCard.attr('data-uid');
if (parseInt(uid, 10) === parseInt(app.user.uid, 10)) {
return app.alertError('[[admin/manage/users:alerts.no-remove-yourself-admin]]');
return alerts.error('[[admin/manage/users:alerts.no-remove-yourself-admin]]');
}
bootbox.confirm('[[admin/manage/users:alerts.confirm-remove-admin]]', function (confirm) {
if (confirm) {
socket.emit('admin.user.removeAdmins', [uid], function (err) {
if (err) {
return app.alertError(err.message);
return alerts.error(err.message);
}
app.alertSuccess('[[admin/manage/users:alerts.remove-admin-success]]');
alerts.success('[[admin/manage/users:alerts.remove-admin-success]]');
userCard.remove();
});
}
@ -45,7 +45,7 @@ define('admin/manage/admins-mods', [
autocomplete.user($('#global-mod-search'), function (ev, ui) {
api.put('/groups/global-moderators/membership/' + ui.item.user.uid).then(() => {
app.alertSuccess('[[admin/manage/users:alerts.make-global-mod-success]]');
alerts.success('[[admin/manage/users:alerts.make-global-mod-success]]');
$('#global-mod-search').val('');
if ($('.global-moderator-area [data-uid="' + ui.item.user.uid + '"]').length) {
@ -56,7 +56,7 @@ define('admin/manage/admins-mods', [
$('.global-moderator-area').prepend(html);
$('#no-global-mods-warning').addClass('hidden');
});
}).catch(app.alertError);
}).catch(alerts.error);
});
$('.global-moderator-area').on('click', '.remove-user-icon', function () {
@ -66,12 +66,12 @@ define('admin/manage/admins-mods', [
bootbox.confirm('[[admin/manage/users:alerts.confirm-remove-global-mod]]', function (confirm) {
if (confirm) {
api.del('/groups/global-moderators/membership/' + uid).then(() => {
app.alertSuccess('[[admin/manage/users:alerts.remove-global-mod-success]]');
alerts.success('[[admin/manage/users:alerts.remove-global-mod-success]]');
userCard.remove();
if (!$('.global-moderator-area').children().length) {
$('#no-global-mods-warning').removeClass('hidden');
}
}).catch(app.alertError);
}).catch(alerts.error);
}
});
});
@ -94,9 +94,9 @@ define('admin/manage/admins-mods', [
member: ui.item.user.uid,
}, function (err) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
app.alertSuccess('[[admin/manage/users:alerts.make-moderator-success]]');
alerts.success('[[admin/manage/users:alerts.make-moderator-success]]');
input.val('');
if ($('.moderator-area[data-cid="' + cid + '"] [data-uid="' + ui.item.user.uid + '"]').length) {
@ -125,9 +125,9 @@ define('admin/manage/admins-mods', [
member: uid,
}, function (err) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
app.alertSuccess('[[admin/manage/users:alerts.remove-moderator-success]]');
alerts.success('[[admin/manage/users:alerts.remove-moderator-success]]');
userCard.remove();
if (!moderatorArea.children().length) {
$('.no-moderator-warning[data-cid="' + cid + '"]').removeClass('hidden');

@ -63,7 +63,7 @@ define('admin/manage/categories', [
modified[cid] = { order: Math.max(1, parseInt(val, 10)) };
api.put('/categories/' + cid, modified[cid]).then(function () {
ajaxify.refresh();
}).catch(err => app.alertError(err));
}).catch(alerts.error);
} else {
return false;
}
@ -183,7 +183,7 @@ define('admin/manage/categories', [
const categoryEl = listEl.querySelector(`li[data-cid="${cid}"]`);
categoryEl.classList[disabled ? 'add' : 'remove']('disabled');
$(categoryEl).find('li a[data-action="toggle"]').first().translateText(disabled ? '[[admin/manage/categories:enable]]' : '[[admin/manage/categories:disable]]');
}).catch(app.alertError)));
}).catch(alerts.error)));
};
function itemDidAdd(e) {
@ -209,7 +209,7 @@ define('admin/manage/categories', [
}
newCategoryId = -1;
api.put('/categories/' + cid, modified[cid]).catch(app.alertError);
api.put('/categories/' + cid, modified[cid]).catch(alerts.error);
}
}

@ -50,7 +50,7 @@ define('admin/manage/category', [
$('#save').on('click', function () {
const tags = $('#tag-whitelist').val() ? $('#tag-whitelist').val().split(',') : [];
if (tags.length && tags.length < parseInt($('#cid-min-tags').val(), 10)) {
return app.alertError('[[admin/manage/categories:alert.not-enough-whitelisted-tags]]');
return alerts.error('[[admin/manage/categories:alert.not-enough-whitelisted-tags]]');
}
const cid = ajaxify.data.category.cid;
@ -89,7 +89,7 @@ define('admin/manage/category', [
const intervalId = setInterval(function () {
socket.emit('categories.getTopicCount', ajaxify.data.category.cid, function (err, count) {
if (err) {
return app.alertError(err);
return alerts.error(err);
}
let percent = 0;
@ -106,9 +106,9 @@ define('admin/manage/category', [
clearInterval(intervalId);
}
modal.modal('hide');
app.alertSuccess('[[admin/manage/categories:alert.purge-success]]');
alerts.success('[[admin/manage/categories:alert.purge-success]]');
ajaxify.go('admin/manage/categories');
}).catch(app.alertError);
}).catch(alerts.error);
return false;
},
@ -139,11 +139,11 @@ define('admin/manage/category', [
copyParent: modal.find('#copyParent').prop('checked'),
}, function (err) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
modal.modal('hide');
app.alertSuccess('[[admin/manage/categories:alert.copy-success]]');
alert.success('[[admin/manage/categories:alert.copy-success]]');
ajaxify.refresh();
});
return false;
@ -215,7 +215,7 @@ define('admin/manage/category', [
$('button[data-action="removeParent"]').parent().addClass('hide');
$('button[data-action="changeParent"]').parent().addClass('hide');
$('button[data-action="setParent"]').removeClass('hide');
}).catch(app.alertError);
}).catch(alerts.error);
});
$('button[data-action="toggle"]').on('click', function () {
const $this = $(this);
@ -226,7 +226,7 @@ define('admin/manage/category', [
$this.translateText(!disabled ? '[[admin/manage/categories:enable]]' : '[[admin/manage/categories:disable]]');
$this.toggleClass('btn-primary', !disabled).toggleClass('btn-danger', disabled);
$this.attr('data-disabled', disabled ? 0 : 1);
}).catch(app.alertError);
}).catch(alerts.error);
});
};
@ -298,7 +298,7 @@ define('admin/manage/category', [
$('button[data-action="removeParent"]').parent().removeClass('hide');
$('button[data-action="setParent"]').addClass('hide');
}).catch(app.alertError);
}).catch(alerts.error);
},
showLinks: true,
});

@ -1,7 +1,7 @@
'use strict';
define('admin/manage/digest', ['bootbox'], function (bootbox) {
define('admin/manage/digest', ['bootbox', 'alerts'], function (bootbox, alerts) {
const Digest = {};
Digest.init = function () {
@ -15,20 +15,20 @@ define('admin/manage/digest', ['bootbox'], function (bootbox) {
if (ok) {
Digest.send(action, undefined, function (err) {
if (err) {
return app.alertError(err);
return alerts.error(err);
}
app.alertSuccess('[[admin/manage/digest:resent-' + interval + ']]');
alerts.success('[[admin/manage/digest:resent-' + interval + ']]');
});
}
});
} else {
Digest.send(action, uid, function (err) {
if (err) {
return app.alertError(err);
return alerts.error(err);
}
app.alertSuccess('[[admin/manage/digest:resent-single]]');
alerts.success('[[admin/manage/digest:resent-single]]');
});
}
});

@ -9,7 +9,8 @@ define('admin/manage/group', [
'slugify',
'api',
'bootbox',
], function (memberList, iconSelect, translator, categorySelector, groupSearch, slugify, api, bootbox) {
'alerts',
], function (memberList, iconSelect, translator, categorySelector, groupSearch, slugify, api, bootbox, alerts) {
const Groups = {};
Groups.init = function () {
@ -104,8 +105,8 @@ define('admin/manage/group', [
ajaxify.go('admin/manage/groups/' + encodeURIComponent(newName), undefined, true);
}
app.alertSuccess('[[admin/manage/groups:edit.save-success]]');
}).catch(app.alertError);
alerts.success('[[admin/manage/groups:edit.save-success]]');
}).catch(alerts.error);
return false;
});
};
@ -123,7 +124,7 @@ define('admin/manage/group', [
case 'toggleOwnership':
api[isOwner ? 'del' : 'put'](`/groups/${ajaxify.data.group.slug}/ownership/${uid}`, {}).then(() => {
ownerFlagEl.toggleClass('invisible');
}).catch(app.alertError);
}).catch(alerts.error);
break;
case 'kick':
@ -133,7 +134,7 @@ define('admin/manage/group', [
}
api.del('/groups/' + ajaxify.data.group.slug + '/membership/' + uid).then(() => {
userRow.slideUp().remove();
}).catch(app.alertError);
}).catch(alerts.error);
});
break;
default:

@ -5,7 +5,8 @@ define('admin/manage/groups', [
'slugify',
'api',
'bootbox',
], function (categorySelector, slugify, api, bootbox) {
'alerts',
], function (categorySelector, slugify, api, bootbox, alerts) {
const Groups = {};
Groups.init = function () {
@ -61,7 +62,7 @@ define('admin/manage/groups', [
case 'delete':
bootbox.confirm('[[admin/manage/groups:alerts.confirm-delete]]', function (confirm) {
if (confirm) {
api.del(`/groups/${slugify(groupName)}`, {}).then(ajaxify.refresh).catch(app.alertError);
api.del(`/groups/${slugify(groupName)}`, {}).then(ajaxify.refresh).catch(alerts.error);
}
});
break;
@ -99,7 +100,7 @@ define('admin/manage/groups', [
},
}, function (err, groups) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
app.parseAndTranslate('admin/manage/groups', 'groups', {

@ -79,7 +79,7 @@ define('admin/manage/privileges', [
}
checkboxRowSelector.updateState($checkboxEl);
} else {
app.alertError('[[error:invalid-data]]');
alerts.error('[[error:invalid-data]]');
}
});
@ -167,17 +167,17 @@ define('admin/manage/privileges', [
const rejects = results.filter(r => r.status === 'rejected');
if (rejects.length) {
rejects.forEach((result) => {
app.alertError(result.reason);
alerts.error(result.reason);
});
} else {
app.alertSuccess('[[admin/manage/privileges:alert.saved]]');
alerts.success('[[admin/manage/privileges:alert.saved]]');
}
});
};
Privileges.discard = function () {
Privileges.refreshPrivilegeTable();
app.alertSuccess('[[admin/manage/privileges:alert.discarded]]');
alerts.success('[[admin/manage/privileges:alert.discarded]]');
};
Privileges.refreshPrivilegeTable = function (groupToHighlight) {
@ -199,7 +199,7 @@ define('admin/manage/privileges', [
hightlightRowByDataAttr('data-group-name', groupToHighlight);
});
}).catch(app.alertError);
}).catch(alert.error);
};
Privileges.exposeAssumedPrivileges = function () {
@ -284,9 +284,9 @@ define('admin/manage/privileges', [
const filter = getPrivilegeFilter();
socket.emit('admin.categories.copyPrivilegesToChildren', { cid, group, filter }, function (err) {
if (err) {
return app.alertError(err.message);
return alerts.error(err.message);
}
app.alertSuccess('[[admin/manage/categories:privileges.copy-success]]');
alerts.success('[[admin/manage/categories:privileges.copy-success]]');
});
};
@ -309,7 +309,7 @@ define('admin/manage/privileges', [
group: group,
}, function (err) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
ajaxify.refresh();
});
@ -321,9 +321,9 @@ define('admin/manage/privileges', [
const filter = getPrivilegeFilter();
socket.emit('admin.categories.copyPrivilegesToAllCategories', { cid, group, filter }, function (err) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
app.alertSuccess('[[admin/manage/categories:privileges.copy-success]]');
alerts.success('[[admin/manage/categories:privileges.copy-success]]');
});
};

@ -1,7 +1,7 @@
'use strict';
define('admin/manage/registration', ['bootbox'], function (bootbox) {
define('admin/manage/registration', ['bootbox', 'alerts'], function (bootbox, alerts) {
const Registration = {};
Registration.init = function () {
@ -13,7 +13,7 @@ define('admin/manage/registration', ['bootbox'], function (bootbox) {
socket.emit(method, { username: username }, function (err) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
parent.remove();
});
@ -41,7 +41,7 @@ define('admin/manage/registration', ['bootbox'], function (bootbox) {
if (confirm) {
socket.emit(method, { email: email, invitedBy: invitedBy }, function (err) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
removeRow();
});

@ -3,9 +3,9 @@
define('admin/manage/tags', [
'bootbox',
'forum/infinitescroll',
'alerts',
'admin/modules/selectable',
], function (bootbox, infinitescroll, selectable) {
], function (bootbox, alerts, selectable) {
const Tags = {};
Tags.init = function () {
@ -40,7 +40,7 @@ define('admin/manage/tags', [
tag: createTagName.val(),
}, function (err) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
createTagName.val('');
@ -58,7 +58,7 @@ define('admin/manage/tags', [
query: $('#tag-search').val(),
}, function (err, result) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
app.parseAndTranslate('admin/manage/tags', 'tags', {
@ -98,9 +98,9 @@ define('admin/manage/tags', [
socket.emit('admin.tags.rename', data, function (err) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
app.alertSuccess('[[admin/manage/tags:alerts.update-success]]');
alerts.success('[[admin/manage/tags:alerts.update-success]]');
ajaxify.refresh();
});
},
@ -129,7 +129,7 @@ define('admin/manage/tags', [
tags: tags,
}, function (err) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
tagsToDelete.remove();
});

@ -1,6 +1,6 @@
'use strict';
define('admin/manage/uploads', ['api', 'bootbox', 'uploader'], function (api, bootbox, uploader) {
define('admin/manage/uploads', ['api', 'bootbox', 'alerts', 'uploader'], function (api, bootbox, alerts, uploader) {
const Uploads = {};
Uploads.init = function () {
@ -25,7 +25,7 @@ define('admin/manage/uploads', ['api', 'bootbox', 'uploader'], function (api, bo
path: file.attr('data-path'),
}).then(() => {
file.remove();
}).catch(app.alertError);
}).catch(alerts.error);
});
});
@ -40,7 +40,7 @@ define('admin/manage/uploads', ['api', 'bootbox', 'uploader'], function (api, bo
folderName: newFolderName,
}).then(() => {
ajaxify.refresh();
}).catch(app.alertError);
}).catch(alerts.error);
});
});
};

@ -76,9 +76,9 @@ define('admin/manage/users', [
function done(successMessage, className, flag) {
return function (err) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
app.alertSuccess(successMessage);
alerts.success(successMessage);
if (className) {
update(className, flag);
}
@ -87,7 +87,7 @@ define('admin/manage/users', [
}
function onSuccess(successMessage, className, flag) {
app.alertSuccess(successMessage);
alerts.success(successMessage);
if (className) {
update(className, flag);
}
@ -101,12 +101,12 @@ define('admin/manage/users', [
$('.manage-groups').on('click', function () {
const uids = getSelectedUids();
if (!uids.length) {
app.alertError('[[error:no-users-selected]]');
alerts.error('[[error:no-users-selected]]');
return false;
}
socket.emit('admin.user.loadGroups', uids, function (err, data) {
if (err) {
return app.alertError(err);
return alerts.error(err);
}
Benchpress.render('admin/partials/manage_user_groups', data).then(function (html) {
const modal = bootbox.dialog({
@ -122,7 +122,7 @@ define('admin/manage/users', [
app.parseAndTranslate('admin/partials/manage_user_groups', { users: [{ groups: [ui.item.group] }] }, function (html) {
$('[data-uid=' + uid + '] .group-area').append(html.find('.group-area').html());
});
}).catch(app.alertError);
}).catch(alerts.error);
});
});
modal.on('click', '.group-area a', function () {
@ -134,7 +134,7 @@ define('admin/manage/users', [
const uid = $(this).parents('[data-uid]').attr('data-uid');
api.del('/groups/' + slugify(groupName) + '/membership/' + uid).then(() => {
groupCard.remove();
}).catch(app.alertError);
}).catch(alerts.error);
return false;
});
});
@ -144,7 +144,7 @@ define('admin/manage/users', [
$('.ban-user').on('click', function () {
const uids = getSelectedUids();
if (!uids.length) {
app.alertError('[[error:no-users-selected]]');
alerts.error('[[error:no-users-selected]]');
return false; // specifically to keep the menu open
}
@ -154,7 +154,7 @@ define('admin/manage/users', [
return api.put('/users/' + uid + '/ban');
})).then(() => {
onSuccess('[[admin/manage/users:alerts.ban-success]]', '.ban', true);
}).catch(app.alertError);
}).catch(alerts.error);
}
});
});
@ -162,7 +162,7 @@ define('admin/manage/users', [
$('.ban-user-temporary').on('click', function () {
const uids = getSelectedUids();
if (!uids.length) {
app.alertError('[[error:no-users-selected]]');
alerts.error('[[error:no-users-selected]]');
return false; // specifically to keep the menu open
}
@ -195,7 +195,7 @@ define('admin/manage/users', [
});
})).then(() => {
onSuccess('[[admin/manage/users:alerts.ban-success]]', '.ban', true);
}).catch(app.alertError);
}).catch(alerts.error);
},
},
},
@ -206,7 +206,7 @@ define('admin/manage/users', [
$('.unban-user').on('click', function () {
const uids = getSelectedUids();
if (!uids.length) {
app.alertError('[[error:no-users-selected]]');
alerts.error('[[error:no-users-selected]]');
return false; // specifically to keep the menu open
}
@ -238,9 +238,9 @@ define('admin/manage/users', [
}
socket.emit('admin.user.validateEmail', uids, function (err) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
app.alertSuccess('[[admin/manage/users:alerts.validate-email-success]]');
alerts.success('[[admin/manage/users:alerts.validate-email-success]]');
update('.notvalidated', false);
update('.validated', true);
unselectAll();
@ -255,9 +255,9 @@ define('admin/manage/users', [
}
socket.emit('admin.user.sendValidationEmail', uids, function (err) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
app.alertSuccess('[[notifications:email-confirm-sent]]');
alerts.success('[[notifications:email-confirm-sent]]');
});
});
@ -331,15 +331,15 @@ define('admin/manage/users', [
)
).then(() => {
if (path !== '/content') {
app.alertSuccess('[[admin/manage/users:alerts.delete-success]]');
alerts.success('[[admin/manage/users:alerts.delete-success]]');
} else {
app.alertSuccess('[[admin/manage/users:alerts.delete-content-success]]');
alerts.success('[[admin/manage/users:alerts.delete-content-success]]');
}
unselectAll();
if (!$('.users-table [component="user/select/single"]').length) {
ajaxify.refresh();
}
}).catch(app.alertError);
}).catch(alerts.error);
}
});
}
@ -399,7 +399,7 @@ define('admin/manage/users', [
modal.on('hidden.bs.modal', function () {
ajaxify.refresh();
});
app.alertSuccess('[[admin/manage/users:alerts.create-success]]');
alerts.success('[[admin/manage/users:alerts.create-success]]');
})
.catch(err => errorEl.translateHtml('[[admin/manage/users:alerts.error-x, ' + err.status.message + ']]').removeClass('hidden'));
}
@ -441,7 +441,7 @@ define('admin/manage/users', [
}
}).fail(function (xhrErr) {
if (xhrErr && xhrErr.responseJSON && xhrErr.responseJSON.error) {
app.alertError(xhrErr.responseJSON.error);
alerts.error(xhrErr.responseJSON.error);
}
});
}

@ -1,6 +1,6 @@
'use strict';
define('admin/modules/search', ['mousetrap'], function (mousetrap) {
define('admin/modules/search', ['mousetrap', 'alerts'], function (mousetrap, alerts) {
const search = {};
function find(dict, term) {
@ -52,7 +52,7 @@ define('admin/modules/search', ['mousetrap'], function (mousetrap) {
socket.emit('admin.getSearchDict', {}, function (err, dict) {
if (err) {
app.alertError(err);
alerts.error(err);
throw err;
}
setupACPSearch(dict);

@ -101,7 +101,7 @@ define('admin/settings', ['uploader', 'mousetrap', 'hooks', 'alerts'], function
$('#clear-sitemap-cache').off('click').on('click', function () {
socket.emit('admin.settings.clearSitemapCache', function () {
app.alertSuccess('Sitemap Cache Cleared!');
alerts.success('Sitemap Cache Cleared!');
});
return false;
});

@ -1,13 +1,13 @@
'use strict';
define('admin/settings/cookies', function () {
define('admin/settings/cookies', ['alerts'], function (alerts) {
const Module = {};
Module.init = function () {
$('#delete-all-sessions').on('click', function () {
socket.emit('admin.deleteAllSessions', function (err) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
window.location.href = config.relative_path + '/login';
});

@ -1,7 +1,7 @@
'use strict';
define('admin/settings/email', ['ace/ace', 'admin/settings'], function (ace) {
define('admin/settings/email', ['ace/ace', 'alerts', 'admin/settings'], function (ace, alerts) {
const module = {};
let emailEditor;
@ -23,9 +23,9 @@ define('admin/settings/email', ['ace/ace', 'admin/settings'], function (ace) {
socket.emit('admin.email.test', { template: $('#test-email').val() }, function (err) {
if (err) {
console.error(err.message);
return app.alertError(err.message);
return alerts.error(err);
}
app.alertSuccess('Test Email Sent');
alerts.success('Test Email Sent');
});
return false;
});
@ -85,7 +85,7 @@ define('admin/settings/email', ['ace/ace', 'admin/settings'], function (ace) {
socket.emit('admin.getServerTime', {}, function (err, now) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
const date = new Date(now.timestamp);

@ -5,10 +5,11 @@ define('admin/settings/navigation', [
'translator',
'iconSelect',
'benchpress',
'alerts',
'jquery-ui/widgets/draggable',
'jquery-ui/widgets/droppable',
'jquery-ui/widgets/sortable',
], function (translator, iconSelect, Benchpress) {
], function (translator, iconSelect, Benchpress, alerts) {
const navigation = {};
let available;
@ -128,9 +129,9 @@ define('admin/settings/navigation', [
socket.emit('admin.navigation.save', nav, function (err) {
if (err) {
app.alertError(err.message);
alerts.error(err);
} else {
app.alertSuccess('Successfully saved navigation');
alerts.success('Successfully saved navigation');
}
});
}

@ -1,7 +1,7 @@
'use strict';
define('admin/settings/social', [], function () {
define('admin/settings/social', ['alerts'], function (alerts) {
const social = {};
social.init = function () {
@ -15,10 +15,10 @@ define('admin/settings/social', [], function () {
socket.emit('admin.social.savePostSharingNetworks', networks, function (err) {
if (err) {
return app.alertError(err);
return alerts.error(err);
}
app.alertSuccess('[[admin/settings/social:save-success]]');
alerts.success('[[admin/settings/social:save-success]]');
});
});
};

@ -156,7 +156,9 @@ ajaxify = window.ajaxify || {};
$('#footer, #content').removeClass('hide').addClass('ajaxifying');
return renderTemplate(url, status.toString(), data.responseJSON || {}, callback);
} else if (status === 401) {
app.alertError('[[global:please_log_in]]');
require(['alerts'], function (alerts) {
alerts.error('[[global:please_log_in]]');
});
app.previousUrl = url;
window.location.href = config.relative_path + '/login';
} else if (status === 302 || status === 308) {
@ -174,7 +176,9 @@ ajaxify = window.ajaxify || {};
}
}
} else if (textStatus !== 'abort') {
app.alertError(data.responseJSON.error);
require(['alerts'], function (alerts) {
alerts.error(data.responseJSON.error);
});
}
}

@ -172,7 +172,10 @@ app.flags = {};
}, function (err) {
if (err) {
app.currentRoom = previousRoom;
return app.alertError(err.message);
require(['alerts'], function (alerts) {
alerts.error(err);
});
return;
}
callback();
@ -189,7 +192,9 @@ app.flags = {};
socket.emit('meta.rooms.leaveCurrent', function (err) {
if (err) {
app.currentRoom = previousRoom;
return app.alertError(err.message);
require(['alerts'], function (alerts) {
alerts.error(err);
});
}
});
};

@ -4,7 +4,8 @@ define('forum/account/blocks', [
'forum/account/header',
'api',
'hooks',
], function (header, api, hooks) {
'alerts',
], function (header, api, hooks, alerts) {
const Blocks = {};
Blocks.init = function () {
@ -19,7 +20,7 @@ define('forum/account/blocks', [
paginate: false,
}, function (err, data) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
// Only show first 10 matches
@ -46,7 +47,7 @@ define('forum/account/blocks', [
Blocks.refreshList = function (err) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
$.get(config.relative_path + '/api/' + ajaxify.currentPage)

@ -1,7 +1,7 @@
'use strict';
define('forum/account/categories', ['forum/account/header'], function (header) {
define('forum/account/categories', ['forum/account/header', 'alerts'], function (header, alerts) {
const Categories = {};
Categories.init = function () {
@ -20,7 +20,7 @@ define('forum/account/categories', ['forum/account/header'], function (header) {
socket.emit('categories.setWatchState', { cid: cids, state: state, uid: ajaxify.data.uid }, function (err, modified_cids) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
updateDropdowns(modified_cids, state);
});
@ -35,11 +35,11 @@ define('forum/account/categories', ['forum/account/header'], function (header) {
socket.emit('categories.setWatchState', { cid: cid, state: state, uid: ajaxify.data.uid }, function (err, modified_cids) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
updateDropdowns(modified_cids, state);
app.alertSuccess('[[category:' + state + '.message]]');
alerts.success('[[category:' + state + '.message]]');
});
});
}

@ -1,7 +1,7 @@
'use strict';
define('forum/account/consent', ['forum/account/header'], function (header) {
define('forum/account/consent', ['forum/account/header', 'alerts'], function (header, alerts) {
const Consent = {};
Consent.init = function () {
@ -10,7 +10,7 @@ define('forum/account/consent', ['forum/account/header'], function (header) {
$('[data-action="consent"]').on('click', function () {
socket.emit('user.gdpr.consent', {}, function (err) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
ajaxify.refresh();
@ -25,9 +25,9 @@ define('forum/account/consent', ['forum/account/header'], function (header) {
el.on('click', function () {
socket.emit(method, { uid: ajaxify.data.uid }, function (err) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
app.alertSuccess(success);
alerts.success(success);
});
});
}

@ -7,7 +7,8 @@ define('forum/account/edit', [
'api',
'hooks',
'bootbox',
], function (header, picture, translator, api, hooks, bootbox) {
'alerts',
], function (header, picture, translator, api, hooks, bootbox, alerts) {
const AccountEdit = {};
AccountEdit.init = function () {
@ -42,14 +43,14 @@ define('forum/account/edit', [
hooks.fire('action:profile.update', userData);
api.put('/users/' + userData.uid, userData).then((res) => {
app.alertSuccess('[[user:profile_update_success]]');
alerts.success('[[user:profile_update_success]]');
if (res.picture) {
$('#user-current-picture').attr('src', res.picture);
}
picture.updateHeader(res.picture);
}).catch(app.alertError);
}).catch(alerts.error);
return false;
}
@ -85,7 +86,7 @@ define('forum/account/edit', [
if (err) {
restoreButton();
return app.alertError(err.message);
return alerts.error(err);
}
confirmBtn.html('<i class="fa fa-check"></i>');
@ -111,9 +112,9 @@ define('forum/account/edit', [
socket.emit('user.emailConfirm', {}, function (err) {
btn.removeAttr('disabled');
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
app.alertSuccess('[[notifications:email-confirm-sent]]');
alerts.success('[[notifications:email-confirm-sent]]');
});
});
}

@ -1,6 +1,6 @@
'use strict';
define('forum/account/edit/email', ['forum/account/header', 'api'], function (header, api) {
define('forum/account/edit/email', ['forum/account/header', 'api', 'alerts'], function (header, api, alerts) {
const AccountEditEmail = {};
AccountEditEmail.init = function () {
@ -20,7 +20,7 @@ define('forum/account/edit/email', ['forum/account/header', 'api'], function (he
if (userData.email === userData.password) {
curPasswordEl.parents('.control-group').toggleClass('has-error', true);
return app.alertError('[[user:email_same_as_password]]');
return alerts.error('[[user:email_same_as_password]]');
}
const btn = $(this);
@ -32,7 +32,7 @@ define('forum/account/edit/email', ['forum/account/header', 'api'], function (he
}).catch((err) => {
setTimeout(() => {
btn.removeClass('disabled').find('i').addClass('hide');
app.alertError(err);
alerts.error(err);
}, 300); // for UX: this call is too fast.
});

@ -1,8 +1,8 @@
'use strict';
define('forum/account/edit/password', [
'forum/account/header', 'translator', 'zxcvbn', 'api',
], function (header, translator, zxcvbn, api) {
'forum/account/header', 'translator', 'zxcvbn', 'api', 'alerts',
], function (header, translator, zxcvbn, api, alerts) {
const AccountEditPassword = {};
AccountEditPassword.init = function () {
@ -91,11 +91,11 @@ define('forum/account/edit/password', [
});
} else {
if (!passwordsmatch) {
app.alertError('[[user:change_password_error_match]]');
alerts.error('[[user:change_password_error_match]]');
}
if (!passwordvalid) {
app.alertError('[[user:change_password_error]]');
alerts.error('[[user:change_password_error]]');
}
}
return false;

@ -1,8 +1,8 @@
'use strict';
define('forum/account/edit/username', [
'forum/account/header', 'api', 'slugify',
], function (header, api, slugify) {
'forum/account/header', 'api', 'slugify', 'alerts',
], function (header, api, slugify, alerts) {
const AccountEditUsername = {};
AccountEditUsername.init = function () {
@ -20,7 +20,7 @@ define('forum/account/edit/username', [
}
if (userData.username === userData.password) {
return app.alertError('[[user:username_same_as_password]]');
return alerts.error('[[user:username_same_as_password]]');
}
const btn = $(this);
@ -38,7 +38,7 @@ define('forum/account/edit/username', [
}
ajaxify.go('user/' + userslug + '/edit');
}).catch(app.alertError)
}).catch(alerts.error)
.finally(() => {
btn.removeClass('disabled').find('i').addClass('hide');
});

@ -10,7 +10,8 @@ define('forum/account/header', [
'accounts/delete',
'api',
'bootbox',
], function (coverPhoto, pictureCropper, components, translator, Benchpress, AccountsDelete, api, bootbox) {
'alerts',
], function (coverPhoto, pictureCropper, components, translator, Benchpress, AccountsDelete, api, bootbox, alerts) {
const AccountHeader = {};
let isAdminOrSelfOrGlobalMod;
@ -117,11 +118,11 @@ define('forum/account/header', [
function toggleFollow(type) {
api[type === 'follow' ? 'put' : 'del']('/users/' + ajaxify.data.uid + '/follow', undefined, function (err) {
if (err) {
return app.alertError(err);
return alerts.error(err);
}
components.get('account/follow').toggleClass('hide', type === 'follow');
components.get('account/unfollow').toggleClass('hide', type === 'unfollow');
app.alertSuccess('[[global:alert.' + type + ', ' + ajaxify.data.username + ']]');
alerts.success('[[global:alert.' + type + ', ' + ajaxify.data.username + ']]');
});
return false;
@ -162,7 +163,7 @@ define('forum/account/header', [
}
ajaxify.refresh();
}).catch(app.alertError);
}).catch(alerts.error);
},
},
},
@ -173,7 +174,7 @@ define('forum/account/header', [
function unbanAccount() {
api.del('/users/' + ajaxify.data.theirid + '/ban').then(() => {
ajaxify.refresh();
}).catch(app.alertError);
}).catch(alerts.error);
}
function flagAccount() {
@ -192,7 +193,7 @@ define('forum/account/header', [
blockerUid: app.user.uid,
}, function (err, blocked) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
translator.translate('[[user:' + (blocked ? 'unblock' : 'block') + '_user]]', function (label) {
@ -217,7 +218,7 @@ define('forum/account/header', [
if (!err) {
ajaxify.refresh();
} else {
app.alertError(err.message);
alerts.error(err);
}
});
});

@ -1,7 +1,7 @@
'use strict';
define('forum/account/info', ['forum/account/header', 'components', 'forum/account/sessions'], function (header, components, sessions) {
define('forum/account/info', ['forum/account/header', 'alerts', 'forum/account/sessions'], function (header, alerts, sessions) {
const Info = {};
Info.init = function () {
@ -15,10 +15,10 @@ define('forum/account/info', ['forum/account/header', 'components', 'forum/accou
const note = $('[component="account/moderation-note"]').val();
socket.emit('user.setModerationNote', { uid: ajaxify.data.uid, note: note }, function (err) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
$('[component="account/moderation-note"]').val('');
app.alertSuccess('[[user:info.moderation-note.success]]');
alerts.success('[[user:info.moderation-note.success]]');
const timestamp = Date.now();
const data = [{
note: utils.escapeHTML(note),

@ -1,7 +1,7 @@
'use strict';
define('forum/account/sessions', ['forum/account/header', 'components', 'api'], function (header, components, api) {
define('forum/account/sessions', ['forum/account/header', 'components', 'api', 'alerts'], function (header, components, api, alerts) {
const Sessions = {};
Sessions.init = function () {
@ -25,9 +25,9 @@ define('forum/account/sessions', ['forum/account/header', 'components', 'api'],
if (errorObj.loggedIn === false) {
window.location.href = config.relative_path + '/login?error=' + errorObj.title;
}
app.alertError(errorObj.title);
alerts.error(errorObj.title);
} catch (e) {
app.alertError('[[error:invalid-data]]');
alerts.error('[[error:invalid-data]]');
}
});
}

@ -1,7 +1,9 @@
'use strict';
define('forum/account/settings', ['forum/account/header', 'components', 'translator', 'api'], function (header, components, translator, api) {
define('forum/account/settings', [
'forum/account/header', 'components', 'translator', 'api', 'alerts',
], function (header, components, translator, api, alerts) {
const AccountSettings = {};
// If page skin is changed but not saved, switch the skin back
@ -21,7 +23,7 @@ define('forum/account/settings', ['forum/account/header', 'components', 'transla
$.get(config.relative_path + '/' + settings.homePageCustom, function () {
saveSettings(settings);
}).fail(function () {
app.alertError('[[error:invalid-home-page-route]]');
alerts.error('[[error:invalid-home-page-route]]');
});
} else {
saveSettings(settings);
@ -67,7 +69,7 @@ define('forum/account/settings', ['forum/account/header', 'components', 'transla
function saveSettings(settings) {
api.put(`/users/${ajaxify.data.uid}/settings`, { settings }).then((newSettings) => {
app.alertSuccess('[[success:settings-saved]]');
alerts.success('[[success:settings-saved]]');
let languageChanged = false;
for (const key in newSettings) {
if (newSettings.hasOwnProperty(key)) {

@ -1,6 +1,6 @@
'use strict';
define('forum/account/uploads', ['forum/account/header'], function (header) {
define('forum/account/uploads', ['forum/account/header', 'alerts'], function (header, alerts) {
const AccountUploads = {};
AccountUploads.init = function () {
@ -12,7 +12,7 @@ define('forum/account/uploads', ['forum/account/header'], function (header) {
socket.emit('user.deleteUpload', { name: name, uid: ajaxify.data.uid }, function (err) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
el.remove();
});

@ -8,7 +8,8 @@ define('forum/category', [
'sort',
'categorySelector',
'hooks',
], function (infinitescroll, share, navigator, topicList, sort, categorySelector, hooks) {
'alerts',
], function (infinitescroll, share, navigator, topicList, sort, categorySelector, hooks, alerts) {
const Category = {};
$(window).on('action:ajaxify.start', function (ev, data) {
@ -69,7 +70,7 @@ define('forum/category', [
socket.emit('categories.setWatchState', { cid: cid, state: state }, function (err) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
$('[component="category/watching/menu"]').toggleClass('hidden', state !== 'watching');
@ -81,7 +82,7 @@ define('forum/category', [
$('[component="category/ignoring/menu"]').toggleClass('hidden', state !== 'ignoring');
$('[component="category/ignoring/check"]').toggleClass('fa-check', state === 'ignoring');
app.alertSuccess('[[category:' + state + '.message]]');
alerts.success('[[category:' + state + '.message]]');
});
});
}
@ -94,7 +95,7 @@ define('forum/category', [
start: ajaxify.data.nextSubCategoryStart,
}, function (err, data) {
if (err) {
return app.alertError(err);
return alerts.error(err);
}
btn.toggleClass('hidden', !data.length || data.length < ajaxify.data.subCategoriesPerPage);
if (!data.length) {
@ -122,7 +123,7 @@ define('forum/category', [
Category.toBottom = function () {
socket.emit('categories.getTopicCount', ajaxify.data.cid, function (err, count) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
navigator.scrollBottom(count - 1);

@ -6,10 +6,10 @@ define('forum/category/tools', [
'topicSelect',
'forum/topic/threadTools',
'components',
'translator',
'api',
'bootbox',
], function (topicSelect, threadTools, components, translator, api, bootbox) {
'alerts',
], function (topicSelect, threadTools, components, api, bootbox, alerts) {
const CategoryTools = {};
CategoryTools.init = function () {
@ -56,13 +56,13 @@ define('forum/category/tools', [
components.get('topic/mark-unread-for-all').on('click', function () {
const tids = topicSelect.getSelectedTids();
if (!tids.length) {
return app.alertError('[[error:no-topics-selected]]');
return alerts.error('[[error:no-topics-selected]]');
}
socket.emit('topics.markAsUnreadForAll', tids, function (err) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
app.alertSuccess('[[topic:markAsUnreadForAll.success]]');
alerts.success('[[topic:markAsUnreadForAll.success]]');
tids.forEach(function (tid) {
$('[component="category/topic"][data-tid="' + tid + '"]').addClass('unread');
});
@ -76,7 +76,7 @@ define('forum/category/tools', [
const tids = topicSelect.getSelectedTids();
if (!tids.length) {
return app.alertError('[[error:no-topics-selected]]');
return alerts.error('[[error:no-topics-selected]]');
}
move.init(tids, null, onCommandComplete);
});
@ -87,12 +87,12 @@ define('forum/category/tools', [
components.get('topic/move-all').on('click', function () {
const cid = ajaxify.data.cid;
if (!ajaxify.data.template.category) {
return app.alertError('[[error:invalid-data]]');
return alerts.error('[[error:invalid-data]]');
}
require(['forum/topic/move'], function (move) {
move.init(null, cid, function (err) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
ajaxify.refresh();
@ -134,12 +134,12 @@ define('forum/category/tools', [
if (ok) {
Promise.all(tids.map(tid => api[method](`/topics/${tid}${path}`, body)))
.then(onComplete)
.catch(app.alertError);
.catch(alerts.error);
}
};
if (!tids.length) {
return app.alertError('[[error:no-topics-selected]]');
return alerts.error('[[error:no-topics-selected]]');
}
switch (command) {
@ -294,7 +294,7 @@ define('forum/category/tools', [
order: baseIndex + ui.item.index() - 1,
}, function (err) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
});
},

@ -11,11 +11,12 @@ define('forum/chats', [
'composer/autocomplete',
'hooks',
'bootbox',
'alerts',
'chat',
], function (
components, translator, mousetrap,
recentChats, search, messages,
autocomplete, hooks, bootbox, chatModule
autocomplete, hooks, bootbox, alerts, chatModule
) {
const Chats = {
initialised: false,
@ -79,7 +80,7 @@ define('forum/chats', [
const mid = ipEl.parents('[data-mid]').attr('data-mid');
socket.emit('modules.chats.getIP', mid, function (err, ip) {
if (err) {
return app.alertError(err);
return alerts.error(err);
}
ipEl.html(ip);
});
@ -126,7 +127,7 @@ define('forum/chats', [
start: start,
}, function (err, data) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
if (!data) {
loading = false;
@ -270,7 +271,7 @@ define('forum/chats', [
uid: uid,
}, function (err) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
Chats.refreshParticipantsList(roomId, modal);
@ -288,7 +289,7 @@ define('forum/chats', [
if (ok) {
socket.emit('modules.chats.leave', roomId, function (err) {
if (err) {
app.alertError(err.message);
alerts.error(err);
}
// Return user to chats page. If modal, close modal.
@ -350,7 +351,7 @@ define('forum/chats', [
newName: modal.find('#roomName').val(),
}, function (err) {
if (err) {
return app.alertError(err.message);
alerts.error(err);
}
});
}
@ -399,7 +400,7 @@ define('forum/chats', [
const roomId = el.attr('data-roomid');
socket.emit('modules.chats.leave', roomId, function (err) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
if (parseInt(roomId, 10) === parseInt(ajaxify.data.roomId, 10)) {
ajaxify.go('user/' + ajaxify.data.userslug + '/chats');

@ -54,7 +54,7 @@ define('forum/chats/messages', [
inputEl.val(msg);
inputEl.attr('data-mid', mid);
messages.updateRemainingLength(inputEl.parent());
return app.alertError(err.message);
return alerts.error(err);
}
});
}
@ -142,7 +142,7 @@ define('forum/chats/messages', [
messages.prepEdit = function (inputEl, messageId, roomId) {
socket.emit('modules.chats.getRaw', { mid: messageId, roomId: roomId }, function (err, raw) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
// Populate the input field with the raw message content
if (inputEl.val().length === 0) {
@ -209,7 +209,7 @@ define('forum/chats/messages', [
roomId: roomId,
}, function (err) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
components.get('chat/message', messageId).toggleClass('deleted', true);
@ -224,7 +224,7 @@ define('forum/chats/messages', [
roomId: roomId,
}, function (err) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
components.get('chat/message', messageId).toggleClass('deleted', false);

@ -1,7 +1,7 @@
'use strict';
define('forum/chats/recent', function () {
define('forum/chats/recent', ['alerts'], function (alerts) {
const recent = {};
recent.init = function () {
@ -31,7 +31,7 @@ define('forum/chats/recent', function () {
after: recentChats.attr('data-nextstart'),
}, function (err, data) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
if (data && data.rooms.length) {

@ -1,7 +1,7 @@
'use strict';
define('forum/chats/search', ['components', 'api'], function (components, api) {
define('forum/chats/search', ['components', 'api', 'alerts'], function (components, api, alerts) {
const search = {};
search.init = function () {
@ -19,7 +19,7 @@ define('forum/chats/search', ['components', 'api'], function (components, api) {
searchBy: 'username',
paginate: false,
}).then(displayResults)
.catch(app.alertError);
.catch(alerts.error);
}
function displayResults(data) {
@ -62,7 +62,7 @@ define('forum/chats/search', ['components', 'api'], function (components, api) {
chatEl.on('click', function () {
socket.emit('modules.chats.hasPrivateChat', userObj.uid, function (err, roomId) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
if (roomId) {
require(['forum/chats'], function (chats) {

@ -1,8 +1,8 @@
'use strict';
define('forum/flags/detail', [
'components', 'translator', 'benchpress', 'forum/account/header', 'accounts/delete', 'api', 'bootbox',
], function (components, translator, Benchpress, AccountHeader, AccountsDelete, api, bootbox) {
'components', 'translator', 'benchpress', 'forum/account/header', 'accounts/delete', 'api', 'bootbox', 'alerts',
], function (components, translator, Benchpress, AccountHeader, AccountsDelete, api, bootbox, alerts) {
const Detail = {};
Detail.init = function () {
@ -27,9 +27,9 @@ define('forum/flags/detail', [
}, {});
api.put(`/flags/${ajaxify.data.flagId}`, data).then((history) => {
app.alertSuccess('[[flags:updated]]');
alerts.success('[[flags:updated]]');
Detail.reloadHistory(history);
}).catch(app.alertError);
}).catch(alerts.error);
break;
}
@ -39,12 +39,12 @@ define('forum/flags/detail', [
note: noteEl.value,
datetime: parseInt(noteEl.getAttribute('data-datetime'), 10),
}).then((payload) => {
app.alertSuccess('[[flags:note-added]]');
alerts.success('[[flags:note-added]]');
Detail.reloadNotes(payload.notes);
Detail.reloadHistory(payload.history);
noteEl.removeAttribute('data-datetime');
}).catch(app.alertError);
}).catch(alerts.error);
break;
case 'delete-note': {
@ -52,10 +52,10 @@ define('forum/flags/detail', [
bootbox.confirm('[[flags:delete-note-confirm]]', function (ok) {
if (ok) {
api.delete(`/flags/${ajaxify.data.flagId}/notes/${datetime}`, {}).then((payload) => {
app.alertSuccess('[[flags:note-deleted]]');
alerts.success('[[flags:note-deleted]]');
Detail.reloadNotes(payload.notes);
Detail.reloadHistory(payload.history);
}).catch(app.alertError);
}).catch(alerts.error);
}
});
break;
@ -127,7 +127,7 @@ define('forum/flags/detail', [
tid: tid,
}, function (err) {
if (err) {
app.alertError(err.message);
alerts.error(err);
}
ajaxify.refresh();

@ -1,6 +1,8 @@
'use strict';
define('forum/flags/list', ['components', 'Chart', 'categoryFilter', 'autocomplete', 'api'], function (components, Chart, categoryFilter, autocomplete, api) {
define('forum/flags/list', [
'components', 'Chart', 'categoryFilter', 'autocomplete', 'api', 'alerts',
], function (components, Chart, categoryFilter, autocomplete, api, alerts) {
const Flags = {};
let selectedCids;
@ -171,12 +173,12 @@ define('forum/flags/list', ['components', 'Chart', 'categoryFilter', 'autocomple
return res.status === 'rejected';
});
if (fulfilled) {
app.alertSuccess('[[flags:bulk-success, ' + fulfilled + ']]');
alerts.success('[[flags:bulk-success, ' + fulfilled + ']]');
ajaxify.refresh();
}
errors.forEach(function (res) {
app.alertError(res.reason);
alerts.error(res.reason);
});
});
}

@ -11,6 +11,7 @@ define('forum/groups/details', [
'slugify',
'categorySelector',
'bootbox',
'alerts',
], function (
memberList,
iconSelect,
@ -21,7 +22,8 @@ define('forum/groups/details', [
api,
slugify,
categorySelector,
bootbox
bootbox,
alerts,
) {
const Details = {};
let groupName;
@ -79,7 +81,7 @@ define('forum/groups/details', [
case 'toggleOwnership':
api[isOwner ? 'del' : 'put'](`/groups/${ajaxify.data.group.slug}/ownership/${uid}`, {}).then(() => {
ownerFlagEl.toggleClass('invisible');
}).catch(app.alertError);
}).catch(alerts.error);
break;
case 'kick':
@ -89,7 +91,7 @@ define('forum/groups/details', [
return;
}
api.del(`/groups/${ajaxify.data.group.slug}/membership/${uid}`, undefined).then(() => userRow.slideUp().remove()).catch(app.alertError);
api.del(`/groups/${ajaxify.data.group.slug}/membership/${uid}`, undefined).then(() => userRow.slideUp().remove()).catch(alerts.error);
});
});
break;
@ -103,11 +105,11 @@ define('forum/groups/details', [
break;
case 'join': // intentional fall-throughs!
api.put('/groups/' + ajaxify.data.group.slug + '/membership/' + (uid || app.user.uid), undefined).then(() => ajaxify.refresh()).catch(app.alertError);
api.put('/groups/' + ajaxify.data.group.slug + '/membership/' + (uid || app.user.uid), undefined).then(() => ajaxify.refresh()).catch(alerts.error);
break;
case 'leave':
api.del('/groups/' + ajaxify.data.group.slug + '/membership/' + (uid || app.user.uid), undefined).then(() => ajaxify.refresh()).catch(app.alertError);
api.del('/groups/' + ajaxify.data.group.slug + '/membership/' + (uid || app.user.uid), undefined).then(() => ajaxify.refresh()).catch(alerts.error);
break;
// TODO (14/10/2020): rewrite these to use api module and merge with above 2 case blocks
@ -126,7 +128,7 @@ define('forum/groups/details', [
if (!err) {
ajaxify.refresh();
} else {
app.alertError(err.message);
alerts.error(err);
}
});
break;
@ -219,8 +221,8 @@ define('forum/groups/details', [
ajaxify.refresh();
}
app.alertSuccess('[[groups:event.updated]]');
}).catch(app.alertError);
alerts.success('[[groups:event.updated]]');
}).catch(alerts.error);
}
};
@ -230,9 +232,9 @@ define('forum/groups/details', [
bootbox.prompt('Please enter the name of this group in order to delete it:', function (response) {
if (response === groupName) {
api.del(`/groups/${ajaxify.data.group.slug}`, {}).then(() => {
app.alertSuccess('[[groups:event.deleted, ' + utils.escapeHTML(groupName) + ']]');
alerts.success('[[groups:event.deleted, ' + utils.escapeHTML(groupName) + ']]');
ajaxify.go('groups');
}).catch(app.alertError);
}).catch(alerts.error);
}
});
}
@ -252,7 +254,7 @@ define('forum/groups/details', [
groupName: ajaxify.data.group.name,
}, function (err) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
ajaxify.refresh();
});
@ -269,7 +271,7 @@ define('forum/groups/details', [
groupName: ajaxify.data.group.name,
}, function (err) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
ajaxify.refresh();
});
@ -290,7 +292,7 @@ define('forum/groups/details', [
if (!err) {
ajaxify.refresh();
} else {
app.alertError(err.message);
alerts.error(err);
}
});
});

@ -1,8 +1,8 @@
'use strict';
define('forum/groups/list', [
'forum/infinitescroll', 'benchpress', 'api', 'bootbox',
], function (infinitescroll, Benchpress, api, bootbox) {
'forum/infinitescroll', 'benchpress', 'api', 'bootbox', 'alerts',
], function (infinitescroll, Benchpress, api, bootbox, alerts) {
const Groups = {};
Groups.init = function () {
@ -16,7 +16,7 @@ define('forum/groups/list', [
name: name,
}).then((res) => {
ajaxify.go('groups/' + res.slug);
}).catch(app.alertError);
}).catch(alerts.error);
}
});
});
@ -72,7 +72,7 @@ define('forum/groups/list', [
},
}, function (err, groups) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
groups = groups.filter(function (group) {
return group.name !== 'registered-users' && group.name !== 'guests';

@ -1,6 +1,6 @@
'use strict';
define('forum/groups/memberlist', ['api', 'bootbox'], function (api, bootbox) {
define('forum/groups/memberlist', ['api', 'bootbox', 'alerts'], function (api, bootbox, alerts) {
const MemberList = {};
let searchInterval;
let groupName;
@ -51,7 +51,7 @@ define('forum/groups/memberlist', ['api', 'bootbox'], function (api, bootbox) {
paginate: false,
}, function (err, result) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
result.users.forEach(function (user) {
foundUsers[user.uid] = user;
@ -79,12 +79,12 @@ define('forum/groups/memberlist', ['api', 'bootbox'], function (api, bootbox) {
if (groupName === 'administrators') {
socket.emit('admin.user.makeAdmins', uids, function (err) {
if (err) {
return app.alertError(err);
return alerts.error(err);
}
done();
});
} else {
Promise.all(uids.map(uid => api.put('/groups/' + ajaxify.data.group.slug + '/membership/' + uid))).then(done).catch(app.alertError);
Promise.all(uids.map(uid => api.put('/groups/' + ajaxify.data.group.slug + '/membership/' + uid))).then(done).catch(alerts.error);
}
}
@ -99,7 +99,7 @@ define('forum/groups/memberlist', ['api', 'bootbox'], function (api, bootbox) {
searchInterval = setTimeout(function () {
socket.emit('groups.searchMembers', { groupName: groupName, query: query }, function (err, results) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
parseAndTranslate(results.users, function (html) {
$('[component="groups/members"] tbody').html(html);
@ -133,7 +133,7 @@ define('forum/groups/memberlist', ['api', 'bootbox'], function (api, bootbox) {
after: members.attr('data-nextstart'),
}, function (err, data) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
if (data && data.users.length) {

@ -1,6 +1,6 @@
'use strict';
define('forum/header', ['forum/header/notifications', 'forum/header/chat'], function (notifications, chat) {
define('forum/header', ['forum/header/notifications', 'forum/header/chat', 'alerts'], function (notifications, chat, alerts) {
const module = {};
module.prepareDOM = function () {
@ -16,7 +16,7 @@ define('forum/header', ['forum/header/notifications', 'forum/header/chat'], func
const status = $(this).attr('data-status');
socket.emit('user.setStatus', status, function (err) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
$('[data-uid="' + app.user.uid + '"] [component="user/status"], [component="header/profilelink"] [component="user/status"]')
.removeClass('away online dnd offline')

@ -1,7 +1,7 @@
'use strict';
define('forum/infinitescroll', ['hooks'], function (hooks) {
define('forum/infinitescroll', ['hooks', 'alerts'], function (hooks, alerts) {
const scroll = {};
let callback;
let previousScrollTop = 0;
@ -75,7 +75,7 @@ define('forum/infinitescroll', ['hooks'], function (hooks) {
socket.emit(hookData.method, hookData.data, function (err, data) {
if (err) {
loadingMore = false;
return app.alertError(err.message);
return alerts.error(err);
}
callback(data, function () {
loadingMore = false;
@ -98,7 +98,7 @@ define('forum/infinitescroll', ['hooks'], function (hooks) {
});
}).fail(function (jqXHR) {
loadingMore = false;
app.alertError(String(jqXHR.responseJSON || jqXHR.statusText));
alerts.error(String(jqXHR.responseJSON || jqXHR.statusText));
});
};

@ -1,7 +1,7 @@
'use strict';
define('forum/notifications', ['components'], function (components) {
define('forum/notifications', ['components', 'alerts'], function (components, alerts) {
const Notifications = {};
Notifications.init = function () {
@ -10,7 +10,7 @@ define('forum/notifications', ['components'], function (components) {
const nid = $(this).parents('[data-nid]').attr('data-nid');
socket.emit('notifications.markRead', nid, function (err) {
if (err) {
return app.alertError(err);
return alerts.error(err);
}
});
});
@ -18,7 +18,7 @@ define('forum/notifications', ['components'], function (components) {
components.get('notifications/mark_all').on('click', function () {
socket.emit('notifications.markAllRead', function (err) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
components.get('notifications/item').removeClass('unread');

@ -2,8 +2,8 @@
define('forum/post-queue', [
'categoryFilter', 'categorySelector', 'api',
], function (categoryFilter, categorySelector, api) {
'categoryFilter', 'categorySelector', 'api', 'alerts',
], function (categoryFilter, categorySelector, api, alerts) {
const PostQueue = {};
PostQueue.init = function () {
@ -27,7 +27,7 @@ define('forum/post-queue', [
socket.emit('posts.' + action, { id: id }, function (err) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
parent.remove();
@ -66,9 +66,7 @@ define('forum/post-queue', [
$this.replaceWith(html.find('.topic-category'));
}
});
}).catch(function (err) {
app.alertError(err);
});
}).catch(alerts.error);
},
});
return false;
@ -99,7 +97,7 @@ define('forum/post-queue', [
content: titleEdit ? undefined : textarea.val(),
}, function (err, data) {
if (err) {
return app.alertError(err);
return alerts.error(err);
}
if (titleEdit) {
if (preview.find('.title-text').length) {

@ -1,7 +1,7 @@
'use strict';
define('forum/reset', function () {
define('forum/reset', ['alerts'], function (alerts) {
const ResetPassword = {};
ResetPassword.init = function () {
@ -13,7 +13,7 @@ define('forum/reset', function () {
if (inputEl.val() && inputEl.val().indexOf('@') !== -1) {
socket.emit('user.reset.send', inputEl.val(), function (err) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
errorEl.addClass('hide');

@ -1,7 +1,7 @@
'use strict';
define('forum/reset_code', ['zxcvbn'], function (zxcvbn) {
define('forum/reset_code', ['zxcvbn', 'alerts'], function (zxcvbn, alerts) {
const ResetCode = {};
ResetCode.init = function () {
@ -33,7 +33,7 @@ define('forum/reset_code', ['zxcvbn'], function (zxcvbn) {
}, function (err) {
if (err) {
ajaxify.refresh();
return app.alertError(err.message);
return alerts.error(err);
}
window.location.href = config.relative_path + '/login';

@ -6,7 +6,8 @@ define('forum/search', [
'autocomplete',
'storage',
'hooks',
], function (searchModule, autocomplete, storage, hooks) {
'alerts',
], function (searchModule, autocomplete, storage, hooks, alerts) {
const Search = {};
Search.init = function () {
@ -142,7 +143,7 @@ define('forum/search', [
function handleSavePreferences() {
$('#save-preferences').on('click', function () {
storage.setItem('search-preferences', JSON.stringify(getSearchDataFromDOM()));
app.alertSuccess('[[search:search-preferences-saved]]');
alerts.success('[[search:search-preferences-saved]]');
return false;
});
@ -151,7 +152,7 @@ define('forum/search', [
const query = $('#search-input').val();
$('#advanced-search')[0].reset();
$('#search-input').val(query);
app.alertSuccess('[[search:search-preferences-cleared]]');
alerts.success('[[search:search-preferences-cleared]]');
return false;
});
}

@ -1,7 +1,7 @@
'use strict';
define('forum/tags', ['forum/infinitescroll'], function (infinitescroll) {
define('forum/tags', ['forum/infinitescroll', 'alerts'], function (infinitescroll, alerts) {
const Tags = {};
Tags.init = function () {
@ -14,7 +14,7 @@ define('forum/tags', ['forum/infinitescroll'], function (infinitescroll) {
socket.emit('topics.searchAndLoadTags', { query: $('#tag-search').val() }, function (err, results) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
onTagsLoaded(results.tags, true);
});
@ -45,7 +45,7 @@ define('forum/tags', ['forum/infinitescroll'], function (infinitescroll) {
after: 0,
}, function (err, data) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
onTagsLoaded(data.tags, true);
});

@ -28,7 +28,7 @@ define('forum/topic', [
if (!String(data.url).startsWith('topic/')) {
navigator.disable();
components.get('navbar/title').find('span').text('').hide();
app.removeAlert('bookmark');
alerts.remove('bookmark');
}
});
@ -89,7 +89,7 @@ define('forum/topic', [
Topic.toBottom = function () {
socket.emit('topics.postcount', ajaxify.data.tid, function (err, postCount) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
navigator.scrollBottom(postCount - 1);
@ -297,7 +297,7 @@ define('forum/topic', [
index: index,
}, function (err) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
ajaxify.data.bookmark = index + 1;
});
@ -308,7 +308,7 @@ define('forum/topic', [
// removes the bookmark alert when we get to / past the bookmark
if (!currentBookmark || parseInt(index, 10) >= parseInt(currentBookmark, 10)) {
app.removeAlert('bookmark');
alerts.remove('bookmark');
}
}

@ -2,10 +2,10 @@
define('forum/topic/change-owner', [
'components',
'postSelect',
'autocomplete',
], function (components, postSelect, autocomplete) {
'alerts',
], function (postSelect, autocomplete, alerts) {
const ChangeOwner = {};
let modal;
@ -71,7 +71,7 @@ define('forum/topic/change-owner', [
}
socket.emit('posts.changeOwner', { pids: postSelect.pids, toUid: toUid }, function (err) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
ajaxify.refresh();

@ -1,7 +1,7 @@
'use strict';
define('forum/topic/delete-posts', ['components', 'postSelect'], function (components, postSelect) {
define('forum/topic/delete-posts', ['postSelect', 'alerts'], function (postSelect, alerts) {
const DeletePosts = {};
let modal;
let deleteBtn;
@ -56,7 +56,7 @@ define('forum/topic/delete-posts', ['components', 'postSelect'], function (compo
}, function (err) {
btn.removeAttr('disabled');
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
closeModal();

@ -1,6 +1,6 @@
'use strict';
define('forum/topic/diffs', ['api', 'bootbox', 'forum/topic/images'], function (api, bootbox) {
define('forum/topic/diffs', ['api', 'bootbox', 'alerts', 'forum/topic/images'], function (api, bootbox, alerts) {
const Diffs = {};
const localeStringOpts = { year: 'numeric', month: 'short', day: 'numeric', hour: 'numeric', minute: 'numeric' };
@ -43,7 +43,7 @@ define('forum/topic/diffs', ['api', 'bootbox', 'forum/topic/images'], function (
$deleteEl.prop('disabled', true);
});
});
}).catch(app.alertError);
}).catch(alerts.error);
};
Diffs.load = function (pid, since, $postContainer) {
@ -59,7 +59,7 @@ define('forum/topic/diffs', ['api', 'bootbox', 'forum/topic/images'], function (
}, function ($html) {
$postContainer.empty().append($html);
});
}).catch(app.alertError);
}).catch(alerts.error);
};
Diffs.restore = function (pid, since, $modal) {
@ -69,8 +69,8 @@ define('forum/topic/diffs', ['api', 'bootbox', 'forum/topic/images'], function (
api.put(`/posts/${pid}/diffs/${since}`, {}).then(() => {
$modal.modal('hide');
app.alertSuccess('[[topic:diffs.post-restored]]');
}).catch(app.alertError);
alerts.success('[[topic:diffs.post-restored]]');
}).catch(alerts.error);
};
Diffs.delete = function (pid, timestamp, $selectEl, $numberOfDiffCon) {
@ -80,9 +80,9 @@ define('forum/topic/diffs', ['api', 'bootbox', 'forum/topic/images'], function (
$selectEl.trigger('change');
const numberOfDiffs = $selectEl.find('option').length;
$numberOfDiffCon.text(numberOfDiffs);
app.alertSuccess('[[topic:diffs.deleted]]');
alerts.success('[[topic:diffs.deleted]]');
});
}).catch(app.alertError);
}).catch(alerts.error);
};
function parsePostHistory(data, blockName) {

@ -1,7 +1,7 @@
'use strict';
define('forum/topic/merge', ['search'], function (search) {
define('forum/topic/merge', ['search', 'alerts'], function (search, alerts) {
const Merge = {};
let modal;
let mergeBtn;
@ -54,7 +54,7 @@ define('forum/topic/merge', ['search'], function (search) {
callback = callback || function () {};
socket.emit('topics.getTopic', tid, function (err, topicData) {
if (err) {
return app.alertError(err);
return alerts.error(err);
}
const title = topicData ? topicData.title : 'No title';
if (selectedTids[tid]) {
@ -93,7 +93,7 @@ define('forum/topic/merge', ['search'], function (search) {
socket.emit('topics.merge', { tids: tids, options: options }, function (err, tid) {
btn.removeAttr('disabled');
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
ajaxify.go('/topic/' + tid);
closeModal();

@ -56,7 +56,7 @@ define('forum/topic/move-post', [
},
clickfn: function (alert, params) {
delete params.timeoutfn;
app.alertSuccess('[[topic:topic_move_posts_undone]]');
alerts.success('[[topic:topic_move_posts_undone]]');
moveCommit.removeAttr('disabled');
},
});
@ -101,10 +101,10 @@ define('forum/topic/move-post', [
if (targetTid && parseInt(targetTid, 10) !== parseInt(fromTid, 10)) {
api.get('/topics/' + targetTid, {}).then(function (data) {
if (!data || !data.tid) {
return app.alertError('[[error:no-topic]]');
return alerts.error('[[error:no-topic]]');
}
if (data.scheduled) {
return app.alertError('[[error:cant-move-posts-to-scheduled]]');
return alerts.error('[[error:cant-move-posts-to-scheduled]]');
}
const translateStr = translator.compile('topic:x-posts-will-be-moved-to-y', postSelect.pids.length, data.title);
moveModal.find('#pids').translateHtml(translateStr);
@ -151,7 +151,7 @@ define('forum/topic/move-post', [
});
closeMoveModal();
}).catch(app.alertError);
}).catch(alerts.error);
}
function closeMoveModal() {

@ -75,7 +75,7 @@ define('forum/topic/move', ['categorySelector', 'alerts', 'hooks'], function (ca
},
clickfn: function (alert, params) {
delete params.timeoutfn;
app.alertSuccess('[[topic:topic_move_undone]]');
alerts.success('[[topic:topic_move_undone]]');
},
});
}
@ -89,7 +89,7 @@ define('forum/topic/move', ['categorySelector', 'alerts', 'hooks'], function (ca
socket.emit(!data.tids ? 'topics.moveAll' : 'topics.move', data, function (err) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
if (typeof data.onComplete === 'function') {

@ -9,8 +9,9 @@ define('forum/topic/postTools', [
'forum/topic/votes',
'api',
'bootbox',
'alerts',
'hooks',
], function (share, navigator, components, translator, votes, api, bootbox, hooks) {
], function (share, navigator, components, translator, votes, api, bootbox, alerts, hooks) {
const PostTools = {};
let staleReplyAnyway = false;
@ -42,7 +43,7 @@ define('forum/topic/postTools', [
socket.emit('posts.loadPostTools', { pid: pid, cid: ajaxify.data.cid }, function (err, data) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
data.posts.display_move_tools = data.posts.display_move_tools && index !== 0;
@ -208,7 +209,7 @@ define('forum/topic/postTools', [
msg = '[[error:' + languageKey + '-minutes, ' + numMinutes + ']]';
}
}
app.alertError(msg);
alerts.error(msg);
return false;
}
return true;
@ -240,9 +241,9 @@ define('forum/topic/postTools', [
const ip = $(this).attr('data-ip');
socket.emit('blacklist.addRule', ip, function (err) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
app.alertSuccess('[[admin/manage/blacklist:ban-ip]]');
alerts.success('[[admin/manage/blacklist:ban-ip]]');
});
});
@ -306,7 +307,7 @@ define('forum/topic/postTools', [
}
socket.emit('posts.getRawPost', toPid, function (err, post) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
quote(post);
@ -352,7 +353,7 @@ define('forum/topic/postTools', [
api[method](`/posts/${pid}/bookmark`, undefined, function (err) {
if (err) {
return app.alertError(err);
return alerts.error(err);
}
const type = method === 'put' ? 'bookmark' : 'unbookmark';
hooks.fire(`action:post.${type}`, { pid: pid });
@ -414,7 +415,7 @@ define('forum/topic/postTools', [
const route = action === 'purge' ? '' : '/state';
const method = action === 'restore' ? 'put' : 'del';
api[method](`/posts/${pid}${route}`).catch(app.alertError);
api[method](`/posts/${pid}${route}`).catch(alerts.error);
});
}

@ -1,7 +1,7 @@
'use strict';
define('forum/topic/replies', ['navigator', 'components', 'forum/topic/posts', 'hooks'], function (navigator, components, posts, hooks) {
define('forum/topic/replies', ['forum/topic/posts', 'hooks', 'alerts'], function (posts, hooks, alerts) {
const Replies = {};
Replies.init = function (button) {
@ -19,7 +19,7 @@ define('forum/topic/replies', ['navigator', 'components', 'forum/topic/posts', '
loading.addClass('hidden');
if (err) {
open.removeClass('hidden');
return app.alertError(err.message);
return alerts.error(err);
}
close.removeClass('hidden');

@ -61,7 +61,7 @@ define('forum/topic/threadTools', [
.then(function () {
eventEl.remove();
})
.catch(app.alertError);
.catch(alerts.error);
}
});
});
@ -70,7 +70,7 @@ define('forum/topic/threadTools', [
topicContainer.on('click', '[component="topic/mark-unread"]', function () {
socket.emit('topics.markUnread', tid, function (err) {
if (err) {
return app.alertError(err);
return alerts.error(err);
}
if (app.previousUrl && !app.previousUrl.match('^/topic')) {
@ -81,7 +81,7 @@ define('forum/topic/threadTools', [
ajaxify.go('category/' + ajaxify.data.category.slug, handleBack.onBackClicked);
}
app.alertSuccess('[[topic:mark_unread.success]]');
alerts.success('[[topic:mark_unread.success]]');
});
return false;
});
@ -90,9 +90,9 @@ define('forum/topic/threadTools', [
const btn = $(this);
socket.emit('topics.markAsUnreadForAll', [tid], function (err) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
app.alertSuccess('[[topic:markAsUnreadForAll.success]]');
alerts.success('[[topic:markAsUnreadForAll.success]]');
btn.parents('.thread-tools.open').find('.dropdown-toggle').trigger('click');
});
return false;
@ -182,7 +182,7 @@ define('forum/topic/threadTools', [
socket.emit('topics.loadTopicTools', { tid: ajaxify.data.tid, cid: ajaxify.data.cid }, function (err, data) {
if (err) {
return app.alertError(err);
return alerts.error(err);
}
app.parseAndTranslate('partials/topic/topic-menu-list', data, function (html) {
dropdownMenu.html(html);
@ -204,7 +204,7 @@ define('forum/topic/threadTools', [
if (ok) {
api[method](`/topics/${tid}${path}`, body)
.then(onComplete)
.catch(app.alertError);
.catch(alerts.error);
}
};
@ -256,7 +256,7 @@ define('forum/topic/threadTools', [
body.expiry = expiry.getTime();
onSuccess();
} else {
app.alertError('[[error:invalid-date]]');
alerts.error('[[error:invalid-date]]');
}
},
},

@ -2,8 +2,8 @@
define('forum/topic/votes', [
'components', 'translator', 'benchpress', 'api', 'hooks', 'bootbox',
], function (components, translator, Benchpress, api, hooks, bootbox) {
'components', 'translator', 'api', 'hooks', 'bootbox', 'alerts',
], function (components, translator, api, hooks, bootbox, alerts) {
const Votes = {};
Votes.addVoteHandler = function () {
@ -20,7 +20,7 @@ define('forum/topic/votes', [
socket.emit('posts.getUpvoters', [pid], function (err, data) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
if (data.length) {
@ -68,7 +68,7 @@ define('forum/topic/votes', [
ajaxify.go('login');
return;
}
return app.alertError(err.message);
return alerts.error(err);
}
hooks.fire('action:post.toggleVote', {
pid: pid,
@ -88,7 +88,7 @@ define('forum/topic/votes', [
}
// Only show error if it's an unexpected error.
return app.alertError(err.message);
return alerts.error(err);
}
app.parseAndTranslate('partials/modals/votes_modal', data, function (html) {

@ -2,8 +2,8 @@
define('forum/unread', [
'topicSelect', 'components', 'topicList', 'categorySelector',
], function (topicSelect, components, topicList, categorySelector) {
'topicSelect', 'components', 'topicList', 'categorySelector', 'alerts',
], function (topicSelect, components, topicList, categorySelector, alerts) {
const Unread = {};
const watchStates = {
@ -26,10 +26,10 @@ define('forum/unread', [
function markAllRead() {
socket.emit('topics.markAllRead', function (err) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
app.alertSuccess('[[unread:topics_marked_as_read.success]]');
alerts.success('[[unread:topics_marked_as_read.success]]');
$('[component="category"]').empty();
$('[component="pagination"]').addClass('hidden');
@ -45,7 +45,7 @@ define('forum/unread', [
}
socket.emit('topics.markAsRead', tids, function (err) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
doneRemovingTids(tids);
@ -64,7 +64,7 @@ define('forum/unread', [
socket.emit('topics.markCategoryTopicsRead', cid, function (err) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
doneRemovingTids(tids);
@ -101,7 +101,7 @@ define('forum/unread', [
function doneRemovingTids(tids) {
removeTids(tids);
app.alertSuccess('[[unread:topics_marked_as_read.success]]');
alerts.success('[[unread:topics_marked_as_read.success]]');
if (!$('[component="category"]').children().length) {
$('#category-no-topics').removeClass('hidden');

@ -2,8 +2,8 @@
define('forum/users', [
'translator', 'benchpress', 'api', 'accounts/invite',
], function (translator, Benchpress, api, AccountInvite) {
'translator', 'benchpress', 'api', 'alerts', 'accounts/invite',
], function (translator, Benchpress, api, alerts, AccountInvite) {
const Users = {};
let searchResultCount = 0;
@ -82,7 +82,7 @@ define('forum/users', [
function loadPage(query) {
api.get('/api/users', query)
.then(renderSearchResults)
.catch(app.alertError);
.catch(alerts.error);
}
function renderSearchResults(data) {

@ -1,6 +1,6 @@
'use strict';
define('accounts/delete', ['api', 'bootbox'], function (api, bootbox) {
define('accounts/delete', ['api', 'bootbox', 'alerts'], function (api, bootbox, alerts) {
const Delete = {};
Delete.account = function (uid, callback) {
@ -40,14 +40,12 @@ define('accounts/delete', ['api', 'bootbox'], function (api, bootbox) {
}
api.del(`/users/${uid}${path}`, {}).then(() => {
app.alertSuccess(successText);
alerts.success(successText);
if (typeof callback === 'function') {
return callback();
}
}).catch(function (err) {
app.alertError(err);
});
}).catch(alerts.error);
});
}

@ -1,6 +1,6 @@
'use strict';
define('accounts/invite', ['api', 'benchpress', 'bootbox'], function (api, Benchpress, bootbox) {
define('accounts/invite', ['api', 'benchpress', 'bootbox', 'alerts'], function (api, Benchpress, bootbox, alerts) {
const Invite = {};
function isACP() {
@ -29,9 +29,7 @@ define('accounts/invite', ['api', 'benchpress', 'bootbox'], function (api, Bench
},
});
});
}).catch((err) => {
app.alertError(err.message);
});
}).catch(alerts.error);
});
};
@ -54,10 +52,8 @@ define('accounts/invite', ['api', 'benchpress', 'bootbox'], function (api, Bench
}
api.post(`/users/${app.user.uid}/invites`, data).then(() => {
app.alertSuccess(`[[${isACP() ? 'admin/manage/users:alerts.email-sent-to' : 'users:invitation-email-sent'}, ${data.emails.replace(/,/g, '&#44; ')}]]`);
}).catch((err) => {
app.alertError(err.message);
});
alerts.success(`[[${isACP() ? 'admin/manage/users:alerts.email-sent-to' : 'users:invitation-email-sent'}, ${data.emails.replace(/,/g, '&#44; ')}]]`);
}).catch(alerts.error);
};
return Invite;

@ -4,7 +4,8 @@ define('accounts/picture', [
'pictureCropper',
'api',
'bootbox',
], (pictureCropper, api, bootbox) => {
'alerts',
], (pictureCropper, api, bootbox, alerts) => {
const Picture = {};
Picture.openChangeModal = () => {
@ -12,7 +13,7 @@ define('accounts/picture', [
uid: ajaxify.data.uid,
}, function (err, pictures) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
// boolean to signify whether an uploaded picture is present in the pictures list
@ -94,7 +95,7 @@ define('accounts/picture', [
changeUserPicture(type, iconBgColor).then(() => {
Picture.updateHeader(type === 'default' ? '' : modal.find('.list-group-item.active img').attr('src'), iconBgColor);
ajaxify.refresh();
}).catch(app.alertError);
}).catch(alerts.error);
}
function onCloseModal() {
@ -203,7 +204,7 @@ define('accounts/picture', [
}, function (err) {
modal.modal('hide');
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
onRemoveComplete();
});

@ -2,7 +2,7 @@
'use strict';
define('autocomplete', ['api'], function (api) {
define('autocomplete', ['api', 'alerts'], function (api, alerts) {
const module = {};
module.user = function (input, params, onselect) {
@ -25,7 +25,7 @@ define('autocomplete', ['api'], function (api) {
api.get('/api/users', params, function (err, result) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
if (result && result.users) {
@ -72,7 +72,7 @@ define('autocomplete', ['api'], function (api) {
query: request.term,
}, function (err, results) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
if (results && results.length) {
const names = results.map(function (group) {
@ -107,7 +107,7 @@ define('autocomplete', ['api'], function (api) {
cid: ajaxify.data.cid || 0,
}, function (err, tags) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
if (tags) {
response(tags);

@ -1,6 +1,6 @@
'use strict';
define('categorySearch', function () {
define('categorySearch', ['alerts'], function (alerts) {
const categorySearch = {};
categorySearch.init = function (el, options) {
@ -77,7 +77,7 @@ define('categorySearch', function () {
showLinks: options.showLinks,
}, function (err, categories) {
if (err) {
return app.alertError(err);
return alerts.error(err);
}
callback(localCategories.concat(categories));
});

@ -1,14 +1,14 @@
'use strict';
define('chat', [
'components', 'taskbar', 'translator', 'hooks', 'bootbox',
], function (components, taskbar, translator, hooks, bootbox) {
'components', 'taskbar', 'translator', 'hooks', 'bootbox', 'alerts'
], function (components, taskbar, translator, hooks, bootbox, alerts) {
const module = {};
let newMessage = false;
module.openChat = function (roomId, uid) {
if (!app.user.uid) {
return app.alertError('[[error:not-logged-in]]');
return alerts.error('[[error:not-logged-in]]');
}
function loadAndCenter(chatModal) {
@ -22,7 +22,7 @@ define('chat', [
} else {
socket.emit('modules.chats.loadRoom', { roomId: roomId, uid: uid || app.user.uid }, function (err, roomData) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
roomData.users = roomData.users.filter(function (user) {
return user && parseInt(user.uid, 10) !== parseInt(app.user.uid, 10);
@ -38,7 +38,7 @@ define('chat', [
function createChat() {
socket.emit('modules.chats.newRoom', { touid: touid }, function (err, roomId) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
if (!ajaxify.data.template.chats) {
@ -53,15 +53,15 @@ define('chat', [
callback = callback || function () { };
if (!app.user.uid) {
return app.alertError('[[error:not-logged-in]]');
return alerts.error('[[error:not-logged-in]]');
}
if (parseInt(touid, 10) === parseInt(app.user.uid, 10)) {
return app.alertError('[[error:cant-chat-with-yourself]]');
return alerts.error('[[error:cant-chat-with-yourself]]');
}
socket.emit('modules.chats.isDnD', touid, function (err, isDnD) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
if (!isDnD) {
return createChat();
@ -81,7 +81,7 @@ define('chat', [
after: 0,
}, function (err, data) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
const rooms = data.rooms.filter(function (room) {
@ -112,7 +112,7 @@ define('chat', [
$('[component="chats/mark-all-read"]').off('click').on('click', function () {
socket.emit('modules.chats.markAllRead', function (err) {
if (err) {
return app.alertError(err);
return alerts.error(err);
}
});
});
@ -134,7 +134,7 @@ define('chat', [
roomId: data.roomId,
}, function (err, roomData) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
roomData.users = roomData.users.filter(function (user) {

@ -1,7 +1,7 @@
'use strict';
define('flags', ['hooks', 'components', 'api'], function (hooks, components, api) {
define('flags', ['hooks', 'components', 'api', 'alerts'], function (hooks, components, api, alerts) {
const Flag = {};
let flagModal;
let flagCommit;
@ -57,9 +57,9 @@ define('flags', ['hooks', 'components', 'api'], function (hooks, components, api
api.put(`/flags/${flagId}`, {
state: 'resolved',
}).then(() => {
app.alertSuccess('[[flags:resolved]]');
alerts.success('[[flags:resolved]]');
hooks.fire('action:flag.resolved', { flagId: flagId });
}).catch(app.alertError);
}).catch(alerts.error);
};
function createFlag(type, id, reason) {
@ -69,11 +69,11 @@ define('flags', ['hooks', 'components', 'api'], function (hooks, components, api
const data = { type: type, id: id, reason: reason };
api.post('/flags', data, function (err, flagId) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
flagModal.modal('hide');
app.alertSuccess('[[flags:modal-submit-success]]');
alerts.success('[[flags:modal-submit-success]]');
if (type === 'post') {
const postEl = components.get('post', 'pid', id);
postEl.find('[component="post/flag"]').addClass('hidden').parent().attr('hidden', '');

@ -38,9 +38,9 @@ define('messages', ['bootbox', 'translator', 'storage', 'alerts'], function (boo
app.removeAlert('email_confirm');
socket.emit('user.emailConfirm', {}, function (err) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
app.alertSuccess('[[notifications:email-confirm-sent]]');
alerts.success('[[notifications:email-confirm-sent]]');
});
};
alerts.alert(msg);

@ -1,6 +1,6 @@
'use strict';
define('navigator', ['forum/pagination', 'components', 'hooks'], function (pagination, components, hooks) {
define('navigator', ['forum/pagination', 'components', 'hooks', 'alerts'], function (pagination, components, hooks, alerts) {
const navigator = {};
let index = 0;
let count = 0;
@ -251,7 +251,7 @@ define('navigator', ['forum/pagination', 'components', 'hooks'], function (pagin
socket.emit('posts.getPostSummaryByIndex', { tid: ajaxify.data.tid, index: index - 1 }, function (err, postData) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
app.parseAndTranslate('partials/topic/navigation-post', { post: postData }, function (html) {
paginationBlockEl

@ -5,10 +5,10 @@ define('notifications', [
'translator',
'components',
'navigator',
'benchpress',
'tinycon',
'hooks',
], function (translator, components, navigator, Benchpress, Tinycon, hooks) {
'alerts',
], function (translator, components, navigator, Tinycon, hooks, alerts) {
const Notifications = {};
let unreadNotifs = {};
@ -28,7 +28,7 @@ define('notifications', [
callback = callback || function () {};
socket.emit('notifications.get', null, function (err, data) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
const notifs = data.unread.concat(data.read).sort(function (a, b) {
@ -82,7 +82,7 @@ define('notifications', [
socket.emit('notifications.getCount', function (err, count) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
Notifications.updateNotifCount(count);
@ -96,7 +96,7 @@ define('notifications', [
function markNotification(nid, read, callback) {
socket.emit('notifications.mark' + (read ? 'Read' : 'Unread'), nid, function (err) {
if (err) {
return app.alertError(err.message);
return alerts.error(err);
}
if (read && unreadNotifs[nid]) {
@ -150,7 +150,7 @@ define('notifications', [
Notifications.markAllRead = function () {
socket.emit('notifications.markAllRead', function (err) {
if (err) {
app.alertError(err.message);
alerts.error(err);
}
unreadNotifs = {};
});

@ -1,6 +1,6 @@
'use strict';
define('pictureCropper', ['cropper'], function (Cropper) {
define('pictureCropper', ['cropper', 'alerts'], function (Cropper, alerts) {
const module = {};
module.show = function (data, callback) {
@ -118,7 +118,7 @@ define('pictureCropper', ['cropper'], function (Cropper) {
cropperModal.find('#upload-progress-box').hide();
cropperModal.find('.upload-btn').removeClass('disabled');
cropperModal.find('.crop-btn').removeClass('disabled');
return app.alertError(err.message);
return alerts.error(err);
}
callback(result.url);
@ -158,7 +158,7 @@ define('pictureCropper', ['cropper'], function (Cropper) {
params: socketData,
}, function (err, result) {
if (err) {
return app.alertError(err);
return alerts.error(err);
}
if (socketData.progress + chunkSize < socketData.size) {
@ -185,9 +185,9 @@ define('pictureCropper', ['cropper'], function (Cropper) {
'Failed to execute \'toDataURL\' on \'HTMLCanvasElement\': Tainted canvases may not be exported.',
];
if (corsErrors.indexOf(err.message) !== -1) {
app.alertError('[[error:cors-error]]');
alerts.error('[[error:cors-error]]');
} else {
app.alertError(err.message);
alerts.error(err.message);
}
return;
}

@ -237,7 +237,7 @@ define('search', ['translator', 'storage', 'hooks', 'alerts'], function (transla
try {
term = encodeURIComponent(term);
} catch (e) {
return app.alertError('[[error:invalid-search-term]]');
return alerts.error('[[error:invalid-search-term]]');
}
const query = {

@ -1,6 +1,8 @@
'use strict';
define('topicThumbs', ['api', 'bootbox', 'uploader', 'benchpress', 'translator', 'jquery-ui/widgets/sortable'], function (api, bootbox, uploader, Benchpress, translator) {
define('topicThumbs', [
'api', 'bootbox', 'alerts', 'uploader', 'benchpress', 'translator', 'jquery-ui/widgets/sortable',
], function (api, bootbox, alerts, uploader, Benchpress, translator) {
const Thumbs = {};
Thumbs.get = id => api.get(`/topics/${id}/thumbs`, {});
@ -97,7 +99,7 @@ define('topicThumbs', ['api', 'bootbox', 'uploader', 'benchpress', 'translator',
path: path,
}).then(() => {
Thumbs.modal.open(payload);
}).catch(app.alertError);
}).catch(alerts.error);
});
}
});
@ -120,7 +122,7 @@ define('topicThumbs', ['api', 'bootbox', 'uploader', 'benchpress', 'translator',
let path = el.getAttribute('data-path');
path = path.replace(new RegExp(`^${config.upload_url}`), '');
api.put(`/topics/${id}/thumbs/order`, { path, order }).catch(app.alertError);
api.put(`/topics/${id}/thumbs/order`, { path, order }).catch(alerts.error);
});
};

Loading…
Cancel
Save