2022-06-06 21:31:33 +02:00
|
|
|
/**
|
|
|
|
* EGroupware eTemplate2 - JS Link list object
|
|
|
|
*
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @package etemplate
|
|
|
|
* @subpackage api
|
|
|
|
* @link https://www.egroupware.org
|
|
|
|
* @author Nathan Gray
|
|
|
|
* @copyright 2022 Nathan Gray
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
import {Et2InputWidget} from "../Et2InputWidget/Et2InputWidget";
|
2024-02-09 17:17:52 +01:00
|
|
|
import {css, html, LitElement, nothing} from "lit";
|
2022-06-06 21:31:33 +02:00
|
|
|
import {et2_createWidget, et2_widget} from "../et2_core_widget";
|
|
|
|
import {et2_file} from "../et2_widget_file";
|
|
|
|
import {Et2Button} from "../Et2Button/Et2Button";
|
|
|
|
import {Et2LinkEntry} from "./Et2LinkEntry";
|
|
|
|
import {egw} from "../../jsapi/egw_global";
|
|
|
|
import {LinkInfo} from "./Et2Link";
|
|
|
|
import {ManualMessage} from "../Validators/ManualMessage";
|
2022-12-14 19:56:27 +01:00
|
|
|
import {Et2Tabs} from "../Layout/Et2Tabs/Et2Tabs";
|
2024-02-09 17:17:52 +01:00
|
|
|
import {Et2VfsSelectButton} from "../Et2Vfs/Et2VfsSelectButton";
|
2024-03-20 21:23:56 +01:00
|
|
|
import {Et2LinkPasteDialog, getClipboardFiles} from "./Et2LinkPasteDialog";
|
2024-04-04 23:38:55 +02:00
|
|
|
import {waitForEvent} from "../Et2Widget/event";
|
2024-05-07 22:46:44 +02:00
|
|
|
import {classMap} from "lit/directives/class-map.js";
|
2022-06-06 21:31:33 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Choose an existing entry, VFS file or local file, and link it to the current entry.
|
|
|
|
*
|
|
|
|
* If there is no "current entry", link information will be stored for submission instead
|
|
|
|
* of being directly linked.
|
|
|
|
*/
|
2024-05-07 22:46:44 +02:00
|
|
|
export class Et2LinkTo extends Et2InputWidget(LitElement)
|
2022-06-06 21:31:33 +02:00
|
|
|
{
|
|
|
|
static get properties()
|
|
|
|
{
|
|
|
|
return {
|
|
|
|
...super.properties,
|
|
|
|
/**
|
|
|
|
* Hide buttons to attach files
|
|
|
|
*/
|
2022-07-21 17:57:50 +02:00
|
|
|
noFiles: {type: Boolean},
|
2022-06-06 21:31:33 +02:00
|
|
|
/**
|
|
|
|
* Limit to just this application - hides app selection
|
|
|
|
*/
|
2022-07-21 17:57:50 +02:00
|
|
|
onlyApp: {type: String},
|
2022-06-06 21:31:33 +02:00
|
|
|
/**
|
|
|
|
* Limit to the listed applications (comma seperated)
|
|
|
|
*/
|
2022-07-21 17:57:50 +02:00
|
|
|
applicationList: {type: String},
|
2022-06-06 21:31:33 +02:00
|
|
|
|
|
|
|
value: {type: Object}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static get styles()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
...super.styles,
|
|
|
|
css`
|
|
|
|
:host(.can_link) #link_button {
|
|
|
|
display: initial;
|
|
|
|
}
|
|
|
|
#link_button {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
et2-link-entry {
|
|
|
|
flex: 1 1 auto;
|
|
|
|
}
|
|
|
|
.input-group__container {
|
|
|
|
flex: 1 1 auto;
|
|
|
|
}
|
2024-05-07 22:46:44 +02:00
|
|
|
|
|
|
|
.form-control-input {
|
2022-06-06 21:31:33 +02:00
|
|
|
display: flex;
|
|
|
|
width: 100%;
|
2022-10-25 19:38:48 +02:00
|
|
|
gap: 0.5rem;
|
|
|
|
}
|
2022-06-06 21:31:33 +02:00
|
|
|
::slotted(.et2_file) {
|
|
|
|
width: 30px;
|
|
|
|
}
|
|
|
|
`
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Still not sure what this does, but it's important.
|
|
|
|
// Seems to be related to rendering and what's available "inside"
|
|
|
|
static get scopedElements()
|
|
|
|
{
|
|
|
|
return {
|
|
|
|
// @ts-ignore
|
|
|
|
...super.scopedElements,
|
|
|
|
'et2-button': Et2Button,
|
2024-02-09 17:17:52 +01:00
|
|
|
'et2-link-entry': Et2LinkEntry,
|
2024-03-20 21:23:56 +01:00
|
|
|
'et2-vfs-select': Et2VfsSelectButton,
|
|
|
|
'et2-link-paste-dialog': Et2LinkPasteDialog
|
2022-06-06 21:31:33 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2024-07-16 16:54:03 +02:00
|
|
|
private get pasteButton() : Et2VfsSelectButton { return this.shadowRoot?.querySelector("#paste"); }
|
2024-04-04 23:38:55 +02:00
|
|
|
|
|
|
|
private get pasteDialog() { return this.pasteButton?.querySelector("et2-link-paste-dialog"); }
|
|
|
|
|
2022-06-06 21:31:33 +02:00
|
|
|
constructor()
|
|
|
|
{
|
|
|
|
super();
|
2022-07-21 17:57:50 +02:00
|
|
|
this.noFiles = false;
|
2022-06-06 21:31:33 +02:00
|
|
|
|
|
|
|
this.handleFilesUploaded = this.handleFilesUploaded.bind(this);
|
|
|
|
this.handleEntrySelected = this.handleEntrySelected.bind(this);
|
2022-06-06 22:42:43 +02:00
|
|
|
this.handleEntryCleared = this.handleEntryCleared.bind(this);
|
2022-06-06 21:31:33 +02:00
|
|
|
this.handleLinkButtonClick = this.handleLinkButtonClick.bind(this);
|
2024-02-09 17:17:52 +01:00
|
|
|
this.handleVfsSelected = this.handleVfsSelected.bind(this);
|
2022-12-12 18:32:08 +01:00
|
|
|
|
|
|
|
this.handleLinkDeleted = this.handleLinkDeleted.bind(this);
|
2022-06-06 21:31:33 +02:00
|
|
|
}
|
|
|
|
|
2022-06-06 22:42:43 +02:00
|
|
|
firstUpdated()
|
2022-06-06 21:31:33 +02:00
|
|
|
{
|
|
|
|
// Add file buttons in
|
|
|
|
// TODO: Replace when they're webcomponents
|
|
|
|
this._fileButtons();
|
|
|
|
}
|
|
|
|
|
2022-12-12 18:32:08 +01:00
|
|
|
connectedCallback()
|
|
|
|
{
|
|
|
|
super.connectedCallback();
|
|
|
|
this.getInstanceManager().DOMContainer.addEventListener("et2-delete", this.handleLinkDeleted);
|
|
|
|
}
|
|
|
|
|
|
|
|
disconnectedCallback()
|
|
|
|
{
|
|
|
|
super.disconnectedCallback();
|
|
|
|
this.getInstanceManager().DOMContainer.removeEventListener("et2-delete", this.handleLinkDeleted);
|
|
|
|
}
|
|
|
|
|
2024-02-09 17:17:52 +01:00
|
|
|
_inputGroupBeforeTemplate()
|
|
|
|
{
|
|
|
|
// only set server-side callback, if we have a real application-id (not null or array)
|
|
|
|
// otherwise it only gives an error on server-side
|
|
|
|
let method = null;
|
|
|
|
let method_id = null;
|
2024-03-20 21:23:56 +01:00
|
|
|
let pasteEnabled = false;
|
|
|
|
let pasteTooltip = ""
|
2024-02-09 17:17:52 +01:00
|
|
|
if(this.value && this.value.to_id && typeof this.value.to_id != 'object')
|
|
|
|
{
|
|
|
|
method = 'EGroupware\\Api\\Etemplate\\Widget\\Link::ajax_link_existing';
|
|
|
|
method_id = this.value.to_app + ':' + this.value.to_id;
|
2024-03-20 21:23:56 +01:00
|
|
|
|
2024-07-16 16:54:03 +02:00
|
|
|
getClipboardFiles().then((files) =>
|
|
|
|
{
|
|
|
|
this.pasteButton.disabled = files.length == 0;
|
|
|
|
});
|
2024-02-09 17:17:52 +01:00
|
|
|
}
|
2024-03-20 21:23:56 +01:00
|
|
|
|
2024-02-09 17:17:52 +01:00
|
|
|
return html`
|
|
|
|
<slot name="before"></slot>
|
|
|
|
<et2-vfs-select
|
2024-05-07 22:46:44 +02:00
|
|
|
id="link"
|
2024-02-09 17:17:52 +01:00
|
|
|
?readonly=${this.readonly}
|
|
|
|
method=${method || nothing}
|
|
|
|
method-id=${method_id || nothing}
|
|
|
|
multiple
|
2024-03-27 22:25:15 +01:00
|
|
|
title=${this.egw().lang("select file(s) from vfs")}
|
2024-02-09 17:17:52 +01:00
|
|
|
.buttonLabel=${this.egw().lang('Link')}
|
2024-05-07 22:46:44 +02:00
|
|
|
@change=${async() =>
|
|
|
|
{
|
|
|
|
this.handleVfsSelected(await this.shadowRoot.getElementById("link")._dialog.getComplete());
|
|
|
|
}}
|
2024-02-09 17:17:52 +01:00
|
|
|
>
|
|
|
|
<et2-button slot="footer" image="copy" id="copy" style="order:3" noSubmit="true"
|
|
|
|
label=${this.egw().lang("copy")}></et2-button>
|
|
|
|
<et2-button slot="footer" image="move" id="move" style="order:3" noSubmit="true"
|
|
|
|
label=${this.egw().lang("move")}></et2-button>
|
2024-03-20 21:23:56 +01:00
|
|
|
</et2-vfs-select>
|
2024-04-04 23:38:55 +02:00
|
|
|
<et2-vfs-select
|
|
|
|
id="paste"
|
|
|
|
image="linkpaste" aria-label=${this.egw().lang("clipboard contents")} noSubmit="true"
|
|
|
|
title=${this.egw().lang("Clipboard contents")}
|
|
|
|
?readonly=${this.readonly}
|
2024-07-16 16:54:03 +02:00
|
|
|
disabled
|
2024-04-04 23:38:55 +02:00
|
|
|
multiple
|
|
|
|
@click=${async(e) =>
|
2024-03-20 21:23:56 +01:00
|
|
|
{
|
|
|
|
// Pre-select all files
|
|
|
|
let files = [];
|
2024-04-04 23:38:55 +02:00
|
|
|
let cbFiles = await getClipboardFiles();
|
|
|
|
cbFiles.forEach(f => files.push(f.path));
|
2024-03-20 21:23:56 +01:00
|
|
|
e.target.firstElementChild.value = files;
|
|
|
|
e.target.firstElementChild.requestUpdate();
|
2024-04-04 23:38:55 +02:00
|
|
|
|
|
|
|
waitForEvent(e.target._dialog, "sl-after-show").then(async() =>
|
|
|
|
{
|
|
|
|
this.handleVfsSelected(await this.pasteButton._dialog.getComplete());
|
|
|
|
});
|
2024-03-20 21:23:56 +01:00
|
|
|
}}
|
|
|
|
>
|
|
|
|
<et2-link-paste-dialog open
|
2024-03-27 22:25:15 +01:00
|
|
|
title=${this.egw().lang("Clipboard contents")}
|
|
|
|
.buttonLabel=${this.egw().lang("link")}
|
|
|
|
>
|
|
|
|
<et2-button slot="footer" image="copy" id="copy" style="order:3" noSubmit="true"
|
2024-04-04 23:38:55 +02:00
|
|
|
?disabled=${!this.value?.to_id}
|
2024-03-27 22:25:15 +01:00
|
|
|
label=${this.egw().lang("copy")}
|
|
|
|
title=${this.egw().lang("Copy selected files")}
|
|
|
|
></et2-button>
|
|
|
|
<et2-button slot="footer" image="move" id="move" style="order:3" noSubmit="true"
|
2024-04-04 23:38:55 +02:00
|
|
|
?disabled=${!this.value?.to_id}
|
2024-03-27 22:25:15 +01:00
|
|
|
label=${this.egw().lang("move")}
|
|
|
|
title=${this.egw().lang("Move selected files")}
|
|
|
|
></et2-button>
|
|
|
|
</et2-link-paste-dialog>
|
2024-03-20 21:23:56 +01:00
|
|
|
</et2-vfs-select>
|
|
|
|
`;
|
2024-02-09 17:17:52 +01:00
|
|
|
}
|
|
|
|
|
2022-06-06 21:31:33 +02:00
|
|
|
/**
|
|
|
|
* @return {TemplateResult}
|
|
|
|
* @protected
|
|
|
|
*/
|
|
|
|
_inputGroupInputTemplate()
|
|
|
|
{
|
|
|
|
return html`
|
2022-07-21 17:57:50 +02:00
|
|
|
<et2-link-entry .onlyApp="${this.onlyApp}"
|
|
|
|
.applicationList="${this.applicationList}"
|
2023-02-03 22:08:27 +01:00
|
|
|
.readonly=${this.readonly}
|
2023-09-19 16:46:41 +02:00
|
|
|
@sl-change=${this.handleEntrySelected}
|
2022-06-06 22:42:43 +02:00
|
|
|
@sl-clear="${this.handleEntryCleared}">
|
2022-06-06 21:31:33 +02:00
|
|
|
</et2-link-entry>
|
|
|
|
<et2-button id="link_button" label="Link" class="link" .noSubmit=${true}
|
|
|
|
@click=${this.handleLinkButtonClick}>
|
|
|
|
</et2-button>
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Replace when they're webcomponents
|
|
|
|
_fileButtons()
|
|
|
|
{
|
2022-07-21 17:57:50 +02:00
|
|
|
if(this.noFiles)
|
2022-06-06 21:31:33 +02:00
|
|
|
{
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
// File upload
|
|
|
|
//@ts-ignore IDE doesn't know about Et2WidgetClass
|
|
|
|
let self : Et2WidgetClass | et2_widget = this;
|
|
|
|
let file_attrs = {
|
|
|
|
multiple: true,
|
|
|
|
id: this.id + '_file',
|
|
|
|
label: '',
|
|
|
|
// Make the whole template a drop target
|
|
|
|
drop_target: this.getInstanceManager().DOMContainer.getAttribute("id"),
|
|
|
|
readonly: this.readonly,
|
|
|
|
|
|
|
|
// Change to this tab when they drop
|
|
|
|
onStart: function(event, file_count)
|
|
|
|
{
|
|
|
|
// Find the tab widget, if there is one
|
|
|
|
let tabs = self;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
tabs = tabs.getParent();
|
|
|
|
}
|
2022-12-14 19:56:27 +01:00
|
|
|
while(tabs != self.getRoot() && tabs.getType() != 'ET2-TABBOX');
|
2022-06-06 21:31:33 +02:00
|
|
|
if(tabs != self.getRoot())
|
|
|
|
{
|
2022-12-14 19:56:27 +01:00
|
|
|
(<Et2Tabs><unknown>tabs).activateTab(self);
|
2022-06-06 21:31:33 +02:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
onFinish: function(event, file_count)
|
|
|
|
{
|
|
|
|
// Auto-link uploaded files
|
|
|
|
self.handleFilesUploaded(event);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
this.file_upload = <et2_file>et2_createWidget("file", file_attrs, this);
|
|
|
|
this.file_upload.set_readonly(this.readonly);
|
|
|
|
this.file_upload.getDOMNode().slot = "before";
|
|
|
|
|
|
|
|
this.append(this.file_upload.getDOMNode());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create links
|
|
|
|
*
|
|
|
|
* Using current value for one end of the link, create links to the provided files or entries
|
|
|
|
*
|
|
|
|
* @param _links
|
|
|
|
*/
|
|
|
|
createLink(_links : LinkInfo[])
|
|
|
|
{
|
|
|
|
let links : LinkInfo[];
|
|
|
|
if(typeof _links == 'undefined')
|
|
|
|
{
|
|
|
|
links = [];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
links = _links;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If no link array was passed in, don't make the ajax call
|
|
|
|
if(links.length > 0)
|
|
|
|
{
|
|
|
|
egw.request("EGroupware\\Api\\Etemplate\\Widget\\Link::ajax_link",
|
|
|
|
[this.value.to_app, this.value.to_id, links]).then((result) => this._link_result(result))
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sent some links, server has a result
|
|
|
|
*
|
|
|
|
* @param {Object} success
|
|
|
|
*/
|
|
|
|
_link_result(success)
|
|
|
|
{
|
|
|
|
if(success)
|
|
|
|
{
|
|
|
|
// Show some kind of success...
|
|
|
|
|
|
|
|
// Reset
|
|
|
|
this.resetAfterLink();
|
|
|
|
|
|
|
|
// Server says it's OK, but didn't store - we'll send this again on submit
|
|
|
|
// This happens if you link to something before it's saved to the DB
|
|
|
|
if(typeof success == "object")
|
|
|
|
{
|
|
|
|
// Save as appropriate in value
|
|
|
|
if(typeof this.value != "object")
|
|
|
|
{
|
|
|
|
this.value = {};
|
|
|
|
}
|
|
|
|
this.value.to_id = success;
|
2022-06-06 22:42:43 +02:00
|
|
|
|
2022-06-06 21:31:33 +02:00
|
|
|
for(let link in success)
|
|
|
|
{
|
|
|
|
// Icon should be in registry
|
|
|
|
if(typeof success[link].icon == 'undefined')
|
|
|
|
{
|
|
|
|
success[link].icon = egw.link_get_registry(success[link].app, 'icon');
|
|
|
|
// No icon, try by mime type - different place for un-saved entries
|
|
|
|
if(success[link].icon == false && success[link].id.type)
|
|
|
|
{
|
|
|
|
// Triggers icon by mime type, not thumbnail or app
|
|
|
|
success[link].type = success[link].id.type;
|
|
|
|
success[link].icon = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Special handling for file - if not existing, we can't ask for title
|
|
|
|
if(success[link].app == 'file' && typeof success[link].title == 'undefined')
|
|
|
|
{
|
|
|
|
success[link].title = success[link].id.name || '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-12 18:32:08 +01:00
|
|
|
// Send an event so listeners can update
|
|
|
|
this.dispatchEvent(new CustomEvent("et2-change", {
|
|
|
|
bubbles: true,
|
|
|
|
detail: typeof success == "object" ? Object.values(success) : []
|
|
|
|
}));
|
2022-06-06 21:31:33 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-08-02 00:49:16 +02:00
|
|
|
this.validators.push(new ManualMessage(this.egw().lang("failed")));
|
2022-06-06 21:31:33 +02:00
|
|
|
}
|
|
|
|
this.dispatchEvent(new CustomEvent('link.et2_link_to', {bubbles: true, detail: success}));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A link was attempted. Reset internal values to get ready for the next one.
|
|
|
|
*/
|
|
|
|
resetAfterLink()
|
|
|
|
{
|
|
|
|
// Hide link button again
|
|
|
|
this.classList.remove("can_link");
|
|
|
|
this.link_button.image = "";
|
|
|
|
|
|
|
|
// Clear internal
|
|
|
|
delete this.value.app;
|
|
|
|
delete this.value.id;
|
|
|
|
|
|
|
|
// Clear file upload
|
|
|
|
for(var file in this.file_upload.options.value)
|
|
|
|
{
|
|
|
|
delete this.file_upload.options.value[file];
|
|
|
|
}
|
|
|
|
this.file_upload.progress.empty();
|
|
|
|
|
|
|
|
// Clear link entry
|
|
|
|
this.select.value = {app: this.select.app, id: ""};
|
2023-09-28 19:00:30 +02:00
|
|
|
this.select._searchNode.clearSearch();
|
|
|
|
this.select._searchNode.select_options = [];
|
2022-06-06 21:31:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Files have been uploaded (successfully), ready to link
|
|
|
|
*
|
|
|
|
* @param event
|
|
|
|
* @protected
|
|
|
|
*/
|
|
|
|
handleFilesUploaded(event)
|
|
|
|
{
|
|
|
|
this.classList.add("can_link");
|
|
|
|
|
|
|
|
let links = [];
|
|
|
|
|
|
|
|
// Get files from file upload widget
|
|
|
|
let files = this.file_upload.get_value();
|
|
|
|
for(let file in files)
|
|
|
|
{
|
|
|
|
links.push({
|
|
|
|
app: 'file',
|
|
|
|
id: file,
|
|
|
|
name: files[file].name,
|
|
|
|
type: files[file].type,
|
|
|
|
|
|
|
|
// Not sure what this is...
|
|
|
|
/*
|
|
|
|
remark: jQuery("li[file='" + files[file].name.replace(/'/g, '"') + "'] > input", self.file_upload.progress)
|
|
|
|
.filter(function ()
|
|
|
|
{
|
|
|
|
return jQuery(this).attr("placeholder") != jQuery(this).val();
|
|
|
|
}).val()
|
|
|
|
*/
|
|
|
|
});
|
|
|
|
}
|
|
|
|
this.createLink(links);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An entry has been selected, ready to link
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
handleEntrySelected(event)
|
|
|
|
{
|
|
|
|
// Could be the app, could be they selected an entry
|
2024-05-21 18:45:17 +02:00
|
|
|
if(event.target == this.select && (
|
|
|
|
typeof this.select.value == "string" && this.select.value ||
|
|
|
|
typeof this.select.value == "object" && this.select.value.id
|
|
|
|
))
|
2022-06-06 21:31:33 +02:00
|
|
|
{
|
|
|
|
this.classList.add("can_link");
|
2023-09-19 16:46:41 +02:00
|
|
|
this.link_button.focus();
|
2022-06-06 21:31:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-06 22:42:43 +02:00
|
|
|
/**
|
|
|
|
* An entry was selected, but instead of clicking "Link", the user cleared the selection
|
|
|
|
*/
|
|
|
|
handleEntryCleared(event)
|
|
|
|
{
|
|
|
|
this.classList.remove("can_link");
|
|
|
|
}
|
|
|
|
|
2022-06-06 21:31:33 +02:00
|
|
|
handleLinkButtonClick(event : MouseEvent)
|
|
|
|
{
|
|
|
|
this.link_button.image = "loading";
|
|
|
|
let link_info : LinkInfo[] = [];
|
|
|
|
if(this.select.value)
|
|
|
|
{
|
|
|
|
let selected = this.select.value;
|
|
|
|
// Extra complicated because LinkEntry doesn't always return a LinkInfo
|
2022-07-21 17:57:50 +02:00
|
|
|
if(this.onlyApp)
|
2022-06-06 21:31:33 +02:00
|
|
|
{
|
2022-07-21 17:57:50 +02:00
|
|
|
selected = <LinkInfo>{app: this.onlyApp, id: selected};
|
2022-06-06 21:31:33 +02:00
|
|
|
}
|
|
|
|
link_info.push(<LinkInfo>selected);
|
|
|
|
}
|
|
|
|
this.createLink(link_info)
|
|
|
|
}
|
|
|
|
|
2022-12-12 18:32:08 +01:00
|
|
|
/**
|
|
|
|
* Handle a link being removed
|
|
|
|
*
|
|
|
|
* Event is thrown every time a link is removed (from a LinkList) but we only care if the
|
|
|
|
* entry hasn't been saved yet and has no ID. In this case we've been keeping the list
|
|
|
|
* to submit and link server-side so we have to remove the deleted link from our list.
|
|
|
|
*
|
|
|
|
* @param {CustomEvent} e
|
|
|
|
*/
|
|
|
|
handleLinkDeleted(e : CustomEvent)
|
|
|
|
{
|
|
|
|
if(e && e.detail && this.value && typeof this.value.to_id == "object")
|
|
|
|
{
|
|
|
|
delete this.value.to_id[e.detail.link_id || ""]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-20 21:23:56 +01:00
|
|
|
handleFilePaste([button, files])
|
|
|
|
{
|
|
|
|
if(!button)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let values = {};
|
|
|
|
for(var i = 0; i < files.length; i++)
|
|
|
|
{
|
|
|
|
values['link:' + files[i]] = {
|
|
|
|
app: 'link',
|
|
|
|
id: files[i],
|
|
|
|
type: 'unknown',
|
|
|
|
icon: 'link',
|
|
|
|
remark: '',
|
|
|
|
title: files[i]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
this._link_result(values);
|
|
|
|
}
|
|
|
|
|
2024-04-04 23:38:55 +02:00
|
|
|
handleVfsSelected([button, selected])
|
2024-02-09 17:17:52 +01:00
|
|
|
{
|
2024-04-04 23:38:55 +02:00
|
|
|
if(!button || !selected?.length)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2024-02-09 17:17:52 +01:00
|
|
|
let values = true;
|
|
|
|
// If entry not yet saved, store for linking on server
|
|
|
|
if(!this.value.to_id || typeof this.value.to_id == 'object')
|
|
|
|
{
|
|
|
|
values = this.value.to_id || {};
|
2024-04-04 23:38:55 +02:00
|
|
|
for(let i = 0; i < selected.length; i++)
|
2024-02-09 17:17:52 +01:00
|
|
|
{
|
2024-04-04 23:38:55 +02:00
|
|
|
const info = this.pasteDialog.fileInfo(selected[i]);
|
|
|
|
values['link:' + selected[i]] = {
|
|
|
|
app: info?.app == "filemanager" ? "link" : info?.app,
|
|
|
|
id: info?.app == "filemanager" ? selected[i] : info?.id,
|
|
|
|
type: 'unknown',
|
|
|
|
icon: 'link',
|
|
|
|
remark: '',
|
|
|
|
title: selected[i]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Send to server to link
|
|
|
|
const files = [];
|
|
|
|
const links = [];
|
|
|
|
selected.forEach(id =>
|
|
|
|
{
|
|
|
|
const info = this.pasteDialog.fileInfo(id);
|
|
|
|
switch(info?.app)
|
2024-02-09 17:17:52 +01:00
|
|
|
{
|
2024-04-04 23:38:55 +02:00
|
|
|
case "filemanager":
|
|
|
|
files.push(id);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
links.push({app: info.app, id: info.id});
|
2024-02-09 17:17:52 +01:00
|
|
|
}
|
2024-04-04 23:38:55 +02:00
|
|
|
});
|
|
|
|
if(files.length > 0)
|
|
|
|
{
|
|
|
|
const file_method = 'EGroupware\\Api\\Etemplate\\Widget\\Link::ajax_link_existing';
|
|
|
|
const methodId = this.value.to_app + ':' + this.value.to_id;
|
|
|
|
this.egw().request(
|
|
|
|
file_method,
|
|
|
|
[methodId, files, button]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if(links.length > 0)
|
|
|
|
{
|
|
|
|
this.createLink(links);
|
2024-02-09 17:17:52 +01:00
|
|
|
}
|
|
|
|
}
|
2024-04-04 23:38:55 +02:00
|
|
|
this.pasteButton.value = [];
|
2024-02-09 17:17:52 +01:00
|
|
|
this._link_result(values);
|
|
|
|
}
|
|
|
|
|
2022-06-06 21:31:33 +02:00
|
|
|
get link_button() : Et2Button
|
|
|
|
{
|
|
|
|
return this.shadowRoot.querySelector("#link_button");
|
|
|
|
}
|
|
|
|
|
|
|
|
get select() : Et2LinkEntry
|
|
|
|
{
|
|
|
|
return this.shadowRoot.querySelector("et2-link-entry");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Types of validation supported by this FormControl (for instance 'error'|'warning'|'info')
|
|
|
|
*
|
|
|
|
* @type {ValidationType[]}
|
|
|
|
*/
|
|
|
|
static get validationTypes() : ValidationType[]
|
|
|
|
{
|
|
|
|
return ['error', 'success'];
|
|
|
|
}
|
2024-05-07 22:46:44 +02:00
|
|
|
|
|
|
|
|
|
|
|
render()
|
|
|
|
{
|
|
|
|
const labelTemplate = this._labelTemplate();
|
|
|
|
const helpTemplate = this._helpTextTemplate();
|
|
|
|
|
|
|
|
return html`
|
|
|
|
<div
|
|
|
|
part="form-control"
|
|
|
|
class=${classMap({
|
|
|
|
'form-control': true,
|
|
|
|
'form-control--medium': true,
|
|
|
|
'form-control--has-label': labelTemplate !== nothing,
|
|
|
|
'form-control--has-help-text': helpTemplate !== nothing
|
|
|
|
})}
|
|
|
|
>
|
|
|
|
${labelTemplate}
|
|
|
|
<div part="form-control-input" class="form-control-input" @sl-change=${() =>
|
|
|
|
{
|
|
|
|
this.dispatchEvent(new Event("change", {bubbles: true}));
|
|
|
|
}}>
|
|
|
|
${this._inputGroupBeforeTemplate()}
|
|
|
|
${this._inputGroupInputTemplate()}
|
|
|
|
</div>
|
|
|
|
${helpTemplate}
|
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
}
|
2022-06-06 21:31:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// @ts-ignore TypeScript is not recognizing that this widget is a LitElement
|
|
|
|
customElements.define("et2-link-to", Et2LinkTo);
|