mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-08-09 08:25:03 +02:00
* Api: Use file selection dialog for selecting target merge document instead of nested menus
This commit is contained in:
@ -20,6 +20,9 @@ import {et2_valueWidget} from "../etemplate/et2_core_valueWidget";
|
||||
import {nm_action} from "../etemplate/et2_extension_nextmatch_actions";
|
||||
import {Et2Dialog} from "../etemplate/Et2Dialog/Et2Dialog";
|
||||
import {Et2Favorites} from "../etemplate/Et2Favorites/Et2Favorites";
|
||||
import {loadWebComponent} from "../etemplate/Et2Widget/Et2Widget";
|
||||
import {Et2VfsSelectDialog} from "../etemplate/Et2Vfs/Et2VfsSelectDialog";
|
||||
import {Et2Checkbox} from "../etemplate/Et2Checkbox/Et2Checkbox";
|
||||
|
||||
/**
|
||||
* Type for push-message
|
||||
@ -795,7 +798,7 @@ export abstract class EgwApp
|
||||
* @param {egwAction} _action
|
||||
* @param {egwActionObject[]} _selected
|
||||
*/
|
||||
merge(_action : egwAction, _selected : egwActionObject[])
|
||||
async mergeAction(_action : egwAction, _selected : egwActionObject[])
|
||||
{
|
||||
// Find what we need
|
||||
let nm = null;
|
||||
@ -809,16 +812,10 @@ export abstract class EgwApp
|
||||
{
|
||||
nm = action.data.nextmatch;
|
||||
}
|
||||
if(as_pdf === null && action.getActionById('as_pdf') !== null)
|
||||
{
|
||||
as_pdf = action.getActionById('as_pdf').checked;
|
||||
}
|
||||
action = action.parent;
|
||||
}
|
||||
let all = nm?.getSelection().all || false;
|
||||
|
||||
as_pdf = as_pdf || false;
|
||||
|
||||
// Get list of entry IDs
|
||||
let ids = [];
|
||||
for(let i = 0; !all && i < _selected.length; i++)
|
||||
@ -826,16 +823,123 @@ export abstract class EgwApp
|
||||
let split = _selected[i].id.split("::");
|
||||
ids.push(split[1]);
|
||||
}
|
||||
let document = await this._getMergeDocument();
|
||||
if(!document.document)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
let vars = {
|
||||
..._action.data.merge_data,
|
||||
pdf: as_pdf,
|
||||
document: document.document,
|
||||
pdf: document.pdf ?? false,
|
||||
select_all: all,
|
||||
id: JSON.stringify(ids)
|
||||
id: ids
|
||||
};
|
||||
if(document.mime == "message/rfc822")
|
||||
{
|
||||
return this._mergeEmail(_action.clone(), vars);
|
||||
}
|
||||
else
|
||||
{
|
||||
vars.id = JSON.stringify(ids);
|
||||
}
|
||||
egw.open_link(egw.link('/index.php', vars), '_blank');
|
||||
}
|
||||
|
||||
/**
|
||||
* Ask the user for a target document to merge into
|
||||
*
|
||||
* @returns {Promise<{document : string, pdf : boolean, mime : string}>}
|
||||
* @protected
|
||||
*/
|
||||
|
||||
protected _getMergeDocument() : Promise<{ document : string, pdf : boolean, mime : string }>
|
||||
{
|
||||
let dirPref = <string>this.egw.preference('document_dir', this.appname) ?? "";
|
||||
let dirs = dirPref.split('/[,\s]+\//');
|
||||
dirs.forEach((d, index) =>
|
||||
{
|
||||
if(index)
|
||||
{
|
||||
d = "/" + d;
|
||||
}
|
||||
});
|
||||
let fileSelect = <Et2VfsSelectDialog><unknown>loadWebComponent('et2-vfs-select-dialog', {
|
||||
class: "egw_app_merge_document",
|
||||
title: this.egw.lang("Insert in document"),
|
||||
mode: "open",
|
||||
path: dirs.pop() ?? "",
|
||||
open: true
|
||||
}, this.et2);
|
||||
let pdf = <Et2Checkbox><unknown>loadWebComponent("et2-checkbox", {
|
||||
slot: "footer",
|
||||
label: "As PDF"
|
||||
}, fileSelect);
|
||||
|
||||
// Disable PDF checkbox for emails
|
||||
fileSelect.addEventListener("et2-select", e =>
|
||||
{
|
||||
let canPDF = true;
|
||||
fileSelect.value.forEach(path =>
|
||||
{
|
||||
if(fileSelect.fileInfo(path).mime == "message/rfc822")
|
||||
{
|
||||
canPDF = false;
|
||||
}
|
||||
});
|
||||
pdf.disabled = !canPDF;
|
||||
});
|
||||
return fileSelect.getComplete().then((values) =>
|
||||
{
|
||||
if(!values[0])
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
const value = values[1].pop() ?? "";
|
||||
const fileInfo = fileSelect.fileInfo(value) ?? {};
|
||||
fileSelect.remove();
|
||||
return {document: value, pdf: pdf.getValue(), mime: fileInfo.mime ?? ""};
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Merging into an email
|
||||
*
|
||||
* @param {object} data
|
||||
* @protected
|
||||
*/
|
||||
protected _mergeEmail(action, data : object)
|
||||
{
|
||||
const ids = data['id'];
|
||||
// egw.open() used if only 1 row selected
|
||||
data['egw_open'] = 'edit-mail--';
|
||||
data['target'] = 'compose_' + data.document;
|
||||
|
||||
// long_task runs menuaction once for each selected row
|
||||
data['nm_action'] = 'long_task';
|
||||
data['popup'] = this.egw.link_get_registry('mail', 'edit_popup');
|
||||
data['message'] = this.egw.lang('insert in %1', data.document);
|
||||
|
||||
data['menuaction'] = 'mail.mail_compose.ajax_merge';
|
||||
action.data = data;
|
||||
|
||||
if(data['select_all'] || ids.length > 1)
|
||||
{
|
||||
data['menuaction'] += "&document=" + data.document + "&merge=" + data.merge;
|
||||
nm_action(action, null, data['target'], {all: data['select_all'], ids: ids});
|
||||
}
|
||||
else
|
||||
{
|
||||
this.egw.open(ids.pop(), 'mail', 'edit', {
|
||||
from: 'merge',
|
||||
document: data.document,
|
||||
merge: data.merge
|
||||
}, data['target']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes actions and handlers on sidebox (delete)
|
||||
*
|
||||
|
Reference in New Issue
Block a user