From b09c6e804f88e692adfed652d4af214c53ec68ae Mon Sep 17 00:00:00 2001 From: nathan Date: Tue, 14 Mar 2023 09:14:15 -0600 Subject: [PATCH] Home: Restore ability to manually add to list portlet Now just using the properties dialog to add --- api/js/etemplate/Et2Portlet/Et2Portlet.ts | 13 ++++++++++- home/inc/class.home_ui.inc.php | 2 +- home/js/Et2PortletList.ts | 28 ++++++++++++++++++++++- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/api/js/etemplate/Et2Portlet/Et2Portlet.ts b/api/js/etemplate/Et2Portlet/Et2Portlet.ts index 6c9593583a..f699f7e960 100644 --- a/api/js/etemplate/Et2Portlet/Et2Portlet.ts +++ b/api/js/etemplate/Et2Portlet/Et2Portlet.ts @@ -411,12 +411,23 @@ export class Et2Portlet extends Et2Widget(SlCard) */ edit_settings() { + let content = this.portletProperties; + + // Add values, but skip any lingering properties + Object.keys(this.settings).forEach(k => + { + if(typeof k == "string" && isNaN(parseInt(k))) + { + content[k] = this.settings[k]; + } + }); + let dialog = new Et2Dialog(this.egw()); dialog.transformAttributes({ callback: this._process_edit.bind(this), template: this.editTemplate, value: { - content: {...this.settings, ...this.portletProperties} + content: content }, buttons: [ { diff --git a/home/inc/class.home_ui.inc.php b/home/inc/class.home_ui.inc.php index cfa6f68502..c7294b4c94 100644 --- a/home/inc/class.home_ui.inc.php +++ b/home/inc/class.home_ui.inc.php @@ -200,7 +200,7 @@ class home_ui $settings = $portlet->get_properties(); foreach($settings as $key => $setting) { - if(is_array($setting) && !array_key_exists('type', $setting)) + if(is_array($setting) && !array_key_exists('type', $setting) || is_numeric($key)) { unset($settings[$key]); } diff --git a/home/js/Et2PortletList.ts b/home/js/Et2PortletList.ts index 966ad980ee..78150ba5e1 100644 --- a/home/js/Et2PortletList.ts +++ b/home/js/Et2PortletList.ts @@ -2,6 +2,8 @@ import {Et2Portlet} from "../../api/js/etemplate/Et2Portlet/Et2Portlet"; import {et2_createWidget} from "../../api/js/etemplate/et2_core_widget"; import {css, html, TemplateResult} from "@lion/core"; import shoelace from "../../api/js/etemplate/Styles/shoelace"; +import {SelectOption} from "../../api/js/etemplate/Et2Select/FindSelectOptions"; +import {Et2Dialog} from "../../api/js/etemplate/Et2Dialog/Et2Dialog"; /** * Home portlet to show a list of entries @@ -147,7 +149,7 @@ export class Et2PortletList extends Et2Portlet { return; } - + // Not used, but delete puts link in event.data let link_data = event.data || false; @@ -158,6 +160,30 @@ export class Et2PortletList extends Et2Portlet } } + /** + * Get a list of user-configurable properties + * @returns {[{name : string, type : string, select_options? : [SelectOption]}]} + */ + get portletProperties() : { name : string, type : string, label : string, select_options? : SelectOption[] }[] + { + return [ + ...super.portletProperties, + {name: "title", type: "et2-textbox", label: "Title"}, + {name: "add", type: "et2-link-entry", label: "Add"} + ] + } + + _process_edit(button_id, value) + { + if(button_id == Et2Dialog.OK_BUTTON && value.add) + { + // Add in to list, remove from value or it will be saved + value.list = [...this.settings.list, value.add]; + delete value.add; + } + super._process_edit(button_id, value); + } + bodyTemplate() : TemplateResult { return html`