Skip to content

Commit

Permalink
now reloading image listing and shows a flash message
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-Philippe Boily committed Aug 2, 2012
1 parent c4873b1 commit 4b3a41d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
18 changes: 16 additions & 2 deletions images/app/assets/javascript/refinery/images.js.coffee.erb
Expand Up @@ -51,8 +51,7 @@ class Images
if getParameterByName("modal") == "true"
window.parent.document.getElementById("dialog_frame").contentDocument.location.reload(true);
else
$('#flash_container', window.parent.document).html($("#inner_flash_container").html())
parent.$(".ui-icon-closethick").trigger("click")
@set_flash_and_reload($("#inner_flash_container").html())

validate: (file) ->
max_file_size = <%= Refinery::Images.max_image_size %>
Expand Down Expand Up @@ -84,6 +83,21 @@ class Images
error: (data) ->
_this.post_error(file, data.responseText)

set_flash_and_reload: (message) ->
form = new FormData();
form.append "notice", message
_this = @ # save current scope so we can use current object methods within $.ajax
$.ajax
type: 'POST'
url: "/refinery/images/set_flash"
data: form
contentType: false
processData: false
success: (data) ->
window.parent.location.reload(true)
error: (data) ->
window.parent.location.reload(true)

after_do_upload: (file) ->
@files.remove file
@upload_next()
Expand Down
5 changes: 5 additions & 0 deletions images/app/controllers/refinery/admin/images_controller.rb
Expand Up @@ -75,6 +75,11 @@ def create
end
end

def set_flash
flash.notice = t('uploaded_successfully', :scope => 'refinery.admin.images.form')
render :nothing => true, :layout => false
end

protected

def init_dialog
Expand Down
1 change: 1 addition & 0 deletions images/config/routes.rb
Expand Up @@ -5,5 +5,6 @@
resources :images, :except => :show do
get :insert, :on => :collection
end
post "images/set_flash" => "images#set_flash"
end
end

0 comments on commit 4b3a41d

Please sign in to comment.