From 36abb19e2cf60f02d72d4fc7c6e97ea61c02d60f Mon Sep 17 00:00:00 2001 From: danielvincent <danielgrippi@gmail.com> Date: Mon, 26 Jul 2010 15:50:41 -0700 Subject: [PATCH] added the uploading photo wjava script --- app/controllers/photos_controller.rb | 5 +--- app/models/photo.rb | 4 +-- app/views/albums/_album.html.haml | 2 +- app/views/layouts/application.html.haml | 4 ++- app/views/photos/_new_photo.haml | 38 +++++++++++++++++++++++-- 5 files changed, 43 insertions(+), 10 deletions(-) diff --git a/app/controllers/photos_controller.rb b/app/controllers/photos_controller.rb index 98abbe95bc..9e59ab7412 100644 --- a/app/controllers/photos_controller.rb +++ b/app/controllers/photos_controller.rb @@ -3,12 +3,9 @@ class PhotosController < ApplicationController def create begin - @photo = Photo.instantiate(params[:photo]) + @photo = Photo.instantiate(params) @photo.person = current_user - - - if @photo.save flash[:notice] = "Successfully uploaded photo." redirect_to @photo.album diff --git a/app/models/photo.rb b/app/models/photo.rb index 6571efad52..01e79ea3b2 100644 --- a/app/models/photo.rb +++ b/app/models/photo.rb @@ -15,8 +15,8 @@ class Photo < Post validates_presence_of :album def self.instantiate params = {} - image_file = params[:image] - params.delete :image + image_file = params[:user_file][0] + params.delete :user_file photo = Photo.new(params) photo.image.store! image_file photo diff --git a/app/views/albums/_album.html.haml b/app/views/albums/_album.html.haml index e30c4b4c64..be8b0b55fb 100644 --- a/app/views/albums/_album.html.haml +++ b/app/views/albums/_album.html.haml @@ -5,6 +5,6 @@ %div.time = link_to(how_long_ago(post), object_path(post)) %div.image_cycle - - for photo in post.photos + - for photo in post.photos[0..3] = image_tag photo.image.url(:thumb_large) diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 0665430a06..948d38e67d 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -20,6 +20,8 @@ = javascript_include_tag 'satisfaction' , 'satisfaction-display' + = javascript_include_tag 'jquery.html5_upload' + %body %header .container @@ -53,7 +55,7 @@ .span-18.append-3.last = yield .span-3.last - = link_to (person_image_tag(current_user), root_path) + = link_to(person_image_tag(current_user), root_path) = link_to "Edit your profile", edit_user_path(current_user) %br %br diff --git a/app/views/photos/_new_photo.haml b/app/views/photos/_new_photo.haml index fd7e58b8a9..22bea3e0e0 100644 --- a/app/views/photos/_new_photo.haml +++ b/app/views/photos/_new_photo.haml @@ -1,8 +1,42 @@ +:javascript + $(function() { + $("#photo_image").html5_upload({ + // WE INSERT ALBUM_ID PARAM HERE + url: "/photos?album_id=#{album.id}", + sendBoundary: window.FormData || $.browser.mozilla, + onStart: function(event, total) { + return confirm("You are trying to upload " + total + " files. Are you sure?"); + }, + setName: function(text) { + $("#progress_report_name").text(text); + }, + setStatus: function(text) { + $("#progress_report_status").text(text); + }, + setProgress: function(val) { + $("#progress_report_bar").css('width', Math.ceil(val*100)+"%"); + }, + onFinishOne: function(event, response, name, number, total) { + //alert(response); + } + }); + }); + + + + = form_for photo, :html => {:multipart => true} do |f| = f.error_messages = f.hidden_field :album_id, :value => album.id %p - = f.file_field :image - = f.submit 'post it!', :class => 'button' + = f.file_field :image, :multiple => 'multiple' + + #progress_report + #progress_report_name + #progress_report_status{ :style => "font-style: italic;" } + #progress_report_bar_container{ :style => "width: 90%; height: 5px;" } + #progress_report_bar{ :style => "background-color: blue; width: 0; height: 100%;" } + + /= f.submit 'post it!', :class => 'button' -- GitLab