Files
NodeBB/public/src/admin/admin.js

235 lines
5.6 KiB
JavaScript
Raw Normal View History

2017-02-18 01:56:23 -07:00
'use strict';
(function () {
2016-07-29 14:26:04 +03:00
var logoutTimer = 0;
var logoutMessage;
2016-07-29 14:26:04 +03:00
function startLogoutTimer() {
if (app.config.adminReloginDuration <= 0) {
return;
}
2016-07-29 14:26:04 +03:00
if (logoutTimer) {
clearTimeout(logoutTimer);
}
2020-12-04 12:01:46 -05:00
// pre-translate language string gh#9046
if (!logoutMessage) {
2020-12-04 12:01:46 -05:00
require(['translator'], function (translator) {
translator.translate('[[login:logged-out-due-to-inactivity]]', function (translated) {
logoutMessage = translated;
2020-12-04 12:01:46 -05:00
});
});
}
2016-07-29 14:26:04 +03:00
logoutTimer = setTimeout(function () {
require(['bootbox'], function (bootbox) {
bootbox.alert({
closeButton: false,
message: logoutMessage,
callback: function () {
window.location.reload();
},
});
2016-07-29 14:26:04 +03:00
});
}, 3600000);
}
require(['hooks'], (hooks) => {
hooks.on('action:ajaxify.end', () => {
showCorrectNavTab();
startLogoutTimer();
});
2016-05-23 13:03:31 +03:00
});
function showCorrectNavTab() {
// show correct tab if url has #
2016-02-13 15:09:09 +02:00
if (window.location.hash) {
2016-09-23 13:13:02 +03:00
$('.nav-pills a[href="' + window.location.hash + '"]').tab('show');
2016-02-13 15:09:09 +02:00
}
2016-05-23 13:03:31 +03:00
}
$(document).ready(function () {
if (!/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
require(['admin/modules/search'], function (search) {
search.init();
});
}
$('[component="logout"]').on('click', function () {
app.logout();
2020-06-10 08:02:07 -04:00
return false;
});
2017-02-03 22:16:04 +00:00
2015-08-21 18:40:59 -04:00
configureSlidemenu();
2016-06-06 08:24:15 -04:00
setupNProgress();
2014-05-15 17:16:17 -04:00
});
$(window).on('action:ajaxify.contentLoaded', function (ev, data) {
2016-03-29 14:57:55 -04:00
selectMenuItem(data.url);
setupRestartLinks();
componentHandler.upgradeDom();
});
2016-06-06 08:24:15 -04:00
function setupNProgress() {
require(['nprogress', 'hooks'], function (NProgress, hooks) {
2020-10-09 11:48:52 -04:00
$(window).on('action:ajaxify.start', function () {
NProgress.set(0.7);
});
2016-06-06 08:24:15 -04:00
hooks.on('action:ajaxify.end', function () {
2020-10-09 11:48:52 -04:00
NProgress.done();
});
2016-06-06 08:24:15 -04:00
});
}
function selectMenuItem(url) {
2016-12-08 17:10:37 -07:00
require(['translator'], function (translator) {
url = url
.replace(/\/\d+$/, '')
.split('/').slice(0, 3).join('/')
2017-01-02 08:59:55 -07:00
.split(/[?#]/)[0].replace(/(\/+$)|(^\/+)/, '');
2016-12-08 17:10:37 -07:00
// If index is requested, load the dashboard
if (url === 'admin') {
url = 'admin/dashboard';
2016-12-08 17:10:37 -07:00
}
2016-12-08 17:10:37 -07:00
url = [config.relative_path, url].join('/');
2016-12-21 15:47:13 -07:00
var fallback;
2016-12-08 17:10:37 -07:00
$('#main-menu li').removeClass('active');
$('#main-menu a').removeClass('active').filter('[href="' + url + '"]').each(function () {
var menu = $(this);
if (menu.parent().attr('data-link')) {
return;
}
2015-08-19 15:52:31 -04:00
menu
.parent().addClass('active')
.parents('.menu-item').addClass('active');
2016-12-21 15:47:13 -07:00
fallback = menu.text();
2016-12-08 17:10:37 -07:00
});
2015-08-20 13:21:12 -04:00
2016-12-21 15:47:13 -07:00
var mainTitle;
var pageTitle;
if (/admin\/plugins\//.test(url)) {
2016-12-21 15:47:13 -07:00
mainTitle = fallback;
pageTitle = '[[admin/menu:section-plugins]] > ' + mainTitle;
2016-12-08 17:10:37 -07:00
} else {
2016-12-21 15:47:13 -07:00
var matches = url.match(/admin\/(.+?)\/(.+?)$/);
if (matches) {
mainTitle = '[[admin/menu:' + matches[1] + '/' + matches[2] + ']]';
pageTitle = '[[admin/menu:section-' +
(matches[1] === 'development' ? 'advanced' : matches[1]) +
']]' + (matches[2] ? (' > ' + mainTitle) : '');
if (matches[2] === 'settings') {
mainTitle = translator.compile('admin/menu:settings.page-title', mainTitle);
}
} else {
mainTitle = '[[admin/menu:section-dashboard]]';
pageTitle = '[[admin/menu:section-dashboard]]';
2016-12-21 15:47:13 -07:00
}
}
2015-10-29 15:47:00 -04:00
2016-12-21 15:47:13 -07:00
pageTitle = translator.compile('admin/admin:acp-title', pageTitle);
2015-10-29 15:47:00 -04:00
2016-12-21 15:47:13 -07:00
translator.translate(pageTitle, function (title) {
2016-12-08 17:10:37 -07:00
document.title = title.replace(/&gt;/g, '>');
});
2016-12-21 15:47:13 -07:00
translator.translate(mainTitle, function (text) {
$('#main-page-title').text(text);
});
2016-12-08 17:10:37 -07:00
});
}
2015-04-17 13:21:45 -04:00
function setupRestartLinks() {
$('.rebuild-and-restart').off('click').on('click', function () {
require(['bootbox'], function (bootbox) {
bootbox.confirm('[[admin/admin:alert.confirm-rebuild-and-restart]]', function (confirm) {
if (confirm) {
require(['admin/modules/instance'], function (instance) {
instance.rebuildAndRestart();
});
}
});
2015-04-17 13:21:45 -04:00
});
});
$('.restart').off('click').on('click', function () {
require(['bootbox'], function (bootbox) {
bootbox.confirm('[[admin/admin:alert.confirm-restart]]', function (confirm) {
if (confirm) {
require(['admin/modules/instance'], function (instance) {
instance.restart();
});
}
});
2015-04-17 13:21:45 -04:00
});
});
2016-12-08 17:10:37 -07:00
}
2015-08-21 17:46:14 -04:00
2015-08-21 18:40:59 -04:00
function configureSlidemenu() {
require(['slideout'], function (Slideout) {
var env = utils.findBootstrapEnvironment();
var slideout = new Slideout({
panel: document.getElementById('panel'),
menu: document.getElementById('menu'),
padding: 256,
tolerance: 70,
});
2017-02-18 01:27:46 -07:00
if (env === 'md' || env === 'lg') {
slideout.disableTouch();
}
2017-02-18 01:27:46 -07:00
$('#mobile-menu').on('click', function () {
slideout.toggle();
});
2017-02-18 01:27:46 -07:00
$('#menu a').on('click', function () {
slideout.close();
});
2015-08-21 18:40:59 -04:00
$(window).on('resize', function () {
slideout.close();
2015-08-21 18:40:59 -04:00
env = utils.findBootstrapEnvironment();
2017-02-18 01:27:46 -07:00
if (env === 'md' || env === 'lg') {
slideout.disableTouch();
$('#header').css({
position: 'relative',
});
} else {
slideout.enableTouch();
$('#header').css({
position: 'fixed',
});
}
});
2017-02-18 01:27:46 -07:00
function onOpeningMenu() {
2017-02-03 22:12:47 +00:00
$('#header').css({
top: ($('#panel').position().top * -1) + 'px',
position: 'absolute',
2017-02-03 22:12:47 +00:00
});
}
2015-08-21 18:40:59 -04:00
slideout.on('open', onOpeningMenu);
2017-02-18 01:27:46 -07:00
slideout.on('close', function () {
$('#header').css({
top: '0px',
position: 'fixed',
});
2015-08-21 18:40:59 -04:00
});
});
}
2017-04-14 00:13:25 -06:00
// tell ace to use the right paths when requiring modules
require(['ace/ace'], function (ace) {
ace.config.set('packaged', true);
ace.config.set('basePath', config.relative_path + '/assets/src/modules/ace/');
});
2017-02-18 02:30:48 -07:00
}());