<!--
Copyright (C) 2019-2023 Nicola Murino

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, version 3.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
-->
{{template "base" .}}

{{define "title"}}{{.Title}}{{end}}

{{define "extra_css"}}
<link href="{{.StaticURL}}/vendor/bootstrap-select/css/bootstrap-select.min.css" rel="stylesheet">
{{end}}

{{define "additionalnavitems"}}
<li class="nav-item dropdown no-arrow mx-1">
    <a class="nav-link dropdown-toggle" href="#" id="infoDropdown" role="button"
        data-toggle="modal" data-target="#infoModal">
        <i class="fas fa-info fa-fw"></i>
    </a>
</li>

<div class="topbar-divider d-none d-sm-block"></div>
{{end}}

{{define "page_body"}}
<div class="card shadow mb-4">
    <div class="card-header py-3">
        <h6 class="m-0 font-weight-bold text-primary">{{.Title}}</h6>
    </div>
    <div class="card-body">
        {{if .Error}}
        <div class="alert alert-warning alert-dismissible fade show" role="alert">
            {{.Error}}
            <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                <span aria-hidden="true">&times;</span>
            </button>
        </div>
        {{end}}
        <form id="eventaction_form" action="{{.CurrentURL}}" method="POST" autocomplete="off">
            <div class="form-group row">
                <label for="idName" class="col-sm-2 col-form-label">Name</label>
                <div class="col-sm-10">
                    <input type="text" class="form-control" id="idName" name="name" placeholder=""
                        value="{{.Action.Name}}" maxlength="255" autocomplete="nope" required {{if eq .Mode 2}}readonly{{end}}>
                </div>
            </div>

            <div class="form-group row">
                <label for="idDescription" class="col-sm-2 col-form-label">Description</label>
                <div class="col-sm-10">
                    <input type="text" class="form-control" id="idDescription" name="description" placeholder=""
                        value="{{.Action.Description}}" maxlength="255" aria-describedby="descriptionHelpBlock">
                    <small id="descriptionHelpBlock" class="form-text text-muted">
                        Optional description
                    </small>
                </div>
            </div>

            <div class="form-group row">
                <label for="idType" class="col-sm-2 col-form-label">Type</label>
                <div class="col-sm-10">
                    <select class="form-control selectpicker" id="idType" name="type" onchange="onTypeChanged(this.value)">
                        {{- range .ActionTypes}}
                        <option value="{{.Value}}" {{if eq $.Action.Type .Value }}selected{{end}}>{{.Name}}</option>
                        {{- end}}
                    </select>
                </div>
            </div>

            <div class="form-group row action-type action-pwd-expiration">
                <label for="idPwdExpirationThreshold" class="col-sm-2 col-form-label">Threshold</label>
                <div class="col-sm-10">
                    <input type="number" min="1" class="form-control" id="idPwdExpirationThreshold" name="pwd_expiration_threshold" placeholder=""
                        aria-describedby="PwdExpirationThresholdHelpBlock" value="{{.Action.Options.PwdExpirationConfig.Threshold}}">
                    <small id="PwdExpirationThresholdHelpBlock" class="form-text text-muted">
                        An email notification will be generated for users whose password expires in a number of days less than or equal to this threshold.
                    </small>
                </div>
            </div>

            <div class="form-group row action-type action-idp">
                <label for="idIDPMode" class="col-sm-2 col-form-label">Mode</label>
                <div class="col-sm-10">
                    <select class="form-control selectpicker" id="idIDPMode" name="idp_mode">
                        <option value="0" {{ if eq .Action.Options.IDPConfig.Mode 0 }}selected{{end}}>Create or update</option>
                        <option value="1" {{ if eq .Action.Options.IDPConfig.Mode 1 }}selected{{end}}>Create if it doesn't exist</option>
                    </select>
                </div>
            </div>

            <div class="form-group row action-type action-idp">
                <label for="idIDPUser" class="col-sm-2 col-form-label">User template</label>
                <div class="col-sm-10">
                    <textarea class="form-control" id="idIDPUser" name="idp_user" rows="4" placeholder=""
                        aria-describedby="idpUserHelpBlock">{{.Action.Options.IDPConfig.TemplateUser}}</textarea>
                    <small id="idpUserHelpBlock" class="form-text text-muted">
                        Template for SFTPGo users in JSON format. Placeholders are supported
                    </small>
                </div>
            </div>

            <div class="form-group row action-type action-idp">
                <label for="idIDAdmin" class="col-sm-2 col-form-label">Admin template</label>
                <div class="col-sm-10">
                    <textarea class="form-control" id="idIDPAdmin" name="idp_admin" rows="4" placeholder=""
                        aria-describedby="idpAdminHelpBlock">{{.Action.Options.IDPConfig.TemplateAdmin}}</textarea>
                    <small id="idpAdminHelpBlock" class="form-text text-muted">
                        Template for SFTPGo admins in JSON format. Placeholders are supported
                    </small>
                </div>
            </div>

            <div class="form-group row action-type action-http">
                <label for="idHTTPEndpoint" class="col-sm-2 col-form-label">Endpoint</label>
                <div class="col-sm-10">
                    <input type="text" class="form-control" id="idHTTPEndpoint" name="http_endpoint" placeholder=""
                        aria-describedby="HTTPEndpointHelpBlock" value="{{.Action.Options.HTTPConfig.Endpoint}}">
                    <small id="HTTPEndpointHelpBlock" class="form-text text-muted">
                        Endpoint URL, i.e https://host:port/path. Placeholders are supported within the URL path
                    </small>
                </div>
            </div>

            <div class="form-group row action-type action-http">
                <label for="idHTTPUsername" class="col-sm-2 col-form-label">Username</label>
                <div class="col-sm-3">
                    <input type="text" class="form-control" id="idHTTPUsername" name="http_username" placeholder=""
                    aria-describedby="usernameHelpBlock" value="{{.Action.Options.HTTPConfig.Username}}" maxlength="255" spellcheck="false">
                    <small id="httpBodyHelpBlock" class="form-text text-muted">
                        Placeholders are supported
                    </small>
                </div>
                <div class="col-sm-2"></div>
                <label for="idHTTPPassword" class="col-sm-2 col-form-label">Password</label>
                <div class="col-sm-3">
                    <input type="password" class="form-control" id="idHTTPPassword" name="http_password" placeholder="" autocomplete="new-password" spellcheck="false"
                        value="{{if .Action.Options.HTTPConfig.Password.IsEncrypted}}{{.RedactedSecret}}{{else}}{{.Action.Options.HTTPConfig.Password.GetPayload}}{{end}}">
                </div>
            </div>

            <div class="card bg-light mb-3 action-type action-http">
                <div class="card-header">
                    <b>HTTP headers</b>
                </div>
                <div class="card-body">
                    <h6 class="card-title mb-4">Placeholders are supported in header values.</h6>
                    <div class="form-group row">
                        <div class="col-md-12 form_field_http_headers_outer">
                            {{range $idx, $val := .Action.Options.HTTPConfig.Headers}}
                            <div class="row form_field_http_headers_outer_row">
                                <div class="form-group col-md-5">
                                    <input type="text" class="form-control" id="idHTTPHeaderKey{{$idx}}" name="http_header_key{{$idx}}" placeholder="Enter key" value="{{$val.Key}}" spellcheck="false">
                                </div>
                                <div class="form-group col-md-5">
                                    <input type="text" class="form-control" id="idHTTPHeaderVal{{$idx}}" name="http_header_val{{$idx}}" placeholder="Enter value" value="{{$val.Value}}" spellcheck="false">
                                </div>
                                <div class="form-group col-md-1"></div>
                                <div class="form-group col-md-1">
                                    <button class="btn btn-circle btn-danger remove_http_header_btn_frm_field">
                                        <i class="fas fa-trash"></i>
                                    </button>
                                </div>
                            </div>
                            {{else}}
                            <div class="row form_field_http_headers_outer_row">
                                <div class="form-group col-md-5">
                                    <input type="text" class="form-control" id="idHTTPHeaderKey0" name="http_header_key0" placeholder="Enter key" spellcheck="false" value="">
                                </div>
                                <div class="form-group col-md-5">
                                    <input type="text" class="form-control" id="idHTTPHeaderVal0" name="http_header_val0" placeholder="Enter value" spellcheck="false" value="">
                                </div>
                                <div class="form-group col-md-1"></div>
                                <div class="form-group col-md-1">
                                    <button class="btn btn-circle btn-danger remove_http_header_btn_frm_field">
                                        <i class="fas fa-trash"></i>
                                    </button>
                                </div>
                            </div>
                            {{end}}
                        </div>
                    </div>

                    <div class="row mx-1">
                        <button type="button" class="btn btn-secondary add_new_header_field_btn">
                            <i class="fas fa-plus"></i> Add new header
                        </button>
                    </div>
                </div>
            </div>

            <div class="card bg-light mb-3 action-type action-http">
                <div class="card-header">
                    <b>Query parameters</b>
                </div>
                <div class="card-body">
                    <h6 class="card-title mb-4">Placeholders are supported in query values.</h6>
                    <div class="form-group row">
                        <div class="col-md-12 form_field_http_query_outer">
                            {{range $idx, $val := .Action.Options.HTTPConfig.QueryParameters}}
                            <div class="row form_field_http_query_outer_row">
                                <div class="form-group col-md-5">
                                    <input type="text" class="form-control" id="idHTTPQueryKey{{$idx}}" name="http_query_key{{$idx}}" placeholder="Enter key" spellcheck="false" value="{{$val.Key}}">
                                </div>
                                <div class="form-group col-md-5">
                                    <input type="text" class="form-control" id="idHTTPQueryVal{{$idx}}" name="http_query_val{{$idx}}" placeholder="Enter value" spellcheck="false" value="{{$val.Value}}">
                                </div>
                                <div class="form-group col-md-1"></div>
                                <div class="form-group col-md-1">
                                    <button class="btn btn-circle btn-danger remove_http_query_btn_frm_field">
                                        <i class="fas fa-trash"></i>
                                    </button>
                                </div>
                            </div>
                            {{else}}
                            <div class="row form_field_http_query_outer_row">
                                <div class="form-group col-md-5">
                                    <input type="text" class="form-control" id="idHTTPQueryKey0" name="http_query_key0" placeholder="Enter key" spellcheck="false" value="">
                                </div>
                                <div class="form-group col-md-5">
                                    <input type="text" class="form-control" id="idHTTPQueryVal0" name="http_query_val0" placeholder="Enter value" spellcheck="false" value="">
                                </div>
                                <div class="form-group col-md-1"></div>
                                <div class="form-group col-md-1">
                                    <button class="btn btn-circle btn-danger remove_http_query_btn_frm_field">
                                        <i class="fas fa-trash"></i>
                                    </button>
                                </div>
                            </div>
                            {{end}}
                        </div>
                    </div>

                    <div class="row mx-1">
                        <button type="button" class="btn btn-secondary add_new_query_field_btn">
                            <i class="fas fa-plus"></i> Add new parameter
                        </button>
                    </div>
                </div>
            </div>

            <div class="form-group row action-type action-http">
                <label for="idHTTPMethod" class="col-sm-2 col-form-label">Method</label>
                <div class="col-sm-10">
                    <select class="form-control selectpicker" id="idHTTPMethod" name="http_method">
                        {{- range .HTTPMethods}}
                        <option value="{{.}}" {{if eq $.Action.Options.HTTPConfig.Method . }}selected{{end}}>{{.}}</option>
                        {{- end}}
                    </select>
                </div>
            </div>

            <div class="form-group row action-type action-http">
                <label for="idHTTPTimeout" class="col-sm-2 col-form-label">Timeout</label>
                <div class="col-sm-10">
                    <input type="number" min="1" max="120" class="form-control" id="idHTTPTimeout" name="http_timeout" placeholder=""
                        aria-describedby="httpTimeoutHelpBlock" value="{{.Action.Options.HTTPConfig.Timeout}}">
                    <small id="httpTimeoutHelpBlock" class="form-text text-muted">
                        Ignored for multipart requests with files as attachments.
                    </small>
                </div>
            </div>

            <div class="form-group action-type action-http">
                <div class="form-check">
                    <input type="checkbox" class="form-check-input" id="idHTTPSkipTLSVerify" name="http_skip_tls_verify"
                        {{if .Action.Options.HTTPConfig.SkipTLSVerify}}checked{{end}}>
                    <label for="idHTTPSkipTLSVerify" class="form-check-label">Skip TLS verify</label>
                </div>
            </div>

            <div class="form-group row action-type action-http">
                <label for="idHTTPBody" class="col-sm-2 col-form-label">Body</label>
                <div class="col-sm-10">
                    <textarea class="form-control" id="idHTTPBody" name="http_body" rows="4" placeholder=""
                        aria-describedby="httpBodyHelpBlock">{{.Action.Options.HTTPConfig.Body}}</textarea>
                    <small id="httpBodyHelpBlock" class="form-text text-muted">
                        Placeholders are supported. Ignored for HTTP get requested. Leave empty for multipart requests.
                    </small>
                </div>
            </div>

            <div class="card bg-light mb-3 action-type action-http">
                <div class="card-header">
                    <b>Multipart body</b>
                </div>
                <div class="card-body">
                    <h6 class="card-title mb-4">Multipart requests allow to combine one or more sets of data into a single body. For each part, you can set a file path or a body as text. Placeholders are supported in file path, body, header values.</h6>
                    <div class="form-group row">
                        <div class="col-md-12 form_field_http_part_outer">
                            {{range $idx, $val := .Action.Options.HTTPConfig.Parts}}
                            <div class="row form_field_http_part_outer_row">
                                <div class="col-md-12">
                                    <div class="row">
                                        <div class="form-group col-md-2">
                                            <input type="text" class="form-control" id="idHTTPPartName{{$idx}}" name="http_part_name{{$idx}}" placeholder="Part name" value="{{$val.Name}}">
                                        </div>
                                        <div class="form-group col-md-3">
                                            <input type="text" class="form-control" id="idHTTPPartFile{{$idx}}" name="http_part_file{{$idx}}" placeholder="File path" value="{{$val.Filepath}}">
                                        </div>
                                        <div class="form-group col-md-5">
                                            <textarea class="form-control" id="idHTTPPartHeaders{{$idx}}" name="http_part_headers{{$idx}}" rows="2" placeholder="Additional part headers"
                                                            aria-describedby="httpPartHeadersHelpBlock{{$idx}}">{{range $val.Headers}}{{.Key}}: {{.Value}}&#010;{{end}}</textarea>
                                            <small id="httpPartHeadersHelpBlock{{$idx}}" class="form-text text-muted">
                                                One header per line as "key: value", example: "Content-Type: application/json", without quotes. Content type for files is automatically detected
                                            </small>
                                        </div>
                                        <div class="form-group col-md-1"></div>
                                        <div class="form-group col-md-1">
                                            <button class="btn btn-circle btn-danger remove_http_part_btn_frm_field">
                                                <i class="fas fa-trash"></i>
                                            </button>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="form-group col-md-10">
                                            <textarea class="form-control" id="idHTTPPartBody{{$idx}}" name="http_part_body{{$idx}}" rows="3" placeholder="Part body">{{$val.Body}}</textarea>
                                        </div>
                                    </div>
                                    <hr>
                                </div>
                            </div>
                            {{else}}
                            <div class="row form_field_http_part_outer_row">
                                <div class="col-md-12">
                                    <div class="row">
                                        <div class="form-group col-md-2">
                                            <input type="text" class="form-control" id="idHTTPPartName0" name="http_part_name0" placeholder="Part name" value="">
                                        </div>
                                        <div class="form-group col-md-3">
                                            <input type="text" class="form-control" id="idHTTPPartFile0" name="http_part_file0" placeholder="File path" value="">
                                        </div>
                                        <div class="form-group col-md-5">
                                            <textarea class="form-control" id="idHTTPPartHeaders0" name="http_part_headers0" rows="2" placeholder="Additional part headers"
                                                            aria-describedby="httpPartHeadersHelpBlock0"></textarea>
                                            <small id="httpPartHeadersHelpBlock0" class="form-text text-muted">
                                                One header per line as "key: value", example: "Content-Type: application/json", without quotes. Content type for files is automatically detected
                                            </small>
                                        </div>
                                        <div class="form-group col-md-1"></div>
                                        <div class="form-group col-md-1">
                                            <button class="btn btn-circle btn-danger remove_http_part_btn_frm_field">
                                                <i class="fas fa-trash"></i>
                                            </button>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="form-group col-md-10">
                                            <textarea class="form-control" id="idHTTPPartBody0" name="http_part_body0" rows="3" placeholder="Part body"></textarea>
                                        </div>
                                    </div>
                                    <hr>
                                </div>
                            </div>
                            {{end}}
                        </div>
                    </div>
                    <div class="row mx-1">
                        <button type="button" class="btn btn-secondary add_new_http_part_field_btn">
                            <i class="fas fa-plus"></i> Add new HTTP part
                        </button>
                    </div>
                </div>
            </div>

            <div class="form-group row action-type action-cmd">
                <label for="idCmdPath" class="col-sm-2 col-form-label">Command</label>
                <div class="col-sm-10">
                    <input type="text" class="form-control" id="idCmdPath" name="cmd_path" placeholder=""
                        aria-describedby="CmdPathHelpBlock" value="{{.Action.Options.CmdConfig.Cmd}}">
                    <small id="CmdPathHelpBlock" class="form-text text-muted">
                        Absolute path of the command to execute
                    </small>
                </div>
            </div>

            <div class="form-group row action-type action-cmd">
                <label for="idCommandArgs" class="col-sm-2 col-form-label">Arguments</label>
                <div class="col-sm-10">
                    <textarea class="form-control" id="idCommandArgs" name="cmd_arguments" rows="2" placeholder=""
                        aria-describedby="commandArgumentsHelpBlock">{{.Action.Options.CmdConfig.GetArgumentsAsString}}</textarea>
                    <small id="commandArgumentsHelpBlock" class="form-text text-muted">
                        Comma separated command arguments. Placeholders are supported.
                    </small>
                </div>
            </div>

            <div class="form-group row action-type action-cmd">
                <label for="idCmdTimeout" class="col-sm-2 col-form-label">Timeout</label>
                <div class="col-sm-10">
                    <input type="number" min="1" max="120" class="form-control" id="idCmdTimeout" name="cmd_timeout" placeholder=""
                        value="{{.Action.Options.CmdConfig.Timeout}}">
                </div>
            </div>

            <div class="card bg-light mb-3 action-type action-cmd">
                <div class="card-header">
                    <b>Environment variables</b>
                </div>
                <div class="card-body">
                    <h6 class="card-title mb-4">Placeholders are supported in values.</h6>
                    <div class="form-group row">
                        <div class="col-md-12 form_field_cmd_env_outer">
                            {{range $idx, $val := .Action.Options.CmdConfig.EnvVars}}
                            <div class="row form_field_cmd_env_outer_row">
                                <div class="form-group col-md-5">
                                    <input type="text" class="form-control" id="idCMDEnvKey{{$idx}}" name="cmd_env_key{{$idx}}" placeholder="Enter key" value="{{$val.Key}}">
                                </div>
                                <div class="form-group col-md-5">
                                    <input type="text" class="form-control" id="idCMDEnvVal{{$idx}}" name="cmd_env_val{{$idx}}" placeholder="Enter value" value="{{$val.Value}}">
                                </div>
                                <div class="form-group col-md-1"></div>
                                <div class="form-group col-md-1">
                                    <button class="btn btn-circle btn-danger remove_cmd_env_btn_frm_field">
                                        <i class="fas fa-trash"></i>
                                    </button>
                                </div>
                            </div>
                            {{else}}
                            <div class="row form_field_cmd_env_outer_row">
                                <div class="form-group col-md-5">
                                    <input type="text" class="form-control" id="idCMDEnvKey0" name="cmd_env_key0" placeholder="Enter key" value="">
                                </div>
                                <div class="form-group col-md-5">
                                    <input type="text" class="form-control" id="idCMDEnvVal0" name="cmd_env_val0" placeholder="Enter value" value="">
                                </div>
                                <div class="form-group col-md-1"></div>
                                <div class="form-group col-md-1">
                                    <button class="btn btn-circle btn-danger remove_cmd_env_btn_frm_field">
                                        <i class="fas fa-trash"></i>
                                    </button>
                                </div>
                            </div>
                            {{end}}
                        </div>
                    </div>

                    <div class="row mx-1">
                        <button type="button" class="btn btn-secondary add_new_cmd_env_field_btn">
                            <i class="fas fa-plus"></i> Add environment variable
                        </button>
                    </div>
                </div>
            </div>

            <div class="form-group row action-type action-smtp">
                <label for="idEmailRecipients" class="col-sm-2 col-form-label">To</label>
                <div class="col-sm-10">
                    <textarea class="form-control" id="idEmailRecipients" name="email_recipients" rows="2" placeholder=""
                        aria-describedby="smtpRecipientsHelpBlock">{{.Action.Options.EmailConfig.GetRecipientsAsString}}</textarea>
                    <small id="smtpRecipientsHelpBlock" class="form-text text-muted">
                        Comma separated recipients. Placeholders are supported
                    </small>
                </div>
            </div>

            <div class="form-group row action-type action-smtp">
                <label for="idEmailBcc" class="col-sm-2 col-form-label">Bcc</label>
                <div class="col-sm-10">
                    <textarea class="form-control" id="idEmailBcc" name="email_bcc" rows="2" placeholder=""
                        aria-describedby="smtpBccHelpBlock">{{.Action.Options.EmailConfig.GetBccAsString}}</textarea>
                    <small id="smtpBccHelpBlock" class="form-text text-muted">
                        Comma separated Bcc addresses. Placeholders are supported
                    </small>
                </div>
            </div>

            <div class="form-group row action-type action-smtp">
                <label for="idEmailSubject" class="col-sm-2 col-form-label">Subject</label>
                <div class="col-sm-10">
                    <input type="text" class="form-control" id="idEmailSubject" name="email_subject" placeholder=""
                        value="{{.Action.Options.EmailConfig.Subject}}" maxlength="255" aria-describedby="emailSubjectHelpBlock">
                    <small id="emailSubjectHelpBlock" class="form-text text-muted">
                        Placeholders are supported
                    </small>
                </div>
            </div>

            <div class="form-group row action-type action-smtp">
                <label for="idEmailContentType" class="col-sm-2 col-form-label">Content type</label>
                <div class="col-sm-10">
                    <select class="form-control selectpicker" id="idEmailContentType" name="email_content_type">
                        <option value="0" {{ if eq .Action.Options.EmailConfig.ContentType 0 }}selected{{end}}>Text/plain</option>
                        <option value="1" {{ if eq .Action.Options.EmailConfig.ContentType 1 }}selected{{end}}>Text/html</option>
                    </select>
                </div>
            </div>

            <div class="form-group row action-type action-smtp">
                <label for="idEmailBody" class="col-sm-2 col-form-label">Body</label>
                <div class="col-sm-10">
                    <textarea class="form-control" id="idEmailBody" name="email_body" rows="4" placeholder=""
                        aria-describedby="smtpBodyHelpBlock">{{.Action.Options.EmailConfig.Body}}</textarea>
                    <small id="smtpBodyHelpBlock" class="form-text text-muted">
                        Placeholders are supported
                    </small>
                </div>
            </div>

            <div class="form-group row action-type action-smtp">
                <label for="idEmailAttachments" class="col-sm-2 col-form-label">Attachments</label>
                <div class="col-sm-10">
                    <textarea class="form-control" id="idEmailAttachments" name="email_attachments" rows="2" placeholder=""
                        aria-describedby="smtpAttachmentsHelpBlock">{{.Action.Options.EmailConfig.GetAttachmentsAsString}}</textarea>
                    <small id="smtpAttachmentsHelpBlock" class="form-text text-muted">
                        Comma separated paths to attach. Placeholders are supported. The total size is limited to 10 MB.
                    </small>
                </div>
            </div>

            <div class="card bg-light mb-3 action-type action-dataretention">
                <div class="card-header">
                    <b>Data retention</b>
                </div>
                <div class="card-body">
                    <h6 class="card-title mb-4">Set the data retention, as hours, per path. Retention applies recursively. Setting 0 as retention means excluding the specified path. "Ignore user permissions" defines whether to delete files even if the user does not have the "delete" permission, by default files will be skipped if the user does not have the "delete" permission.</h6>
                    <div class="form-group row">
                        <div class="col-md-12 form_field_data_retention_outer">
                            {{range $idx, $val := .Action.Options.RetentionConfig.Folders}}
                            <div class="row form_field_data_retention_outer_row">
                                <div class="form-group col-md-4">
                                    <input type="text" class="form-control" id="idFolderRetentionPath{{$idx}}" name="folder_retention_path{{$idx}}" placeholder="path, i.e. /dir" value="{{$val.Path}}">
                                </div>
                                <div class="form-group col-md-2">
                                    <input type="number" min="0" class="form-control" id="idFolderRetentionVal{{$idx}}" name="folder_retention_val{{$idx}}" placeholder="Hours" value="{{$val.Retention}}">
                                </div>
                                <div class="form-group col-md-4">
                                    <select class="form-control selectpicker" id="idFolderRetentionOptions{{$idx}}" name="folder_retention_options{{$idx}}" multiple>
                                        <option value="1" {{if $val.DeleteEmptyDirs}}selected{{end}}>Delete empty dirs</option>
                                        <option value="2" {{if $val.IgnoreUserPermissions}}selected{{end}}>Ignore user permissions</option>
                                    </select>
                                </div>
                                <div class="form-group col-md-1"></div>
                                <div class="form-group col-md-1">
                                    <button class="btn btn-circle btn-danger remove_data_retention_btn_frm_field">
                                        <i class="fas fa-trash"></i>
                                    </button>
                                </div>
                            </div>
                            {{else}}
                            <div class="row form_field_data_retention_outer_row">
                                <div class="form-group col-md-4">
                                    <input type="text" class="form-control" id="idFolderRetentionPath0" name="folder_retention_path0" placeholder="path, i.e. /dir" value="">
                                </div>
                                <div class="form-group col-md-2">
                                    <input type="number" min="0" class="form-control" id="idFolderRetentionVal0" name="folder_retention_val0" placeholder="Hours" value="">
                                </div>
                                <div class="form-group col-md-4">
                                    <select class="form-control selectpicker" id="idFolderRetentionOptions0" name="folder_retention_options0" multiple>
                                        <option value="1">Delete empty dirs</option>
                                        <option value="2">Ignore user permissions</option>
                                    </select>
                                </div>
                                <div class="form-group col-md-1"></div>
                                <div class="form-group col-md-1">
                                    <button class="btn btn-circle btn-danger remove_data_retention_btn_frm_field">
                                        <i class="fas fa-trash"></i>
                                    </button>
                                </div>
                            </div>
                            {{end}}
                        </div>
                    </div>

                    <div class="row mx-1">
                        <button type="button" class="btn btn-secondary add_new_data_retention_field_btn">
                            <i class="fas fa-plus"></i> Add new path
                        </button>
                    </div>
                </div>
            </div>

            <div class="form-group row action-type action-fs">
                <label for="idFsActionType" class="col-sm-2 col-form-label">Fs action</label>
                <div class="col-sm-10">
                    <select class="form-control selectpicker" id="idFsActionType" name="fs_action_type" onchange="onFsActionChanged(this.value)">
                        {{- range .FsActions}}
                        <option value="{{.Value}}" {{if eq $.Action.Options.FsConfig.Type .Value }}selected{{end}}>{{.Name}}</option>
                        {{- end}}
                    </select>
                </div>
            </div>

            <div class="card bg-light mb-3 action-type action-fs-type action-fs-rename">
                <div class="card-header">
                    <b>Rename</b>
                </div>
                <div class="card-body">
                    <h6 class="card-title mb-4">Paths to rename as seen by SFTPGo users. Placeholders are supported. The required permissions are granted automatically</h6>
                    <div class="form-group row">
                        <div class="col-md-12 form_field_fs_rename_outer">
                            {{range $idx, $val := .Action.Options.FsConfig.Renames}}
                            <div class="row form_field_fs_rename_outer_row">
                                <div class="form-group col-md-5">
                                    <input type="text" class="form-control" id="idFsRenameSource{{$idx}}" name="fs_rename_source{{$idx}}" placeholder="Source path" value="{{$val.Key}}">
                                </div>
                                <div class="form-group col-md-5">
                                    <input type="text" class="form-control" id="idFsRenameTarget{{$idx}}" name="fs_rename_target{{$idx}}" placeholder="Target path" value="{{$val.Value}}">
                                </div>
                                <div class="form-group col-md-1"></div>
                                <div class="form-group col-md-1">
                                    <button class="btn btn-circle btn-danger remove_fs_rename_btn_frm_field">
                                        <i class="fas fa-trash"></i>
                                    </button>
                                </div>
                            </div>
                            {{else}}
                            <div class="row form_field_fs_rename_outer_row">
                                <div class="form-group col-md-5">
                                    <input type="text" class="form-control" id="idFsRenameSource0" name="fs_rename_source0" placeholder="Source path" value="">
                                </div>
                                <div class="form-group col-md-5">
                                    <input type="text" class="form-control" id="idFsRenameTarget0" name="fs_rename_target0" placeholder="Target path" value="">
                                </div>
                                <div class="form-group col-md-1"></div>
                                <div class="form-group col-md-1">
                                    <button class="btn btn-circle btn-danger remove_fs_rename_btn_frm_field">
                                        <i class="fas fa-trash"></i>
                                    </button>
                                </div>
                            </div>
                            {{end}}
                        </div>
                    </div>

                    <div class="row mx-1">
                        <button type="button" class="btn btn-secondary add_new_fs_rename_field_btn">
                            <i class="fas fa-plus"></i> Add new
                        </button>
                    </div>
                </div>
            </div>

            <div class="form-group row action-type action-fs-type action-fs-delete">
                <label for="idFsDelete" class="col-sm-2 col-form-label">Paths</label>
                <div class="col-sm-10">
                    <textarea class="form-control" id="idFsDelete" name="fs_delete_paths" rows="2"
                        aria-describedby="fsDeleteHelpBlock">{{.Action.Options.FsConfig.GetDeletesAsString}}</textarea>
                    <small id="fsDeleteHelpBlock" class="form-text text-muted">
                        Comma separated paths to delete as seen by SFTPGo users. Placeholders are supported. The required permissions are granted automatically
                    </small>
                </div>
            </div>

            <div class="form-group row action-type action-fs-type action-fs-mkdir">
                <label for="idFsMkdir" class="col-sm-2 col-form-label">Paths</label>
                <div class="col-sm-10">
                    <textarea class="form-control" id="idFsMkdir" name="fs_mkdir_paths" rows="2"
                        aria-describedby="fsMkdirHelpBlock">{{.Action.Options.FsConfig.GetMkDirsAsString}}</textarea>
                    <small id="fsMkdirHelpBlock" class="form-text text-muted">
                        Comma separated directories paths to create as seen by SFTPGo users. Placeholders are supported. The required permissions are granted automatically
                    </small>
                </div>
            </div>

            <div class="form-group row action-type action-fs-type action-fs-exist">
                <label for="idFsExist" class="col-sm-2 col-form-label">Paths</label>
                <div class="col-sm-10">
                    <textarea class="form-control" id="idFsExist" name="fs_exist_paths" rows="2"
                        aria-describedby="fsExistHelpBlock">{{.Action.Options.FsConfig.GetExistAsString}}</textarea>
                    <small id="fsExistHelpBlock" class="form-text text-muted">
                        Comma separated paths to check for existence as seen by SFTPGo users. Placeholders are supported. The required permissions are granted automatically
                    </small>
                </div>
            </div>

            <div class="card bg-light mb-3 action-type action-fs-type action-fs-copy">
                <div class="card-header">
                    <b>Copy</b>
                </div>
                <div class="card-body">
                    <h6 class="card-title mb-4">Paths to copy as seen by SFTPGo users. Placeholders are supported. The required permissions are granted automatically</h6>
                    <div class="form-group row">
                        <div class="col-md-12 form_field_fs_copy_outer">
                            {{range $idx, $val := .Action.Options.FsConfig.Copy}}
                            <div class="row form_field_fs_copy_outer_row">
                                <div class="form-group col-md-5">
                                    <input type="text" class="form-control" id="idFsCopySource{{$idx}}" name="fs_copy_source{{$idx}}" placeholder="Source path" value="{{$val.Key}}">
                                </div>
                                <div class="form-group col-md-5">
                                    <input type="text" class="form-control" id="idFsCopyTarget{{$idx}}" name="fs_copy_target{{$idx}}" placeholder="Target path" value="{{$val.Value}}">
                                </div>
                                <div class="form-group col-md-1"></div>
                                <div class="form-group col-md-1">
                                    <button class="btn btn-circle btn-danger remove_fs_copy_btn_frm_field">
                                        <i class="fas fa-trash"></i>
                                    </button>
                                </div>
                            </div>
                            {{else}}
                            <div class="row form_field_fs_copy_outer_row">
                                <div class="form-group col-md-5">
                                    <input type="text" class="form-control" id="idFsCopySource0" name="fs_copy_source0" placeholder="Source path" value="">
                                </div>
                                <div class="form-group col-md-5">
                                    <input type="text" class="form-control" id="idFsCopyTarget0" name="fs_copy_target0" placeholder="Target path" value="">
                                </div>
                                <div class="form-group col-md-1"></div>
                                <div class="form-group col-md-1">
                                    <button class="btn btn-circle btn-danger remove_fs_copy_btn_frm_field">
                                        <i class="fas fa-trash"></i>
                                    </button>
                                </div>
                            </div>
                            {{end}}
                        </div>
                    </div>

                    <div class="row mx-1">
                        <button type="button" class="btn btn-secondary add_new_fs_copy_field_btn">
                            <i class="fas fa-plus"></i> Add new
                        </button>
                    </div>
                </div>
            </div>

            <div class="form-group row action-type action-fs-type action-fs-compress">
                <label for="idFsCompressName" class="col-sm-2 col-form-label">Archive path</label>
                <div class="col-sm-10">
                    <input type="text" class="form-control" id="idFsCompressName" name="fs_compress_name" placeholder=""
                            value="{{.Action.Options.FsConfig.Compress.Name}}" maxlength="255"  aria-describedby="fsCompressNameHelpBlock">
                    <small id="fsCompressPathsHelpBlock" class="form-text text-muted">
                        Full path, as seen by SFTPGo users, to the zip archive to create. Placeholders are supported. If the specified file already exists, it is overwritten
                    </small>
                </div>
            </div>

            <div class="form-group row action-type action-fs-type action-fs-compress">
                <label for="idFsCompressPaths" class="col-sm-2 col-form-label">Paths</label>
                <div class="col-sm-10">
                    <textarea class="form-control" id="idFsCompressPaths" name="fs_compress_paths" rows="2"
                        aria-describedby="fsCompressPathsHelpBlock">{{.Action.Options.FsConfig.GetCompressPathsAsString}}</textarea>
                    <small id="fsCompressPathsHelpBlock" class="form-text text-muted">
                        Comma separated paths to compress (zip) as seen by SFTPGo users. Placeholders are supported. The required permissions are granted automatically
                    </small>
                </div>
            </div>

            <input type="hidden" name="_form_token" value="{{.CSRFToken}}">
            <div class="col-sm-12 text-right px-0">
                <button type="submit" class="btn btn-primary mt-3 ml-3 px-5" name="form_action" value="submit">Submit</button>
            </div>
        </form>
    </div>
