//~OPTIONS
{
  extends: "fcfManagement:templates/pages/base.tmpl",
  access:   ["root"],
}

//~ARGUMENTS
{
  title: "Managing sitemap files",
}

//~TEMPLATE menu
@{{
  render.template("@controls:menu", {
    root:           "/fcfpackages/fcfManagement/system",
    current:        route.uri,
    enableRoot:     true,
  })
}}@


//~ARGUMENTS body
{
  enableMultilingual: fcf.argProg(),
  settings:           fcf.argProg(),
}


//~TEMPLATE body
<h4>!{{Sitemap file}}!:</h4>
<a href="/sitemap/sitemap.xml" target="_blank">@{{fcf.rtrim(fcf.application.getConfiguration().site,"/") + "/sitemap/sitemap.xml" }}@</a>

<p>
<h4>!{{Apply a multilingual URL prefix in the sitemap file}}!</h4>
@{{ render.template("@controls:checkbox",
                    {
                      title: fcf.t("Using multilingual site pages"),
                      value: fcf.argRef("settings.multilingual"),
                      enable: fcf.argRef("enableMultilingual"),
                    }
                  )
                }}@
<description>!{{To support multilingualism, multiple languages must be installed in the system. You also need to enable one of the language identification parameters "By URL prefix" or "By URL parameter" on}}! <a href="/fcfpackages/fcfManagement/translations/translations">/fcfpackages/fcfManagement/translations/translations</a></description>
</p>

<p>
<h4>!{{Frequency of file updates}}!</h4>
@{{ render.template("@controls:checkbox",
                    {
                      title: fcf.t("Automatically update files with the specified frequency"),
                      value: fcf.argRef("settings.enableAutoUpdate"),
                    }
                  )
                }}@
</p>
<p>
@{{ render.template("@controls:int-edit",
                    {
                      fcfAlias: "days",
                      value:  fcf.argRef("settings.autoUpdateDays"),
                      enable: fcf.argRef("settings.enableAutoUpdate"),
                      width: "100px",
                      min:   0,
                      max:   365,
                    }
                  )
                }}@
/!{{Days}}!
@{{ render.template("@controls:int-edit",
                    {
                      fcfAlias: "hours",
                      value: fcf.argRef("settings.autoUpdateHours"),
                      enable: fcf.argRef("settings.enableAutoUpdate"),
                      width: "100px",
                      min:   0,
                      max:   24,
                    }
                  )
                }}@
/!{{Hours}}!
</p>

<p><h4>!{{Default values}}!</h4></p>
<div style="padding: 8px 0px">
!{{Priority}}! @{{ render.template("@controls:float-edit",
                                        {
                                          value: fcf.argRef("settings.priorityDefault"),
                                          width: "100px"
                                          })
                                        }}@
&nbsp;&nbsp;&nbsp;&nbsp;
!{{Update rate}}! @{{ render.template("@controls:select",
                                        {
                                          fcfAlias:  "changefreqDefault",
                                          value:     fcf.argRef("settings.changefreqDefault"),
                                          items:     fcf.map(["always", "hourly", "daily", "weekly", "monthly", "yearly", "never"],
                                                             (k,v)=>{ return     [v,v]}),
                                          width:    "100px"})
                                        }}@
&nbsp;&nbsp;&nbsp;&nbsp;
!{{Multilingual}}! @{{ render.template("@controls:checkbox",
                                        {
                                          value:                      fcf.argRef("settings.multilingualDefault"),
                                          resulutionMultilingual:     fcf.argRef("enableMultilingual"),
                                          enableMultilingual:         fcf.argRef("settings.multilingual"),
                                          enable:                     fcf.argVal("@{{args.resulutionMultilingual && args.enableMultilingual}}@"),
                                          })
                                        }}@
</p>
<description>!{{These values are set only for those elements for which the system did not specify values programmatically or in the system settings}}!</description>

