Skip to content

Commit

Permalink
Remove image - Fix SpinaCMS#376
Browse files Browse the repository at this point in the history
  • Loading branch information
Bramjetten committed Jun 5, 2018
1 parent 7674138 commit 7214431
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
(() => {
const application = Stimulus.Application.start()

application.register("image-form", class extends Stimulus.Controller {
static get targets() {
return ["image", "field", "button"]
}

remove(e) {
// Prevent link
e.preventDefault()
e.stopPropagation()

// Remove image and reset field
this.imageTarget.remove()
this.buttonTarget.remove()
this.fieldTarget.value = null
}

})
})()
2 changes: 1 addition & 1 deletion app/assets/stylesheets/spina/_forms.sass
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ input.datepicker
&:hover .button
background: tint(#efefef, 20%)

&:active .button
.button:active
background: shade(#efefef, 10%)

.placeholder
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/spina/admin/media_picker_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def show

def select
if params[:multiple]
@images = Image.find(params[:image_ids])
@images = Image.where(id: params[:image_ids])
else
@image = Image.find(params[:image_id])
end
Expand Down
3 changes: 0 additions & 3 deletions app/controllers/spina/admin/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ def update
format.html { redirect_to spina.edit_admin_page_url(@page, params: {locale: @locale}), flash: {success: t('spina.pages.saved')} }
format.js
else
50.times do
Rails.logger.info @page.errors.inspect
end
format.html do
@page_parts = @page.view_template_page_parts(current_theme).map { |part| @page.part(part) }
render :edit, layout: 'spina/admin/admin'
Expand Down
1 change: 1 addition & 0 deletions app/views/spina/admin/media_picker/select.js.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
let hidden_input = $("input[data-hidden-field-id='<%= j params[:hidden_field_id] %>']");
hidden_input.parents('.media_picker').find('.image').remove();
hidden_input.val("");

<% if @image.present? %>
hidden_input.parents('.media_picker').append("<%=j render partial: 'spina/admin/images/image', object: @image, locals: {simple: true} %>");
Expand Down
13 changes: 10 additions & 3 deletions app/views/spina/admin/partables/images/_form.html.haml
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
.horizontal-form-label
= f.object.title
.horizontal-form-content
.horizontal-form-content{data: {controller: "image-form"}}
= link_to admin_media_picker_path(selected_ids: [f.object.partable_id], hidden_field_id: "media_picker_#{f.object.object_id}"), remote: true, class: 'media_picker clearfix' do
.placeholder
%span.button.button-small.button-round
%i.icon.icon-dots
=t 'spina.images.choose_image'

- if f.object.partable.file.attached?
%br/

%span.button.button-small.button-round{data: {action: "click->image-form#remove", target: "image-form.button"}}
%i.icon.icon-trash
=t 'spina.images.remove_image'

- if f.object.partable.file.attached?
.image
.image{data: {target: 'image-form.image'}}
= image_tag variant(f.object.partable.file, resize: "300x300^", crop: "300x300+0+0")

= f.hidden_field :partable_id, data: {hidden_field_id: "media_picker_#{f.object.object_id}"}
= f.hidden_field :partable_id, data: {hidden_field_id: "media_picker_#{f.object.object_id}", target: 'image-form.field'}
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ en:
upload: Upload images
choose_images: Choose images
choose_image: Choose image
remove_image: Remove image

wysiwyg:
paragraph: Paragraph
Expand Down
1 change: 1 addition & 0 deletions config/locales/nl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ nl:
delete: Verwijderen
upload: kies een bestand
choose_image: Kies afbeelding
remove_image: Verwijder afbeelding

forgot_password:
new: Wachtwoord vergeten
Expand Down

0 comments on commit 7214431

Please sign in to comment.