Remove new_nested action from images controller. Use cocoon gem to manage new nested fields creation on images.
This commit is contained in:
@@ -22,7 +22,7 @@
|
||||
</div>
|
||||
|
||||
<div class="images small-12 column">
|
||||
<%= render 'images/nested_images', imageable: @investment %>
|
||||
<%= render 'images/nested_image', imageable: @investment, f: f %>
|
||||
</div>
|
||||
|
||||
<div class="documents small-12 column">
|
||||
|
||||
@@ -10,13 +10,8 @@
|
||||
|
||||
<%= link_to_add_association t('documents.form.add_new_document'), f, :documents,
|
||||
partial: "documents/document_fields",
|
||||
render_options: {
|
||||
locals: {
|
||||
document: Document.new(documentable: documentable)
|
||||
},
|
||||
},
|
||||
id: "new_document_link",
|
||||
class: "button hollow",
|
||||
class: "button hollow #{"hide" if documentable.documents.count >= documentable.class.max_documents_allowed}",
|
||||
data: {
|
||||
association_insertion_node: "#nested-documents",
|
||||
association_insertion_method: "append"
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
<%= f.file_field :attachment,
|
||||
accept: imageable_accepted_content_types_extensions,
|
||||
label: false,
|
||||
class: 'js-document-attachment',
|
||||
class: 'js-image-attachment',
|
||||
data: {
|
||||
url: direct_uploads_url("direct_upload[resource_type]": @image.imageable_type,
|
||||
"direct_upload[resource_id]": @image.imageable_id,
|
||||
|
||||
31
app/views/images/_image_fields.html.erb
Normal file
31
app/views/images/_image_fields.html.erb
Normal file
@@ -0,0 +1,31 @@
|
||||
<div id="<%= dom_id(f.object) %>" class="image direct-upload">
|
||||
<%= f.hidden_field :id %>
|
||||
<%= f.hidden_field :user_id, value: current_user.id %>
|
||||
<%= f.hidden_field :cached_attachment %>
|
||||
|
||||
<div class="small-12 column title">
|
||||
<%= f.text_field :title, placeholder: t("images.new.form.title_placeholder") %>
|
||||
</div>
|
||||
|
||||
<%= render_image(f.object, :thumb, false) if f.object.attachment.exists? %>
|
||||
|
||||
<div class="small-12 column attachment-actions">
|
||||
<div class="small-9 column action-add attachment-errors image-attachment">
|
||||
<%= render_image_attachment(f, imageable, f.object) %>
|
||||
</div>
|
||||
<div class="small-3 column action-remove text-right">
|
||||
<%= render_destroy_image_link(f.object) %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="small-6 column">
|
||||
<p class="file-name">
|
||||
<%= image_attachment_file_name(f.object) %>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="small-12 column">
|
||||
<div class="progress-bar-placeholder"><div class="loading-bar"></div></div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
@@ -1,51 +0,0 @@
|
||||
<div id="<%= image_nested_field_wrapper_id %>" class="image direct-upload">
|
||||
<%= hidden_field_tag :id,
|
||||
image.id,
|
||||
name: image_nested_field_name(image, :id),
|
||||
id: image_nested_field_id(image, :id) if image.persisted? %>
|
||||
<%= hidden_field_tag :user_id,
|
||||
current_user.id,
|
||||
name: image_nested_field_name(image, :user_id),
|
||||
id: image_nested_field_id(image, :user_id) %>
|
||||
<%= hidden_field_tag :cached_attachment,
|
||||
image.cached_attachment,
|
||||
name: image_nested_field_name(image, :cached_attachment),
|
||||
id: image_nested_field_id(image, :cached_attachment) %>
|
||||
|
||||
<div class="small-12 column title">
|
||||
<%= label_tag :title,
|
||||
t("activerecord.attributes.image.title"),
|
||||
class: image.errors[:title].any? ? "error" : "" %>
|
||||
|
||||
<%= text_field_tag :title,
|
||||
image.title,
|
||||
placeholder: t("images.new.form.title_placeholder"),
|
||||
name: image_nested_field_name(image, :title),
|
||||
id: image_nested_field_id(image, :title),
|
||||
class: image.errors[:title].any? ? "error" : "" %>
|
||||
<% if image.errors[:title].any? %>
|
||||
<small class="error"><%= image.errors[:title].join(", ") %></small>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<%= render_image(image, :thumb, false) if image.attachment.exists? %>
|
||||
|
||||
<div class="small-12 column attachment-actions">
|
||||
<div class="small-9 column action-add attachment-errors image-attachment">
|
||||
<%= render_image_attachment(image) %>
|
||||
</div>
|
||||
<div class="small-3 column action-remove text-right">
|
||||
<%= render_destroy_image_link(image) %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="small-6 column">
|
||||
<p class="file-name">
|
||||
<%= image_attachment_file_name(image) %>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="small-12 column">
|
||||
<div class="progress-bar-placeholder"><div class="loading-bar"></div></div>
|
||||
</div>
|
||||
</div>
|
||||
25
app/views/images/_nested_image.html.erb
Normal file
25
app/views/images/_nested_image.html.erb
Normal file
@@ -0,0 +1,25 @@
|
||||
<div>
|
||||
<%= f.label :image, t("images.form.title") %>
|
||||
<p class="help-text"><%= imageables_note(imageable) %></p>
|
||||
|
||||
<div id="nested-image">
|
||||
<%= f.fields_for :image do |image_builder| %>
|
||||
<%= render 'images/image_fields', f: image_builder, imageable: imageable %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<%= link_to_add_association t('images.form.add_new_image'), f, :image,
|
||||
force_non_association_create: true,
|
||||
partial: "images/image_fields",
|
||||
id: "new_image_link",
|
||||
class: "button hollow #{"hide" if imageable.image.present?}",
|
||||
render_options: {
|
||||
locals: { imageable: imageable }
|
||||
},
|
||||
data: {
|
||||
association_insertion_node: "#nested-image",
|
||||
association_insertion_method: "append"
|
||||
} %>
|
||||
|
||||
<hr>
|
||||
@@ -1,16 +0,0 @@
|
||||
<div class="images-list">
|
||||
<%= label_tag :image, t("images.form.title") %>
|
||||
<p class="help-text"><%= imageables_note(imageable) %></p>
|
||||
|
||||
<%= render 'images/nested_fields', image: imageable.image, index: 0 if imageable.image.present? %>
|
||||
</div>
|
||||
|
||||
<% if imageable.image.blank? %>
|
||||
<%= link_to t("images.form.add_new_image"),
|
||||
new_nested_images_path(imageable_type: imageable.class.name, index: 0),
|
||||
remote: true,
|
||||
id: "new_image_link",
|
||||
class: "button hollow" %>
|
||||
<% end %>
|
||||
|
||||
<hr>
|
||||
@@ -1,7 +1 @@
|
||||
App.Imageable.destroyNestedImage("<%= image_nested_field_wrapper_id %>", "<%= j render('layouts/flash') %>")
|
||||
<% new_image_link = link_to t("images.form.add_new_image"),
|
||||
new_nested_images_path(imageable_type: @image.imageable_type),
|
||||
remote: true,
|
||||
id: "new_image_link",
|
||||
class: "button hollow" %>
|
||||
App.Imageable.updateNewImageButton("<%= j new_image_link %>")
|
||||
App.Imageable.destroyNestedImage("<%= dom_id(@image) %>")
|
||||
@@ -1,2 +0,0 @@
|
||||
App.Imageable.new("<%= j render('images/nested_fields', image: @image) %>")
|
||||
App.DirectUploads.initializeDirectUpload($('#nested_image input.direct_upload_attachment[type=file]'))
|
||||
@@ -1,12 +0,0 @@
|
||||
<% if params[:nested_image] == "true" %>
|
||||
|
||||
App.Imageable.uploadNestedImage("<%= image_nested_field_wrapper_id %>",
|
||||
"<%= j render('images/nested_fields', image: @image) %>",
|
||||
<%= @image.cached_attachment.present? %>)
|
||||
<% else %>
|
||||
|
||||
App.Imageable.uploadPlainImage("plain_image_fields",
|
||||
"<%= j render('images/plain_fields', image: @image) %>",
|
||||
<%= @image.cached_attachment.present? %>)
|
||||
|
||||
<% end %>
|
||||
@@ -47,7 +47,7 @@
|
||||
</div>
|
||||
|
||||
<div class="images small-12 column">
|
||||
<%= render 'images/nested_images', imageable: @proposal %>
|
||||
<%= render 'images/nested_image', imageable: @proposal, f: f %>
|
||||
</div>
|
||||
|
||||
<div class="documents small-12 column">
|
||||
|
||||
Reference in New Issue
Block a user