/* Description: Login access and menu Date: 2025//3/6 Creator: Clemens Schwaighofer */ export { LoginNavMenu }; import { isObject, getObjectCount } from './JavaScriptHelpers.mjs'; import { exists } from './DomHelpers.mjs'; class LoginNavMenu { hec; l10n; /** * action box creator * @param {Object} hec HtmlElementCreator * @param {Object} l10n l10nTranslation */ constructor(hec, l10n) { this.hec = hec; this.l10n = l10n; } /** * create login string and logout button elements * @param {String} login_string the login string to show on the left * @param {String} [header_id='mainHeader'] the target for the main element block * if not set mainHeader is assumed * this is the target div for the "loginRow" */ createLoginRow(login_string, header_id = 'mainHeader') { // if header does not exist, we do nothing if (exists(header_id)) { // that row must exist already, if not it must be the first in the "mainHeader" if (!exists('loginRow')) { $('#' + header_id).html(this.hec.phfo(this.hec.cel('div', 'loginRow', '', ['loginRow', 'flx-spbt']))); } // clear out just in case for first entry // fill with div name & login/logout button $('#loginRow').html(this.hec.phfo(this.hec.cel('div', 'loginRow-name', login_string))); $('#loginRow').append(this.hec.phfo(this.hec.cel('div', 'loginRow-info', ''))); $('#loginRow').append(this.hec.phfo( this.hec.aelx( // outer div this.hec.cel('div', 'loginRow-logout'), // inner element this.hec.cel('input', 'logout', '', [], { value: this.l10n.__('Logout'), type: 'button', onClick: 'loginLogout()' }) ) )); } } /** * create the top nav menu that switches physical between pages * (edit access data based) * @param {Object} nav_menu the built nav menu with highlight info * @param {String} [header_id='mainHeader'] the target for the main element block * if not set mainHeader is assumed * this is the target div for the "menuRow" */ createNavMenu(nav_menu, header_id = 'mainHeader') { // must be an object if (isObject(nav_menu) && getObjectCount(nav_menu) > 1) { // do we have more than one entry, if not, do not show (single page) if (!exists('menuRow')) { $('#' + header_id).html(this.hec.phfo(this.hec.cel('div', 'menuRow', '', ['menuRow', 'flx-s']))); } var content = []; $.each(nav_menu, function(key, item) { // key is number // item is object with entries if (key != 0) { content.push(this.hec.phfo(this.hec.cel('div', '', '·', ['pd-2']))); } // ignore item.popup for now if (item.enabled) { // set selected based on window.location.href as the php set will not work if (window.location.href.indexOf(item.url) != -1) { item.selected = 1; } // create the entry content.push(this.hec.phfo( this.hec.aelx( this.hec.cel('div'), this.hec.cel('a', '', item.name, ['pd-2'].concat(item.selected ? 'highlight': ''), { href: item.url }) ) )); } }); $('#menuRow').html(content.join('')); } else { $('#menuRow').hide(); } } } // __END__