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 @@
- <div id="attachments">
- <div id="attachments-toolbar">
- <%= link_to_function image_tag('admin/plus.png'), 'add_attachment()', :title => "Add attachment" %>
- </div>
- <h3 id="attachments-title">Attachments (<%= @page.attachments.count %>)</h3>
- <%= image('spinner.gif', :id => "attachments-spinner", :style => "display: none; float: right; margin: 5px;") %>
- <%= render :partial => "attachment", :collection => @page.attachments %>
- </div>
\ 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 @@
-<table id="attachment_<%= attachment.id %>" class="attachment">
- <tr>
- <td><%= attachment.thumbnails.empty? ? "" :
- image_tag(attachment.thumbnails.first.public_filename,
- :class => "thumbnail")%></td>
- <td> <%= File.basename(attachment.public_filename) %></td>
- <td><%= link_to_function image("minus", :title => "Remove attachment"), "remove_attachment(#{attachment.id})" %></td>
- </tr>
-</table>
\ 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 @@
+<li id="attachment_<%= attachment.id %>" class="attachment">
+ <% 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' %>
+</li>
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 @@
+<div id="attachments">
+ <div class="toolbar">
+ <%= image_tag('admin/plus.png', :alt => 'Add') %>
+ </div>
+ <h3>Attachments (<%= @page.attachments.count %>)</h3>
+
+ <% unless @page.attachments.count.zero? %>
+ <ol>
+ <%= render :partial => 'attachment', :collection => @page.attachments %>
+ </ol>
+ <% end %>
+</div>
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('<p class="attachment" id="file_#{id}"><label>Upload file: </label><input type="file" name="page[add_attachments][]" /> <a href="#" onclick="Element.remove(\'file_#{id}\')">Cancel</a></p>');
- 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('<input type="hidden" name="page[delete_attachments][]" value="#{id}" />');
- new Insertion.Bottom(attachments_box, template.evaluate({id: id}));
- if(typeof $('attachments').down("#attachments-deleted") == 'undefined')
- {
- new Insertion.After('attachments-title', '<p class="attachment" id="attachments-deleted">Removed attachments will be deleted when you Save this page.</p>');
+document.observe("dom:loaded", function() {
+ when('attachments', function(container) {
+ var upload = '<div class="attachment-upload"><label>Upload file: <input type="file" name="page[add_attachments][]" /></label> <img src="/images/admin/minus.png" alt="cancel" /></div>'
+ var deletion = new Template('<input type="hidden" name="page[delete_attachments][]" value="#{id}" />')
+ var notice = '<p class="notice">Removed attachments will be deleted when you save this page.</p>'
+
+ 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;
+}