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'];
|
app.cacheBuster = config['cache-buster'];
|
||||||
|
|
||||||
let hooks;
|
|
||||||
require(['hooks'], function (_hooks) {
|
|
||||||
hooks = _hooks;
|
|
||||||
});
|
|
||||||
|
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
ajaxify.parseData();
|
ajaxify.parseData();
|
||||||
app.load();
|
app.load();
|
||||||
@@ -92,8 +87,9 @@ app.flags = {};
|
|||||||
'search',
|
'search',
|
||||||
'forum/unread',
|
'forum/unread',
|
||||||
'forum/header',
|
'forum/header',
|
||||||
|
'hooks',
|
||||||
'timeago/jquery.timeago',
|
'timeago/jquery.timeago',
|
||||||
], function (taskbar, helpers, pagination, translator, messages, search, unread, header) {
|
], function (taskbar, helpers, pagination, translator, messages, search, unread, header, hooks) {
|
||||||
header.prepareDOM();
|
header.prepareDOM();
|
||||||
translator.prepareDOM();
|
translator.prepareDOM();
|
||||||
taskbar.init();
|
taskbar.init();
|
||||||
@@ -140,42 +136,30 @@ app.flags = {};
|
|||||||
};
|
};
|
||||||
|
|
||||||
app.alert = function (params) {
|
app.alert = function (params) {
|
||||||
|
console.warn('[deprecated] app.alert is deprecated, please use alerts.alert');
|
||||||
require(['alerts'], function (alerts) {
|
require(['alerts'], function (alerts) {
|
||||||
alerts.alert(params);
|
alerts.alert(params);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
app.removeAlert = function (id) {
|
app.removeAlert = function (id) {
|
||||||
|
console.warn('[deprecated] app.removeAlert is deprecated, please use alerts.remove');
|
||||||
require(['alerts'], function (alerts) {
|
require(['alerts'], function (alerts) {
|
||||||
alerts.remove(id);
|
alerts.remove(id);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
app.alertSuccess = function (message, timeout) {
|
app.alertSuccess = function (message, timeout) {
|
||||||
app.alert({
|
console.warn('[deprecated] app.alertSuccess is deprecated, please use alerts.success');
|
||||||
alert_id: utils.generateUUID(),
|
require(['alerts'], function (alerts) {
|
||||||
title: '[[global:alert.success]]',
|
alerts.success(message, timeout);
|
||||||
message: message,
|
|
||||||
type: 'success',
|
|
||||||
timeout: timeout || 5000,
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
app.alertError = function (message, timeout) {
|
app.alertError = function (message, timeout) {
|
||||||
message = (message && message.message) || message;
|
console.warn('[deprecated] app.alertError is deprecated, please use alerts.error');
|
||||||
|
require(['alerts'], function (alerts) {
|
||||||
if (message === '[[error:revalidate-failure]]') {
|
alerts.error(message, timeout);
|
||||||
socket.disconnect();
|
|
||||||
app.reconnect();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
app.alert({
|
|
||||||
alert_id: utils.generateUUID(),
|
|
||||||
title: '[[global:alert.error]]',
|
|
||||||
message: message,
|
|
||||||
type: 'danger',
|
|
||||||
timeout: timeout || 10000,
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -322,9 +306,11 @@ app.flags = {};
|
|||||||
};
|
};
|
||||||
|
|
||||||
app.newTopic = function (cid, tags) {
|
app.newTopic = function (cid, tags) {
|
||||||
hooks.fire('action:composer.topic.new', {
|
require(['hooks'], function (hooks) {
|
||||||
cid: cid || ajaxify.data.cid || 0,
|
hooks.fire('action:composer.topic.new', {
|
||||||
tags: tags || (ajaxify.data.tag ? [ajaxify.data.tag] : []),
|
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) {
|
function createNew(params) {
|
||||||
app.parseAndTranslate('alert', params, function (html) {
|
app.parseAndTranslate('alert', params, function (html) {
|
||||||
let alert = $('#' + params.alert_id);
|
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) {
|
function updateAlert(alert, params) {
|
||||||
alert.find('strong').html(params.title);
|
alert.find('strong').html(params.title);
|
||||||
alert.find('p').html(params.message);
|
alert.find('p').html(params.message);
|
||||||
|
|||||||
Reference in New Issue
Block a user