Index: app/views/admin/page/_attachments_box.rhtml
===================================================================
--- app/views/admin/page/_attachments_box.rhtml (revision 421)
+++ app/views/admin/page/_attachments_box.rhtml (revision 422)
@@ -1,8 +0,0 @@
-    
-
- <%= link_to_function image_tag('admin/plus.png'), 'add_attachment()', :title => "Add attachment" %> -
-

Attachments (<%= @page.attachments.count %>)

- <%= image('spinner.gif', :id => "attachments-spinner", :style => "display: none; float: right; margin: 5px;") %> - <%= render :partial => "attachment", :collection => @page.attachments %> -
\ No newline at end of file Index: app/views/admin/page/_attachment.rhtml =================================================================== --- app/views/admin/page/_attachment.rhtml (revision 421) +++ app/views/admin/page/_attachment.rhtml (revision 422) @@ -1,9 +0,0 @@ - - - - - - -
<%= attachment.thumbnails.empty? ? "" : - image_tag(attachment.thumbnails.first.public_filename, - :class => "thumbnail")%> <%= File.basename(attachment.public_filename) %><%= link_to_function image("minus", :title => "Remove attachment"), "remove_attachment(#{attachment.id})" %>
\ No newline at end of file Index: app/views/admin/page/_attachment.html.erb =================================================================== --- app/views/admin/page/_attachment.html.erb (revision 0) +++ app/views/admin/page/_attachment.html.erb (revision 422) @@ -0,0 +1,8 @@ +
  • + <% unless attachment.thumbnails.empty? %> + <%= link_to image_tag(attachment.thumbnails.first.public_filename), + attachment.public_filename, :class => 'thumbnail' %> + <% end %> + <%= File.basename(attachment.public_filename) %> + <%= image_tag "admin/minus.png", :alt => "Delete", :class => 'delete' %> +
  • Index: app/views/admin/page/_attachments_box.html.erb =================================================================== --- app/views/admin/page/_attachments_box.html.erb (revision 0) +++ app/views/admin/page/_attachments_box.html.erb (revision 422) @@ -0,0 +1,12 @@ +
    +
    + <%= image_tag('admin/plus.png', :alt => 'Add') %> +
    +

    Attachments (<%= @page.attachments.count %>)

    + + <% unless @page.attachments.count.zero? %> +
      + <%= render :partial => 'attachment', :collection => @page.attachments %> +
    + <% end %> +
    Index: page_attachments_extension.rb =================================================================== --- page_attachments_extension.rb (revision 421) +++ page_attachments_extension.rb (revision 422) @@ -1,5 +1,5 @@ require_dependency 'application' -require File.dirname(__FILE__)+'/lib/geometry' +require File.dirname(__FILE__) + '/lib/geometry' require 'tempfile' class PageAttachmentsExtension < Radiant::Extension @@ -7,9 +7,9 @@ description "Adds page-attachment-style asset management." url "http://seancribbs.com" -# define_routes do |map| -# map.connect 'admin/attachments/:action/:id', :controller => 'page_attachments' -# end + # define_routes do |map| + # map.connect 'admin/attachments/:action/:id', :controller => 'page_attachments' + # end def activate # Contents of attachment_fu/init.rb @@ -38,4 +38,4 @@ def deactivate end -end \ No newline at end of file +end Index: public/javascripts/page_attachments.js =================================================================== --- public/javascripts/page_attachments.js (revision 421) +++ public/javascripts/page_attachments.js (revision 422) @@ -1,18 +1,28 @@ -function add_attachment() { - var attachments_box = $('attachments'); - var template = new Template('

    Cancel

    '); - new Insertion.Bottom(attachments_box, template.evaluate({id: Math.round(Math.random() * 100000)})); -} -function remove_attachment(id){ - if(confirm("Really delete this attachment?")){ - var attachments_box = $('attachments'); - Element.remove("attachment_"+id); - var template = new Template(''); - new Insertion.Bottom(attachments_box, template.evaluate({id: id})); - if(typeof $('attachments').down("#attachments-deleted") == 'undefined') - { - new Insertion.After('attachments-title', '

    Removed attachments will be deleted when you Save this page.

    '); +document.observe("dom:loaded", function() { + when('attachments', function(container) { + var upload = '
    cancel
    ' + var deletion = new Template('') + var notice = '

    Removed attachments will be deleted when you save this page.

    ' + + container.observe('click', function(e) { + var target = $(e.target) + + if (target.match('img[alt=Add]')) { + container.insert(upload) } - new Effect.Highlight('attachments-deleted'); - } -} \ No newline at end of file + else if (target.match('a.cancel')) { + e.findElement('.attachment-upload').remove() + e.stop() + } + else if (target.match('img.delete')) { + if (confirm("Really delete this attachment?")) { + var attachment = e.findElement('.attachment') + var id = attachment.id.split('_').last() + attachment.remove() + if (!container.down('p.notice')) container.insert(notice) + container.insert(deletion.evaluate({ id: id })) + } + } + }) + }) +}) Index: public/stylesheets/page_attachments.css =================================================================== --- public/stylesheets/page_attachments.css (revision 421) +++ public/stylesheets/page_attachments.css (revision 422) @@ -1,26 +1,48 @@ - #attachments { - clear: both; - border: 1px solid #d4cba4; - background: white; - margin: 10px 0; - } - #attachments-toolbar { - float: right; - padding: 10px; - } - #attachments h3 { - background: #eae3c5; - margin: 0; - padding: 0.5em; - } - p.attachment { - padding: 0.5em; - margin: 0.5em; - } - table.attachment { - margin: 0.5em; - display: inline; - } - .attachment img.thumbnail { - border: 2px solid #d4cba4; - } \ No newline at end of file +#attachments { + clear: both; + border: 1px solid #d4cba4; + background: white; + margin: 10px 0; +} +#attachments .toolbar { + float: right; + padding: 10px; + width: 50px; + text-align: right; +} +#attachments .toolbar img { + padding: 5px; + cursor: pointer; +} +#attachments h3, #attachments p.notice { + background: #eae3c5; + margin: 0; + padding: 0.5em; +} +#attachments .attachment-upload { + padding: 0.8em; +} +#attachments p.notice { + padding: .5em .8em; + font-style: italic; + font-size: 90%; + color: red; +} +#attachments .attachment-upload img, +#attachments .attachment img.delete { + cursor: pointer; + padding: 2px; + margin-left: .5em; +} +#attachments ol { + list-style: none; + padding: 10px; + margin: 0; +} +#attachments ol li { + display: inline; + margin-right: 1em; +} +#attachments .attachment .thumbnail img { + border: 2px solid #d4cba4; +}