migrated ACP themes page from html rendered via js to template engine

v1.18.x
Julian Lam 11 years ago
parent 5bf9c6db7b
commit a2fb4a66b0

@ -1,5 +1,5 @@
"use strict"; "use strict";
/*global define, socket, app, bootbox, tabIndent, config, RELATIVE_PATH*/ /*global define, socket, app, bootbox, tabIndent, config, RELATIVE_PATH, templates */
define('forum/admin/themes', ['forum/admin/settings'], function(Settings) { define('forum/admin/themes', ['forum/admin/settings'], function(Settings) {
var Themes = {}; var Themes = {};
@ -71,17 +71,17 @@ define('forum/admin/themes', ['forum/admin/settings'], function(Settings) {
if (confirm) { if (confirm) {
socket.emit('admin.themes.set', { socket.emit('admin.themes.set', {
type: 'local', type: 'local',
id: 'nodebb-theme-cerulean' id: 'nodebb-theme-vanilla'
}, function(err) { }, function(err) {
if (err) { if (err) {
return app.alertError(err.message); return app.alertError(err.message);
} }
highlightSelectedTheme('nodebb-theme-cerulean'); highlightSelectedTheme('nodebb-theme-vanilla');
app.alert({ app.alert({
alert_id: 'admin:theme', alert_id: 'admin:theme',
type: 'success', type: 'success',
title: 'Theme Changed', title: 'Theme Changed',
message: 'You have successfully reverted your NodeBB back to it\'s default theme. Restarting your NodeBB <i class="fa fa-refresh fa-spin"></i>', message: 'You have successfully reverted your NodeBB back to it\'s default theme.',
timeout: 3500 timeout: 3500
}); });
}); });
@ -95,34 +95,19 @@ define('forum/admin/themes', ['forum/admin/settings'], function(Settings) {
return app.alertError(err.message); return app.alertError(err.message);
} }
var instListEl = $('#installed_themes').empty(), liEl; var instListEl = $('#installed_themes');
if (!themes.length) { if (!themes.length) {
instListEl.append($('<li/ >').addClass('no-themes').html('No installed themes found')); instListEl.append($('<li/ >').addClass('no-themes').html('No installed themes found'));
return; return;
} else {
templates.parse('partials/admin/theme_list', {
themes: themes
}, function(html) {
instListEl.html(html);
highlightSelectedTheme(config['theme:id']);
});
} }
for (var x = 0, numThemes = themes.length; x < numThemes; x++) {
liEl = $('<li/ >').attr({
'data-type': 'local',
'data-theme': themes[x].id
}).html('<img src="' + (themes[x].screenshot ? RELATIVE_PATH + '/css/previews/' + themes[x].id : RELATIVE_PATH + '/images/themes/default.png') + '" />' +
'<div>' +
'<div class="pull-right">' +
'<button class="btn btn-primary" data-action="use">Use</button> ' +
'</div>' +
'<h4>' + themes[x].name + '</h4>' +
'<p>' +
themes[x].description +
(themes[x].url ? ' (<a href="' + themes[x].url + '">Homepage</a>)' : '') +
'</p>' +
'</div>' +
'<div class="clear">');
instListEl.append(liEl);
}
highlightSelectedTheme(config['theme:id']);
}); });
// Proper tabbing for "Custom CSS" field // Proper tabbing for "Custom CSS" field
@ -138,26 +123,23 @@ define('forum/admin/themes', ['forum/admin/settings'], function(Settings) {
}; };
Themes.render = function(bootswatch) { Themes.render = function(bootswatch) {
var themeContainer = $('#bootstrap_themes').empty(), var themeContainer = $('#bootstrap_themes');
numThemes = bootswatch.themes.length, themeEl, theme;
templates.parse('partials/admin/theme_list', {
for (var x = 0; x < numThemes; x++) { themes: bootswatch.themes.map(function(theme) {
theme = bootswatch.themes[x]; return {
themeEl = $('<li />').attr({ type: 'bootswatch',
'data-type': 'bootswatch', id: theme.name,
'data-css': theme.cssCdn, name: theme.name,
'data-theme': theme.name description: theme.description,
}).html('<img src="' + theme.thumbnail + '" />' + screenshot_url: theme.thumbnail,
'<div>' + url: theme.preview,
'<div class="pull-right">' + css: theme.cssCdn
'<button class="btn btn-primary" data-action="use">Use</button> ' + };
'</div>' + })
'<h4>' + theme.name + '</h4>' + }, function(html) {
'<p>' + theme.description + '</p>' + themeContainer.html(html);
'</div>' + });
'<div class="clear">');
themeContainer.append(themeEl);
}
}; };
Themes.prepareWidgets = function() { Themes.prepareWidgets = function() {

@ -39,6 +39,15 @@ module.exports = function(Meta) {
return next(); return next();
} else { } else {
var configObj = JSON.parse(file.toString()); var configObj = JSON.parse(file.toString());
// Minor adjustments for API output
configObj.type = 'local';
if (configObj.screenshot) {
configObj.screenshot_url = nconf.get('relative_path') + '/css/previews/' + configObj.id
} else {
configObj.screenshot_url = nconf.get('relative_path') + '/images/themes/default.png';
}
next(err, configObj); next(err, configObj);
} }
}); });

Loading…
Cancel
Save