2014-05-14 18:46:11 -04:00
|
|
|
"use strict";
|
2015-08-20 23:36:59 -04:00
|
|
|
/*global componentHandler, define, socket, app, ajaxify, utils, bootbox, Mousetrap, Hammer, RELATIVE_PATH*/
|
2014-05-14 18:46:11 -04:00
|
|
|
|
|
|
|
|
(function() {
|
2014-10-09 18:42:31 -04:00
|
|
|
$(document).ready(function() {
|
2014-10-08 17:06:35 -04:00
|
|
|
setupKeybindings();
|
2014-10-09 18:42:31 -04:00
|
|
|
|
|
|
|
|
if(!/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
|
2014-10-09 18:48:35 -04:00
|
|
|
require(['admin/modules/search'], function(search) {
|
|
|
|
|
search.init();
|
|
|
|
|
});
|
2014-10-09 18:42:31 -04:00
|
|
|
}
|
|
|
|
|
|
2015-07-20 17:13:25 -04:00
|
|
|
$(window).on('action:ajaxify.contentLoaded', function(ev, data) {
|
2014-10-09 18:42:31 -04:00
|
|
|
var url = data.url;
|
|
|
|
|
|
|
|
|
|
selectMenuItem(data.url);
|
2015-04-17 13:21:45 -04:00
|
|
|
setupRestartLinks();
|
2015-08-20 23:36:59 -04:00
|
|
|
|
|
|
|
|
componentHandler.upgradeDom();
|
2014-10-09 18:42:31 -04:00
|
|
|
});
|
2014-12-08 10:27:54 -05:00
|
|
|
|
2015-06-19 14:33:56 -04:00
|
|
|
$('[component="logout"]').on('click', app.logout);
|
2015-08-21 17:46:14 -04:00
|
|
|
app.alert = launchSnackbar;
|
2014-05-15 17:16:17 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
socket.emit('admin.config.get', function(err, config) {
|
|
|
|
|
if(err) {
|
|
|
|
|
return app.alert({
|
|
|
|
|
alert_id: 'config_status',
|
|
|
|
|
timeout: 2500,
|
|
|
|
|
title: 'Error',
|
2014-10-09 00:38:43 -04:00
|
|
|
message: 'NodeBB encountered a problem getting config: ' + err.message,
|
2014-05-15 17:16:17 -04:00
|
|
|
type: 'danger'
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// move this to admin.config
|
|
|
|
|
app.config = config;
|
2015-07-20 17:16:30 -04:00
|
|
|
$(window).trigger('action:config.loaded');
|
2014-10-09 00:11:15 -04:00
|
|
|
});
|
|
|
|
|
|
2014-10-08 17:06:35 -04:00
|
|
|
function setupKeybindings() {
|
|
|
|
|
Mousetrap.bind('ctrl+shift+a r', function() {
|
2015-06-08 15:50:33 -04:00
|
|
|
require(['admin/modules/instance'], function(instance) {
|
|
|
|
|
instance.reload();
|
|
|
|
|
});
|
2014-10-08 17:06:35 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Mousetrap.bind('ctrl+shift+a R', function() {
|
|
|
|
|
socket.emit('admin.restart');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Mousetrap.bind('/', function(e) {
|
|
|
|
|
$('#acp-search input').focus();
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
}
|
2014-10-09 18:42:31 -04:00
|
|
|
|
|
|
|
|
function selectMenuItem(url) {
|
2015-08-20 14:13:21 -04:00
|
|
|
url = url
|
|
|
|
|
.replace(/\/\d+$/, '')
|
|
|
|
|
.split('/').slice(0, 3).join('/');
|
2015-04-03 11:17:58 -04:00
|
|
|
|
2015-05-05 11:37:02 -04:00
|
|
|
// If index is requested, load the dashboard
|
|
|
|
|
if (url === 'admin') {
|
|
|
|
|
url = 'admin/general/dashboard';
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-19 15:52:31 -04:00
|
|
|
$('#main-menu li').removeClass('active');
|
|
|
|
|
$('#main-menu a').removeClass('active').each(function() {
|
2014-10-09 18:42:31 -04:00
|
|
|
var menu = $(this),
|
2015-08-19 15:52:31 -04:00
|
|
|
href = menu.attr('href'),
|
2015-08-20 12:24:24 -04:00
|
|
|
isLink = menu.parent().attr('data-link') === '1';
|
2014-10-09 18:42:31 -04:00
|
|
|
|
2015-08-21 10:53:47 -04:00
|
|
|
if (!isLink && href && href === [config.relative_path, url].join('/')) {
|
2015-08-19 15:52:31 -04:00
|
|
|
menu
|
|
|
|
|
.parent().addClass('active')
|
|
|
|
|
.parents('.menu-item').addClass('active');
|
2015-08-20 13:21:12 -04:00
|
|
|
|
|
|
|
|
$('#main-page-title').text(menu.text() + (menu.parents('.menu-item').children('a').text() === 'Settings' ? ' Settings' : ''));
|
2014-10-09 18:42:31 -04:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-17 13:21:45 -04:00
|
|
|
function setupRestartLinks() {
|
|
|
|
|
$('.restart').off('click').on('click', function() {
|
|
|
|
|
bootbox.confirm('Are you sure you wish to restart NodeBB?', function(confirm) {
|
|
|
|
|
if (confirm) {
|
2015-06-08 15:52:39 -04:00
|
|
|
require(['admin/modules/instance'], function(instance) {
|
|
|
|
|
instance.restart();
|
2015-04-17 13:21:45 -04:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('.reload').off('click').on('click', function() {
|
2015-06-08 15:50:33 -04:00
|
|
|
require(['admin/modules/instance'], function(instance) {
|
|
|
|
|
instance.reload();
|
2015-04-17 13:21:45 -04:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
2015-08-21 17:46:14 -04:00
|
|
|
|
|
|
|
|
function launchSnackbar(params) {
|
|
|
|
|
var bar = $.snackbar({
|
|
|
|
|
content: "<strong>" + params.title + "</strong> " + params.message,
|
|
|
|
|
timeout: 3000,
|
|
|
|
|
htmlAllowed: true
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (params.clickfn) {
|
|
|
|
|
bar.on('click', clickfn);
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-05-14 18:46:11 -04:00
|
|
|
}());
|