diff --git a/app/controllers/basil_controller.rb b/app/controllers/basil_controller.rb index 6a45d7e3..4ca0d352 100644 --- a/app/controllers/basil_controller.rb +++ b/app/controllers/basil_controller.rb @@ -322,6 +322,7 @@ class BasilController < ApplicationController user: current_user ) @commission.update(saved_at: DateTime.current) + render json: { success: true }, status: 200 end def delete @@ -330,6 +331,7 @@ class BasilController < ApplicationController user: current_user ) @commission.destroy! + render json: { success: true }, status: 200 end private diff --git a/app/controllers/content_controller.rb b/app/controllers/content_controller.rb index 651bc79e..5ff8cd9a 100644 --- a/app/controllers/content_controller.rb +++ b/app/controllers/content_controller.rb @@ -157,6 +157,8 @@ class ContentController < ApplicationController @random_image_including_private_pool_cache = ImageUpload.where( user_id: current_user.id, ).group_by { |image| [image.content_type, image.content_id] } + @basil_images = BasilCommission.where(entity: @content) + .where.not(saved_at: nil) respond_to do |format| format.html { render 'content/edit', locals: { content: @content } } diff --git a/app/views/basil/content.html.erb b/app/views/basil/content.html.erb index 1c4dbec2..c38e4635 100644 --- a/app/views/basil/content.html.erb +++ b/app/views/basil/content.html.erb @@ -190,7 +190,7 @@ function commission_basil(style) { <% else %> <%= link_to "Save", '#', class: 'purple-text js-save-commission', data: { endpoint: basil_save_path(commission) } %> <% end %> - <%= link_to "Delete", basil_delete_path(commission), class: 'red-text right right-align', style: 'margin-right: 0' %> + <%= link_to "Delete", '#', class: 'js-delete-commission red-text right right-align', style: 'margin-right: 0', data: { endpoint: basil_delete_path(commission) } %> @@ -217,5 +217,19 @@ $(document).ready(function() { console.log(data); }); }); + + $('.js-delete-commission').click(function() { + $(this).text('Deleting...'); + $(this).closest('.card').hide(); + + var delete_endpoint = $(this).data('endpoint'); + $.ajax({ + url: delete_endpoint, + type: 'DELETE', + success: function(result) { + $(this).closest('.card').hide(); + } + }); + }); }); <% end %> \ No newline at end of file diff --git a/app/views/content/form/images/_edit_list.html.erb b/app/views/content/form/images/_edit_list.html.erb index ebe3bbbf..2911cbb8 100644 --- a/app/views/content/form/images/_edit_list.html.erb +++ b/app/views/content/form/images/_edit_list.html.erb @@ -30,3 +30,31 @@ <% end %> + +<% if @basil_images.any? %> + <% @basil_images.each do |commission| %> +
+
+ <%= link_to commission.image, class: 'z-depth-1 hoverable right', target: '_new' do %> + <%= image_tag commission.image, style: 'max-width: 100%' %> + <% end %> +
+
+
+ Generated with <%= link_to 'Basil', basil_path %> + + <%# Filesize.from("#{commission.image.src_file_size}B").to_f('KB').round(2) %> + +
+
+ <%= link_to 'Open', commission.image, class: 'btn white black-text', target: '_new' %> + <%= link_to 'Delete', basil_delete_path(commission), + class: 'btn white black-text js-remove-image', + method: 'delete', + remote: true, + data: { confirm: "Are you sure? This can't be undone." } %> +
+
+
+ <% end %> +<% end %> \ No newline at end of file