
<%= render '/shared/errors_list', error_object: dotation %>
<div class="form-group">
  <%= form.label :name %>
  <%= form.text_field :name, class: 'form-control', placeholder: 'Wprowadź nazwę' %>
</div>
 <div class="form-group">
   <%= form.label :formal_name %>
   <%= form.text_field :formal_name, class: 'form-control', placeholder: 'Wprowadź nazwę formalną' %>
</div>

<div class="row">
  <div class="col-md-4">
    <div class="form-group">
      <%= form.label :points %>
      <%= form.text_field :points, class: 'form-control', placeholder: 'Wprowadź punktację dla tej dotacji' %>
    </div>
  </div>
  <div class="col-md-4">
    <%= form.label :date_from %>
    <div class="input-group date" id="date_from_date" data-target-input="nearest">
      <%= form.text_field :date_from, class: 'form-control datetimepicker-input', 'data-target': '#date_from_date', placeholder: 'Wprowadź datę' %>
      <div class="input-group-append" data-target="#date_from_date" data-toggle="datetimepicker">
        <div class="input-group-text"><i class="fa fa-calendar"></i></div>
      </div>
    </div>
  </div>
  <div class="col-md-4">
    <%= form.label :date_to %>
    <div class="input-group date" id="date_from_to" data-target-input="nearest">
      <%= form.text_field :date_to, class: 'form-control datetimepicker-input', 'data-target': '#date_from_to', placeholder: 'Wprowadź datę' %>
      <div class="input-group-append" data-target="#date_from_to" data-toggle="datetimepicker">
        <div class="input-group-text"><i class="fa fa-calendar"></i></div>
      </div>
    </div>
  </div>
</div>
<div class="row">
  <div class="col-md-4">
    <%= form.label :start_date %>
    <div class="input-group date" id="start_date_date" data-target-input="nearest">
      <%= form.text_field :start_date, class: 'form-control datetimepicker-input', 'data-target': '#start_date_date', placeholder: 'Wprowadź datę' %>
      <div class="input-group-append" data-target="#start_date_date" data-toggle="datetimepicker">
        <div class="input-group-text"><i class="fa fa-calendar"></i></div>
      </div>
    </div>
  </div>
  <div class="col-md-4">
    <%= form.label :end_date %>
    <div class="input-group date" id="end_date_date" data-target-input="nearest">
      <%= form.text_field :end_date, class: 'form-control datetimepicker-input', 'data-target': '#end_date_date', placeholder: 'Wprowadź datę' %>
      <div class="input-group-append" data-target="#end_date_date" data-toggle="datetimepicker">
        <div class="input-group-text"><i class="fa fa-calendar"></i></div>
      </div>
    </div>
  </div>
  <div class="col-md-4">
    <%= form.label :announcement_date %>
    <div class="input-group date" id="announcement_date_date" data-target-input="nearest">
      <%= form.text_field :announcement_date, class: 'form-control datetimepicker-input', 'data-target': '#announcement_date_date', placeholder: 'Wprowadź datę' %>
      <div class="input-group-append" data-target="#announcement_date_date" data-toggle="datetimepicker">
        <div class="input-group-text"><i class="fa fa-calendar"></i></div>
      </div>
    </div>
  </div>
</div>
<div class="row">
  <div class="col-md-4">
    <div class="form-check">
      <%= form.check_box(:start_date_quarter, { class: 'form-check-input' }) %>
      <%= form.label :start_date_quarter %>
    </div>
  </div>
  <div class="col-md-4">
    <div class="form-check">
    <%= form.check_box(:end_date_quarter, { class: 'form-check-input' }) %>
    <%= form.label :end_date_quarter %>
    </div>
  </div>
  <div class="col-md-4">
    <div class="form-check">
      <%= form.check_box(:ann_date_quarter, { class: 'form-check-input' }) %>
      <%= form.label :ann_date_quarter %>
  </div>
</div>
<div class="form-group">
    <%= form.label :localization %>
    <%= form.text_field :localization, class: 'form-control', placeholder: 'Wprowadź region' %>
  </div>
</div>
<div class="row">
  <div class="col-md-6">
    <div class="row">
      <div class="col-md-9">
        <div class="form-group">
          <%= form.label :min_amount %>
          <%= form.text_field :min_amount, class: 'form-control', placeholder: 'Minimalna wartość projektu' %>
        </div>
      </div>
      <div class="col-md-3">
        <div class="form-group">
          <%= form.label :min_amount_curr_id %>
          <%= form.select(:min_amount_curr_id, @currencies.collect {|p| [ p.name, p.id ] }, { include_blank: false }, class: 'form-control select2' ) %>
        </div>
      </div>
    </div>
  </div>
  <div class="col-md-6">
    <div class="row">
      <div class="col-md-9">
        <div class="form-group">
          <%= form.label :max_amount %>
          <%= form.text_field :max_amount, class: 'form-control', placeholder: 'Maksymalna wartość projektu' %>
        </div>
      </div>
      <div class="col-md-3">
        <div class="form-group">
          <%= form.label :max_amount_curr_id %>
          <%= form.select(:max_amount_curr_id, @currencies.collect {|p| [ p.name, p.id ] }, { include_blank: false, }, class: 'form-control select2' ) %>
        </div>
      </div>
    </div>
  </div>
</div>
<div class="row">
  <div class="col-md-6">
    <div class="row">
      <div class="col-md-9">
        <div class="form-group">
          <%= form.label :min_dot_ammount %>
          <%= form.text_field :min_dot_ammount, class: 'form-control', placeholder: 'Minimalna wartość dotacji' %>
        </div>
      </div>
      <div class="col-md-3">
        <div class="form-group">
          <%= form.label :min_dot_amount_curr_id %>
          <%= form.select(:min_dot_amount_curr_id, @currencies.collect {|p| [ p.name, p.id ] }, { include_blank: false }, class: 'form-control select2' ) %>
        </div>
      </div>
    </div>
  </div>
  <div class="col-md-6">
    <div class="row">
      <div class="col-md-9">
        <div class="form-group">
          <%= form.label :max_dot_ammount %>
          <%= form.text_field :max_dot_ammount, class: 'form-control', placeholder: 'Maksymalna wartość dotacji' %>
        </div>
      </div>
      <div class="col-md-3">
        <div class="form-group">
          <%= form.label :max_dot_amount_curr_id %>
          <%= form.select(:max_dot_amount_curr_id, @currencies.collect {|p| [ p.name, p.id ] }, { include_blank: false, }, class: 'form-control select2' ) %>
        </div>
      </div>
    </div>
  </div>
</div>
<div class="form-group">
  <%= form.label :max_percent %>
  <%= form.text_field :max_percent, class: 'form-control', placeholder: 'Maksymalny poziom dofinansowania' %>
</div>
<div class="form-group">
  <%= form.label :company_sizes %>
  <%= form.select(:company_size_ids, @company_sizes.collect {|p| [ p.name, p.id ] }, { include_blank: false }, { class: 'form-control duallistbox', multiple: true } ) %>
</div>
<div class="form-group">
  <%= form.label :company_activities %>
  <%= form.select(:company_activity_ids, @company_activities.collect {|p| [ p.name, p.id ] }, { include_blank: false }, { class: 'form-control duallistbox', multiple: true } ) %>
</div>
<div class="form-group">
  <%= form.label :projects %>
  <%= form.select(:project_ids, @projects.collect {|p| [ p.name, p.id ] }, { include_blank: false }, { class: 'form-control duallistbox', multiple: true } ) %>
</div>
<div class="form-group">
  <%= form.label :expenses %>
  <%= form.select(:expense_ids, @expenses.collect {|p| [ p.name, p.id ] }, { include_blank: false }, { class: 'form-control duallistbox', multiple: true } ) %>
</div>
<div class="row">
  <div class="col-md-6">
    <div class="form-group">
      <%= form.label :expert_id %>
      <%= form.select(:expert_id, @experts.collect {|p| [ p.name, p.id ] }, { include_blank: true }, class: 'form-control select2' ) %>
    </div>
  </div>
  <div class="col-md-6">
    <div class="form-group">
      <%= form.label :expert_info %>
      <%= form.text_area :expert_info, class: 'form-control', placeholder: 'Opinia eksperta' %>    </div>
  </div>
</div>
<div class="form-group">
  <%= form.label :full_descr %>
  <%= form.text_area :full_descr, class: 'form-control', placeholder: 'Opis dotacji' %>
</div>
<div class="form-group">
  <%= form.label :positioning_text %>
  <%= form.text_area :positioning_text, class: 'form-control', placeholder: 'Tekst pozycjonujący' %>
</div>
<div class="form-group">
  <%= form.label :partner_id %>
  <%= form.select(:partner_id, @partners.collect {|p| [ p.name, p.id ] }, { include_blank: false }, class: 'form-control select2' ) %>
</div>
<div class="form-group">
  <%= form.label :tags %>
  <%= form.select(:tag_ids, @tags.collect {|p| [ p.name, p.id ] }, { include_blank: false }, { class: 'form-control duallistbox', multiple: true } ) %>
</div>

<div class="card-footer">
  <%= link_to '< Wróć', grants_path, class: 'btn btn-info' %>
  <button type="submit" class="btn btn-primary">Zapisz</button>
</div>

<script type="text/javascript">
  $( document ).ready(function() {
    tinymce.remove('#dotation_full_descr');
    tinymce.remove('#dotation_expert_info');
    tinymce.remove('#dotation_positioning_text');
    tinymce.init({
      selector: '#dotation_full_descr',
      height: 500,
      menubar: false,
      plugins: [
        'advlist', 'autolink', 'lists', 'link', 'image', 'charmap', 'preview',
        'anchor', 'searchreplace', 'visualblocks', 'code', 'fullscreen',
        'insertdatetime', 'media', 'table', 'code', 'wordcount'
      ],
      toolbar: 'undo redo | blocks | ' +
      'bold italic backcolor | alignleft aligncenter ' +
      'alignright alignjustify | bullist numlist outdent indent | ' +
      'removeformat link image media | table tableinsertdialog tablecellprops tableprops advtablerownumbering',
      /* enable title field in the Image dialog*/
      image_title: true,
      /* enable automatic uploads of images represented by blob or data URIs*/
      automatic_uploads: true,
      /*
        URL of our upload handler (for more details check: https://www.tiny.cloud/docs/configure/file-image-upload/#images_upload_url)
        images_upload_url: 'postAcceptor.php',
        here we add custom filepicker only to Image dialog
      */
      file_picker_types: 'image',
      /* and here's our custom image picker*/
      file_picker_callback: (cb, value, meta) => {
        const input = document.createElement('input');
        input.setAttribute('type', 'file');
        input.setAttribute('accept', 'image/*');

        input.addEventListener('change', (e) => {
          const file = e.target.files[0];

          const reader = new FileReader();
          reader.addEventListener('load', () => {
            /*
              Note: Now we need to register the blob in TinyMCEs image blob
              registry. In the next release this part hopefully won't be
              necessary, as we are looking to handle it internally.
            */
            const id = 'blobid' + (new Date()).getTime();
            const blobCache =  tinymce.activeEditor.editorUpload.blobCache;
            const base64 = reader.result.split(',')[1];
            const blobInfo = blobCache.create(id, file, base64);
            blobCache.add(blobInfo);

            /* call the callback and populate the Title field with the file name */
            cb(blobInfo.blobUri(), { title: file.name });
          });
          reader.readAsDataURL(file);
        });

        input.click();
      },
      content_style: 'body { font-family:Helvetica,Arial,sans-serif; font-size:16px }'
    });

    tinymce.init({
      selector: '#dotation_expert_info',
      height: 500,
      menubar: false,
      plugins: [
        'advlist', 'autolink', 'lists', 'link', 'image', 'charmap', 'preview',
        'anchor', 'searchreplace', 'visualblocks', 'code', 'fullscreen',
        'insertdatetime', 'media', 'table', 'code', 'wordcount'
      ],
      toolbar: 'undo redo | blocks | ' +
      'bold italic backcolor | alignleft aligncenter ' +
      'alignright alignjustify | bullist numlist outdent indent | ' +
      'removeformat link | table tableinsertdialog tablecellprops tableprops advtablerownumbering',
      content_style: 'body { font-family:Helvetica,Arial,sans-serif; font-size:16px }',
      language: 'pl'
    });

    tinymce.init({
      selector: '#dotation_positioning_text',
      height: 500,
      menubar: false,
      plugins: [
        'advlist', 'autolink', 'lists', 'link', 'image', 'charmap', 'preview',
        'anchor', 'searchreplace', 'visualblocks', 'code', 'fullscreen',
        'insertdatetime', 'media', 'table', 'code', 'wordcount'
      ],
      toolbar: 'undo redo | blocks | ' +
      'bold italic backcolor | alignleft aligncenter ' +
      'alignright alignjustify | bullist numlist outdent indent | ' +
      'removeformat link | table tableinsertdialog tablecellprops tableprops advtablerownumbering',
      content_style: 'body { font-family:Helvetica,Arial,sans-serif; font-size:16px }'
    });
  });
</script>
