Skip to content

Commit

Permalink
images get inserted without having to close the facebox and open it a…
Browse files Browse the repository at this point in the history
…gain
  • Loading branch information
Jeff Kreeftmeijer committed Jun 4, 2010
1 parent 02189c4 commit 822b99f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
12 changes: 6 additions & 6 deletions app/controllers/wysihat_files_controller.rb
Expand Up @@ -3,19 +3,19 @@ def index
@wysihat_file, @wysihat_files = WysihatFile.new, WysihatFile.all
render :layout => false
end

def create
@wysihat_file = WysihatFile.new(params[:wysihat_file])
@wysihat_file = WysihatFile.new(:file => params[:wysihat_file][:file])

responds_to_parent do
render :update do |page|
if(@wysihat_file.save)
page.insert_html :bottom, :wysihat_files, :partial => 'wysihat_file', :object => @wysihat_file
page.insert_html :bottom, :wysihat_files, :partial => 'wysihat_file', :object => @wysihat_file
end
end
end
end
end

def destroy
@wysihat_file = WysihatFile.find(params[:id])
respond_to do |wants|
Expand Down
9 changes: 7 additions & 2 deletions app/helpers/wysihat_files_helper.rb
@@ -1,13 +1,18 @@
module WysihatFilesHelper
def include_link(file)
def include_link(file)
function = file.file_content_type.starts_with?('image') ?
".insertImage(this.href);" :
".insertHTML('<a href=\"' + this.href + '\">#{file.file_file_name}</a>');"

link_to_function(
file.file_file_name,
"$$('iframe##{params[:editor]}')[0]#{function}facebox.close();",
"$$('iframe##{editor_id}')[0]#{function}facebox.close();",
:href => file.file.url
)
end

def editor_id
return params[:wysihat_file][:editor] if params[:wysihat_file] && params[:wysihat_file][:editor]
params[:editor]
end
end
6 changes: 4 additions & 2 deletions app/views/wysihat_files/_form.html.erb
@@ -1,13 +1,15 @@
<% form_for @wysihat_file, :html => { :multipart => true, :target => 'file_upload' } do |f| %>

<%= f.hidden_field(:editor, :value => params[:editor]) %>

<p>
<%= f.label :file %><br/>
<%= f.file_field :file %>
</p>
<p>
<%= f.submit %>
</p>

<% end %>

<iframe id='file_upload' name="file_upload" style="width:1px;height:1px;border:0px" src="about:blank"></iframe>

0 comments on commit 822b99f

Please sign in to comment.