Permalink
Browse files

wip allow create photoset from photo upload

  • Loading branch information...
1 parent bdc80df commit 7853e319ce0c9af217b3c2a9ea115de4fc38aa0c @trevorturk trevorturk committed Apr 17, 2012
Showing with 19 additions and 3 deletions.
  1. +1 −1 app/models/photo_set.rb
  2. +2 −1 app/models/photo_upload.rb
  3. +16 −1 app/views/root/submit2.html.erb
@@ -1,7 +1,7 @@
class PhotoSet < ActiveRecord::Base
attr_accessor :terms
- attr_accessible :photo_1, :photo_2, :your_title, :your_name, :terms, :status
+ attr_accessible :photo_1, :photo_2, :your_title, :your_name, :terms, :status, :remote_photo_1_url, :remote_photo_2_url
mount_uploader :photo_1, PhotoUploader
mount_uploader :photo_2, PhotoUploader
@@ -7,7 +7,8 @@ class PhotoUpload < ActiveRecord::Base
def as_json(*)
json = super
- json["photo_url_m"] = photo.url(:m)
+ json["photo_url"] = root_url.chomp('/') + photo.url
+ json["photo_url_m"] = root_url.chomp('/') + photo.url(:m)
json
end
end
@@ -16,17 +16,32 @@
<div class="fileupload"></div>
<% end %>
+<%= form_for PhotoSet.new, :html => {:multipart => true} do |f| %>
+ <%= f.text_field :remote_photo_1_url, :class => 'photo_set_photo_url' %>
+ <%= f.text_field :remote_photo_2_url, :class => 'photo_set_photo_url' %>
+ <%= f.text_field :your_name, :placeholder => '(YOUR NAME)', :maxlength => 27 %>
+ <%= f.text_field :your_title, :placeholder => '(YOUR TITLE)', :maxlength => 27 %>
+ <%= f.submit "Submit" %>
+<% end %>
+
<script src="/javascripts/jquery.js"></script>
<script src="/javascripts/jquery.ui.widget.js"></script>
<script src="/javascripts/jquery.fileupload.js"></script>
<script>
-$(function () {
+$(function() {
$('#fileupload1, #fileupload2').fileupload({
dataType: 'json',
done: function (e, data) {
$.each(data.result, function (index, photo_upload) {
$('.fileupload:empty').first().append("<div><img src='" + photo_upload.photo_url_m + "'></div>");
+
+ $('.photo_set_photo_url').each(function(index) {
+ if ($(this).val() == '') {
+ $(this).val(photo_upload.photo_url);
+ return false;
+ }
+ });
});
}
});

0 comments on commit 7853e31

Please sign in to comment.