<commit_before><#include "pagescommon.ftl">

<#assign debugMode = false>

<#if !content??>
  <#assign content = {}>
</#if>
<#assign pathPlaceholder = "/myUrl">

<#-- NOTE: don't use container=false anymore, use @fields type="default-compact" -->
<#macro pageAttrField fieldObj value="" id="" namePrefix="" expandLangVisible=true>
    <#if fieldObj.type?has_content>
        <#local useAltTooltip = (fieldObj.type == "LONG_TEXT")>
        <#local fieldIdNum = getNextFieldIdNum()>
        <#if !id?has_content>
          <#local id = getNextFieldId(fieldIdNum)>
        </#if>
        <#if fieldObj.maxLength?has_content && (fieldObj.maxLength?number > 0)>
          <#local maxLength = fieldObj.maxLength?number/>
        <#else>
          <#local maxLength = ""/>
        </#if>
        <#local labelDetail = ""/>
        <#local tooltip = rawString(fieldObj.help!"")/>
        <#local defaultExpandLang = Static["com.ilscipio.scipio.cms.template.AttributeExpander$ExpandLang"].getDefaultExpandLang()!>
        <#local expandLang = fieldObj.expandLang!defaultExpandLang>
        <#if expandLang?has_content && expandLang != "NONE">
          <#local expandLang = Static["com.ilscipio.scipio.cms.template.AttributeExpander$ExpandLang"].fromStringSafe(expandLang?string)!><#-- make sure we have the enum not just the string -->
          <#if expandLang?has_content>
            <#local supportedLangStr = "${rawString(uiLabelMap.CmsSupportedLang)}: ${rawString(expandLang.getDescriptionWithExample(locale)!)}"/>
            <#if expandLangVisible>
              <#local labelDetail = supportedLangStr>
            <#else>
              <#local tooltip = appendToSentence(tooltip, supportedLangStr + ".")>
            </#if>
          <#else>
            <#-- ERROR: invalid db value; always report -->
            <#local dummy = Static["org.ofbiz.base.util.Debug"].logError("Cms: Error: Attribute '" + (fieldObj.id!"") + "' has invalid expandLang (" + expandLang + ")", "editPageFtl")>
          </#if>
        </#if>
        <#if fieldObj.targetType?has_content>
          <#local tooltip = appendToSentence(tooltip, "targetType: " + fieldObj.targetType + ".")>
        </#if>
        <#local rawLabelDetail = labelDetail><#-- save it -->
        <#local fieldLabel = fieldObj.displayName!"Field">
        <#if labelDetail?has_content>
          <#local labelDetail><span class="label-detail">${escapeVal(labelDetail, 'html')}</span></#local>
        </#if>
        <#if useAltTooltip>
          <#-- NOTE: 2017-04-06: MUST DISABLE REGULAR TOOLTIP entirely for LONG_TEXT, it interferes with the editor in some modes.
            instead just put a tooltip on the label, using hackish method -->
          <#if tooltip?has_content>
            <#local fieldLabelWithTooltip><a href="javascript:void(0);" class="${styles.tooltip!}" title="${tooltip}">${fieldLabel}</a></#local>
            <#local fieldLabel = wrapAsRaw({'raw':rawString(fieldLabel), 'htmlmarkup':fieldLabelWithTooltip})>
          </#if>
          <#local tooltip = false>
        </#if>
        <#local required = toBooleanCms(fieldObj.required!)!false>
        <#local containerClass = "+page-attr-field">
        <#local name = namePrefix + (fieldObj.name!"")>
        <#switch fieldObj.type>
            <#case "LONG_TEXT">
              <#local containerClass = addClassArg(containerClass, "page-attr-type-longtext")>
              <#-- DEV NOTE: the rich editor should only display FTL-related functions 
                if fieldObj.expandLang == "FTL" -->
              <@field label=fieldLabel labelDetail=labelDetail type="textarea" class="+editor" name=name placeholder=(fieldObj.defaultValue!"") tooltip=tooltip required=required maxlength=maxLength id=id value=value containerClass=containerClass/>
            <#break>
            <#case "BOOLEAN">
              <#local containerClass = addClassArg(containerClass, "page-attr-type-boolean")>
              <#-- NOTE: BOOLEAN supports expansion languages - if they are enabled, cannot use the simple checkbox -->
              <#if !fieldObj.expandLang?has_content || fieldObj.expandLang == "NONE">
                <#-- TODO?: review this, it's because default-compact looks ugly in this case... maybe default-compact needs a review... -->
                <@fields type="default">
                  <#-- FIXME: CHECKBOX breaks ternary logic and default value logic!... -->
                  <@field label=fieldLabel labelDetail=labelDetail type="checkbox" name=name tooltip=tooltip required=required maxlength=maxLength id=id 
                      value="true" altValue="false" 
                      checked=(toBooleanCms(fieldObj.value!)!toBooleanCms(fieldObj.defaultValue!)!false) containerClass=containerClass/>
                </@fields>
              <#else>
                <@field label=fieldLabel labelDetail=labelDetail type="input" name=name placeholder=(fieldObj.defaultValue!"") tooltip=tooltip required=required maxlength=maxLength id=id value=value containerClass=containerClass/>
              </#if>
            <#break>
            <#case "INTEGER">
                <#-- DEV NOTE: cannot enforce [0-9-] here because expandLang supports expressions (TODO: restrict if no expandLang or expandLang=NONE) -->
                <#local containerClass = addClassArg(containerClass, "page-attr-type-integer")>
                <@field label=fieldLabel labelDetail=labelDetail type="input" name=name placeholder=(fieldObj.defaultValue!"") tooltip=tooltip required=required maxlength=maxLength id=id value=value/>
            <#break>
            <#case "SHORT_TEXT">
                <#local containerClass = addClassArg(containerClass, "page-attr-type-shorttext")>
            <#default>
                <@field label=fieldLabel labelDetail=labelDetail type="input" name=name placeholder=(fieldObj.defaultValue!"") tooltip=tooltip required=required maxlength=maxLength id=id value=value containerClass=containerClass/>
        </#switch>
    </#if>
