Permalink
Browse files

Uploadify up and running.

  • Loading branch information...
1 parent 917a921 commit 6524e95a27ba7e0723383103012bd1585a4f1326 Dave South committed Sep 1, 2010
@@ -17,7 +17,10 @@ def edit
def create
if @photo.save
- redirect_to [@story, @photo], :notice => 'Photo successfully created'
+ respond_to do |format|
+ format.html { redirect_to [@story, @photo], :notice => 'Photo successfully created' }
+ format.js { render :text => 'Photo successfully created'}
+ end
else
render :new
end
@@ -1,2 +1,25 @@
module ApplicationHelper
+ def photo_uploadify
+ session_key_name = Rails.application.config.session_options[:key]
+ %Q{
+ <script type='text/javascript'>
+ $('#photo_upload').uploadify({
+ script : '#{story_photos_path(@story)}',
+ fileDataName : 'photo[image]',
+ uploader : '/uploadify/uploadify.swf',
+ cancelImg : '/uploadify/cancel.png',
+ fileExt : '*.png;*.jpg;*.gif',
+ sizeLimit : #{10.megabytes},
+ multi : true,
+ auto : true,
+ scriptData : {
+ '_http_accept': 'application/javascript',
+ '_method' : 'post',
+ '#{session_key_name}' : encodeURIComponent('#{u(cookies[session_key_name])}'),
+ 'authenticity_token' : encodeURIComponent('#{u(form_authenticity_token)}')
+ }
+ });
+ </script>
+ }.strip.gsub(/[\n ]+/, ' ').html_safe
+ end
end
@@ -1,14 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
- <title>MongoidCarrierwaveUploadify</title>
- <%= stylesheet_link_tag :all %>
- <%= javascript_include_tag :defaults %>
- <%= csrf_meta_tag %>
-</head>
-<body>
-
-<%= yield %>
-
-</body>
-</html>
@@ -0,0 +1,10 @@
+!!! 5
+%html{ :lang => :en }
+ %head
+ %title Mongoid/Carrier/Uploadify
+ = stylesheet_link_tag :all
+ = javascript_include_tag :defaults
+ = csrf_meta_tag
+
+ %body
+ = yield
@@ -3,5 +3,7 @@
= render 'form'
= link_to 'Show', [@story, @photo]
-\|
+|
= link_to 'Back', @story
+|
+= link_to 'Destroy', [@story, @photo], :confirm => 'Are you sure?', :method => :delete
@@ -32,3 +32,15 @@
= link_to 'Back', :stories
|
= link_to 'Add photo', new_story_photo_path(@story)
+
+%br
+%br
+
+/ This division is replaced with a flash button by Uploadify
+#photo_upload
+
+/ Only load uploadify javascript on pages they are needed
+= javascript_include_tag '/uploadify/swfobject.js', '/uploadify/jquery.uploadify.v2.1.0.min.js'
+
+/ See application_helper.rb for this code
+= photo_uploadify
View
@@ -19,7 +19,7 @@ class Application < Rails::Application
# -- all .rb files in that directory are automatically loaded.
# Custom directories with classes and modules you want to be autoloadable.
- # config.autoload_paths += %W(#{config.root}/extras)
+ config.autoload_paths += %W(#{config.root}/lib/include)
# Only load the plugins named here, in the order given (default is alphabetical).
# :all can be used as a placeholder for all plugins not explicitly named.
@@ -2,6 +2,12 @@
MongoidCarrierwaveUploadify::Application.config.session_store :cookie_store, :key => '_mongoid-carrierwave-uploadify_session'
+Rails.application.config.middleware.insert_before(
+ ActionDispatch::Session::CookieStore,
+ FlashSessionCookieMiddleware,
+ Rails.application.config.session_options[:key]
+)
+
# Use the database for sessions instead of the cookie-based default,
# which shouldn't be used to store highly confidential information
# (create the session table with "rake db:sessions:create")
@@ -0,0 +1,18 @@
+require 'rack/utils'
+
+class FlashSessionCookieMiddleware
+ def initialize(app, session_key = '_session_id')
+ @app = app
+ @session_key = session_key
+ end
+
+ def call(env)
+ if env['HTTP_USER_AGENT'] =~ /^(Adobe|Shockwave) Flash/
+ req = Rack::Request.new(env)
+ env['HTTP_COOKIE'] = [@session_key, req.params[@session_key]].join('=').freeze unless req.params[@session_key].nil?
+ env['HTTP_ACCEPT'] = "#{req.params['_http_accept']}".freeze unless req.params['_http_accept'].nil?
+ end
+
+ @app.call(env)
+ end
+end
@@ -54,3 +54,33 @@ div.field, div.actions {
font-size: 12px;
list-style: square;
}
+
+.uploadifyQueueItem {
+ font: 11px Verdana, Geneva, sans-serif;
+ border: 2px solid #E5E5E5;
+ background-color: #F5F5F5;
+ margin-top: 5px;
+ padding: 10px;
+ width: 350px;
+}
+.uploadifyError {
+ border: 2px solid #FBCBBC !important;
+ background-color: #FDE5DD !important;
+}
+.uploadifyQueueItem .cancel {
+ float: right;
+}
+.uploadifyProgress {
+ background-color: #FFFFFF;
+ border-top: 1px solid #808080;
+ border-left: 1px solid #808080;
+ border-right: 1px solid #C5C5C5;
+ border-bottom: 1px solid #C5C5C5;
+ margin-top: 10px;
+ width: 100%;
+}
+.uploadifyProgressBar {
+ background-color: #0099FF;
+ width: 1px;
+ height: 3px;
+}
View
0 public/uploadify/cancel.png 100755 → 100644
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
No changes.
View
0 public/uploadify/swfobject.js 100755 → 100644
No changes.
View
0 public/uploadify/uploadify.css 100755 → 100644
No changes.
View
0 public/uploadify/uploadify.swf 100755 → 100644
No changes.

0 comments on commit 6524e95

Please sign in to comment.