Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
528f73f
commit f6f64ba
Showing
8 changed files
with
61 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
app/assets/javascripts/admin/photos.js.coffee
100644 → 100755
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,3 +1,27 @@ | |||
# Place all the behaviors and hooks related to the matching controller here. | # Place all the behaviors and hooks related to the matching controller here. | ||
# All this logic will automatically be available in application.js. | # All this logic will automatically be available in application.js. | ||
# You can use CoffeeScript in this file: http://coffeescript.org/ | # You can use CoffeeScript in this file: http://coffeescript.org/ | ||
|
|||
jQuery -> | |||
$('#photo_file').attr('name','photo[file]') | |||
$('#new_photo').fileupload | |||
dataType: 'script' | |||
add: (e, data) -> | |||
types = /(\.|\/)(gif|jpe?g|png|mov|mpeg|mpeg4|avi)$/i | |||
file = data.files[0] | |||
if types.test(file.type) || types.test(file.name) | |||
data.context = $(tmpl("template-upload", file)) | |||
$('#new_photo').append(data.context) | |||
$('.actions input[type="submit"]').click (e) -> | |||
$('.actions input[type="submit"]').attr("disabled", true) | |||
data.submit() | |||
e.preventDefault() | |||
else | |||
alert("#{file.name} is not a gif, jpg or png image file") | |||
progress: (e, data) -> | |||
if data.context | |||
progress = parseInt(data.loaded / data.total * 100, 10) | |||
data.context.find('.bar').css('width', progress + '%') | |||
done: (e, data) -> | |||
$('.actions input[type="submit"]').off('click') | |||
$('.actions input[type="submit"]').attr("enabled", true) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,18 +1,28 @@ | |||
<% @photo = @gallery.photos.new %> | <% @photo = @gallery.photos.new %> | ||
<%= form_for [:admin, @gallery, @photo], :class=>"form-horizontal panel" do |f| %> | <%= form_for [:admin, @gallery, @photo], :class=>"form-horizontal panel", :html=> {multipart: true} do |f| %> | ||
<div class="panel-body"> | <div class="panel-body"> | ||
<%= f.file_field :file %> | <% if @photo.errors.any? %> | ||
</div> | <div id="error_explanation"> | ||
<div class="panel-footer text-right"> | <h2><%= pluralize(@photo.errors.count, "error") %> prohibited this photo from being saved:</h2> | ||
<%= f.submit :action, :class=> "btn btn-primary" %> | |||
</div> | |||
|
|
||
<ul> | |||
<% @photo.errors.full_messages.each do |msg| %> | |||
<li><%= msg %></li> | |||
<% end %> | |||
</ul> | |||
</div> | |||
<% end %> | |||
<%= f.file_field :file, multiple: true, name: 'photo[file]', :hint=> "You can select multiple files" %> | |||
|
|||
</div> | |||
<div class="panel-footer text-right actions"> | |||
<%= f.submit "Start Upload", :class=> "btn btn-primary", data: { disable_with: "Please wait..." } %> | |||
</div> | |||
<% end %> | <% end %> | ||
<script> | <% # jquery photo template # %> | ||
$(function(){ | <script id="template-upload" type="text/x-tmpl"><div class="upload">{%=o.name%}<div class="progress"><div class="progress-bar bar" style="width: 0%"></div></div></div></script> | ||
|
|||
$('#photo_file').pixelFileInput({ placeholder: 'No file selected...' }); | |||
}); | |||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1 @@ | |||
<%= image_tag(@photo.file.url(:small), class: 'thumb') %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,5 @@ | |||
<% if @photo.new_record? %> | |||
alert('Failed'); | |||
<% else %> | |||
$('ul.thumbnails').append("<%=j render partial: 'photos/upload', locals: { photo: @photo } %>"); | |||
<% end %> |