Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
basic
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
xrm
basic
Commits
181fa351
Commit
181fa351
authored
5 years ago
by
S.Listl
Browse files
Options
Downloads
Patches
Plain Diff
Email fixed
parent
3458ece7
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
process/Address_lib/process.js
+16
-15
16 additions, 15 deletions
process/Address_lib/process.js
process/DocumentTemplate_lib/process.js
+77
-60
77 additions, 60 deletions
process/DocumentTemplate_lib/process.js
process/Offer_lib/process.js
+501
-501
501 additions, 501 deletions
process/Offer_lib/process.js
with
594 additions
and
576 deletions
process/Address_lib/process.js
+
16
−
15
View file @
181fa351
import
(
"
Employee_lib
"
);
import
(
"
system.swing
"
);
import
(
"
system.text
"
);
import
(
"
system.db
"
);
...
...
@@ -12,16 +13,16 @@ import("DocumentTemplate_lib");
/*
* Creates a Address Object
*
* @param {String} p
RelationID
req relationid for which address should be retrieved
* @param {String} pAddressI
D
opt addressid for which address should be retrieved
* @param {String} p
ContactId
req relationid for which address should be retrieved
* @param {String} pAddressI
d
opt addressid for which address should be retrieved
* @param {boolean} pPerson whether the address is from a person, not an organisation
*
* @return {String} the formatted address
*/
function
AddrObject
(
pRelationID
,
pPerson
,
pAddressI
D
)
function
AddrObject
(
pContactId
,
pPerson
,
pAddressI
d
)
{
this
.
Data
=
fetchAddressData
(
[
pRelationID
]
,
[[
""
,
"
addressformat
"
,
""
]
],
pAddressI
D
,
pPerson
);
this
.
Data
=
fetchAddressData
(
[
pContactId
],
[
new
Placeholder
(
""
,
Placeholder
.
types
.
ADDRESSFORMAT
,
""
)
],
pAddressI
d
,
pPerson
);
this
.
fmt
=
this
.
Data
[
0
][
0
][
26
];
/*
...
...
@@ -58,13 +59,13 @@ function getAddressesData( pCondition, pConfig, pSenderID, pAddressID )
{
switch
(
pConfig
[
i
].
target
)
{
case
Placeholder
Utils
.
targets
.
EMPLOYEE
:
case
Placeholder
.
targets
.
EMPLOYEE
:
employeeconfig
.
push
(
pConfig
[
i
]);
break
;
case
Placeholder
Utils
.
targets
.
SENDER
:
case
Placeholder
.
targets
.
SENDER
:
senderconfig
.
push
(
pConfig
[
i
]);
break
;
case
Placeholder
Utils
.
targets
.
RECIPIENT
:
case
Placeholder
.
targets
.
RECIPIENT
:
default
:
config
.
push
(
pConfig
[
i
]);
break
;
...
...
@@ -75,7 +76,7 @@ function getAddressesData( pCondition, pConfig, pSenderID, pAddressID )
if
(
senderconfig
.
length
>
0
)
var
senderdata
=
getAddressData
([
pSenderID
],
senderconfig
);
if
(
employeeconfig
.
length
>
0
)
var
employeedata
=
getAddressData
([
vars
.
get
(
"
$global.user
"
).
relationid
],
employeeconfig
);
var
employeedata
=
getAddressData
([
EmployeeUtils
.
getCurrentContactId
()
],
employeeconfig
);
if
(
data
.
length
>
0
&&
(
senderconfig
.
length
>
0
||
employeeconfig
.
length
>
0
))
{
var
ze
=
data
[
0
];
...
...
@@ -141,13 +142,13 @@ function fetchAddressData( pCondition, pConfig, AddressID, pPerson )
{
switch
(
pConfig
[
i
].
type
)
{
case
Placeholder
Utils
.
types
.
SQLPART
:
//sql part
case
Placeholder
.
types
.
SQLPART
:
//sql part
fields
.
push
(
pConfig
[
i
].
valueDefinition
);
//TODO: maybe do vars.resolveVariables
output
.
push
([
pos
++
,
pConfig
[
i
].
type
]);
header
.
push
(
pConfig
[
i
].
placeholderName
);
break
;
case
Placeholder
Utils
.
types
.
SQLPARTFUNCTION
:
// adito SQL functions
fields
.
push
(
pConfig
[
i
].
valueDefinition
.
call
());
case
Placeholder
.
types
.
SQLPARTFUNCTION
:
// adito SQL functions
fields
.
push
(
"
(
"
+
pConfig
[
i
].
valueDefinition
.
call
()
+
"
)
"
);
output
.
push
([
pos
++
,
pConfig
[
i
].
type
]);
header
.
push
(
pConfig
[
i
].
placeholderName
);
break
;
...
...
@@ -168,7 +169,7 @@ function fetchAddressData( pCondition, pConfig, AddressID, pPerson )
output
.
push
([
pos
++
,
pConfig
[
i
].
type
]);
header
.
push
(
pConfig
[
i
].
placeholderName
);
break
;
case
Placeholder
Utils
.
types
.
ADDRESSFORMAT
:
case
Placeholder
.
types
.
ADDRESSFORMAT
:
if
(
posaddrfields
==
-
1
)
{
var
sortfields
=
[
"
ORGANISATION.NAME
"
,
"
PERSON.LASTNAME
"
];
...
...
@@ -266,14 +267,14 @@ function setAddressData( pData )
{
switch
(
output
[
z
][
1
]
)
{
case
Placeholder
Utils
.
types
.
SQLPART
:
case
Placeholder
Utils
.
types
.
SQLPARTFUNCTION
:
case
Placeholder
.
types
.
SQLPART
:
case
Placeholder
.
types
.
SQLPARTFUNCTION
:
case
"
afunction
"
:
case
"
resolveIDFunction
"
:
case
"
select
"
:
row
[
z
]
=
sqlresult
[
i
][
output
[
z
][
0
]];
break
;
case
Placeholder
Utils
.
types
.
ADDRESSFORMAT
:
case
Placeholder
.
types
.
ADDRESSFORMAT
:
if
(
addrdata
.
length
==
0
)
addrdata
=
_getAddrData
(
sqlresult
[
i
].
slice
(
output
[
z
][
0
],
output
[
z
][
0
]
+
addrfields
.
length
)
);
row
[
z
]
=
_formatAddrData
(
addrdata
,
output
[
z
][
2
],
false
);
break
;
...
...
This diff is collapsed.
Click to expand it.
process/DocumentTemplate_lib/process.js
+
77
−
60
View file @
181fa351
import
(
"
Communication_lib
"
);
import
(
"
system.neon
"
);
import
(
"
system.logging
"
);
import
(
"
Employee_lib
"
);
import
(
"
KeywordRegistry_basic
"
);
import
(
"
Document_lib
"
);
...
...
@@ -62,6 +62,13 @@ DocumentTemplate.loadTemplate = function (pTemplateId)
return
new
DocumentTemplate
();
//TODO: throw error?
}
DocumentTemplate
.
_replaceText
=
function
(
pText
,
pReplacements
)
{
for
(
let
placeholder
in
pReplacements
)
pText
=
pText
.
replace
(
placeholder
,
pReplacements
[
placeholder
],
"
ig
"
);
return
pText
;
}
DocumentTemplate
.
prototype
.
toString
=
function
()
{
return
this
.
content
;
...
...
@@ -83,7 +90,8 @@ DocumentTemplate.prototype.getReplacedContent = function (pReplacements)
for
(
let
i
in
pReplacements
)
pReplacements
[
i
]
=
text
.
replaceAll
(
pReplacements
[
i
],
{
"
\n
"
:
"
<br>
"
});
case
DocumentTemplate
.
types
.
TXT
:
return
text
.
replaceAll
(
this
.
content
,
pReplacements
);
let
decodedContent
=
util
.
decodeBase64String
(
this
.
content
)
return
DocumentTemplate
.
_replaceText
(
decodedContent
,
pReplacements
);
case
DocumentTemplate
.
types
.
EML
:
return
this
.
_getReplacedEML
(
pReplacements
);
case
DocumentTemplate
.
types
.
ODT
:
...
...
@@ -116,24 +124,11 @@ DocumentTemplate.prototype.getReplacedContentByContactId = function (pContactId)
*/
DocumentTemplate
.
prototype
.
_getReplacedEML
=
function
(
pReplacements
)
{
var
email
=
mail
.
parseRFC
(
this
.
content
,
"
UTF-8
"
);
var
email
=
mail
.
parseRFC
(
util
.
decodeBase64String
(
this
.
content
)
);
var
htmlText
=
email
[
mail
.
MAIL_HTMLTEXT
];
return
text
.
replaceAll
(
htmlText
,
pReplacements
);
}
/**
* replaces placeholders for plain text
*
* @param {Object} pReplacements mapping with replacements for every placeholder
*
* @return {String} the replaced content
*/
DocumentTemplate
.
prototype
.
_getReplacedText
=
function
(
pReplacements
)
{
return
text
.
replaceAll
(
this
.
content
,
pReplacements
);
return
DocumentTemplate
.
_replaceText
(
htmlText
,
pReplacements
);
}
/*
* replaces a given Odt-File on the server and returns the replaced base64-file
*
...
...
@@ -212,10 +207,14 @@ DocumentTemplate.prototype._getReplacedODT = function (pReplacements)
*/
DocumentTemplate
.
prototype
.
_getReplacedDOCX
=
function
(
pReplacements
)
{
var
replacements
=
{};
for
(
let
placeholder
in
pReplacements
)
replacements
[
placeholder
.
slice
(
3
,
-
3
)]
=
pReplacements
[
placeholder
];
//this is executed as a process because of better performance
var
documentData
=
process
.
execute
(
"
getDocxDocument_serverProcess
"
,
{
templateb64
:
this
.
content
,
placeholderConfig
:
JSON
.
stringify
(
PlaceholderUtils
.
removePreAndPostFix
(
pR
eplacements
)
)
//process.execute is only able to handle strings
placeholderConfig
:
JSON
.
stringify
(
r
eplacements
)
//process.execute is only able to handle strings
});
return
documentData
;
...
...
@@ -238,13 +237,27 @@ DocumentTemplateUtils.getSingleReplacedDocument = function (pTemplateId, pContac
return
template
.
getReplacedTextByContactId
(
pContactId
);
}
/**
* represents a placeholder
*
* @param {String} pName name of the placeholder (without prefix and postfix)
* @param {String} pType type of the placeholder, see PlaceholderUtils.types
* @param {String|Function} pValueDef string or function (depends on the type) defining the value
* @param {String} [pTarget] what contact is used to get the data, see PlaceholderUtils.targets
*/
function
Placeholder
(
pName
,
pType
,
pValueDef
,
pTarget
)
{
this
.
placeholderName
=
PlaceholderUtils
.
formatPlaceholder
(
pName
);
this
.
type
=
pType
;
this
.
target
=
pTarget
||
Placeholder
.
targets
.
RECIPIENT
;
this
.
valueDefinition
=
pValueDef
;
}
function
PlaceholderUtils
()
{}
/**
* placeholder types, defines how the value is acquired
*/
Placeholder
Utils
.
types
=
{
Placeholder
.
types
=
{
ADDRESSFORMAT
:
"
ADDRESSFORMAT
"
,
SQLPART
:
"
SQLPART
"
,
SQLPARTFUNCTION
:
"
SQLPARTFUNCTION
"
...
...
@@ -252,76 +265,72 @@ PlaceholderUtils.types = {
/**
* placeholder targets, defines whose data is used
*/
PlaceholderUtils
.
targets
=
{
Placeholder
.
targets
=
{
/**
* use the data of the recipient (default)
*/
RECIPIENT
:
"
RECIPIENT
"
,
/**
* use the data of the sender
*/
SENDER
:
"
SENDER
"
,
/**
* use the data of the user
*/
EMPLOYEE
:
"
EMPLOYEE
"
};
function
PlaceholderUtils
()
{}
/**
* Returns the placeholder with the required prefix and postfix added.
* This function defines the format for placeholders.
*/
PlaceholderUtils
.
formatPlaceholder
=
function
(
pPlaceholder
)
PlaceholderUtils
.
formatPlaceholder
=
function
(
pPlaceholder
,
pEscapeForRegex
)
{
return
"
{@
"
+
pPlaceholder
+
"
@}
"
;
}
/**
* Removes the prefix and postfix from the pReplacements map. This is required for the docxTemplater
* where they are added separately
*/
PlaceholderUtils
.
removePreAndPostFix
=
function
(
pReplacements
)
{
var
unformattedReplacements
=
{};
for
(
let
placeholder
in
pReplacements
)
{
let
unformatted
=
placeholder
.
slice
(
2
,
-
2
);
unformattedReplacements
[
unformatted
]
=
pReplacements
[
placeholder
]
}
return
unformattedReplacements
;
}
/**
* gets the placeholder configuration
* placeholder configuration
*
* @return {Array} array of placeholders
*/
PlaceholderUtils
.
getPlaceholders
=
function
()
{
//these functions should make adding placeholders easier and require less code:
/**
* represents a placeholder
*
* @param {String} pName name of the placeholder (without prefix and postfix)
* @param {String} pType type of the placeholder, see PlaceholderUtils.types
* @param {String|Function} pValueDef string or function (depends on the type) defining the value
* @param {String} [pTarget] what contact is used to get the data, see PlaceholderUtils.targets
* add an address format placeholder to placeholders
*/
function
Placeholder
(
pName
,
pType
,
pValueDef
,
pTarget
)
{
this
.
placeholderName
=
PlaceholderUtils
.
formatPlaceholder
(
pName
);
this
.
type
=
pType
;
this
.
target
=
pTarget
||
PlaceholderUtils
.
targets
.
RECIPIENT
;
this
.
valueDefinition
=
pValueDef
;
}
function
_addAddressFormat
(
pName
,
pFormat
,
pTarget
)
{
placeholders
.
push
(
new
Placeholder
(
pName
,
Placeholder
Utils
.
types
.
ADDRESSFORMAT
,
pFormat
,
pTarget
));
placeholders
.
push
(
new
Placeholder
(
pName
,
Placeholder
.
types
.
ADDRESSFORMAT
,
pFormat
,
pTarget
));
}
function
_addSqlPart
(
pName
,
pSqlPart
,
pAddBraces
)
/**
* Add a sub-sql placeholder to placeholders. For further information regarding the full query, you can take
* a look at the function 'fetchAddressData' in Address_lib. You can use fields from CONTACT, ADDRESS, ORGANISATION and PERSON.
*/
function
_addSqlPart
(
pName
,
pSqlPart
,
pTarget
,
pAddBraces
)
{
placeholders
.
push
(
new
Placeholder
(
pName
,
Placeholder
Utils
.
types
.
SQLPART
,
pAddBraces
?
"
(
"
+
pSqlPart
+
"
)
"
:
pSqlPart
));
placeholders
.
push
(
new
Placeholder
(
pName
,
Placeholder
.
types
.
SQLPART
,
pAddBraces
?
"
(
"
+
pSqlPart
+
"
)
"
:
pSqlPart
,
pTarget
));
}
/**
* Add a placeholder to placeholders with a function that returns a sub-sql. The function will be called
* with no parameters. You have to deliver an actual function, don't call it here.
*/
function
_addSqlPartFunction
(
pName
,
pSqlPartFunction
,
pTarget
)
{
placeholders
.
push
(
new
Placeholder
(
pName
,
Placeholder
Utils
.
types
.
SQLPARTFUNCTION
,
pSqlPartFunction
,
pTarget
));
placeholders
.
push
(
new
Placeholder
(
pName
,
Placeholder
.
types
.
SQLPARTFUNCTION
,
pSqlPartFunction
,
pTarget
));
}
var
placeholders
=
[];
//placeholders should be added here:
_addAddressFormat
(
"
address
"
,
"
{street} {buildingno}
"
);
_addAddressFormat
(
"
zipCode
"
,
"
{zip}
"
);
_addAddressFormat
(
"
city
"
,
"
{city}
"
);
...
...
@@ -330,10 +339,18 @@ PlaceholderUtils.getPlaceholders = function ()
_addAddressFormat
(
"
country
"
,
"
{country}
"
);
_addAddressFormat
(
"
letterSalutation
"
,
"
{letter_salutation}
"
);
_addAddressFormat
(
"
fullAddress
"
,
""
);
_addAddressFormat
(
"
senderOrgname
"
,
"
{organisation_name}
"
,
PlaceholderUtils
.
targets
.
SENDER
);
_addAddressFormat
(
"
senderAddress
"
,
"
{street} {buildingno}
"
,
PlaceholderUtils
.
targets
.
SENDER
);
_addAddressFormat
(
"
senderZipCity
"
,
"
{country} - {zip} {city}
"
,
PlaceholderUtils
.
targets
.
SENDER
);
_addAddressFormat
(
"
senderFullAddress
"
,
""
,
PlaceholderUtils
.
targets
.
SENDER
);
_addAddressFormat
(
"
senderOrgname
"
,
"
{organisation_name}
"
,
Placeholder
.
targets
.
SENDER
);
_addAddressFormat
(
"
senderAddress
"
,
"
{street} {buildingno}
"
,
Placeholder
.
targets
.
SENDER
);
_addAddressFormat
(
"
senderZipCity
"
,
"
{country} - {zip} {city}
"
,
Placeholder
.
targets
.
SENDER
);
_addAddressFormat
(
"
senderFullAddress
"
,
""
,
Placeholder
.
targets
.
SENDER
);
_addSqlPart
(
"
orgname
"
,
"
ORGANISATION.NAME
"
);
_addSqlPartFunction
(
"
phone
"
,
CommUtil
.
getStandardSubSqlPhone
);
_addSqlPartFunction
(
"
email
"
,
CommUtil
.
getStandardSubSqlMail
);
_addSqlPartFunction
(
"
senderPhone
"
,
CommUtil
.
getStandardSubSqlPhone
,
Placeholder
.
targets
.
SENDER
);
_addSqlPartFunction
(
"
senderEmail
"
,
CommUtil
.
getStandardSubSqlMail
,
Placeholder
.
targets
.
SENDER
);
return
placeholders
;
}
...
...
This diff is collapsed.
Click to expand it.
process/Offer_lib/process.js
+
501
−
501
View file @
181fa351
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment