<%
# encoding: utf-8
#
# Redmine plugin for Document Management System "Features"
#
# Copyright © 2011    Vít Jonáš <vit.jonas@gmail.com>
# Copyright © 2012    Daniel Munn <dan.munn@munnster.co.uk>
# Copyright © 2011-22 Karel Pičman <karel.picman@kontron.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
%>

<% html_title l(:dmsf) %>

<%= render partial: 'path', locals: { folder: @folder, filename: nil, title: l(:heading_send_documents_by_email) } %>

<%= form_tag(email_entries_path(id: @project, folder_id: @folder), { method: :post }) do %>
  <%= hidden_field_tag 'email[zipped_content]', @email_params[:zipped_content] %>
  <%= hidden_field_tag 'email[folders]', @email_params[:folders].to_json %>
  <%= hidden_field_tag 'email[files]', @email_params[:files].to_json %>
  <%= hidden_field_tag 'email[from]', @email_params[:from] %>
  <%= hidden_field_tag 'email[reply_to]', @email_params[:reply_to] %>
  <%= hidden_field_tag 'back_url', @back_url %>
  <div class="box tabular">
    <p>
      <%= label_tag '', l(:label_email_from) %>
      <%= text_field_tag 'email[from_disabled]', @email_params[:from], class: 'dmsf-full-width', disabled: true %>
    </p>
    <p>
      <%= label_tag 'email[to]', l(:label_email_to) %>
      <span>
        <%= text_field_tag 'email[to]', @email_params[:to], class: 'dmsf-full-width', required: true %>
        <%= link_to l(:button_add), add_email_dmsf_path(id: @project),
          title: l(:label_email_address_add), class: 'icon icon-add', remote: true %>
      </span>
    </p>
    <p>
      <%= label_tag 'email[cc]', l(:label_email_cc) %>
      <%= text_field_tag 'email[cc]', @email_params[:cc], class: 'dmsf-full-width' %>
    </p>
    <p>
      <%= label_tag 'email[subject]', l(:label_email_subject) %>
      <%= text_field_tag 'email[subject]', @email_params[:subject], class: 'dmsf-full-width' %>
    </p>
    <p>
      <%= label_tag '', l(:label_email_documents) %>
      <span>
        <%= link_to 'Documents.zip', download_email_entries_path(id: @project, folder_id: @folder,
                                                                 path: @email_params[:zipped_content]) %>
        <%= l(:label_or) %>
        <%= check_box_tag('email[links_only]', 1, Setting.plugin_redmine_dmsf['dmsf_documents_email_links_only'],
              onchange: "$('#public_url').toggle($('#email_links_only').prop('checked'))")
        %>
        <%= l(:label_links_only) %>
        <%= render partial: 'dmsf_public_urls/new' %>
      </span>
    </p>
    <p>
      <%= label_tag 'email[body]', l(:label_email_body) %>
      <%= text_area_tag 'email[body]', @email_params['body'], rows: '20', class: 'dmsf-full-width' %>
    </p>
    <div class="form-actions">
      <%= submit_tag l(:label_email_send), class: 'button-positive' %>
    </div>
  </div>
<% end %>

<%= wikitoolbar_for 'email_body' %>
