refactor: removed parsing for taskbar

harmony doesnt have a taskbar
This commit is contained in:
Barış Soner Uşaklı
2023-05-04 15:38:30 -04:00
parent ae7547e2e0
commit e832d365ba

View File

@@ -1,35 +1,33 @@
'use strict'; 'use strict';
define('taskbar', ['benchpress', 'translator', 'hooks'], function (Benchpress, translator, hooks) { define('taskbar', ['translator', 'hooks'], function (translator, hooks) {
const taskbar = {}; const taskbar = {};
let noTaskbar = false;
taskbar.init = function () { taskbar.init = function () {
const self = this; taskbar.taskbar = $('[component="taskbar"]');
taskbar.tasklist = taskbar.taskbar.find('ul');
if (!taskbar.taskbar.length || !taskbar.tasklist.length) {
noTaskbar = true;
return;
}
taskbar.taskbar.on('click', 'li', async function () {
const $btn = $(this);
const moduleName = $btn.attr('data-module');
const uuid = $btn.attr('data-uuid');
Benchpress.render('modules/taskbar', {}).then(function (html) { const module = await app.require(moduleName);
self.taskbar = $(html); if (!$btn.hasClass('active')) {
self.tasklist = self.taskbar.find('ul'); minimizeAll();
$(document.body).append(self.taskbar); module.load(uuid);
taskbar.toggleNew(uuid, false);
self.taskbar.on('click', 'li', async function () { taskbar.tasklist.removeClass('active');
const $btn = $(this); $btn.addClass('active');
const moduleName = $btn.attr('data-module'); } else {
const uuid = $btn.attr('data-uuid'); module.minimize(uuid);
}
const module = await app.require(moduleName); return false;
if (!$btn.hasClass('active')) {
minimizeAll();
module.load(uuid);
taskbar.toggleNew(uuid, false);
taskbar.tasklist.removeClass('active');
$btn.addClass('active');
} else {
module.minimize(uuid);
}
return false;
});
}); });
$(window).on('action:app.loggedOut', function () { $(window).on('action:app.loggedOut', function () {
@@ -38,6 +36,9 @@ define('taskbar', ['benchpress', 'translator', 'hooks'], function (Benchpress, t
}; };
taskbar.close = async function (moduleName, uuid) { taskbar.close = async function (moduleName, uuid) {
if (noTaskbar) {
return;
}
// Sends signal to the appropriate module's .close() fn (if present) // Sends signal to the appropriate module's .close() fn (if present)
const btnEl = taskbar.tasklist.find('[data-module="' + module + '"][data-uuid="' + uuid + '"]'); const btnEl = taskbar.tasklist.find('[data-module="' + module + '"][data-uuid="' + uuid + '"]');
@@ -50,6 +51,9 @@ define('taskbar', ['benchpress', 'translator', 'hooks'], function (Benchpress, t
}; };
taskbar.closeAll = function (module) { taskbar.closeAll = function (module) {
if (noTaskbar) {
return;
}
// module is optional // module is optional
let selector = '[data-uuid]'; let selector = '[data-uuid]';
@@ -63,6 +67,9 @@ define('taskbar', ['benchpress', 'translator', 'hooks'], function (Benchpress, t
}; };
taskbar.discard = function (module, uuid) { taskbar.discard = function (module, uuid) {
if (noTaskbar) {
return;
}
const btnEl = taskbar.tasklist.find('[data-module="' + module + '"][data-uuid="' + uuid + '"]'); const btnEl = taskbar.tasklist.find('[data-module="' + module + '"][data-uuid="' + uuid + '"]');
btnEl.remove(); btnEl.remove();
@@ -71,6 +78,9 @@ define('taskbar', ['benchpress', 'translator', 'hooks'], function (Benchpress, t
taskbar.push = function (module, uuid, options, callback) { taskbar.push = function (module, uuid, options, callback) {
callback = callback || function () {}; callback = callback || function () {};
if (noTaskbar) {
return callback();
}
const element = taskbar.tasklist.find('li[data-uuid="' + uuid + '"]'); const element = taskbar.tasklist.find('li[data-uuid="' + uuid + '"]');
const data = { const data = {
@@ -90,6 +100,9 @@ define('taskbar', ['benchpress', 'translator', 'hooks'], function (Benchpress, t
}; };
taskbar.get = function (module) { taskbar.get = function (module) {
if (noTaskbar) {
return [];
}
const items = $('[data-module="' + module + '"]').map(function (idx, el) { const items = $('[data-module="' + module + '"]').map(function (idx, el) {
return $(el).data(); return $(el).data();
}); });
@@ -98,11 +111,17 @@ define('taskbar', ['benchpress', 'translator', 'hooks'], function (Benchpress, t
}; };
taskbar.minimize = function (module, uuid) { taskbar.minimize = function (module, uuid) {
if (noTaskbar) {
return;
}
const btnEl = taskbar.tasklist.find('[data-module="' + module + '"][data-uuid="' + uuid + '"]'); const btnEl = taskbar.tasklist.find('[data-module="' + module + '"][data-uuid="' + uuid + '"]');
btnEl.toggleClass('active', false); btnEl.toggleClass('active', false);
}; };
taskbar.toggleNew = function (uuid, state, silent) { taskbar.toggleNew = function (uuid, state, silent) {
if (noTaskbar) {
return;
}
const btnEl = taskbar.tasklist.find('[data-uuid="' + uuid + '"]'); const btnEl = taskbar.tasklist.find('[data-uuid="' + uuid + '"]');
btnEl.toggleClass('new', state); btnEl.toggleClass('new', state);
@@ -112,7 +131,7 @@ define('taskbar', ['benchpress', 'translator', 'hooks'], function (Benchpress, t
}; };
taskbar.updateActive = function (uuid) { taskbar.updateActive = function (uuid) {
if (!taskbar.tasklist) { if (noTaskbar) {
return; return;
} }
@@ -125,11 +144,17 @@ define('taskbar', ['benchpress', 'translator', 'hooks'], function (Benchpress, t
}; };
taskbar.isActive = function (uuid) { taskbar.isActive = function (uuid) {
if (noTaskbar) {
return false;
}
const taskBtn = taskbar.tasklist.find('li[data-uuid="' + uuid + '"]'); const taskBtn = taskbar.tasklist.find('li[data-uuid="' + uuid + '"]');
return taskBtn.hasClass('active'); return taskBtn.hasClass('active');
}; };
function update() { function update() {
if (noTaskbar) {
return;
}
const tasks = taskbar.tasklist.find('li'); const tasks = taskbar.tasklist.find('li');
if (tasks.length > 0) { if (tasks.length > 0) {
@@ -140,10 +165,16 @@ define('taskbar', ['benchpress', 'translator', 'hooks'], function (Benchpress, t
} }
function minimizeAll() { function minimizeAll() {
if (noTaskbar) {
return;
}
taskbar.tasklist.find('.active').removeClass('active'); taskbar.tasklist.find('.active').removeClass('active');
} }
function createTaskbarItem(data, callback) { function createTaskbarItem(data, callback) {
if (noTaskbar) {
return callback();
}
translator.translate(data.options.title, function (taskTitle) { translator.translate(data.options.title, function (taskTitle) {
const title = $('<div></div>').text(taskTitle || 'NodeBB Task').html(); const title = $('<div></div>').text(taskTitle || 'NodeBB Task').html();
@@ -196,6 +227,9 @@ define('taskbar', ['benchpress', 'translator', 'hooks'], function (Benchpress, t
}; };
taskbar.update = function (module, uuid, options) { taskbar.update = function (module, uuid, options) {
if (noTaskbar) {
return;
}
const element = taskbar.tasklist.find('[data-module="' + module + '"][data-uuid="' + uuid + '"]'); const element = taskbar.tasklist.find('[data-module="' + module + '"][data-uuid="' + uuid + '"]');
if (!element.length) { if (!element.length) {
return; return;