Skip to content
Snippets Groups Projects
Commit c1d5a568 authored by S.Listl's avatar S.Listl
Browse files

Serial letter export

parent 2c5dec63
No related branches found
No related tags found
No related merge requests found
Showing
with 382 additions and 144 deletions
import("system.text");
import("Employee_lib");
import("system.vars");
import("system.result");
import("system.neon");
import("DocumentTemplate_lib");
//if this was done for every row, like in a lookup, the performance would be very bad
if (vars.get("$sys.viewmode") == neon.FRAME_VIEWMODE_MASK)
{
var templateId = vars.get("$field.DOCUMENTTEMPLATE_ID");
var template;
if (templateId)
template = DocumentTemplate.loadTemplate(templateId);
else
template = DocumentTemplate.loadTemplate(vars.get("$field.BULKMAILID"), "BULKMAIL");
var contactId = EmployeeUtils.getCurrentContactId();
var preview = template.getReplacedEmailsByContactIds([contactId]);
result.string(preview[contactId].body);
}
\ No newline at end of file
import("Bulkmail_lib");
import("system.text");
import("Employee_lib");
import("system.vars");
import("system.result");
import("system.neon");
import("DocumentTemplate_lib");
//if this was done for every row, like in a lookup, the performance would be very bad
if (vars.get("$sys.viewmode") == neon.FRAME_VIEWMODE_MASK)
{
var template = BulkMailUtils.getBulkMailTemplate(vars.get("$field.BULKMAILID"), vars.get("$field.DOCUMENTTEMPLATE_ID"));
var contactId = EmployeeUtils.getCurrentContactId();
var preview = template.getReplacedEmailsByContactIds([contactId]);
result.string(preview[contactId].body);
}
import("system.vars");
import("Email_lib");
EmailUtils.openNewMail(vars.getString("$field.CONTACTID"));
\ No newline at end of file
import("system.vars");
import("DocumentTemplate_lib");
LetterUtils.openNewLetter(vars.get("$field.CONTACTID"));
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<entity xmlns="http://www.adito.de/2018/ao/Model" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" VERSION="1.3.10" xsi:schemaLocation="http://www.adito.de/2018/ao/Model adito://models/xsd/entity/1.3.10">
<name>SerialLetter_entity</name>
<majorModelMode>DISTRIBUTED</majorModelMode>
<icon>VAADIN:ENVELOPES</icon>
<title>Serial letter</title>
<contentTitleProcess>%aditoprj%/entity/SerialLetter_entity/contentTitleProcess.js</contentTitleProcess>
<recordContainer>db</recordContainer>
<entityFields>
<entityProvider>
<name>#PROVIDER</name>
<dependencies>
<entityDependency>
<name>8cb1a355-eb91-414a-8860-0210b18bd1ba</name>
<entityName>SerialLetterAddRecipients_entity</entityName>
<fieldName>SerialLetters</fieldName>
<isConsumer v="false" />
</entityDependency>
</dependencies>
</entityProvider>
<entityActionField>
<name>downloadLetter</name>
<title>Download letter</title>
<onActionProcess>%aditoprj%/entity/SerialLetter_entity/entityfields/downloadletter/onActionProcess.js</onActionProcess>
<iconId>VAADIN:DOWNLOAD_ALT</iconId>
</entityActionField>
<entityField>
<name>SERIALLETTERID</name>
</entityField>
<entityField>
<name>DOCUMENTTEMPLATE_ID</name>
<title>Document Template</title>
<consumer>Templates</consumer>
</entityField>
<entityConsumer>
<name>Recipients</name>
<dependency>
<name>dependency</name>
<entityName>LetterRecipient_entity</entityName>
<fieldName>SerialLetterRecipients</fieldName>
</dependency>
<children>
<entityParameter>
<name>SerialLetterId_param</name>
<valueProcess>%aditoprj%/entity/SerialLetter_entity/entityfields/recipients/children/serialletterid_param/valueProcess.js</valueProcess>
</entityParameter>
</children>
</entityConsumer>
<entityField>
<name>ICON</name>
<contentType>IMAGE</contentType>
<valueProcess>%aditoprj%/entity/SerialLetter_entity/entityfields/icon/valueProcess.js</valueProcess>
</entityField>
<entityConsumer>
<name>Templates</name>
<dependency>
<name>dependency</name>
<entityName>DocumentTemplate_entity</entityName>
<fieldName>DocumentTemplateProvider</fieldName>
</dependency>
</entityConsumer>
<entityField>
<name>TITLE</name>
<title>Title</title>
<mandatory v="true" />
</entityField>
</entityFields>
<recordContainers>
<dbRecordContainer>
<name>db</name>
<alias>Data_alias</alias>
<fromClauseProcess>%aditoprj%/entity/SerialLetter_entity/recordcontainers/db/fromClauseProcess.js</fromClauseProcess>
<linkInformation>
<linkInformation>
<name>5d9c983a-b129-437a-ae9d-203fb8ad03ec</name>
<tableName>SERIALLETTER</tableName>
<primaryKey>SERIALLETTERID</primaryKey>
<isUIDTable v="true" />
<readonly v="false" />
</linkInformation>
<linkInformation>
<name>bc81b1c3-ce99-4581-ac70-4e24bebb0c75</name>
<tableName>DOCUMENTTEMPLATE</tableName>
<primaryKey>DOCUMENTTEMPLATEID</primaryKey>
<isUIDTable v="false" />
<readonly v="true" />
</linkInformation>
</linkInformation>
<recordFieldMappings>
<dbRecordFieldMapping>
<name>DOCUMENTTEMPLATE_ID.value</name>
<recordfield>SERIALLETTER.DOCUMENTTEMPLATE_ID</recordfield>
</dbRecordFieldMapping>
<dbRecordFieldMapping>
<name>SERIALLETTERID.value</name>
<recordfield>SERIALLETTER.SERIALLETTERID</recordfield>
</dbRecordFieldMapping>
<dbRecordFieldMapping>
<name>DOCUMENTTEMPLATE_ID.displayValue</name>
<recordfield>DOCUMENTTEMPLATE.NAME</recordfield>
</dbRecordFieldMapping>
<dbRecordFieldMapping>
<name>TITLE.value</name>
<recordfield>SERIALLETTER.TITLE</recordfield>
</dbRecordFieldMapping>
</recordFieldMappings>
</dbRecordContainer>
</recordContainers>
</entity>
<name>SerialLetter_entity</name>
<majorModelMode>DISTRIBUTED</majorModelMode>
<icon>VAADIN:ENVELOPES</icon>
<title>Serial letter</title>
<contentTitleProcess>%aditoprj%/entity/SerialLetter_entity/contentTitleProcess.js</contentTitleProcess>
<recordContainer>db</recordContainer>
<entityFields>
<entityProvider>
<name>#PROVIDER</name>
<dependencies>
<entityDependency>
<name>8cb1a355-eb91-414a-8860-0210b18bd1ba</name>
<entityName>SerialLetterAddRecipients_entity</entityName>
<fieldName>SerialLetters</fieldName>
<isConsumer v="false" />
</entityDependency>
</dependencies>
</entityProvider>
<entityActionField>
<name>downloadLetter</name>
<title>Export letter</title>
<onActionProcess>%aditoprj%/entity/SerialLetter_entity/entityfields/downloadletter/onActionProcess.js</onActionProcess>
<iconId>VAADIN:DOWNLOAD_ALT</iconId>
</entityActionField>
<entityField>
<name>SERIALLETTERID</name>
</entityField>
<entityField>
<name>DOCUMENTTEMPLATE_ID</name>
<title>Document Template</title>
<consumer>Templates</consumer>
<mandatory v="true" />
</entityField>
<entityConsumer>
<name>Recipients</name>
<dependency>
<name>dependency</name>
<entityName>LetterRecipient_entity</entityName>
<fieldName>SerialLetterRecipients</fieldName>
</dependency>
<children>
<entityParameter>
<name>SerialLetterId_param</name>
<valueProcess>%aditoprj%/entity/SerialLetter_entity/entityfields/recipients/children/serialletterid_param/valueProcess.js</valueProcess>
</entityParameter>
</children>
</entityConsumer>
<entityField>
<name>ICON</name>
<contentType>IMAGE</contentType>
<valueProcess>%aditoprj%/entity/SerialLetter_entity/entityfields/icon/valueProcess.js</valueProcess>
</entityField>
<entityConsumer>
<name>Templates</name>
<dependency>
<name>dependency</name>
<entityName>DocumentTemplate_entity</entityName>
<fieldName>DocumentTemplateProvider</fieldName>
</dependency>
</entityConsumer>
<entityField>
<name>TITLE</name>
<title>Title</title>
<mandatory v="true" />
</entityField>
<entityField>
<name>DESCRIPTION</name>
<title>Description</title>
<contentType>LONG_TEXT</contentType>
</entityField>
</entityFields>
<recordContainers>
<dbRecordContainer>
<name>db</name>
<alias>Data_alias</alias>
<fromClauseProcess>%aditoprj%/entity/SerialLetter_entity/recordcontainers/db/fromClauseProcess.js</fromClauseProcess>
<linkInformation>
<linkInformation>
<name>5d9c983a-b129-437a-ae9d-203fb8ad03ec</name>
<tableName>SERIALLETTER</tableName>
<primaryKey>SERIALLETTERID</primaryKey>
<isUIDTable v="true" />
<readonly v="false" />
</linkInformation>
<linkInformation>
<name>bc81b1c3-ce99-4581-ac70-4e24bebb0c75</name>
<tableName>DOCUMENTTEMPLATE</tableName>
<primaryKey>DOCUMENTTEMPLATEID</primaryKey>
<isUIDTable v="false" />
<readonly v="true" />
</linkInformation>
</linkInformation>
<recordFieldMappings>
<dbRecordFieldMapping>
<name>DOCUMENTTEMPLATE_ID.value</name>
<recordfield>SERIALLETTER.DOCUMENTTEMPLATE_ID</recordfield>
</dbRecordFieldMapping>
<dbRecordFieldMapping>
<name>SERIALLETTERID.value</name>
<recordfield>SERIALLETTER.SERIALLETTERID</recordfield>
</dbRecordFieldMapping>
<dbRecordFieldMapping>
<name>DOCUMENTTEMPLATE_ID.displayValue</name>
<recordfield>DOCUMENTTEMPLATE.NAME</recordfield>
</dbRecordFieldMapping>
<dbRecordFieldMapping>
<name>TITLE.value</name>
<recordfield>SERIALLETTER.TITLE</recordfield>
</dbRecordFieldMapping>
<dbRecordFieldMapping>
<name>DESCRIPTION.value</name>
<recordfield>SERIALLETTER.DESCRIPTION</recordfield>
/entity>
import("system.util");
import("DocumentTemplate_lib");
import("system.neon");
import("Bulkmail_lib");
import("system.vars");
import("system.notification");
import("Employee_lib");
//var params = {
// binId : "1234"
//}
//notification.addNotification(util.getNewUUID(), null, null, null, "DownloadReady", notification.PRIO_NORMAL, 2, notification.STATE_UNSEEN, [EmployeeUtils.getCurrentUserId()], "yes", "desc")
var document = SerialLetterUtils.buildSerialLetter(vars.get("$field.SERIALLETTERID"));
\ No newline at end of file
import("system.result");
import("system.vars");
import("system.tools");
var allRoles = tools.getAllRoles();
var roleTitle = vars.get("$this.value");
if (roleTitle in allRoles)
roleTitle = allRoles[roleTitle][0];
result.string(roleTitle);
\ No newline at end of file
import("system.result");
result.string(JSON.stringify(["INTERNAL_EVERYONE", "INTERNAL_GROUPWARE", "INTERNAL_SNMP", "INTERNAL_DESIGNER", "INTERNAL_TECHNICAL"]));
\ No newline at end of file
import("system.result");
import("system.vars");
import("system.tools");
var roles = [];
var userTitle = vars.exists("$param.UserTitle_param") && vars.get("$param.UserTitle_param");
var allRoles = tools.getAllRoles();
if (userTitle && tools.existUsers(userTitle))
{
var existsObj = {};
tools.getRoles(userTitle).forEach(function (role)
{
if (!this[role] && role != "INTERNAL_EVERYONE")
{
var roleTitle = role;
if (role in allRoles)
roleTitle = allRoles[role][0];
roles.push([role, role, roleTitle]);
this[role] = true;
}
}, existsObj);
}
result.object(roles);
\ No newline at end of file
import("system.result");
import("system.vars");
import("system.tools");
var userTitle = vars.exists("$param.UserTitle_param") && vars.get("$param.UserTitle_param");
var role = vars.get("$local.uid");
if (userTitle)
{
var user = tools.getUser(userTitle);
var roles = tools.getRoles(userTitle);
roles = roles.filter(function (row)
{
return row != role;
});
user[tools.ROLES] = roles;
tools.updateUser(user);
}
\ No newline at end of file
import("system.result");
import("system.vars");
import("system.tools");
var userTitle = vars.exists("$param.UserTitle_param") && vars.get("$param.UserTitle_param");
var newRole = vars.get("$local.rowdata")["ROLE.value"];
if (userTitle && tools.existUsers(userTitle) && newRole != "INTERNAL_EVERYONE")
{
var user = tools.getUser(userTitle);
var roles = tools.getRoles(userTitle);
var roleObj = {};
roles = [newRole].concat(roles)
.filter(function (role)
{
var exists = role in this;
this[role] = true;
return !exists;
}, roleObj);
user[tools.ROLES] = roles;
tools.updateUser(user);
}
\ No newline at end of file
import("system.result");
import("system.vars");
import("system.tools");
var userTitle = vars.exists("$param.UserTitle_param") && vars.get("$param.UserTitle_param");
var oldRole = vars.get("$local.uid");
var newRole = vars.get("$local.rowdata")["ROLE.value"];
if (userTitle && oldRole != newRole)
{
var user = tools.getUser(userTitle);
var roles = tools.getRoles(userTitle);
var roleObj = {};
roleObj[oldRole] = true;
roles = [newRole].concat(roles)
.filter(function (role)
{
var exists = role in roleObj;
roleObj[role] = true;
return !exists;
});
user[tools.ROLES] = roles;
tools.updateUser(user);
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<entity xmlns="http://www.adito.de/2018/ao/Model" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" VERSION="1.3.9" xsi:schemaLocation="http://www.adito.de/2018/ao/Model adito://models/xsd/entity/1.3.9">
<name>EmployeeRole_entity</name>
<majorModelMode>DISTRIBUTED</majorModelMode>
<title>Role</title>
<titlePlural>Roles</titlePlural>
<recordContainer>jdito</recordContainer>
<entityFields>
<entityProvider>
<name>#PROVIDER</name>
</entityProvider>
<entityField>
<name>UID</name>
</entityField>
<entityParameter>
<name>UserTitle_param</name>
<expose v="true" />
<mandatory v="true" />
<description>PARAMETER</description>
</entityParameter>
<entityProvider>
<name>EmployeeRoles</name>
<dependencies>
<entityDependency>
<name>3bcec57a-7165-4773-9253-5ecab26ee3f4</name>
<entityName>Employee_entity</entityName>
<fieldName>EmployeeRoles</fieldName>
<isConsumer v="false" />
</entityDependency>
</dependencies>
<children>
<entityParameter>
<name>UserTitle_param</name>
<expose v="true" />
<mandatory v="true" />
</entityParameter>
</children>
</entityProvider>
<entityField>
<name>ROLE</name>
<title>Role</title>
<consumer>Roles</consumer>
<linkedContext>Role</linkedContext>
<displayValueProcess>%aditoprj%/entity/EmployeeRole_entity/entityfields/role/displayValueProcess.js</displayValueProcess>
</entityField>
<entityConsumer>
<name>Roles</name>
<dependency>
<name>dependency</name>
<entityName>Role_entity</entityName>
<fieldName>FilteredRoles</fieldName>
</dependency>
<children>
<entityParameter>
<name>ExcludeRoles_param</name>
<valueProcess>%aditoprj%/entity/EmployeeRole_entity/entityfields/roles/children/excluderoles_param/valueProcess.js</valueProcess>
</entityParameter>
</children>
</entityConsumer>
<entityField>
<name>TARGETCONTEXT</name>
</entityField>
</entityFields>
<recordContainers>
<jDitoRecordContainer>
<name>jdito</name>
<jDitoRecordAlias>Data_alias</jDitoRecordAlias>
<contentProcess>%aditoprj%/entity/EmployeeRole_entity/recordcontainers/jdito/contentProcess.js</contentProcess>
<onInsert>%aditoprj%/entity/EmployeeRole_entity/recordcontainers/jdito/onInsert.js</onInsert>
<onUpdate>%aditoprj%/entity/EmployeeRole_entity/recordcontainers/jdito/onUpdate.js</onUpdate>
<onDelete>%aditoprj%/entity/EmployeeRole_entity/recordcontainers/jdito/onDelete.js</onDelete>
<recordFieldMappings>
<jDitoRecordFieldMapping>
<name>UID.value</name>
</jDitoRecordFieldMapping>
<jDitoRecordFieldMapping>
<name>ROLE.value</name>
</jDitoRecordFieldMapping>
<jDitoRecordFieldMapping>
<name>ROLE.displayValue</name>
</jDitoRecordFieldMapping>
<jDitoRecordFieldMapping>
<name>TARGETCONTEXT.value</name>
</jDitoRecordFieldMapping>
</recordFieldMappings>
</jDitoRecordContainer>
</recordContainers>
</entity>
......@@ -6073,7 +6073,8 @@
<key>%0 new recipients will be added to the serial letter.</key>
</entry>
<entry>
<key>Download letter</key>
<key>Export letter</key>
<value>Brief exportieren</value>
</entry>
<entry>
<key>Add to serial letter</key>
......
import("system.logging");
import("system.vars");
var varses = ["$"];
var varses = [
"$local.content",
"$local.data",
"$local.description",
"$local.idvalue",
"$local.idvalues",
"$local.row",
"$local.row_id",
"$local.rowdata",
"$local.uid",
"$local.binId",
];
var existses = {};
varses.forEach(function (v) {
this[v] = vars.exists(v);
......
......@@ -10,6 +10,7 @@ import("system.db");
import("DocumentTemplate_lib");
import("Email_lib");
import("system.process");
import("system.notification");
/**
* functions for bulk mails
......@@ -51,11 +52,7 @@ BulkMailUtils.sendBulkMail = function (pBulkMailId)
.andPrepare("BULKMAIL.BULKMAILID", pBulkMailId)
.buildSql("select DOCUMENTTEMPLATE_ID, SUBJECT, SENDER from BULKMAIL", "1=2")
);
var template;
if (templateId)
template = DocumentTemplate.loadTemplate(templateId);
else
template = DocumentTemplate.loadTemplate(pBulkMailId, "BULKMAIL");
var template = BulkMailUtils.getBulkMailTemplate(pBulkMailId, templateId);
var recipientData = db.table(SqlCondition.begin()
.andPrepare("BULKMAILRECIPIENT.BULKMAIL_ID", pBulkMailId)
......@@ -155,6 +152,23 @@ BulkMailUtils.addRecipients = function (pBulkMailId, pContactIds)
db.inserts(inserts);
}
/**
* Loads the document template of a bulk mail. If the bulk mail itself has a
* template, it is preferred over the documentTemplate-id.
*
* @param {String} pBulkMailId bulkmail id
* @param {String} pDocumentTemplateId documentTemplate id
*
* @return {DocumentTemplate} the document template, null if no content was found.
*/
BulkMailUtils.getBulkMailTemplate = function (pBulkMailId, pDocumentTemplateId)
{
var template = DocumentTemplate.loadTemplate(pBulkMailId, "BULKMAIL");
if (template === null)
template = DocumentTemplate.loadTemplate(pDocumentTemplateId);
return template;
}
function SerialLetterUtils () {}
SerialLetterUtils.addRecipients = function (pBulkMailId, pContactIds)
......@@ -183,7 +197,12 @@ SerialLetterUtils.openAddRecipientView = function (pContactIds)
SerialLetterUtils.buildSerialLetter = function (pSerialLetterId)
{
process.executeAsync("buildSerialLetter_serverProcess", {
process.execute("buildSerialLetter_serverProcess", {
"serialLetterId" : pSerialLetterId
}, false, "_____USER_bcdfb521-c7d0-4ef1-8916-78e7d3232046", process.THREADPRIORITY_VERYHIGH);
});
}
SerialLetterUtils.makeDownloadNotification = function (pTitle, pBinaryId, pUser)
{
notification.addNotification(pContentId, pLinkInfo, pImageInfo, pOriginatorName, pType, pForcedPriority, pDaysToLive, pState, pUser, pCaption, pDescription)
}
\ No newline at end of file
......@@ -135,7 +135,7 @@ DocumentTemplate.prototype.getReplacedContent = function (pReplacements)
{
case DocumentTemplate.types.HTML:
for (let i in pReplacements)
pReplacements[i] = text.replaceAll(pReplacements[i], {"\n" : "<br>"});
pReplacements[i] = text.text2html(pReplacements[i], false);
case DocumentTemplate.types.TXT:
let decodedContent = util.decodeBase64String(this.content)
return DocumentTemplate._replaceText(decodedContent, pReplacements);
......@@ -194,7 +194,6 @@ DocumentTemplate.prototype.getSerialLetterByContactIds = function (pContactIds)
{
let replaceArray = [];
for (let i = 0, l = pContactIds.length; i < l; i++)
for (let ii = 0; ii < 1000; ii++)
replaceArray.push(replacements[pContactIds[i]]);
return this._getReplacedODT(replaceArray);
}
......@@ -223,8 +222,8 @@ DocumentTemplate.prototype.getReplacedEmailsByContactIds = function (pContactIds
else
{
let body = this.getReplacedContent(replacements[contactId]);
if (this.type == DocumentTemplate.types.TXT)
body = text.replaceAll(body, {"\n" : "<br>"});
if (this.type == DocumentTemplate.types.TXT || this.type == DocumentTemplate.types.PLAIN)
body = text.text2html(body, false);
emailObj[contactId] = new Email(null, null, null, body);
}
}
......
import("system.logging");
import("system.result");
import("system.vars");
import("KeywordRegistry_basic");
......@@ -20,6 +19,5 @@ var contactIds = db.table(SqlCondition.begin()
.buildSql("select CONTACT_ID from LETTERRECIPIENT join CONTACT on LETTERRECIPIENT.CONTACT_ID = CONTACT.CONTACTID", "1=2")
);
var document = template.getSerialLetterByContactIds(contactIds);
logging.log("ja")
if (document)
neon.download(document, template.filename);
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment