<%= stylesheet_link_tag  'select2' %>
<div class="box-body">
  <% if @all_page.errors.any? %>
    <%= raw errors_to_html(@all_page.errors) %>
  <% end %>
  <div class="form-group">
    <label>Nazwa skrócona</label>
    <%= text_field :all_page, :name, class: "form-control", placeholder: 'Nazwa' %>
  </div>
  <div class="form-group">
    <label>Tytuł na liście wpisów</label>
    <%= text_field :all_page, :title, class: "form-control", placeholder: 'Tytuł' %>
  </div>
  <div class="form-group">
    <label>Krótki opis dla Wpisu (wyświetlany na liście skróconej)</label>
    <%= text_area :all_page, :small_text, :class => "form-control" %>
  </div>
  <div class="form-group">
    <label>Treść</label>
    <%= text_area :all_page, :full_text, :class => "summernote" %>
  </div>
  <div class="box-footer">
    <%= hidden_field :all_page, :type_of %>
    <%= hidden_field :all_page, :article_id %>
    <%= hidden_field_tag 'publish', '0' %>
    <%= submit_tag 'Zapisz', class: "btn btn-primary" %>
    <%= link_to 'Zapisz i Opublikuj', '#', class: 'btn btn-success', onclick: 'publishForm()' %>
    <% if action_name.eql?('edit') %>
    <%= link_to 'Podgląd', '/site/preview/' + @all_page.id.to_s, class: 'btn btn-info pull-right', target: '__blank' %>
    <% end %>
  </div>

</div>
<% content_for :footer_scripts do %>
<%= javascript_include_tag 'select2' %>
  <script type="text/javascript">
  function publishForm() {
    $('#publish').val('1');
    <% if action_name.eql?('edit') %>
      form = document.getElementById('all_page_form_id');
      Rails.fire(form, 'submit');
    <% else %>
      $('#all_page_form_id').submit();
    <% end %>
    //$('#all_page_form_id').dispatchEvent(new Event('submit', {bubbles: true}));
  }
    $(document).ready(function() {
      $('.select2').select2();
      $('.summernote').summernote({
        height: 300,
        tabsize: 2,
        lang: 'pl-PL',
        toolbar: [
          ['style'],
          ['style', ['bold', 'italic', 'underline', 'hr', 'strikethrough', 'clear', 'fontname', 'superscript', 'subscript']],
          ['fontsize', ['fontsize']],
          ['color', ['color']],
          ['para', ['ul', 'ol', 'paragraph']],
          ['insert', ['picture', 'link', 'video']],
          ['table', ['table']],
          ["view", ["fullscreen", "codeview"]],
          ['height', ['height']],
          ['history', ['undo', 'redo']],
          ['help', ['help']]
        ]
      });
    });
  </script>
  <% end %>
