Link fixes

- Fix actual Expose didn't work on links themselves
- Adjust delete button / context menu caption to match file/link
This commit is contained in:
nathan 2022-05-12 10:08:59 -06:00
parent a3a63f3586
commit b9d145a40b
5 changed files with 64 additions and 18 deletions

View File

@ -10,7 +10,7 @@
*/ */
import {ExposeMixin} from "../Expose/ExposeMixin"; import {ExposeMixin, ExposeValue} from "../Expose/ExposeMixin";
import {css, html, LitElement} from "@lion/core"; import {css, html, LitElement} from "@lion/core";
import {Et2Widget} from "../Et2Widget/Et2Widget"; import {Et2Widget} from "../Et2Widget/Et2Widget";
import {et2_IDetachedDOM} from "../et2_core_interfaces"; import {et2_IDetachedDOM} from "../et2_core_interfaces";
@ -158,6 +158,16 @@ export class Et2Link extends ExposeMixin<Et2Widget>(Et2Widget(LitElement)) imple
return this._title; 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) set value(_value : LinkInfo | string)
{ {
if(!_value) if(!_value)
@ -215,6 +225,35 @@ export class Et2Link extends ExposeMixin<Et2Widget>(Et2Widget(LitElement)) imple
this.value = _value; this.value = _value;
} }
get exposeValue() : ExposeValue
{
let info = <ExposeValue><unknown>{
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 * If app or entry_id has changed, we'll update the title
* *
@ -246,13 +285,17 @@ export class Et2Link extends ExposeMixin<Et2Widget>(Et2Widget(LitElement)) imple
_handleClick(_ev : MouseEvent) : boolean _handleClick(_ev : MouseEvent) : boolean
{ {
this.egw().open(Object.assign({ // If super didn't handle it (returns false), just use egw.open()
app: this.app, if(super._handleClick(_ev))
id: this.entry_id {
}, this.dataset), "", this.link_hook, this.dataset.extra_args, this.target_app || this.app, this.target_app); 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(); _ev.stopImmediatePropagation();
return true; return false;
} }
getDetachedAttributes(_attrs : string[]) getDetachedAttributes(_attrs : string[])
@ -289,6 +332,7 @@ export interface LinkInfo
link_id? : string; link_id? : string;
comment? : string comment? : string
icon? : string, icon? : string,
help? : string,
// Extra information for things like files // Extra information for things like files
download_url? : string, download_url? : string,

View File

@ -270,7 +270,7 @@ export class Et2LinkList extends Et2LinkString
{ {
this._delete_link(link); this._delete_link(link);
}} }}
aria-label="${this.egw().lang("Delete")}" aria-label="${this.egw().lang(link.app === "file" ? "Delete" : "Unlink")}"
> >
</et2-image>`; </et2-image>`;
} }
@ -513,7 +513,7 @@ export class Et2LinkList extends Et2LinkString
this.context.getItem("zip").set_enabled(this._link_list.length >= 2); this.context.getItem("zip").set_enabled(this._link_list.length >= 2);
// Show delete item only if the widget is not readonly // Show delete item only if the widget is not readonly
this.context.getItem("delete").set_enabled(!this.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.data = _link_data;
this.context.showAt(_ev.pageX, _ev.pageY, true); this.context.showAt(_ev.pageX, _ev.pageY, true);
_ev.preventDefault(); _ev.preventDefault();

View File

@ -173,7 +173,7 @@ export class Et2LinkString extends Et2Widget(LitElement) implements et2_IDetache
protected _linkTemplate(link) : TemplateResult protected _linkTemplate(link) : TemplateResult
{ {
return html` return html`
<et2-link app="${link.app}" entry_id="${link.id}" .value=${link}></et2-link>`; <et2-link app="${link.app}" entry_id="${link.id}" .value=${link} ._parent=${this}></et2-link>`;
} }
/** /**
@ -242,11 +242,12 @@ export class Et2LinkString extends Et2Widget(LitElement) implements et2_IDetache
return; return;
} }
this._loadingPromise = this.egw().jsonq('EGroupware\\Api\\Etemplate\\Widget\\Link::ajax_link_list', [_value]).then(_value => this._loadingPromise = <Promise<LinkInfo[]>>(this.egw().jsonq('EGroupware\\Api\\Etemplate\\Widget\\Link::ajax_link_list', [_value]))
{ .then(_value =>
this._addLinks(_value); {
this._loadingPromise = null; this._addLinks(_value);
}) this._loadingPromise = null;
})
} }
getDetachedAttributes(_attrs : string[]) getDetachedAttributes(_attrs : string[])

View File

@ -499,9 +499,12 @@ export function ExposeMixin<B extends Constructor<LitElement>>(superclass : B)
{ {
if(exposable === this) 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) catch(e)

View File

@ -194,7 +194,6 @@ class Link extends Etemplate\Widget
if ($link['app'] == Api\Link::VFS_APPNAME) if ($link['app'] == Api\Link::VFS_APPNAME)
{ {
$link['target'] = '_blank'; $link['target'] = '_blank';
$link['label'] = 'Delete';
$link['help'] = lang('Delete this file'); $link['help'] = lang('Delete this file');
$link['title'] = Api\Vfs::decodePath($link['title']); $link['title'] = Api\Vfs::decodePath($link['title']);
$link['icon'] = Api\Link::vfs_path($link['app2'],$link['id2'],$link['id'],true); $link['icon'] = Api\Link::vfs_path($link['app2'],$link['id2'],$link['id'],true);
@ -214,7 +213,6 @@ class Link extends Etemplate\Widget
else else
{ {
$link['icon'] = Api\Link::get_registry($link['app'], 'icon'); $link['icon'] = Api\Link::get_registry($link['app'], 'icon');
$link['label'] = 'Unlink';
$link['help'] = lang('Remove this link (not the entry itself)'); $link['help'] = lang('Remove this link (not the entry itself)');
} }
} }