add_item.html.erb 5.31 KB
<% uuid = SecureRandom.uuid %>
<% if @row_item.present? %>
    <div class="panel panel-default" data-id="<%= @row_item %>">

      <div class="panel-heading" style="margin-top:20px;margin-bottom:20px;" role="tab" id="heading_<%= @row_item %>">
        <h4>
          <div class="row">
            <div class="col-md-10">
              <a role="button" data-toggle="collapse" data-parent="#accordion" href="#collapse-<%= uuid %>-<%= @row_item %>" aria-expanded="true" aria-controls="collapse-<%= uuid %>-<%= @row_item %>" >
                Item <%= @row_item %>
              </a>
            </div>
            <div class="col-md-2">
              <%= link_to '#', class: 'sort-repeat-row sort-up', data: {repeat_id: params[:repeat_id]} do %>
                          <i class="fa fa-arrow-up"></i>
              <% end %>
              <%= link_to '#', class: 'sort-repeat-row sort-down', data: {repeat_id: params[:repeat_id]} do %>
                          <i class="fa fa-arrow-down"></i>
              <% end %>                        

              <%= link_to url_for(:controller => 'admin/page_contents', :action => 'delete_item', id: @obj.id, row_item: @row_item, parent_item_index: params[:parent_item_index], repeat_id: params[:repeat_id]), class: 'delete-repeat-row' do %>
                <i class="fa fa-trash"></i>
              <% end %>
            </div>
          </div>

        </h4>
      </div>

      <div id="collapse-<%= uuid %>-<%= @row_item %>" class="panel-collapse collapse" role="tabpanel" aria-labelledby="heading-<%= uuid %>-<%= @row_item %>">
        <div class="panel-body">
          <%= fields_for @obj do |form| %>
              <% sort_markers(@obj, @obj.page_content_markers.select{|item| item.row_item == @row_item && item.parent_id.to_s == params[:parent_item_index].to_s && item.repeat_id == params[:repeat_id] }).each_with_index do |item, index| %>
                  <%= form.fields_for :page_content_markers, item, child_index: (@current_row + index)   do |form2| %>
                      <div class="form-group">
                        <%= form2.label :text_value, form2.object.marker_name || form2.object.marker, :class => "control-label" %>
                        <% if form2.object.condition %>
                            <%= form2.check_box :text_value %>
                        <% end %>                        
                        <% if form2.object.get_marker_type(@obj.type_content) == 'string' %>
                            <%= form2.text_field :text_value, :class => "form-control" %>
                        <% end %>
                        <% if form2.object.get_marker_type(@obj.type_content) == 'text' %>
                            <%= form2.text_area :text_value, :class => "form-control page_html_content" %>
                        <% end %>
                        <% if form2.object.get_marker_type(@obj.type_content) == 'textarea' %>
                            <%= form2.text_area :text_value, :class => "form-control" %>
                        <% end %>                        
                        <% if form2.object.get_marker_type(@obj.type_content) == 'file' %>
                            <%= form2.hidden_field :text_value %>
                            <div class="preview">
                              <% if form2.object.text_value.present? %>
                                      <% if Kanjai::PageContentMarker.image?(form2.object.text_value) %>
                                          <div class="image-preview-block without-border">
                                            <div class="image-preview">
                                              <img src="<%= form2.object.text_value %>" alt="preview" />
                                            </div>
                                          </div>
                                      <% else %>
                                          <%= link_to 'file', form2.object.text_value %>
                                      <% end %>
                              <% end %>
                            </div>
                            <div class="btn-group">
                              <%= link_to t('actions.choose_file'), get_files_admin_images_url, class: 'btn btn-primary content-choose-image'  %>
                              <%= link_to t('actions.remove_file'), get_files_admin_images_url, class: "btn btn-danger content-remove-image #{form2.object.text_value.present? ? '' : 'not-visible'}"  %>
                            </div>  
                        <% end %>

                      </div>
                  <% end %>
              <% end %>
          <% end %>

          <%  sub_repeat_elements = @template_part.field_options.select{|item| item[:name] == 'repeat' && item[:repeatItemId].to_s == params[:repeat_id] } %>

          <% sub_repeat_elements.each do |sub_repeat_element| %>
            <% sub_row_items = @obj.page_content_markers.select{|item| item.row_item.to_i > 0 && item.parent_id == params[:parent_item_index] && item.repeat_id == sub_repeat_element[:id]}.collect(&:row_item).uniq %>

            <%= render partial: 'kanjai/admin/pages/content_types/repeat_item', locals: {repeat_element: sub_repeat_element, row_items: sub_row_items, template_part: @template_part, form: nil, margin_index: params[:margin_index].to_i + 1, parent_item_index: @row_item} %>
          <% end %>


        </div>
      </div>



    </div>



<% end %>