From b9d145a40b2c52436d02fabd8ef164127f64982d Mon Sep 17 00:00:00 2001 From: nathan Date: Thu, 12 May 2022 10:08:59 -0600 Subject: [PATCH] Link fixes - Fix actual Expose didn't work on links themselves - Adjust delete button / context menu caption to match file/link --- api/js/etemplate/Et2Link/Et2Link.ts | 56 ++++++++++++++++++++--- api/js/etemplate/Et2Link/Et2LinkList.ts | 4 +- api/js/etemplate/Et2Link/Et2LinkString.ts | 13 +++--- api/js/etemplate/Expose/ExposeMixin.ts | 7 ++- api/src/Etemplate/Widget/Link.php | 2 - 5 files changed, 64 insertions(+), 18 deletions(-) diff --git a/api/js/etemplate/Et2Link/Et2Link.ts b/api/js/etemplate/Et2Link/Et2Link.ts index bc776c3825..76d543e6fa 100644 --- a/api/js/etemplate/Et2Link/Et2Link.ts +++ b/api/js/etemplate/Et2Link/Et2Link.ts @@ -10,7 +10,7 @@ */ -import {ExposeMixin} from "../Expose/ExposeMixin"; +import {ExposeMixin, ExposeValue} from "../Expose/ExposeMixin"; import {css, html, LitElement} from "@lion/core"; import {Et2Widget} from "../Et2Widget/Et2Widget"; import {et2_IDetachedDOM} from "../et2_core_interfaces"; @@ -158,6 +158,16 @@ export class Et2Link extends ExposeMixin(Et2Widget(LitElement)) imple return this._title; } + /** + * Get a value representation of the link. + * + * @returns {LinkInfo | string} + */ + get value() : LinkInfo | string + { + return this.app && this.entry_id ? this.app + ":" + this.entry_id : ""; + } + set value(_value : LinkInfo | string) { if(!_value) @@ -215,6 +225,35 @@ export class Et2Link extends ExposeMixin(Et2Widget(LitElement)) imple this.value = _value; } + get exposeValue() : ExposeValue + { + let info = { + app: this.app, + id: this.entry_id, + path: this.dataset['icon'] + }; + info['label'] = this.title; + info = Object.assign(info, this.dataset); + + if(info['remark']) + { + info['label'] += " - " + info['remark']; + } + if(!info.path && this.app == "file") + { + // Fallback to check the "normal" place if path wasn't available + info.path = "/webdav.php/apps/" + this.dataset.app2 + "/" + this.dataset.id2 + "/" + this.entry_id; + } + + if(typeof info["type"] !== "undefined") + { + // Links use "type" for mimetype. + info.mime = info["type"]; + } + + return info; + } + /** * If app or entry_id has changed, we'll update the title * @@ -246,13 +285,17 @@ export class Et2Link extends ExposeMixin(Et2Widget(LitElement)) imple _handleClick(_ev : MouseEvent) : boolean { - this.egw().open(Object.assign({ - app: this.app, - id: this.entry_id - }, this.dataset), "", this.link_hook, this.dataset.extra_args, this.target_app || this.app, this.target_app); + // If super didn't handle it (returns false), just use egw.open() + if(super._handleClick(_ev)) + { + this.egw().open(Object.assign({ + app: this.app, + id: this.entry_id + }, this.dataset), "", this.link_hook, this.dataset.extra_args, this.target_app || this.app, this.target_app); + } _ev.stopImmediatePropagation(); - return true; + return false; } getDetachedAttributes(_attrs : string[]) @@ -289,6 +332,7 @@ export interface LinkInfo link_id? : string; comment? : string icon? : string, + help? : string, // Extra information for things like files download_url? : string, diff --git a/api/js/etemplate/Et2Link/Et2LinkList.ts b/api/js/etemplate/Et2Link/Et2LinkList.ts index f8dbae5663..493eb52983 100644 --- a/api/js/etemplate/Et2Link/Et2LinkList.ts +++ b/api/js/etemplate/Et2Link/Et2LinkList.ts @@ -270,7 +270,7 @@ export class Et2LinkList extends Et2LinkString { this._delete_link(link); }} - aria-label="${this.egw().lang("Delete")}" + aria-label="${this.egw().lang(link.app === "file" ? "Delete" : "Unlink")}" > `; } @@ -513,7 +513,7 @@ export class Et2LinkList extends Et2LinkString this.context.getItem("zip").set_enabled(this._link_list.length >= 2); // Show delete item only if the widget is not readonly this.context.getItem("delete").set_enabled(!this.readonly); - + this.context.getItem("delete").caption = _link_data.app === "file" ? this.egw().lang("Delete file") : this.egw().lang("Delete link"); this.context.data = _link_data; this.context.showAt(_ev.pageX, _ev.pageY, true); _ev.preventDefault(); diff --git a/api/js/etemplate/Et2Link/Et2LinkString.ts b/api/js/etemplate/Et2Link/Et2LinkString.ts index d355daf95b..e9bd4b725e 100644 --- a/api/js/etemplate/Et2Link/Et2LinkString.ts +++ b/api/js/etemplate/Et2Link/Et2LinkString.ts @@ -173,7 +173,7 @@ export class Et2LinkString extends Et2Widget(LitElement) implements et2_IDetache protected _linkTemplate(link) : TemplateResult { return html` - `; + `; } /** @@ -242,11 +242,12 @@ export class Et2LinkString extends Et2Widget(LitElement) implements et2_IDetache return; } - this._loadingPromise = this.egw().jsonq('EGroupware\\Api\\Etemplate\\Widget\\Link::ajax_link_list', [_value]).then(_value => - { - this._addLinks(_value); - this._loadingPromise = null; - }) + this._loadingPromise = >(this.egw().jsonq('EGroupware\\Api\\Etemplate\\Widget\\Link::ajax_link_list', [_value])) + .then(_value => + { + this._addLinks(_value); + this._loadingPromise = null; + }) } getDetachedAttributes(_attrs : string[]) diff --git a/api/js/etemplate/Expose/ExposeMixin.ts b/api/js/etemplate/Expose/ExposeMixin.ts index 0af874459c..af431f8ed9 100644 --- a/api/js/etemplate/Expose/ExposeMixin.ts +++ b/api/js/etemplate/Expose/ExposeMixin.ts @@ -499,9 +499,12 @@ export function ExposeMixin>(superclass : B) { if(exposable === this) { - options.index = index; + options.index = mediaContent.length; + } + if(exposable.isExposable()) + { + mediaContent.push(...exposable.getMedia(Object.assign({}, IMAGE_DEFAULT, exposable.exposeValue))); } - mediaContent.push(...exposable.getMedia(Object.assign({}, IMAGE_DEFAULT, exposable.exposeValue))); }); } catch(e) diff --git a/api/src/Etemplate/Widget/Link.php b/api/src/Etemplate/Widget/Link.php index 021adf1b25..6da23a852d 100644 --- a/api/src/Etemplate/Widget/Link.php +++ b/api/src/Etemplate/Widget/Link.php @@ -194,7 +194,6 @@ class Link extends Etemplate\Widget if ($link['app'] == Api\Link::VFS_APPNAME) { $link['target'] = '_blank'; - $link['label'] = 'Delete'; $link['help'] = lang('Delete this file'); $link['title'] = Api\Vfs::decodePath($link['title']); $link['icon'] = Api\Link::vfs_path($link['app2'],$link['id2'],$link['id'],true); @@ -214,7 +213,6 @@ class Link extends Etemplate\Widget else { $link['icon'] = Api\Link::get_registry($link['app'], 'icon'); - $link['label'] = 'Unlink'; $link['help'] = lang('Remove this link (not the entry itself)'); } }