</#macro>

<#assign primaryTargetPathOptions = [
    { "key" : "/cmsPagePlainNoAuth", "description" : "http, no-auth" },
    { "key" : "/cmsPagePlainAuth", "description" : "http, auth" },
    { "key" : "/cmsPageSecureNoAuth", "description" : "https, no-auth" },
    { "key" : "/cmsPageSecureAuth", "description" : "https, auth" }
]>

<#-- The Content -->
<#-- EDIT PAGE -->
<#if template?has_content || meta?has_content>
  <#if webSiteId?has_content><#-- 2016-11-30: currently this depends highly on website, can't omit --><commit_msg>cms: editPage: bugfix boolean value read<commit_after><#include "pagescommon.ftl">

<#assign debugMode = false>

<#if !content??>
  <#assign content = {}>
</#if>
<#assign pathPlaceholder = "/myUrl">

<#-- NOTE: don't use container=false anymore, use @fields type="default-compact" -->
<#macro pageAttrField fieldObj value="" id="" namePrefix="" expandLangVisible=true>
    <#if fieldObj.type?has_content>
        <#local useAltTooltip = (fieldObj.type == "LONG_TEXT")>
        <#local fieldIdNum = getNextFieldIdNum()>
        <#if !id?has_content>
          <#local id = getNextFieldId(fieldIdNum)>
        </#if>
        <#if fieldObj.maxLength?has_content && (fieldObj.maxLength?number > 0)>
          <#local maxLength = fieldObj.maxLength?number/>
        <#else>
          <#local maxLength = ""/>
        </#if>
        <#local labelDetail = ""/>
        <#local tooltip = rawString(fieldObj.help!"")/>
        <#local defaultExpandLang = Static["com.ilscipio.scipio.cms.template.AttributeExpander$ExpandLang"].getDefaultExpandLang()!>
        <#local expandLang = fieldObj.expandLang!defaultExpandLang>
        <#if expandLang?has_content && expandLang != "NONE">
          <#local expandLang = Static["com.ilscipio.scipio.cms.template.AttributeExpander$ExpandLang"].fromStringSafe(expandLang?string)!><#-- make sure we have the enum not just the string -->
          <#if expandLang?has_content>
            <#local supportedLangStr = "${rawString(uiLabelMap.CmsSupportedLang)}: ${rawString(expandLang.getDescriptionWithExample(locale)!)}"/>
            <#if expandLangVisible>
              <#local labelDetail = supportedLangStr>
            <#else>
              <#local tooltip = appendToSentence(tooltip, supportedLangStr + ".")>
            </#if>
          <#else>
            <#-- ERROR: invalid db value; always report -->
            <#local dummy = Static["org.ofbiz.base.util.Debug"].logError("Cms: Error: Attribute '" + (fieldObj.id!"") + "' has invalid expandLang (" + expandLang + ")", "editPageFtl")>
          </#if>
        </#if>
        <#if fieldObj.targetType?has_content>
          <#local tooltip = appendToSentence(tooltip, "targetType: " + fieldObj.targetType + ".")>
        </#if>
        <#local rawLabelDetail = labelDetail><#-- save it -->
        <#local fieldLabel = fieldObj.displayName!"Field">
        <#if labelDetail?has_content>
          <#local labelDetail><span class="label-detail">${escapeVal(labelDetail, 'html')}</span></#local>
        </#if>
        <#if useAltTooltip>
          <#-- NOTE: 2017-04-06: MUST DISABLE REGULAR TOOLTIP entirely for LONG_TEXT, it interferes with the editor in some modes.
            instead just put a tooltip on the label, using hackish method -->
          <#if tooltip?has_content>
            <#local fieldLabelWithTooltip><a href="javascript:void(0);" class="${styles.tooltip!}" title="${tooltip}">${fieldLabel}</a></#local>
            <#local fieldLabel = wrapAsRaw({'raw':rawString(fieldLabel), 'htmlmarkup':fieldLabelWithTooltip})>
          </#if>
          <#local tooltip = false>
        </#if>
        <#local required = toBooleanCms(fieldObj.required!)!false>
        <#local containerClass = "+page-attr-field">
        <#local name = namePrefix + (fieldObj.name!"")>
        <#switch fieldObj.type>
            <#case "LONG_TEXT">
              <#local containerClass = addClassArg(containerClass, "page-attr-type-longtext")>
              <#-- DEV NOTE: the rich editor should only display FTL-related functions 
                if fieldObj.expandLang == "FTL" -->
              <@field label=fieldLabel labelDetail=labelDetail type="textarea" class="+editor" name=name placeholder=(fieldObj.defaultValue!"") tooltip=tooltip required=required maxlength=maxLength id=id value=value containerClass=containerClass/>
            <#break>
            <#case "BOOLEAN">
              <#local containerClass = addClassArg(containerClass, "page-attr-type-boolean")>
              <#-- NOTE: BOOLEAN supports expansion languages - if they are enabled, cannot use the simple checkbox -->
              <#if !fieldObj.expandLang?has_content || fieldObj.expandLang == "NONE">
                <#-- TODO?: review this, it's because default-compact looks ugly in this case... maybe default-compact needs a review... -->
                <@fields type="default">
                  <@field label=fieldLabel labelDetail=labelDetail type="checkbox" name=name tooltip=tooltip required=required maxlength=maxLength id=id 
                      value="true" altValue="false" 
                      checked=(toBooleanCms(value)!toBooleanCms(fieldObj.defaultValue!)!false) containerClass=containerClass/>
                </@fields>
              <#else>
                <@field label=fieldLabel labelDetail=labelDetail type="input" name=name placeholder=(fieldObj.defaultValue!"") tooltip=tooltip required=required maxlength=maxLength id=id value=value containerClass=containerClass/>
              </#if>
            <#break>
            <#case "INTEGER">
                <#-- DEV NOTE: cannot enforce [0-9-] here because expandLang supports expressions (TODO: restrict if no expandLang or expandLang=NONE) -->
                <#local containerClass = addClassArg(containerClass, "page-attr-type-integer")>
                <@field label=fieldLabel labelDetail=labelDetail type="input" name=name placeholder=(fieldObj.defaultValue!"") tooltip=tooltip required=required maxlength=maxLength id=id value=value/>
            <#break>
            <#case "SHORT_TEXT">
                <#local containerClass = addClassArg(containerClass, "page-attr-type-shorttext")>
            <#default>
                <@field label=fieldLabel labelDetail=labelDetail type="input" name=name placeholder=(fieldObj.defaultValue!"") tooltip=tooltip required=required maxlength=maxLength id=id value=value containerClass=containerClass/>
        </#switch>
    </#if>
</#macro>

<#assign primaryTargetPathOptions = [
    { "key" : "/cmsPagePlainNoAuth", "description" : "http, no-auth" },
    { "key" : "/cmsPagePlainAuth", "description" : "http, auth" },
    { "key" : "/cmsPageSecureNoAuth", "description" : "https, no-auth" },
    { "key" : "/cmsPageSecureAuth", "description" : "https, auth" }
]>

<#-- The Content -->
<#-- EDIT PAGE -->
<#if template?has_content || meta?has_content>
  <#if webSiteId?has_content><#-- 2016-11-30: currently this depends highly on website, can't omit -->
{'fraction_non_alphanumeric': 0.14555546989437976, 'fraction_numerical': 0.003083802328270758, 'mean_word_length': 3.0024683739586546, 'pattern_counts': {'":': 0, '<': 204, '<?xml version=': 0, '>': 206, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1780921', 'n_tokens_mistral': 3788, 'n_tokens_neox': 3674, 'n_words': 820}