Skip to content

Commit

Permalink
added p1 changes to public/src/admin/appearance/themes.js
Browse files Browse the repository at this point in the history
  • Loading branch information
minghanm committed Sep 21, 2024
1 parent 936b81c commit e59f8a7
Showing 1 changed file with 79 additions and 66 deletions.
145 changes: 79 additions & 66 deletions public/src/admin/appearance/themes.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,87 +10,100 @@ define('admin/appearance/themes', ['bootbox', 'translator', 'alerts'], function
const action = target.attr('data-action');

if (action && action === 'use') {
const parentEl = target.parents('[data-theme]');
const themeType = parentEl.attr('data-type');
const cssSrc = parentEl.attr('data-css');
const themeId = parentEl.attr('data-theme');

if (config['theme:id'] === themeId) {
return;
}
handleThemeChange(target);
}
});
};

function handleThemeChange(target) {
const parentEl = target.parents('[data-theme]');
const themeType = parentEl.attr('data-type');
const cssSrc = parentEl.attr('data-css');
const themeId = parentEl.attr('data-theme');

if (config['theme:id'] === themeId) {
return;
}
setTheme(themeType, themeId, cssSrc);
}

function setTheme(themeType, themeId, cssSrc) {
socket.emit('admin.themes.set', {
type: themeType,
id: themeId,
src: cssSrc,
}, function (err) {
if (err) {
return alerts.error(err);
}
config['theme:id'] = themeId;
highlightSelectedTheme(themeId);
showThemeChangeAlert();
});
}

function showThemeChangeAlert() {
alerts.alert({
alert_id: 'admin:theme',
type: 'info',
title: '[[admin/appearance/themes:theme-changed]]',
message: '[[admin/appearance/themes:restart-to-activate]]',
timeout: 5000,
clickfn: rebuildAndRestartInstance,
});
}

function rebuildAndRestartInstance() {
require(['admin/modules/instance'], function (instance) {
instance.rebuildAndRestart();
});
}

$('#revert_theme').on('click', function () {
if (config['theme:id'] === 'nodebb-theme-harmony') {
return;
}
bootbox.confirm('[[admin/appearance/themes:revert-confirm]]', function (confirm) {
if (confirm) {
socket.emit('admin.themes.set', {
type: themeType,
id: themeId,
src: cssSrc,
type: 'local',
id: 'nodebb-theme-harmony',
}, function (err) {
if (err) {
return alerts.error(err);
}
config['theme:id'] = themeId;
highlightSelectedTheme(themeId);

config['theme:id'] = 'nodebb-theme-harmony';
highlightSelectedTheme('nodebb-theme-harmony');
alerts.alert({
alert_id: 'admin:theme',
type: 'info',
type: 'success',
title: '[[admin/appearance/themes:theme-changed]]',
message: '[[admin/appearance/themes:restart-to-activate]]',
timeout: 5000,
clickfn: function () {
require(['admin/modules/instance'], function (instance) {
instance.rebuildAndRestart();
});
},
message: '[[admin/appearance/themes:revert-success]]',
timeout: 3500,
});
});
}
});
});

$('#revert_theme').on('click', function () {
if (config['theme:id'] === 'nodebb-theme-harmony') {
return;
}
bootbox.confirm('[[admin/appearance/themes:revert-confirm]]', function (confirm) {
if (confirm) {
socket.emit('admin.themes.set', {
type: 'local',
id: 'nodebb-theme-harmony',
}, function (err) {
if (err) {
return alerts.error(err);
}
config['theme:id'] = 'nodebb-theme-harmony';
highlightSelectedTheme('nodebb-theme-harmony');
alerts.alert({
alert_id: 'admin:theme',
type: 'success',
title: '[[admin/appearance/themes:theme-changed]]',
message: '[[admin/appearance/themes:revert-success]]',
timeout: 3500,
});
});
}
});
});

socket.emit('admin.themes.getInstalled', function (err, themes) {
if (err) {
return alerts.error(err);
}
socket.emit('admin.themes.getInstalled', function (err, themes) {
if (err) {
return alerts.error(err);
}

const instListEl = $('#installed_themes');
const instListEl = $('#installed_themes');

if (!themes.length) {
instListEl.append($('<li/ >').addClass('no-themes').translateHtml('[[admin/appearance/themes:no-themes]]'));
} else {
app.parseAndTranslate('admin/partials/theme_list', {
themes: themes,
}, function (html) {
instListEl.html(html);
highlightSelectedTheme(config['theme:id']);
});
}
});
};
if (!themes.length) {
instListEl.append($('<li/ >').addClass('no-themes').translateHtml('[[admin/appearance/themes:no-themes]]'));
} else {
app.parseAndTranslate('admin/partials/theme_list', {
themes: themes,
}, function (html) {
instListEl.html(html);
highlightSelectedTheme(config['theme:id']);
});
}
});

function highlightSelectedTheme(themeId) {
translator.translate('[[admin/appearance/themes:select-theme]] || [[admin/appearance/themes:current-theme]]', function (text) {
Expand Down

0 comments on commit e59f8a7

Please sign in to comment.