Skip to content

Commit

Permalink
Droppable
Browse files Browse the repository at this point in the history
  • Loading branch information
Bramjetten committed Aug 4, 2017
1 parent 3246d29 commit 6b94d6d
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 11 deletions.
1 change: 1 addition & 0 deletions app/assets/javascripts/spina/admin/application.coffee.erb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#= require ./uploads
#= require ./navigation
#= require ./notifications
#= require ./media_gallery

#= require ./account
#= require ./confirm_delete
Expand Down
40 changes: 40 additions & 0 deletions app/assets/javascripts/spina/admin/media_gallery.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
ready = ->
$('.media-folder').droppable(
drop: (event, ui) ->
$(ui.draggable).addClass('dropped').fadeOut()
photoCount = parseInt($(this).find('.media-folder-thumbnail').attr('data-badge'))
imgSrc = $(ui.draggable).find('img').attr('src')

$(this).removeClass('dropping')
$(this).find('.media-folder-thumbnail').attr('data-badge', photoCount + 1)
$(this).find('.media-folder-thumbnail img').attr('src', imgSrc)

url = $(this).attr('data-add-to-media-folder-url')
photo_id = $(ui.draggable).find('input[type="radio"]').val()

$.ajax({
url: url,
type: 'PUT',
data: {
photo_id: photo_id
},
dataType: 'json',
success: (result) ->
console.log result
})

over: (event, ui) ->
$(ui.draggable).addClass('dropping')

$(this).addClass('dropping')
out: (event, ui) ->
$(ui.draggable).removeClass('dropping')

$(this).removeClass('dropping')
)

$('.gallery .infinite-scroll .item').draggable(
revert: 'invalid'
)

$(document).on 'turbolinks:load', ready
25 changes: 16 additions & 9 deletions app/assets/stylesheets/spina/_gallery.sass
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
margin: 8px
overflow: hidden
position: relative
transition: transform .3s ease
width: 150px
z-index: 3

Expand Down Expand Up @@ -86,16 +87,22 @@
word-break: break-word
z-index: 3

&:hover
.overlay
background: rgba(0, 0, 0, 0.5)
// &:hover
// .overlay
// background: rgba(0, 0, 0, 0.5)
a
opacity: 1
transform: translateY(0%)
// a
// opacity: 1
// transform: translateY(0%)
.photo-name
transform: translateY(0%)
// .photo-name
// transform: translateY(0%)
&.dropping:not(.media-folder)
transform: scale(0.8)

&.dropped:not(.media-folder)
transform: scale(0)

form
height: 100%
Expand Down Expand Up @@ -276,7 +283,7 @@
justify-content: center
line-height: 20px

&:hover
&:hover, &.dropping
.media-folder-thumbnail
transform: rotate(-4deg)
.media-folder-thumbnail:after
Expand Down
8 changes: 7 additions & 1 deletion app/controllers/spina/admin/photos_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ def media_folder
@photos = @media_folder.photos.sorted.page(params[:page])
end

def add_to_media_folder
@media_folder = MediaFolder.find(params[:id])
@media_folder.photos << Photo.find(params[:photo_id])
render json: @media_folder
end

def media_library
redirect_to spina.admin_photos_path
end
Expand All @@ -32,7 +38,7 @@ def create
def destroy
@photo = Photo.find(params[:id])
@photo.destroy
redirect_to spina.admin_photos_url
redirect_back fallback_location: spina.admin_photos_url
end

def photo_select
Expand Down
2 changes: 1 addition & 1 deletion app/views/spina/admin/photos/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
= f.file_field :files, multiple: true, data: {customfileinput: true}

- @media_folders.each do |media_folder|
= link_to media_folder_admin_photos_path(media_folder), class: 'item media-folder' do
= link_to media_folder_admin_photos_path(media_folder), class: 'item media-folder', data: {add_to_media_folder_url: add_to_media_folder_admin_photos_url(media_folder)} do
.media-folder-thumbnail{data: {badge: media_folder.photos.count}}
- if media_folder.photos.any?
= image_tag media_folder.photos.last.file.thumb
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
post 'insert_photo/:page_part_id' => 'photos#insert_photo', as: :insert_photo
post 'insert_photo_collection/:page_part_id' => 'photos#insert_photo_collection', as: :insert_photo_collection
get 'folder/:id' => 'photos#media_folder', as: :media_folder
put 'folder/:id' => 'photos#add_to_media_folder', as: :add_to_media_folder
end
end
end
Expand Down

0 comments on commit 6b94d6d

Please sign in to comment.