<p><h4>!{{URLs included in the sitemap file}}!</h4></p>
<fieldset>
@{{
  render.template("@controls:table", {
    fcfClass: "fcf-border",
    value:    fcf.argRef("settings.sitemapItems"),
    outputRowCount: 10,
    columns: [
      {
        alias: "url",
        title: "!{URL}!",
        type:  "string",
        args: {
          width: "100%",
        }
      },
      {
        alias:    "priority",
        title:    "!{Sitemap priority}!",
        type:     "float",
        mode:     "edit",
        template: "@controls:default-view",
        args: {
          width:        "100%",
          min:          0,
          max:          1,
          defaultValue: fcf.argRef("settings.priorityDefault"),
          defaultFlag:  fcf.argRecordRef("priorityDefaultFlag"),
        }
      },
      {
        alias: "multilingual",
        title: "!{Multilingual}!",
        type:  "boolean",
        mode:  "edit",
        template: "@controls:default-view",
        args: {
          defaultValue:               fcf.argRef("settings.multilingualDefault"),
          defaultFlag:                fcf.argRecordRef("multilingualDefaultFlag"),
          resulutionMultilingual:     fcf.argRef("enableMultilingual"),
          enableMultilingual:         fcf.argRef("settings.multilingual"),
          enable:                     fcf.argVal("@{{args.resulutionMultilingual && args.enableMultilingual}}@"),
        }
      },
      {
        alias: "changefreq",
        title: "!{Update rate}!",
        type:  "enum",
        mode:  "edit",
        template: "@controls:default-view",
        items: fcf.map(["always", "hourly", "daily", "weekly", "monthly", "yearly", "never"],(k,v)=>{ return [v,v]}),
        template: "@controls:default-view",
        args:{
          defaultValue: fcf.argRef("settings.changefreqDefault"),
          defaultFlag:  fcf.argRecordRef("changefreqDefaultFlag"),
        }
      },
      {
        alias: "enable",
        title: "!{Enable}!",
        type:  "boolean",
        mode:  "edit",
      },
    ],
    enableToolbar: true,
    enableSearch: true,
  });
}}@
<description>!{{Files added automatically}}!</description>
</fieldset>

<p><h4>!{{Additional URLs to include in the sitemap file}}!</h4></p>
<fieldset>
@{{
  render.template("@controls:table", {
    fcfAlias: "test-table",
    fcfClass: "fcf-border",
    value:    fcf.argRef("settings.additionalSitemapItems"),
    columns: [
      {
        alias: "url",
        title: "!{URL}!",
        type:  "string",
        mode:  "edit",
        args: {
          width: "100%",
        }
      },
      {
        alias: "priority",
        title: "!{Sitemap priority}!",
        type:  "float",
        mode:  "edit",
        args: {
          width: "100%",
          min: 0,
          max: 1,
        }
      },
      {
        alias: "multilingual",
        title: "!{Multilingual}!",
        type:  "boolean",
        mode:  "edit",
        args: {
          resulutionMultilingual: fcf.argRef("enableMultilingual"),
          enableMultilingual:     fcf.argRef("settings.multilingual"),
          enable:                 fcf.argVal("@{{!!args.resulutionMultilingual && !!args.enableMultilingual}}@"),
        }
      },
      {
        alias: "changefreq",
        title: "!{Update rate}!",
        type:  "enum",
        mode:  "edit",
        items: fcf.map(["always", "hourly", "daily", "weekly", "monthly", "yearly", "never"],(k,v)=>{ return [v,v]}),
      },
      {
        alias: "enable",
        title: "!{Enable}!",
        type:  "boolean",
        mode:  "edit",
      },

      {
        alias: "buttons",
        title: "",
        type:  "string",
        template: "@controls:button",
        args:{
          title:          "!{Remove}!",
          fcfEventClick:  "parent.getParent().onRemoveRecord(parent.getRecordIndexByDomElement(this))"
        }
      },
    ],
    enableToolbar: true,
    enableSearch: true,
    toolbarLeftItems: fcf.argVal([
      fcf.argTmpl("@controls:button", {title: fcf.t("Add record"), fcfEventClick:"parent.getParent().onNewRecord()"})
    ]),
  });
}}@
</fieldset>


<br>
<p>
@{{ render.template("@controls:button",
                    {
                      title: fcf.t("Update sitemap files"),
                      fcfEventClick: "parent.onUpdateFiles()"
                    }
                  )
                }}@
</p>

<p>
@{{ render.template("@controls:button",
                    {
                      fcfAlias: "save",
                      title: fcf.t("Save"),
                      enable: false,
                      fcfEventClick: "parent.onSave()"
                    }
                  )
                }}@
@{{ render.template("@controls:button",
                    {
                      fcfAlias: "cancel",
                      title: fcf.t("Cancel"),
                      enable: false,
                      fcfEventClick: "parent.onCancel()"
                    }
                  )
                }}@
</p>
