public
Description: Radiant Image and Assets Extension
Homepage: http://github.com/kbingman/assets_extension/wikis
Clone URL: git://github.com/kbingman/assets_extension.git
added acts_as_list, changed the models around and got reordering to work 
properly
Keith Bingman (author)
Sat Mar 22 14:27:20 -0700 2008
commit  96e829366c80e00084033e3e68119b028be7e2f7
tree    d5b597fa2a1ec38bc7c1447c450dbc7a216bba4e
parent  89f83465d2f704c6916b12dc62768b03fd707392
...
45
46
47
48
49
50
 
 
 
51
52
53
...
78
79
80
81
 
82
83
84
...
91
92
93
94
 
95
96
97
...
45
46
47
 
 
 
48
49
50
51
52
53
...
78
79
80
 
81
82
83
84
...
91
92
93
 
94
95
96
97
0
@@ -45,9 +45,9 @@ class Admin::AssetController < ApplicationController
0
   
0
   def reorder
0
     params[:attachments].each_with_index do |id,idx|
0
- association = AssetAssociation.find_by_page_id(params[:id], :conditions => ['asset_id = ?', id])
0
- association.position = idx+1
0
- association.save
0
+ attachment = Attachment.find_by_page_id(params[:id], :conditions => ['asset_id = ?', id])
0
+ attachment.position = idx+1
0
+ attachment.save
0
     end
0
     render :nothing => true
0
   end
0
@@ -78,7 +78,7 @@ class Admin::AssetController < ApplicationController
0
   def clear_bucket
0
     session[:bucket] = nil
0
     render :update do |page|
0
- page[:bucket].replace_html ''
0
+ page[:bucket].replace_html '<p><em>Your bucket is empty.</em></p>'
0
     end
0
   end
0
   
0
@@ -91,7 +91,7 @@ class Admin::AssetController < ApplicationController
0
     end
0
   end
0
   
0
- def remove_asset
0
+ def remove_asset
0
     @asset = Asset.find(params[:asset])
0
     @page = Page.find(params[:page])
0
     @page.assets.delete(@asset)
...
9
10
11
12
13
 
 
14
15
16
...
21
22
23
24
 
25
26
27
...
9
10
11
 
 
12
13
14
15
16
...
21
22
23
 
24
25
26
27
0
@@ -9,8 +9,8 @@ class Asset < ActiveRecord::Base
0
                  :thumbnails => {}
0
   validates_as_attachment
0
   
0
- has_many :asset_associations
0
- has_many :pages, :through => :asset_associations
0
+ has_many :attachments
0
+ has_many :pages, :through => :attachments
0
   
0
   belongs_to :created_by, :class_name => 'User', :foreign_key => 'created_by'
0
   belongs_to :updated_by, :class_name => 'User', :foreign_key => 'updated_by'
0
@@ -21,7 +21,7 @@ class Asset < ActiveRecord::Base
0
     true
0
   end
0
 
0
- # Hacked image method to get the image from the database. This seems to be a leftover
0
+ # Hacked image method to get the image from the database. This seems to be a leftover from when I made thumbnails on upload.
0
   def image_data(thumbnail = nil)
0
     thumbnail.nil? ? current_data : thumbnails.find_by_thumbnail(thumbnail.to_s).current_data
0
   end
...
26
27
28
29
 
30
31
32
...
38
39
40
41
 
42
43
44
...
26
27
28
 
29
30
31
32
...
38
39
40
 
41
42
43
44
0
@@ -26,7 +26,7 @@ module AssetTags
0
     result = []
0
     # all = tag.attr['all']
0
     # all == 'true' ? assets = Asset.find(:all) : assets = tag.locals.page.assets
0
- associations = tag.locals.page.asset_associations.sort_by{ |a| a.position }
0
+ associations = tag.locals.page.attachments.sort_by{ |a| a.position }
0
     tag.locals.assets = associations
0
     associations.each do |assoc|
0
       tag.locals.asset = assoc.asset
0
@@ -38,7 +38,7 @@ module AssetTags
0
   tag 'asset:first' do |tag|
0
      # all = tag.attr['all']
0
      # all == 'true' ? assets = Asset.find(:all) :
0
- associations = tag.locals.page.asset_associations.sort_by{ |a| a.position }
0
+ associations = tag.locals.page.attachments.sort_by{ |a| a.position }
0
      if first = associations.first
0
        tag.locals.asset = first.asset
0
        tag.expand
