mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
refactor: deprecate app.alert functions user alerts module directly
This commit is contained in:
@@ -14,11 +14,6 @@ app.flags = {};
|
||||
|
||||
app.cacheBuster = config['cache-buster'];
|
||||
|
||||
let hooks;
|
||||
require(['hooks'], function (_hooks) {
|
||||
hooks = _hooks;
|
||||
});
|
||||
|
||||
$(document).ready(function () {
|
||||
ajaxify.parseData();
|
||||
app.load();
|
||||
@@ -92,8 +87,9 @@ app.flags = {};
|
||||
'search',
|
||||
'forum/unread',
|
||||
'forum/header',
|
||||
'hooks',
|
||||
'timeago/jquery.timeago',
|
||||
], function (taskbar, helpers, pagination, translator, messages, search, unread, header) {
|
||||
], function (taskbar, helpers, pagination, translator, messages, search, unread, header, hooks) {
|
||||
header.prepareDOM();
|
||||
translator.prepareDOM();
|
||||
taskbar.init();
|
||||
@@ -140,42 +136,30 @@ app.flags = {};
|
||||
};
|
||||
|
||||
app.alert = function (params) {
|
||||
console.warn('[deprecated] app.alert is deprecated, please use alerts.alert');
|
||||
require(['alerts'], function (alerts) {
|
||||
alerts.alert(params);
|
||||
});
|
||||
};
|
||||
|
||||
app.removeAlert = function (id) {
|
||||
console.warn('[deprecated] app.removeAlert is deprecated, please use alerts.remove');
|
||||
require(['alerts'], function (alerts) {
|
||||
alerts.remove(id);
|
||||
});
|
||||
};
|
||||
|
||||
app.alertSuccess = function (message, timeout) {
|
||||
app.alert({
|
||||
alert_id: utils.generateUUID(),
|
||||
title: '[[global:alert.success]]',
|
||||
message: message,
|
||||
type: 'success',
|
||||
timeout: timeout || 5000,
|
||||
console.warn('[deprecated] app.alertSuccess is deprecated, please use alerts.success');
|
||||
require(['alerts'], function (alerts) {
|
||||
alerts.success(message, timeout);
|
||||
});
|
||||
};
|
||||
|
||||
app.alertError = function (message, timeout) {
|
||||
message = (message && message.message) || message;
|
||||
|
||||
if (message === '[[error:revalidate-failure]]') {
|
||||
socket.disconnect();
|
||||
app.reconnect();
|
||||
return;
|
||||
}
|
||||
|
||||
app.alert({
|
||||
alert_id: utils.generateUUID(),
|
||||
title: '[[global:alert.error]]',
|
||||
message: message,
|
||||
type: 'danger',
|
||||
timeout: timeout || 10000,
|
||||
console.warn('[deprecated] app.alertError is deprecated, please use alerts.error');
|
||||
require(['alerts'], function (alerts) {
|
||||
alerts.error(message, timeout);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -322,9 +306,11 @@ app.flags = {};
|
||||
};
|
||||
|
||||
app.newTopic = function (cid, tags) {
|
||||
hooks.fire('action:composer.topic.new', {
|
||||
cid: cid || ajaxify.data.cid || 0,
|
||||
tags: tags || (ajaxify.data.tag ? [ajaxify.data.tag] : []),
|
||||
require(['hooks'], function (hooks) {
|
||||
hooks.fire('action:composer.topic.new', {
|
||||
cid: cid || ajaxify.data.cid || 0,
|
||||
tags: tags || (ajaxify.data.tag ? [ajaxify.data.tag] : []),
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -18,6 +18,38 @@ define('alerts', ['translator', 'components', 'hooks'], function (translator, co
|
||||
}
|
||||
};
|
||||
|
||||
module.success = function (message, timeout) {
|
||||
module.alert({
|
||||
alert_id: utils.generateUUID(),
|
||||
title: '[[global:alert.success]]',
|
||||
message: message,
|
||||
type: 'success',
|
||||
timeout: timeout || 5000,
|
||||
});
|
||||
};
|
||||
|
||||
module.error = function (message, timeout) {
|
||||
message = (message && message.message) || message;
|
||||
|
||||
if (message === '[[error:revalidate-failure]]') {
|
||||
socket.disconnect();
|
||||
app.reconnect();
|
||||
return;
|
||||
}
|
||||
|
||||
module.alert({
|
||||
alert_id: utils.generateUUID(),
|
||||
title: '[[global:alert.error]]',
|
||||
message: message,
|
||||
type: 'danger',
|
||||
timeout: timeout || 10000,
|
||||
});
|
||||
};
|
||||
|
||||
module.remove = function (id) {
|
||||
$('#alert_button_' + id).remove();
|
||||
};
|
||||
|
||||
function createNew(params) {
|
||||
app.parseAndTranslate('alert', params, function (html) {
|
||||
let alert = $('#' + params.alert_id);
|
||||
@@ -56,10 +88,6 @@ define('alerts', ['translator', 'components', 'hooks'], function (translator, co
|
||||
});
|
||||
}
|
||||
|
||||
module.remove = function (id) {
|
||||
$('#alert_button_' + id).remove();
|
||||
};
|
||||
|
||||
function updateAlert(alert, params) {
|
||||
alert.find('strong').html(params.title);
|
||||
alert.find('p').html(params.message);
|
||||
|
||||
Reference in New Issue
Block a user