Skip to content
Snippets Groups Projects
onValidation.js 2.46 KiB
import("system.logging");
import("system.neon");
import("system.translate");
import("system.result");
import("system.vars");
import("Bulkmail_lib");
import("DocumentTemplate_lib");
import("KeywordRegistry_basic");

if (vars.exists("$context.currentTemplateType") && (vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW || vars.get("$sys.recordstate") == neon.OPERATINGSTATE_EDIT))
{
    var kind = vars.get("$field.KIND");
    var classification = vars.get("$field.CLASSIFICATION");
    
    var type;
    if (vars.exists("$context.currentTemplateType"))
        type = vars.get("$context.currentTemplateType");
    
    if (type == "undefined")
        type = undefined;
    
    if (type != undefined)
    {
        // Bulkmail
        if (kind == $KeywordRegistry.documentTemplateType$mail() && classification == $KeywordRegistry.documentTemplateTypeCategory$serial() 
                && !BulkMailUtils.isValidTemplateType(type)
        // Single mail
         || kind == $KeywordRegistry.documentTemplateType$mail() && classification == $KeywordRegistry.documentTemplateTypeCategory$single() 
                && type != DocumentTemplate.types.EML && type != DocumentTemplate.types.HTML && type != DocumentTemplate.types.PLAIN && type != DocumentTemplate.types.TXT
        // Single letter
         || kind == $KeywordRegistry.documentTemplateType$letter() && classification == $KeywordRegistry.documentTemplateTypeCategory$single()
                && type != DocumentTemplate.types.DOCX && type != DocumentTemplate.types.ODT && type != DocumentTemplate.types.PLAIN && type != DocumentTemplate.types.TXT
        // Bulkletter
         || kind == $KeywordRegistry.documentTemplateType$letter() && classification == $KeywordRegistry.documentTemplateTypeCategory$serial()
                && type != DocumentTemplate.types.ODT
        // Modular HTML template
         || kind == $KeywordRegistry.documentTemplateType$textModular() && classification == $KeywordRegistry.documentTemplateTypeCategory$htmlTemplate()
                && type != DocumentTemplate.types.HTML
        // Modular - all except HTML template
         || kind == $KeywordRegistry.documentTemplateType$textModular() && classification != $KeywordRegistry.documentTemplateTypeCategory$htmlTemplate()
                && type != DocumentTemplate.types.PLAIN && type != DocumentTemplate.types.TXT
        )
        {
            result.string(translate.text("Wrong filetype for the current document template type and classification."))
        }
    }
}