...
1
2
3
4
5
 
 
6
7
8
...
1
2
3
 
 
4
5
6
7
8
0
@@ -1,8 +1,8 @@
0
 module PageAssetAssociations
0
   def self.included(base)
0
     base.class_eval {
0
- has_many :asset_associations
0
- has_many :assets, :through => :asset_associations
0
+ has_many :attachments, :order => :position
0
+ has_many :assets, :through => :attachments
0
     }
0
   end
0
   
...
1
 
 
 
2
3
4
5
6
7
8
9
 
 
 
 
10
11
 
12
13
14
...
1
2
3
4
5
6
7
8
9
10
 
 
11
12
13
14
15
 
16
17
18
19
0
@@ -1,14 +1,19 @@
0
 - @stylesheets << 'admin/assets'
0
+- include_javascript 'assets'
0
+- include_javascript 'dragdrop'
0
+
0
 #bucket-container
0
   - if @page
0
     #attachment-container
0
       %h4
0
         Attached Assets&nbsp;
0
         %span.note Assets associated with this page.
0
- %a{ :href => "#", :id => 'reorder', :onclick => "reorder_attachments(#{@page.id}); return false;" } Reorder
0
- %a{ :href => "#", :id => 'done', :onclick => "done_reordering(); return false;", :style => 'display:none' } Done reordering
0
+ %span#reorder
0
+ %a{ :href => "#", :onclick => "reorder_attachments(#{@page.id}); return false;" } Reorder
0
+ %span#done{ :style => 'display:none' }
0
+ %a{ :href => "#", :onclick => "done_reordering(); return false;" } Done reordering
0
       %ul#attachments
0
- = render :partial => "admin/asset/page_assets" unless @page.assets.empty?
0
+ = render :partial => "admin/asset/page_assets"
0
         
0
   %p{ :style => "clear:both;" }
0
   
...
1
2
3
4
5
6
7
8
9
 
 
 
 
10
11
12
...
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
0
@@ -1,12 +1,13 @@
0
-- include_javascript 'assets'
0
-- include_javascript 'dragdrop'
0
-
0
 %ul#bucket
0
   - if session[:bucket]
0
     - session[:bucket].each do |filename, values|
0
       - info = values[1]
0
       - asset = Asset.find(info[:id])
0
       = render :partial => "admin/asset/asset", :locals => { :asset => asset, :id_name => 'asset' }
0
+ - else
0
+ %li
0
+ %p
0
+ %em Your bucket is empty
0
       
0
 
0
 
...
1
2
3
4
5
 
 
 
 
 
 
 
 
 
 
 
6
7
...
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
 
0
@@ -1,7 +1,12 @@
0
-- if @page.assets
0
- - @page.asset_associations.sort_by{ |a| a.position }.each do |assoc|
0
- = render :partial => "admin/asset/asset", :locals => { :asset => assoc.asset, :id_name => 'attachment' }
0
- // - @page.assets.each do |asset|
0
- // = render :partial => "admin/asset/asset", :locals => { :asset => asset, :id_name => 'attachment' }
0
+- unless @page.assets.empty?
0
+ - @page.attachments.each do |a|
0
+ = render :partial => "admin/asset/asset", :locals => { :asset => a.asset, :id_name => 'attachment' }
0
+
0
+- else
0
+ %li
0
+ %p
0
+ %em You have no attached assets.
0
+
0
+
0
+
0
 
0
-%p{ :style => "clear:both;" }
...
1
 
2
3
...
 
1
2
3
0
@@ -1,2 +1,2 @@
0
-%th
0
+%th.assets
0
   Assets
0
\ No newline at end of file
...
23
24
25
26
27
 
 
28
29
30
...
23
24
25
 
 
26
27
28
29
30
0
@@ -23,8 +23,8 @@ class AssetsExtension < Radiant::Extension
0
   
0
   def activate
0
     raise "The Shards extension is required and must be loaded first!" unless defined?(Shards)
0
- admin.page.index.add :sitemap_head, 'assets_extra_th', :before => "status_column_header"
0
- admin.page.index.add :node, 'assets_extra_td', :before => "status_column"
0
+ admin.page.index.add :sitemap_head, 'assets_extra_th', :after => "status_column_header"
0
+ admin.page.index.add :node, 'assets_extra_td', :after => "status_column"
0
     admin.page.edit.add :form_bottom, '/admin/asset/assets_container', :before => "edit_buttons"
0
     
0
     require_dependency 'application'

Comments

    No one has commented yet.