Skip to content
Snippets Groups Projects
Commit 62563247 authored by Johannes Hörmann's avatar Johannes Hörmann
Browse files

refactor DocumentTemplate: show editor only for text templates

parent fe6c1959
No related branches found
No related tags found
No related merge requests found
Showing
with 53 additions and 75 deletions
......@@ -2,18 +2,9 @@
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.6.xsd">
<changeSet author="j.hoermann" id="1dd1c707-1ae3-4df3-9b94-84601e835ab1">
<insert tableName="AB_KEYWORD_ENTRY">
<column name="AB_KEYWORD_ENTRYID" value="5ff35897-8e2e-4b6f-adbe-2f62b4120f00"/>
<column name="KEYID" value="7 "/>
<column name="TITLE" value="Plaintext template - Only for .txt and .html"/>
<column name="CONTAINER" value="DocumentTemplateTypeCategory"/>
<column name="SORTING" valueNumeric="6"/>
<column name="ISESSENTIAL" valueNumeric="1"/>
<column name="ISACTIVE" valueNumeric="1"/>
</insert>
<insert tableName="AB_KEYWORD_ENTRY">
<column name="AB_KEYWORD_ENTRYID" value="0d30ed22-bb79-450a-a027-6786e7bb6028"/>
<column name="KEYID" value="8 "/>
<column name="KEYID" value="7 "/>
<column name="TITLE" value="HTML template - Only for .html"/>
<column name="CONTAINER" value="DocumentTemplateTypeCategory"/>
<column name="SORTING" valueNumeric="7"/>
......@@ -34,5 +25,4 @@
<column name="BOOL_VALUE" valueNumeric="1"/>
</insert>
</changeSet>
</databaseChangeLog>
......@@ -139,6 +139,7 @@
<title>Content</title>
<contentType>HTML</contentType>
<contentTypeProcess>%aditoprj%/entity/BulkMail_entity/entityfields/content/contentTypeProcess.js</contentTypeProcess>
<state>EDITABLE</state>
<stateProcess>%aditoprj%/entity/BulkMail_entity/entityfields/content/stateProcess.js</stateProcess>
<valueProcess>%aditoprj%/entity/BulkMail_entity/entityfields/content/valueProcess.js</valueProcess>
<displayValueProcess>%aditoprj%/entity/BulkMail_entity/entityfields/content/displayValueProcess.js</displayValueProcess>
......
import("system.logging");
import("DocumentTemplate_lib");
import("system.neon");
import("system.vars");
......@@ -7,6 +8,8 @@ import("system.vars");
if(vars.get("$sys.viewmode") == neon.FRAME_VIEWMODE_DATASET)
{
[content, type] = DocumentTemplateUtils.getTemplateContent(vars.get("$field.DOCUMENTTEMPLATE_ID"), new FileUpload(vars.get("$local.value")));
vars.set("$context.currentTemplateType", type)
vars.set("$field.content", content)
logging.log(JSON.stringify(["valChange", type], null, "\t"))
vars.set("$field.DOCUMENTTEMPLATE_ID", "");
vars.set("$field.content", content);
vars.set("$context.currentTemplateType", type);
}
import("system.logging");
import("system.result");
import("system.vars");
import("system.neon");
import("DocumentTemplate_lib");
logging.log(JSON.stringify(["stateProcess"], null, "\t"))
// in edit mode
if (vars.get("$sys.recordstate") != neon.OPERATINGSTATE_VIEW &&
(vars.get("$context.currentTemplateType") == DocumentTemplate.types.EML
|| vars.get("$context.currentTemplateType") == DocumentTemplate.types.HTML)) // TODO: invisible for html as there are problems with images which are removed by the html-editor
{
logging.log(JSON.stringify(["state", vars.get("$context.currentTemplateType")], null, "\t"))
result.string(neon.COMPONENTSTATE_INVISIBLE);
}
// in view mode disable, show preview instead: directly after save (in edit view) the state is changed to OPERATINGSTATE_VIEW and this triggers the initionalisation of the html editor (if it is visible)
// For EML-files or other large files this is very bad, as the editor needs a very long time to initialize
else if (vars.get("$sys.recordstate") == neon.OPERATINGSTATE_VIEW)
{
logging.log(JSON.stringify(["state2", vars.get("$context.currentTemplateType")], null, "\t"))
result.string(neon.COMPONENTSTATE_INVISIBLE);
}
else
{
logging.log(JSON.stringify(["edit", vars.get("$context.currentTemplateType")], null, "\t"))
result.string(neon.COMPONENTSTATE_EDITABLE);
}
\ No newline at end of file
......@@ -147,14 +147,9 @@
<name>Content</name>
<title>Text</title>
<contentType>LONG_TEXT</contentType>
<contentTypeProcess>%aditoprj%/entity/DocumentTemplate_entity/entityfields/content/contentTypeProcess.js</contentTypeProcess>
<stateProcess>%aditoprj%/entity/DocumentTemplate_entity/entityfields/content/stateProcess.js</stateProcess>
<valueProcess>%aditoprj%/entity/DocumentTemplate_entity/entityfields/content/valueProcess.js</valueProcess>
<displayValueProcess>%aditoprj%/entity/DocumentTemplate_entity/entityfields/content/displayValueProcess.js</displayValueProcess>
<onValueChange>%aditoprj%/entity/DocumentTemplate_entity/entityfields/content/onValueChange.js</onValueChange>
<onValueChangeTypes>
<element>MASK</element>
</onValueChangeTypes>
</entityField>
<entityField>
<name>CLASSIFICATION</name>
......
......@@ -7,6 +7,7 @@ import("system.vars");
if((vars.get("$sys.operatingstate") == neon.OPERATINGSTATE_EDIT || vars.get("$sys.operatingstate") == neon.OPERATINGSTATE_NEW))
{
[content, type] = DocumentTemplateUtils.getTemplateContent(vars.get("$field.DOCUMENTTEMPLATEID"), new FileUpload(vars.get("$local.value")));
vars.set("$context.currentTemplateType", type);
vars.set("$field.Content", content)
}
import("system.vars");
import("system.vars");
import("KeywordRegistry_basic");
import("DocumentTemplate_lib");
vars.set("$field.REPLACEMENTNAME", null);
vars.set("$field.REPLACEMENTNAME", null);
\ No newline at end of file
if (vars.get("$local.value") != $KeywordRegistry.documentTemplateTypeCategory$htmlTemplate() && vars.get("$field.KIND") == $KeywordRegistry.documentTemplateType$textModular())
{
vars.set("$context.currentTemplateType", DocumentTemplate.types.TXT);
}
\ No newline at end of file
import("KeywordRegistry_basic");
import("system.result");
import("system.vars");
import("DocumentTemplate_lib");
//!!! changes here have to be also done in Preview.valueProcess!!!
if (vars.exists("$context.currentTemplateType"))
{
if (vars.get("$context.currentTemplateType") == DocumentTemplate.types.HTML)
result.string("HTML");
// force HTML for documentTemplateTypeCategory$htmlTemplate and mail if bindata is not set else use type form bindata
else if (!vars.get("$field.BINDATA") && (vars.get("$field.CLASSIFICATION") == $KeywordRegistry.documentTemplateTypeCategory$htmlTemplate()))
{
result.string("HTML");
}
}
\ No newline at end of file
import("system.vars");
// needed to correctly save the file
vars.set("$context.changedContentByUser", true);
import("DocumentTemplate_lib");
import("KeywordRegistry_basic");
import("system.result");
import("system.vars");
import("system.neon");
if (vars.exists("$context.currentTemplateType") && (vars.get("$field.Content") || !vars.get("$field.BINDATA")))
if (vars.get("$field.KIND") == $KeywordRegistry.documentTemplateType$textModular() && vars.get("$field.CLASSIFICATION") != $KeywordRegistry.documentTemplateTypeCategory$htmlTemplate())
{
var type = vars.get("$context.currentTemplateType");
if ((type != DocumentTemplate.types.TXT ||
// Workaround: prevent removing images via html-editor -> use only the preview-field if it's html and not the content field
// That's why type HTML -> invisible
type == DocumentTemplate.types.HTML) && !(vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW && !vars.get("$field.BINDATA")))
{
result.string(neon.COMPONENTSTATE_INVISIBLE);
}
else
result.string(neon.COMPONENTSTATE_EDITABLE);
result.string(neon.COMPONENTSTATE_EDITABLE);
}
else
result.string(neon.COMPONENTSTATE_INVISIBLE);
\ No newline at end of file
{
result.string(neon.COMPONENTSTATE_INVISIBLE);
}
\ No newline at end of file
......@@ -3,10 +3,12 @@ import("system.vars");
import("Entity_lib");
import("Document_lib");
if (vars.get("$this.value") == null && vars.get("$field.BINDATA"))
if (!vars.get("$this.value") && vars.get("$field.BINDATA"))
{
var uploadValue = DocumentUtil.getFilenameFromUpload(vars.get("$field.BINDATA"));
uploadValue = uploadValue.replace(/\.[^/.]+$/, "")
if (uploadValue.length > 40)
uploadValue = uploadValue.substr(0, 40);
......
......@@ -3,5 +3,4 @@ import("KeywordRegistry_basic");
import("system.vars");
result.object(vars.get("$field.KIND") == $KeywordRegistry.documentTemplateType$textModular() &&
(vars.get("$field.CLASSIFICATION") == $KeywordRegistry.documentTemplateTypeCategory$textTemplate()
|| vars.get("$field.CLASSIFICATION") == $KeywordRegistry.documentTemplateTypeCategory$htmlTemplate()))
\ No newline at end of file
vars.get("$field.CLASSIFICATION") == $KeywordRegistry.documentTemplateTypeCategory$htmlTemplate())
\ No newline at end of file
......@@ -7,8 +7,7 @@ import("system.result");
if(vars.get("$sys.viewmode") == neon.FRAME_VIEWMODE_TABLE ||
(vars.get("$field.KIND") == $KeywordRegistry.documentTemplateType$textModular() &&
(vars.get("$field.CLASSIFICATION") == $KeywordRegistry.documentTemplateTypeCategory$textTemplate()
|| vars.get("$field.CLASSIFICATION") == $KeywordRegistry.documentTemplateTypeCategory$htmlTemplate())))
vars.get("$field.CLASSIFICATION") == $KeywordRegistry.documentTemplateTypeCategory$htmlTemplate()))
{
result.string(neon.COMPONENTSTATE_EDITABLE);
}
\ No newline at end of file
import("system.logging");
import("system.neon");
import("system.translate");
import("system.result");
......
......@@ -6,6 +6,5 @@ var rowdata = vars.get("$local.rowdata");
var content = vars.get("$field.Content");
var upload = new FileUpload(vars.get("$field.BINDATA"));
var rowId = vars.get("$local.uid");
var changedByUser = vars.exists("$context.changedContentByUser")
DocumentTemplateUtils.updateTemplateData(rowId, upload, rowdata["DOCUMENTTEMPLATE.KIND"], content, rowdata["DOCUMENTTEMPLATE.CLASSIFICATION"], rowdata["DOCUMENTTEMPLATE.NAME"], changedByUser);
\ No newline at end of file
DocumentTemplateUtils.updateTemplateData(rowId, upload, rowdata["DOCUMENTTEMPLATE.KIND"], content, rowdata["DOCUMENTTEMPLATE.CLASSIFICATION"], rowdata["DOCUMENTTEMPLATE.NAME"]);
\ No newline at end of file
......@@ -80,14 +80,6 @@ DocumentTemplate.prototype._resolveEmbeddedTemplate = function ()
var templates = [];
// then load the possible replacement names
if (this.type == DocumentTemplate.types.TXT || this.type == DocumentTemplate.types.HTML)
{
templates = db.table(SqlCondition.begin()
.andPrepare("DOCUMENTTEMPLATE.KIND", $KeywordRegistry.documentTemplateType$textModular())
.andPrepare("DOCUMENTTEMPLATE.CLASSIFICATION", $KeywordRegistry.documentTemplateTypeCategory$textTemplate())
.buildSql("select DOCUMENTTEMPLATEID, REPLACEMENTNAME from DOCUMENTTEMPLATE"));
}
if (this.type == DocumentTemplate.types.HTML)
{
......@@ -767,28 +759,38 @@ function DocumentTemplateUtils () {}
* @param {String} pText text input
* @param {String} pClassification the classification type. Used if pText is not empty. Defines if it is saved as txt or html.
* @param {String} pTemplateName name of the template
* @param {Boolean} pChangedByUser if false the data in pText is ignored
* @return {FileUpload} a FileUpload object with the data
*/
DocumentTemplateUtils.chooseSuppliedTemplate = function (pFileUpload, pKind, pText, pClassification, pTemplateName, pChangedByUser)
DocumentTemplateUtils.chooseSuppliedTemplate = function (pFileUpload, pKind, pText, pClassification, pTemplateName)
{
if (pFileUpload.isFilled() && pText != "")
{
// use fileUpload but use the custom text as bindata
pFileUpload.bindata = util.encodeBase64String(pText);
}
else if (!pFileUpload.isFilled() && pText != "" && (pChangedByUser == undefined || pChangedByUser))
else if (!pFileUpload.isFilled() && pText != "")
{
pFileUpload.filename = pTemplateName;
// if it is a htmlTemplate save it with the html extension
if (pClassification == $KeywordRegistry.documentTemplateTypeCategory$htmlTemplate() || pKind == $KeywordRegistry.documentTemplateType$mail())
if (pClassification == $KeywordRegistry.documentTemplateTypeCategory$htmlTemplate())
pFileUpload.fileExtension = "html";
else
pFileUpload.fileExtension = "txt";
pFileUpload.bindata = util.encodeBase64String(pText);
}
var fileUploadType = DocumentTemplate.types.fromMimeType(pFileUpload.mimeType);
// treat txt as html for emails
if (pKind == $KeywordRegistry.documentTemplateType$mail() && fileUploadType != DocumentTemplate.types.HTML && fileUploadType != DocumentTemplate.types.EML)
{
pFileUpload.fileExtension = "html";
// convert text to html
pFileUpload.bindata = util.encodeBase64String(text.text2html(util.decodeBase64String(pFileUpload.bindata), true));
}
return pFileUpload;
}
......@@ -808,9 +810,9 @@ DocumentTemplateUtils.insertTemplateData = function (pTemplateId, pFileUpload, p
/**
* updates a template from a document template in ASYS_BINARIES
*/
DocumentTemplateUtils.updateTemplateData = function (pTemplateId, pFileUpload, pKind, pText, pClassification, pTemplateName, pChangedByUser)
DocumentTemplateUtils.updateTemplateData = function (pTemplateId, pFileUpload, pKind, pText, pClassification, pTemplateName)
{
pFileUpload = DocumentTemplateUtils.chooseSuppliedTemplate(pFileUpload, pKind, pText, pClassification, pTemplateName, pChangedByUser)
pFileUpload = DocumentTemplateUtils.chooseSuppliedTemplate(pFileUpload, pKind, pText, pClassification, pTemplateName)
if (pFileUpload.isFilled())
{
var assignmentTable = "DOCUMENTTEMPLATE";
......
......@@ -153,8 +153,7 @@ $KeywordRegistry.documentTemplateType$attachment = function(){return $KeywordReg
$KeywordRegistry.documentTemplateTypeCategory = function(){return "DocumentTemplateTypeCategory";};
$KeywordRegistry.documentTemplateTypeCategory$single = function(){return $KeywordRegistry._autoPad("1");};
$KeywordRegistry.documentTemplateTypeCategory$serial = function(){return $KeywordRegistry._autoPad("2");};
$KeywordRegistry.documentTemplateTypeCategory$textTemplate = function(){return $KeywordRegistry._autoPad("7");};
$KeywordRegistry.documentTemplateTypeCategory$htmlTemplate = function(){return $KeywordRegistry._autoPad("8");};
$KeywordRegistry.documentTemplateTypeCategory$htmlTemplate = function(){return $KeywordRegistry._autoPad("7");};
$KeywordRegistry.classificationType = function(){return "ClassificationType";};
$KeywordRegistry.classificationType$salesproject = function(){return $KeywordRegistry._autoPad("SALESPROJ");};
......
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