Add addressbook's "Save as infolog" to new merge dialog

This commit is contained in:
nathan 2024-07-08 12:59:45 -06:00
parent 0d6e885ac3
commit 6d7b097072
4 changed files with 50 additions and 46 deletions

View File

@ -24,6 +24,10 @@ import {LitElement} from "lit";
import {Et2SelectCountry} from "../../api/js/etemplate/Et2Select/Select/Et2SelectCountry";
import {Et2SelectState} from "../../api/js/etemplate/Et2Select/Select/Et2SelectState";
import type {EgwAction} from "../../api/js/egw_action/EgwAction";
import {EgwActionObject} from "../../api/js/egw_action/EgwActionObject";
import {Et2MergeDialog} from "../../api/js/etemplate/Et2Dialog/Et2MergeDialog";
import {et2_createWidget} from "../../api/js/etemplate/et2_core_widget";
/**
* Object to call app.addressbook.openCRMview with
@ -1166,48 +1170,60 @@ class AddressbookApp extends EgwApp
return emails;
}
/**
* Ask the user for a target document to merge into
*
* Overridden from parent to add addressbook's options:
* - save as infolog
*
* @returns {Promise<{document : string, pdf : boolean, mime : string}>}
* @protected
*/
protected async _getMergeDocument(et2?, action? : EgwAction, selected? : EgwActionObject[]) : Promise<{
documents : { path : string; mime : string }[];
options : { [p : string] : string | boolean }
}>
{
const promise = super._getMergeDocument(et2, action, selected);
// Find dialog
const dialog = this.et2?.getDOMNode()?.querySelector('et2-merge-dialog') ?? document.body.querySelector('et2-merge-dialog');
// Add additional option UI by loading a template
const options = <Et2MergeDialog><unknown>et2_createWidget('template', {
application: this.appname,
id: this.appname + ".mail_merge_dialog",
}, dialog);
// Wait for template load
const wait = [];
options.loadingFinished(wait);
await Promise.all(wait);
// Get template values, add them in
const result = await promise;
result.options = {...this.et2.getInstanceManager().getValues(options), ...result.options};
return result;
}
/**
* Merge the selected contacts into the target document.
*
* Normally we let the framework handle this, but in addressbook we want to
* interfere and customize things a little to ask about saving to infolog.
* interfere and customize things a little to save to infolog.
*
* @param {egwAction} action - The document they clicked
* @param {egwActionObject[]} selected - Rows selected
*/
_mergeEmail(action, data)
{
// Special processing for email documents - ask about infolog
if(action && data && (data.id.length > 1 || data.select_all))
if(data.options.info_type)
{
const callback = (button, value) =>
{
if(button == Et2Dialog.OK_BUTTON)
{
if(value.infolog)
{
data.menuaction += '&to_app=infolog&info_type=' + value.info_type;
data.merge += '&to_app=infolog&info_type=' + data.options.info_type;
}
// Normal processing otherwise
return super._mergeEmail(action, data);
}
};
let dialog = new Et2Dialog(this.egw);
dialog.transformAttributes({
callback: callback,
title: action.caption,
buttons: Et2Dialog.BUTTONS_OK_CANCEL,
type: Et2Dialog.QUESTION_MESSAGE,
template: egw.webserverUrl + '/addressbook/templates/default/mail_merge_dialog.xet',
value: {content: {info_type: 'email'}, sel_options: this.et2.getArrayMgr('sel_options').data}
});
document.body.appendChild(<LitElement><unknown>dialog);
}
else
{
// Normal processing for only one contact selected
return super._mergeEmail(action, data);
}
}
/**
* Retrieve the current state of the application for future restoration

View File

@ -2,22 +2,6 @@
<!DOCTYPE overlay PUBLIC "-//EGroupware GmbH//eTemplate 2.0//EN" "https://www.egroupware.org/etemplate2.0.dtd">
<overlay>
<template id="addressbook.mail_merge_dialog" template="" lang="" group="0" version="">
<grid>
<columns>
<column/>
<column/>
</columns>
<rows>
<row>
<et2-description value="Do you want to send the message to all selected entries, WITHOUT further editing?"></et2-description>
</row>
<row>
<et2-hbox>
<et2-checkbox id="infolog" label="Save as infolog"></et2-checkbox>
<et2-select id="info_type"></et2-select>
</et2-hbox>
</row>
</rows>
</grid>
<et2-select id="info_type" emptyLabel="Save as infolog"></et2-select>
</template>
</overlay>

View File

@ -22,6 +22,7 @@ export class Et2MergeDialog extends Et2Widget(LitElement)
et2-details::part(content) {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: var(--sl-spacing-medium);
}
`,
];
@ -139,6 +140,7 @@ export class Et2MergeDialog extends Et2Widget(LitElement)
label="${this.egw().lang("Link to each entry")}"
></et2-checkbox>
<et2-checkbox label=${this.egw().lang("Merge individually")} id="individual"></et2-checkbox>
<slot></slot>
</et2-details>
</et2-vfs-select-dialog>`;
}

View File

@ -861,6 +861,8 @@ export abstract class EgwApp
if(document.documents.length == 1 && document.documents[0].mime == "message/rfc822")
{
vars.document = document.documents[0].path;
// Remove not applicable options
['pdf', 'download'].forEach(k => delete vars.options[k]);
return this._mergeEmail(_action.clone(), vars);
}
else