</div>
{{end}}

{{define "dialog"}}
<div class="modal fade" id="infoModal" tabindex="-1" role="dialog" aria-labelledby="infoModalLabel"
    aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="infoModalLabel">
                    Supported placeholders
                </h5>
                <button class="close" type="button" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <p>
                    <span class="shortcut"><b>{{`{{Name}}`}}</b></span> => Username, folder name, admin username for provider events, domain name for certificate events.
                </p>
                <p>
                    <span class="shortcut"><b>{{`{{Event}}`}}</b></span> => Event name, for example "upload", "download" for filesystem events or "add", "update" for provider events.
                </p>
                <p>
                    <span class="shortcut"><b>{{`{{Status}}`}}</b></span> => Status for "upload", "download" and "ssh_cmd" events. 1 means no error, 2 means a generic error occurred, 3 means quota exceeded error.
                </p>
                <p>
                    <span class="shortcut"><b>{{`{{StatusString}}`}}</b></span> => Status as string. Possible values "OK", "KO".
                </p>
                <p>
                    <span class="shortcut"><b>{{`{{ErrorString}}`}}</b></span> => Error details. Replaced with an empty string if no errors occur.
                </p>
                <p>
                    <span class="shortcut"><b>{{`{{VirtualPath}}`}}</b></span> => Path seen by SFTPGo users, for example "/adir/afile.txt".
                </p>
                <p>
                    <span class="shortcut"><b>{{`{{VirtualDirPath}}`}}</b></span> => Parent directory for VirtualPath, for example if VirtualPath is "/adir/afile.txt", VirtualDirPath is "/adir".
                </p>
                <p>
                    <span class="shortcut"><b>{{`{{FsPath}}`}}</b></span> => Full filesystem path, for example "/user/homedir/adir/afile.txt" or "C:/data/user/homedir/adir/afile.txt" on Windows.
                </p>
                <p>
                    <span class="shortcut"><b>{{`{{ObjectName}}`}}</b></span> => File/directory name, for example "afile.txt" or provider object name.
                </p>
                <p>
                    <span class="shortcut"><b>{{`{{ObjectType}}`}}</b></span> => Object type for provider events: "user", "group", "admin", etc.
                </p>
                <p>
                    <span class="shortcut"><b>{{`{{VirtualTargetPath}}`}}</b></span> => Virtual target path for renames.
                </p>
                <p>
                    <span class="shortcut"><b>{{`{{VirtualTargetDirPath}}`}}</b></span> => Parent directory for VirtualTargetPath.
                </p>
                <p>
                    <span class="shortcut"><b>{{`{{TargetName}}`}}</b></span> => Target object name for renames.
                </p>
                <p>
                    <span class="shortcut"><b>{{`{{FsTargetPath}}`}}</b></span> => Full filesystem target path for renames.
                </p>
                <p>
                    <span class="shortcut"><b>{{`{{FileSize}}`}}</b></span> => File size.
                </p>
                <p>
                    <span class="shortcut"><b>{{`{{Elapsed}}`}}</b></span> => Elapsed time as milliseconds for filesystem events.
                </p>
                <p>
                    <span class="shortcut"><b>{{`{{Protocol}}`}}</b></span> => Protocol, for example "SFTP", "FTP".
                </p>
                <p>
                    <span class="shortcut"><b>{{`{{IP}}`}}</b></span> => Client IP address.
                </p>
                <p>
                    <span class="shortcut"><b>{{`{{Role}}`}}</b></span> => User or admin role.
                </p>
                <p>
                    <span class="shortcut"><b>{{`{{Timestamp}}`}}</b></span> =>  Event timestamp as nanoseconds since epoch.
                </p>
                <p>
                    <span class="shortcut"><b>{{`{{Email}}`}}</b></span> =>  For filesystem events, this is the email associated with the user performing the action. For the provider events, this is the email associated with the affected user or admin. Blank in all other cases.
                </p>
                <p>
                    <span class="shortcut"><b>{{`{{ObjectData}}`}}</b></span> => Provider object data serialized as JSON with sensitive fields removed.
                </p>
                <p>
                    <span class="shortcut"><b>{{`{{RetentionReports}}`}}</b></span> => Data retention reports as zip compressed CSV files. Supported as email attachment, file path for multipart HTTP request and as single parameter for HTTP requests body.
                </p>
                <p>
                    <span class="shortcut"><b>{{`{{IDPField<fieldname>}}`}}</b></span> => Identity Provider custom fields containing a string.
                </p>
            </div>
            <div class="modal-footer">
                <button class="btn btn-primary" type="button" data-dismiss="modal">OK</button>
            </div>
        </div>
    </div>
