papermill 1.3.4 → 1.3.5
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/app/controllers/papermill_controller.rb +41 -15
- data/app/views/papermill/_asset.html.erb +1 -1
- data/app/views/papermill/edit.html.erb +0 -1
- data/{lib/papermill → generators/papermill_initializer}/papermill_initializer.rb +45 -0
- data/generators/papermill_initializer/papermill_initializer_generator.rb +1 -1
- data/lib/papermill/form_builder.rb +2 -2
- data/lib/papermill/papermill_asset.rb +1 -1
- data/lib/papermill/papermill_options.rb +4 -0
- data/public/papermill/papermill.js +7 -7
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.3.
|
1
|
+
1.3.5
|
@@ -1,9 +1,27 @@
|
|
1
1
|
class PapermillController < ApplicationController
|
2
|
-
|
2
|
+
unloadable
|
3
|
+
prepend_before_filter :load_asset, :only => [ "show", "destroy", "update", "edit", "crop" ]
|
4
|
+
prepend_before_filter :load_old_asset_and_assetable, :only => ["create"]
|
3
5
|
prepend_before_filter :load_assets, :only => [ "sort", "mass_delete", "mass_edit", "mass_thumbnail_reset" ]
|
4
|
-
|
5
6
|
skip_before_filter :verify_authenticity_token, :only => [:create] # not needed (Flash same origin policy)
|
6
7
|
|
8
|
+
before_filter :authorize_create, :only => [:create]
|
9
|
+
before_filter :authorize_update_and_destroy, :only => [:update, :destroy]
|
10
|
+
before_filter :authorize_multiple_modification, :only => [:sort, :mass_delete, :mass_edit, :mass_thumbnail_reset]
|
11
|
+
|
12
|
+
def authorize_create
|
13
|
+
eval(Papermill::options[:authorize_create])
|
14
|
+
end
|
15
|
+
|
16
|
+
def authorize_update_and_destroy
|
17
|
+
eval(Papermill::options[:authorize_update_and_destroy])
|
18
|
+
end
|
19
|
+
|
20
|
+
def authorize_multiple_modification
|
21
|
+
eval(Papermill::options[:authorize_multiple_modification])
|
22
|
+
end
|
23
|
+
|
24
|
+
|
7
25
|
def show
|
8
26
|
# first escaping is done by rails prior to route recognition, need to do a second one on MSWIN systems to get original one.
|
9
27
|
params[:style] = CGI::unescape(params[:style]) if Papermill::MSWIN
|
@@ -17,10 +35,15 @@ class PapermillController < ApplicationController
|
|
17
35
|
def create
|
18
36
|
@asset = params[:asset_class].constantize.new(params.reject{|k, v| !(PapermillAsset.columns.map(&:name)+["Filedata", "Filename"]).include?(k)})
|
19
37
|
if @asset.save
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
38
|
+
@old_asset.destroy if @old_asset
|
39
|
+
render :update do |page|
|
40
|
+
page.replace params[:Fileid], :partial => "papermill/asset", :object => @asset, :locals => { :gallery => params[:gallery], :thumbnail_style => params[:thumbnail_style], :targetted_geometry => params[:targetted_geometry] }
|
41
|
+
page.remove "papermill_asset_#{@old_asset.id}" if @old_asset
|
42
|
+
end
|
43
|
+
else
|
44
|
+
page << %{ notify("#{@asset.name}", @asset.errors.full_messages.join('<br />'), "error"); }
|
45
|
+
page.remove params[:Fileid]
|
46
|
+
page.show "papermill_asset_#{@old_asset.id}" if @old_asset
|
24
47
|
end
|
25
48
|
end
|
26
49
|
|
@@ -31,13 +54,7 @@ class PapermillController < ApplicationController
|
|
31
54
|
def crop
|
32
55
|
render :action => "crop", :layout => false
|
33
56
|
end
|
34
|
-
|
35
|
-
def receive_from_pixlr
|
36
|
-
@asset.file = params[:image]
|
37
|
-
@asset.destroy_thumbnails
|
38
|
-
render :nothing => true
|
39
|
-
end
|
40
|
-
|
57
|
+
|
41
58
|
def update
|
42
59
|
@asset.create_thumb_file(params[:target], params[:papermill_asset].merge({ :geometry => "#{params[:target]}#" })) if params[:target]
|
43
60
|
render :update do |page|
|
@@ -86,11 +103,20 @@ class PapermillController < ApplicationController
|
|
86
103
|
end
|
87
104
|
|
88
105
|
private
|
106
|
+
|
107
|
+
def load_old_asset_and_assetable
|
108
|
+
unless params[:gallery]
|
109
|
+
@old_asset = PapermillAsset.find(:first, :conditions => {:assetable_type => params[:assetable_type], :assetable_id => params[:assetable_id], :assetable_key => params[:assetable_key]})
|
110
|
+
end
|
111
|
+
@assetable = params[:assetable_type].constantize.find_by_id(params[:assetable_id])
|
112
|
+
end
|
113
|
+
|
89
114
|
def load_asset
|
90
|
-
@asset = PapermillAsset.find(params[:id] || (params[:id0] + params[:id1] + params[:id2]).to_i)
|
115
|
+
@asset = PapermillAsset.find(params[:id] || (params[:id0] + params[:id1] + params[:id2]).to_i, :include => "assetable")
|
116
|
+
@assetable = @asset.assetable
|
91
117
|
end
|
92
118
|
|
93
119
|
def load_assets
|
94
|
-
@assets = (params[:papermill_asset] || []).map{ |id| PapermillAsset.find(id) }
|
120
|
+
@assets = (params[:papermill_asset] || []).map{ |id| PapermillAsset.find(id, :include => "assetable") }
|
95
121
|
end
|
96
122
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
<%- dom_id = "papermill_asset_#{asset.id}" -%>
|
2
|
-
<%- delete_link = %{<a onclick="if(confirm('#{escape_javascript t("papermill.delete-confirmation", :resource => asset.name)}')){ jQuery.ajax({async:true,
|
2
|
+
<%- delete_link = %{<a onclick="if(confirm('#{escape_javascript t("papermill.delete-confirmation", :resource => asset.name)}')){ jQuery.ajax({async:true, dataType:'script', type:'delete', url:'#{papermill_url(asset)}'})}; return false;" href="#" class="delete"><img title="#{escape_javascript t("papermill.delete", :resource => asset.name)}" src="/papermill/images/delete.png" alt="delete"/></a>} %>
|
3
3
|
|
4
4
|
<div id="<%= dom_id %>" class="asset" title="<%= t("papermill.#{(thumbnail_style) ? "thumbnail-" : ""}edit-title", :resource => asset.name) %>" onDblClick="popup(jQuery(this).attr('rel')); return false;" rel="<%= edit_papermill_url(asset, :targetted_geometry => targetted_geometry) %>">
|
5
5
|
<%= delete_link %>
|
@@ -8,7 +8,6 @@
|
|
8
8
|
<%= image_tag(@asset.url("400x400>"), :onDblClick => "popup('#{crop_papermill_path(@asset, :target => "original", :targetted_geometry => params[:targetted_geometry])}'); return false;", :title => I18n.t("papermill.crop", :resource => @asset.name)) %>
|
9
9
|
|
10
10
|
|
11
|
-
<%# @test = "webonrails.com/wp-content/uploads/2008/11/hosting-rails-app-and-wordpress-on-same-domainas-folder-instead-of-subdomain-webonrails_1225783508773.png" %>
|
12
11
|
<%# link_to I18n.t("papermill.edit-with-pixlr", :resource => @asset.name), "http://www.pixlr.com/editor/?image=http://#{@test || request.env["HTTP_HOST"] + @asset.url}&target=http://#{receive_from_pixlr_papermill_path(@asset)}&method=POST", :target => "_blank" %>
|
13
12
|
<div style="clear:both;"></div>
|
14
13
|
<% else %>
|
@@ -180,6 +180,10 @@ module Papermill
|
|
180
180
|
# Default named_scope name for catch-all :papermill declaration
|
181
181
|
|
182
182
|
# :base_association_name => :assets,
|
183
|
+
|
184
|
+
# Do you want papermill_assets to touch your assetable when CRUDed? (true|false|updated_at_field_name)
|
185
|
+
|
186
|
+
# :touch => false,
|
183
187
|
|
184
188
|
# Set to true to require aliases in all url/path, disabling the
|
185
189
|
# Don't forget to give an alias value to options[:thumbnail][:style] if true!
|
@@ -218,6 +222,47 @@ module Papermill
|
|
218
222
|
|
219
223
|
# If you use those defaults, the first asset will end-up in RAILS_ROOT/public/system/papermill/000/000/001/original/my_first_asset_name.ext
|
220
224
|
# You'll access it with my_domain.com/system/papermill/000/000/001/original/my_first_asset_name.ext
|
225
|
+
|
226
|
+
# You can add authorization support. The code is eval'ed directly in the controller (don't ask why, the answer is full of 'unloadable', 'ApplicationController has been removed from the module tree but is still active', etc.)
|
227
|
+
|
228
|
+
# :authorize_create => "true",
|
229
|
+
# :authorize_multiple_modification => "true",
|
230
|
+
# :authorize_update_and_destroy => "true",
|
231
|
+
|
232
|
+
# For example, this is my own setup.
|
233
|
+
# You'll need a public ApplicationController#current_user,
|
234
|
+
# adapt the authorization part (can_edit(Assetable)) to your own needs :
|
235
|
+
|
236
|
+
# :authorize_create => %{
|
237
|
+
# unless @assetable.nil? || current_user.can_edit?(@assetable)
|
238
|
+
# render :update do |page|
|
239
|
+
# page << %{notify("Wrong credentials", "You can't create an asset here", "error");}
|
240
|
+
# page.remove params[:Fileid]
|
241
|
+
# page.show "papermill_asset_" + @old_asset.id.to_s if @old_asset
|
242
|
+
# end
|
243
|
+
# false
|
244
|
+
# end
|
245
|
+
# },
|
246
|
+
# :authorize_update_and_destroy => %{
|
247
|
+
# unless @asset.try(:assetable).nil? || current_user.can_edit?(@asset.assetable)
|
248
|
+
# render :update do |page|
|
249
|
+
# page << %{notify("Wrong credentials", "You can't edit or destroy assets here", "error");}
|
250
|
+
# end
|
251
|
+
# false
|
252
|
+
# end
|
253
|
+
# },
|
254
|
+
# :authorize_multiple_modification => %{
|
255
|
+
# authorized = true
|
256
|
+
# @assets && @assets.each do |asset|
|
257
|
+
# authorized = authorized && current_user.can_edit?(asset.assetable)
|
258
|
+
# end
|
259
|
+
# unless authorized
|
260
|
+
# render :update do |page|
|
261
|
+
# page << %{notify("Wrong credentials", "You can't do edit or destroy assets here", "error");}
|
262
|
+
# end
|
263
|
+
# false
|
264
|
+
# end
|
265
|
+
# }
|
221
266
|
}
|
222
267
|
end
|
223
268
|
end
|
@@ -6,7 +6,7 @@ class PapermillInitializerGenerator < Rails::Generator::Base
|
|
6
6
|
puts "Copying papermill initializer to config/initializers/..."
|
7
7
|
FileUtils.rm_rf("#{RAILS_ROOT}/config/initializers/papermill.rb")
|
8
8
|
FileUtils.cp_r(
|
9
|
-
File.join(File.dirname(__FILE__), '
|
9
|
+
File.join(File.dirname(__FILE__), 'papermill_initializer.rb'),
|
10
10
|
"#{RAILS_ROOT}/config/initializers/papermill.rb"
|
11
11
|
)
|
12
12
|
puts "Done! Check config/initializer/papermill.rb for result."
|
@@ -148,8 +148,8 @@ module ActionView::Helpers::FormTagHelper
|
|
148
148
|
size = [width && "width:#{width}px", height && "height:#{height}px"].compact.join("; ")
|
149
149
|
if og = options[:gallery]
|
150
150
|
vp, hp, vm, hm, b = [og[:vpadding], og[:hpadding], og[:vmargin], og[:hmargin], og[:border_thickness]].map &:to_i
|
151
|
-
gallery_width = (og[:width] || width) && "width:#{og[:width] || og[:columns]*(width+(hp+hm+b)*2)}px;" || ""
|
152
|
-
gallery_height = (og[:height] || height) && "min-height:#{og[:height] || og[:lines]*(height+(vp+vm+b)*2)}px;" || ""
|
151
|
+
gallery_width = (og[:width] || width) && "width:#{og[:width] || og[:columns]*(width.to_i+(hp+hm+b)*2)}px;" || ""
|
152
|
+
gallery_height = (og[:height] || height) && "min-height:#{og[:height] || og[:lines]*(height.to_i+(vp+vm+b)*2)}px;" || ""
|
153
153
|
html << %{##{dom_id} { #{gallery_width} #{gallery_height} }}
|
154
154
|
html << %{##{dom_id} .asset { margin:#{vm}px #{hm}px; border-width:#{b}px; padding:#{vp}px #{hp}px; #{size}; }}
|
155
155
|
else
|
@@ -12,7 +12,7 @@ class PapermillAsset < ActiveRecord::Base
|
|
12
12
|
|
13
13
|
validates_attachment_presence :file
|
14
14
|
|
15
|
-
belongs_to :assetable, :polymorphic => true
|
15
|
+
belongs_to :assetable, :polymorphic => true, :touch => Papermill::options[:touch]
|
16
16
|
default_scope :order => 'position'
|
17
17
|
|
18
18
|
named_scope :key, lambda { |assetable_key| { :conditions => ['assetable_key = ?', assetable_key.to_s] }}
|
@@ -49,6 +49,7 @@ module Papermill
|
|
49
49
|
:watermark => "/images/rails.png",
|
50
50
|
:watermark_im_command => %{- | composite \\( %s -resize 100% \\) - -dissolve 20% -gravity center -geometry +0+0 },
|
51
51
|
:base_association_name => :assets,
|
52
|
+
:touch => false,
|
52
53
|
:alias_only => false,
|
53
54
|
:aliases => {},
|
54
55
|
:use_url_key => false,
|
@@ -57,5 +58,8 @@ module Papermill
|
|
57
58
|
:use_id_partition => true,
|
58
59
|
:papermill_url_prefix => "/system/papermill",
|
59
60
|
:papermill_path_prefix => ":rails_root/public/system/papermill",
|
61
|
+
:authorize_create => true,
|
62
|
+
:authorize_update_and_destroy => true,
|
63
|
+
:authorize_multiple_modification => true,
|
60
64
|
}
|
61
65
|
end
|
@@ -41,8 +41,6 @@ notify = function(title, message, type) {
|
|
41
41
|
if(type == "warning") { jQuery.jGrowl(message, { header: title, life: 15000, theme: type }) }
|
42
42
|
if(type == "error") { jQuery.jGrowl(message, { header: title, sticky: true, theme: type }) }
|
43
43
|
}
|
44
|
-
|
45
|
-
|
46
44
|
var Papermill = {
|
47
45
|
files_queued: 0,
|
48
46
|
file_dialog_complete: function(num_selected, num_queued)
|
@@ -71,12 +69,13 @@ var Papermill = {
|
|
71
69
|
div.append(jQuery('<span></span>').attr('class', 'name').html(file.name.substring(0, 10) + '...'));
|
72
70
|
div.append(jQuery('<span></span>').attr('class', 'status').html(SWFUPLOAD_PENDING));
|
73
71
|
div.append(jQuery('<span></span>').attr('class', 'progress').append('<span></span>'));
|
74
|
-
|
75
72
|
if(self.settings.file_queue_limit == 1) {
|
76
|
-
jQuery("#" + self.settings.upload_id).
|
77
|
-
|
78
|
-
|
73
|
+
old_asset = jQuery("#" + self.settings.upload_id).children()[0];
|
74
|
+
if(old_asset) {
|
75
|
+
jQuery(old_asset).hide();
|
76
|
+
}
|
79
77
|
}
|
78
|
+
jQuery("#" + self.settings.upload_id).append(div);
|
80
79
|
})
|
81
80
|
this.startUpload(this.sorted_queue[this.index++].id);
|
82
81
|
}
|
@@ -84,6 +83,7 @@ var Papermill = {
|
|
84
83
|
upload_start: function(file)
|
85
84
|
{
|
86
85
|
jQuery('#' + file.id + ' .status').html(SWFUPLOAD_LOADING);
|
86
|
+
this.addFileParam(file.id, "Fileid", file.id);
|
87
87
|
},
|
88
88
|
upload_progress: function(file, bytes, total)
|
89
89
|
{
|
@@ -101,7 +101,7 @@ var Papermill = {
|
|
101
101
|
},
|
102
102
|
upload_success: function(file, data)
|
103
103
|
{
|
104
|
-
|
104
|
+
eval(data);
|
105
105
|
},
|
106
106
|
upload_complete: function(file)
|
107
107
|
{
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: papermill
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "Benoit B\xC3\xA9n\xC3\xA9zech"
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-02-
|
12
|
+
date: 2010-02-10 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -60,6 +60,7 @@ files:
|
|
60
60
|
- generators/papermill_assets/USAGE
|
61
61
|
- generators/papermill_assets/papermill_assets_generator.rb
|
62
62
|
- generators/papermill_initializer/USAGE
|
63
|
+
- generators/papermill_initializer/papermill_initializer.rb
|
63
64
|
- generators/papermill_initializer/papermill_initializer_generator.rb
|
64
65
|
- generators/papermill_table/USAGE
|
65
66
|
- generators/papermill_table/papermill_table_generator.rb
|
@@ -73,7 +74,6 @@ files:
|
|
73
74
|
- lib/papermill/papermill.rb
|
74
75
|
- lib/papermill/papermill_asset.rb
|
75
76
|
- lib/papermill/papermill_helper.rb
|
76
|
-
- lib/papermill/papermill_initializer.rb
|
77
77
|
- lib/papermill/papermill_options.rb
|
78
78
|
- lib/papermill/papermill_paperclip_processor.rb
|
79
79
|
- public/.DS_Store
|