This commit is contained in:
rgarcia
2017-10-04 22:55:28 +02:00
parent 30a2db635d
commit 06a1b96fcd
4 changed files with 16 additions and 68 deletions

View File

@@ -19,9 +19,10 @@ class DirectUpload
if @resource_type.present? && @resource_relation.present? && (@attachment.present? || @cached_attachment.present?)
@resource = @resource_type.constantize.find_or_initialize_by(id: @resource_id)
if true #@resource.class.reflections[@resource_relation].macro == :has_one
#@relation = @resource.send("build_#{resource_relation}", relation_attributtes)
if @resource.respond_to?(:images)
@relation = @resource.images.send("build", relation_attributtes)
elsif @resource.class.reflections[@resource_relation].macro == :has_one
@relation = @resource.send("build_#{resource_relation}", relation_attributtes)
else
@relation = @resource.send(@resource_relation).build(relation_attributtes)
end

View File

@@ -1,9 +1,9 @@
<%= back_link_to admin_question_path(@answer.question) %>
<div>
<%= link_to "Add image", new_admin_answer_image_path(@answer) %>
</div>
<% @answer.images.each do |image| %>
<%= render_image(image, :large, true) if image.present? %>
<% end %>
<div>
<%= link_to "Add image", new_admin_answer_image_path(@answer) %>
</div>

View File

@@ -1,66 +1,10 @@
<%= form_for(Poll::Question::Answer.new,
url: admin_answer_images_path(@answer),
method: :post) do |f| %>
<div class="images small-12 column">
<%# render 'images/nested_image', imageable: @answer, f: f %>
<%= f.label :images, t("images.form.title") %>
<%= render 'images/nested_image', imageable: @answer, f: f, image_fields: :images %>
</div>
<p class="help-text"><%# imageables_note(imageable) %></p>
<div id="nested-image">
<%= f.fields_for :images do |image_builder| %>
<%# render 'images/image_fields', f: image_builder, imageable: imageable %>
<div id="<%= dom_id(f.object) %>" class="image direct-upload nested-fields">
<%= 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.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, @answer, f.object) %>
</div>
<div class="small-3 column action-remove text-right">
<%= render_destroy_image_link(f, 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>
<hr>
</div>
<% end %>
</div>
<%= link_to_add_association t('images.form.add_new_image'), f, :images,
force_non_association_create: true,
partial: "images/image_fields",
id: "new_image_link",
class: "button hollow",
render_options: {
locals: { imageable: @answer }
},
data: {
association_insertion_node: "#nested-image",
association_insertion_method: "append"
} %>
</div>
<%= f.submit "Save image" %>
<% end %>

View File

@@ -1,17 +1,20 @@
<%= f.label :image, t("images.form.title") %>
<%= image_fields ||= :image %>
<%= f.label image_fields, t("images.form.title") %>
<p class="help-text"><%= imageables_note(imageable) %></p>
<div id="nested-image">
<%= f.fields_for :image do |image_builder| %>
<%= f.fields_for image_fields do |image_builder| %>
<%= render 'images/image_fields', f: image_builder, imageable: imageable %>
<% end %>
</div>
<%= link_to_add_association t('images.form.add_new_image'), f, :image,
<%= link_to_add_association t('images.form.add_new_image'), f, image_fields,
force_non_association_create: true,
partial: "images/image_fields",
id: "new_image_link",
class: "button hollow #{"hide" if imageable.image.present?}",
class: "button hollow
#{"hide" if image_fields == :image && imageable.image.present?}",
render_options: {
locals: { imageable: imageable }
},