/* * This file is part of the Kimai time-tracking app. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ /*! * [KIMAI] KimaiActiveRecords: responsible to display the users active records */ import KimaiPlugin from '../KimaiPlugin'; export default class KimaiActiveRecords extends KimaiPlugin { constructor(selector, selectorEmpty) { super(); this.selector = selector; this.selectorEmpty = selectorEmpty; } getId() { return 'active-records'; } init() { const menu = document.querySelector(this.selector); // the menu can be hidden if user has no permissions to see it if (menu === null) { return; } const dropdown = menu.querySelector('ul.dropdown-menu'); this.attributes = dropdown.dataset; this.itemList = dropdown.querySelector('li > ul.menu'); this.label = menu.querySelector('a > span.label'); const self = this; const handle = function() { self.reloadActiveRecords(); }; document.addEventListener('kimai.timesheetUpdate', handle); document.addEventListener('kimai.timesheetDelete', handle); document.addEventListener('kimai.activityUpdate', handle); document.addEventListener('kimai.activityDelete', handle); document.addEventListener('kimai.projectUpdate', handle); document.addEventListener('kimai.projectDelete', handle); document.addEventListener('kimai.customerUpdate', handle); document.addEventListener('kimai.customerDelete', handle); } emptyList() { this.itemList.innerHTML = ''; } _toggleMenu(hasEntries) { const menu = document.querySelector(this.selector); const menuEmpty = document.querySelector(this.selectorEmpty); menu.style.display = hasEntries ? 'inline-block' : 'none'; if (menuEmpty !== null) { menuEmpty.style.display = !hasEntries ? 'inline-block' : 'none'; } } setEntries(entries) { this._toggleMenu(entries.length > 0); if (entries.length === 0) { this.label.innerText = ''; this.emptyList(); return; } let htmlToInsert = ''; const durations = this.getContainer().getPlugin('timesheet-duration'); for (let timesheet of entries) { htmlToInsert += `
${ timesheet.project.name } (${ timesheet.project.customer.name })
` + `` + `