</div>
{{end}}

{{define "extra_js"}}
<script src="{{.StaticURL}}/vendor/bootstrap-select/js/bootstrap-select.min.js"></script>
<script type="text/javascript">
    $("body").on("click", ".add_new_header_field_btn", function () {
        let index = $(".form_field_http_headers_outer").find(".form_field_http_headers_outer_row").length;
        while (document.getElementById("idHTTPHeaderKey"+index) != null){
            index++;
        }
        $(".form_field_http_headers_outer").append(`
            <div class="row form_field_http_headers_outer_row">
                <div class="form-group col-md-5">
                    <input type="text" class="form-control" id="idHTTPHeaderKey${index}" name="http_header_key${index}" placeholder="Enter key" spellcheck="false" value="">
                </div>
                <div class="form-group col-md-5">
                    <input type="text" class="form-control" id="idHTTPHeaderVal${index}" name="http_header_val${index}" placeholder="Enter value" spellcheck="false" value="">
                </div>
                <div class="form-group col-md-1"></div>
                <div class="form-group col-md-1">
                    <button class="btn btn-circle btn-danger remove_http_header_btn_frm_field">
                        <i class="fas fa-trash"></i>
                    </button>
                </div>
            </div>
            `);
        });

    $("body").on("click", ".remove_http_header_btn_frm_field", function () {
        $(this).closest(".form_field_http_headers_outer_row").remove();
    });

    $("body").on("click", ".add_new_query_field_btn", function () {
        let index = $(".form_field_http_query_outer").find(".form_field_http_query_outer_row").length;
        while (document.getElementById("idHTTPQueryKey"+index) != null){
            index++;
        }
        $(".form_field_http_query_outer").append(`
            <div class="row form_field_http_query_outer_row">
                <div class="form-group col-md-5">
                    <input type="text" class="form-control" id="idHTTPQueryKey${index}" name="http_query_key${index}" placeholder="Enter key" spellcheck="false" value="">
                </div>
                <div class="form-group col-md-5">
                    <input type="text" class="form-control" id="idHTTPQueryVal${index}" name="http_query_val${index}" placeholder="Enter value" spellcheck="false" value="">
                </div>
                <div class="form-group col-md-1"></div>
                <div class="form-group col-md-1">
                    <button class="btn btn-circle btn-danger remove_http_query_btn_frm_field">
                        <i class="fas fa-trash"></i>
                    </button>
                </div>
            </div>
            `);
        });

    $("body").on("click", ".remove_http_query_btn_frm_field", function () {
        $(this).closest(".form_field_http_query_outer_row").remove();
    });

    $("body").on("click", ".add_new_cmd_env_field_btn", function () {
        let index = $(".form_field_cmd_env_outer").find(".form_field_cmd_env_outer_row").length;
        while (document.getElementById("idCMDEnvKey"+index) != null){
            index++;
        }
        $(".form_field_cmd_env_outer").append(`
            <div class="row form_field_cmd_env_outer_row">
                <div class="form-group col-md-5">
                    <input type="text" class="form-control" id="idCMDEnvKey${index}" name="cmd_env_key${index}" placeholder="Enter key" value="">
                </div>
                <div class="form-group col-md-5">
                    <input type="text" class="form-control" id="idCMDEnvVal${index}" name="cmd_env_val${index}" placeholder="Enter value" value="">
                </div>
                <div class="form-group col-md-1"></div>
                <div class="form-group col-md-1">
                    <button class="btn btn-circle btn-danger remove_cmd_env_btn_frm_field">
                        <i class="fas fa-trash"></i>
                    </button>
                </div>
            </div>
            `);
        });

    $("body").on("click", ".remove_cmd_env_btn_frm_field", function () {
        $(this).closest(".form_field_cmd_env_outer_row").remove();
    });

    $("body").on("click", ".add_new_data_retention_field_btn", function () {
        let index = $(".form_field_data_retention_outer").find(".form_field_data_retention_outer_row").length;
        while (document.getElementById("idFolderRetentionPath"+index) != null){
            index++;
        }
        $(".form_field_data_retention_outer").append(`
            <div class="row form_field_data_retention_outer_row">
                <div class="form-group col-md-4">
                    <input type="text" class="form-control" id="idFolderRetentionPath${index}" name="folder_retention_path${index}" placeholder="path, i.e. /dir" value="">
                </div>
                <div class="form-group col-md-2">
                    <input type="number" min="0" class="form-control" id="idFolderRetentionVal${index}" name="folder_retention_val${index}" placeholder="Hours" value="">
                </div>
                <div class="form-group col-md-4">
                    <select class="form-control" id="idFolderRetentionOptions${index}" name="folder_retention_options${index}" multiple>
                        <option value="1">Delete empty dirs</option>
                        <option value="2">Ignore user permissions</option>
                    </select>
                </div>
                <div class="form-group col-md-1"></div>
                <div class="form-group col-md-1">
                    <button class="btn btn-circle btn-danger remove_data_retention_btn_frm_field">
                        <i class="fas fa-trash"></i>
                    </button>
                </div>
            </div>
            `);
        $("#idFolderRetentionOptions"+index).selectpicker();
    });

    $("body").on("click", ".remove_data_retention_btn_frm_field", function () {
        $(this).closest(".form_field_data_retention_outer_row").remove();
    });

    $("body").on("click", ".add_new_fs_rename_field_btn", function () {
        let index = $(".form_field_fs_rename_outer").find(".form_field_fs_rename_outer_row").length;
        while (document.getElementById("idFsRenameSource"+index) != null){
            index++;
        }
        $(".form_field_fs_rename_outer").append(`
            <div class="row form_field_fs_rename_outer_row">
                <div class="form-group col-md-5">
                    <input type="text" class="form-control" id="idFsRenameSource${index}" name="fs_rename_source${index}" placeholder="Source path" value="">
                </div>
                <div class="form-group col-md-5">
                    <input type="text" class="form-control" id="idFsRenameTarget${index}" name="fs_rename_target${index}" placeholder="Target path" value="">
                </div>
                <div class="form-group col-md-1"></div>
                <div class="form-group col-md-1">
                    <button class="btn btn-circle btn-danger remove_fs_rename_btn_frm_field">
                        <i class="fas fa-trash"></i>
                    </button>
                </div>
            </div>
            `);
        });

    $("body").on("click", ".remove_fs_rename_btn_frm_field", function () {
        $(this).closest(".form_field_fs_rename_outer_row").remove();
    });

    $("body").on("click", ".add_new_fs_copy_field_btn", function () {
        let index = $(".form_field_fs_copy_outer").find(".form_field_fs_copy_outer_row").length;
        while (document.getElementById("idFsCopySource"+index) != null){
            index++;
        }
        $(".form_field_fs_copy_outer").append(`
            <div class="row form_field_fs_copy_outer_row">
                <div class="form-group col-md-5">
                    <input type="text" class="form-control" id="idFsCopySource${index}" name="fs_copy_source${index}" placeholder="Source path" value="">
                </div>
                <div class="form-group col-md-5">
                    <input type="text" class="form-control" id="idFsCopyTarget${index}" name="fs_copy_target${index}" placeholder="Target path" value="">
                </div>
                <div class="form-group col-md-1"></div>
                <div class="form-group col-md-1">
                    <button class="btn btn-circle btn-danger remove_fs_copy_btn_frm_field">
                        <i class="fas fa-trash"></i>
                    </button>
                </div>
            </div>
            `);
        });

    $("body").on("click", ".remove_fs_copy_btn_frm_field", function () {
        $(this).closest(".form_field_fs_copy_outer_row").remove();
    });

    $("body").on("click", ".add_new_http_part_field_btn", function () {
        let index = $(".form_field_http_part_outer").find(".form_field_http_part_outer_row").length;
        while (document.getElementById("idHTTPPartName"+index) != null){
            index++;
        }
        $(".form_field_http_part_outer").append(`
            <div class="row form_field_http_part_outer_row">
                <div class="col-md-12">
                    <div class="row">
                        <div class="form-group col-md-2">
                            <input type="text" class="form-control" id="idHTTPPartName${index}" name="http_part_name${index}" placeholder="Part name" value="">
                        </div>
                        <div class="form-group col-md-3">
                            <input type="text" class="form-control" id="idHTTPPartFile${index}" name="http_part_file${index}" placeholder="File path" value="">
                        </div>
                        <div class="form-group col-md-5">
                            <textarea class="form-control" id="idHTTPPartHeaders${index}" name="http_part_headers${index}" rows="2" placeholder="Additional part headers"
                                        aria-describedby="httpPartHeadersHelpBlock${index}"></textarea>
                            <small id="httpPartHeadersHelpBlock${index}" class="form-text text-muted">
                                One header per line as "key: value", example: "Content-Type: application/json", without quotes. Content type for files is automatically detected
                            </small>
                        </div>
                        <div class="form-group col-md-1"></div>
                        <div class="form-group col-md-1">
                            <button class="btn btn-circle btn-danger remove_http_part_btn_frm_field">
                                <i class="fas fa-trash"></i>
                            </button>
                        </div>
                    </div>
                    <div class="row">
                        <div class="form-group col-md-10">
                            <textarea class="form-control" id="idHTTPPartBody${index}" name="http_part_body${index}" rows="3" placeholder="Part body"></textarea>
                        </div>
                    </div>
                    <hr>
                </div>
            </div>
            `);
        });

    $("body").on("click", ".remove_http_part_btn_frm_field", function () {
        $(this).closest(".form_field_http_part_outer_row").remove();
    });

    function onTypeChanged(val){
        $('.action-type').hide();
        switch (val) {
            case '1':
                $('.action-http').show();
                break;
            case '2':
                $('.action-cmd').show();
                break;
            case '3':
                $('.action-smtp').show();
                break;
            case '8':
                $('.action-dataretention').show();
                break;
            case '9':
                $('.action-fs').show();
                onFsActionChanged($("#idFsActionType").val());
                break;
            case '11':
                $('.action-pwd-expiration').show();
                break;
            case '13':
                $('.action-idp').show();
                break;
        }
    }

    function onFsActionChanged(val){
        $('.action-fs-type').hide();
        switch (val) {
            case '1':
                $('.action-fs-rename').show();
                break;
            case '2':
                $('.action-fs-delete').show();
                break;
            case '3':
                $('.action-fs-mkdir').show();
                break;
            case '4':
                $('.action-fs-exist').show();
                break;
            case '5':
                $('.action-fs-compress').show();
                break;
            case '6':
                $('.action-fs-copy').show();
                break;
        }
    }

    $(document).ready(function () {
        onTypeChanged('{{.Action.Type}}');
        onFsActionChanged('{{.Action.Options.FsConfig.Type}}');
    });
</script>
{{end}}