Permalink
Browse files

adds more flexibility to helpers responsible for view generating

  • Loading branch information...
1 parent 5f8d67b commit 9817e58f15f7940830b961142a1ae79fbeef9eaa @rbrancher rbrancher committed Apr 3, 2012
@@ -67,7 +67,7 @@
uploader.bind('Init', function(up, params) {
if ($('#' + settings.container + '-runtimeInfo').length > 0) $('#' + settings.container + '-runtimeInfo').text("Current runtime: " + params.runtime);
- if ($container.find("dt").length > 0 && $container.find("dt").text() == "") $container.find("dt").text($container.attr('id'));
+ // if ($container.find("dt").length > 0 && $container.find("dt").text() == "") $container.find("dt").text($container.attr('id'));
$("a.remove").live('click', function() {
@@ -95,10 +95,10 @@
uploader.bind('FilesAdded', function(up, files) {
$.each(files, function(i, file) {
$('#' + container + '-' + queue_element).append(
- '<dd id="' + file.id + '" class="file">' +
+ '<li id="' + file.id + '" class="attachment">' +
file.name + ' (' + plupload.formatSize(file.size) + ') <span class="status"></span>' +
- '</dd>'
- ).find("dd:last").append(
+ '</li>'
+ ).find("li:last").append(
$('<a href="javascript://" class="remove btn btn-mini">x</a>').bind('click', function () {
uploader.removeFile(file);
$(this).parent().remove();
@@ -114,10 +114,10 @@
});
uploader.bind('Error', function(up, err) {
- $('#' + container + '-' + queue_element).append("<dd class='attachment error'>Error: " + err.code +
+ $('#' + container + '-' + queue_element).append("<li class='attachment error'>Error: " + err.code +
", Message: " + err.message +
(err.file ? ", File: " + err.file.name : "") +
- "</dd>");
+ "</li>");
up.refresh(); // Reposition Flash/Silverlight
});
@@ -1,25 +1,11 @@
module MediaMagickHelper
- def attachment_container(model, relation)
- content_tag :div, id: model.class.to_s.downcase << '-' << relation.to_s, class: 'attachmentUploader', data: { model: model.class.to_s.downcase, id: model.id.to_s, relation: relation.to_s } do
+ def attachment_container(model, relation, newAttachments = {}, loadedAttachments= {})
+ content_tag :div, id: model.class.to_s.downcase << '-' << relation.to_s, class: 'attachmentUploader ' << relation.to_s, data: { model: model.class.to_s.downcase, id: model.id.to_s, relation: relation.to_s } do
if block_given?
yield
else
- render :partial => "/upload", :locals => { :model => model, :relations => relation }
+ render :partial => "/upload", :locals => { model: model, relations: relation, newAttachments: newAttachments, loadedAttachments: loadedAttachments }
end
end
end
-
- def attachment_item(tag, model, options = {})
- default_options = options.merge(
- data: {
- id: model.id.to_s
- }
- )
-
- default_options[:class] << ' attachment'
-
- content_tag tag, default_options do
- yield if block_given?
- end
- end
end
@@ -1,4 +1,4 @@
<li class="attachment" data-id="<%= attachment.to_param %>">
<%= link_to attachment.filename, attachment.url unless attachment.file.nil? %>
- <a href="javascript://" class="remove btn btn-mini btn-danger">remove</a>
+ <%= link_to t('media_magick.remove'), "javascript://", method: "delete", confirm: t('media_magick.confirm_removal'), class: "remove btn btn-mini btn-danger" %>
</li>
@@ -1,4 +1,4 @@
<li class="attachment" data-id="<%= attachment.to_param %>">
- <a href="javascript://" class="remove btn btn-mini btn-danger">remove</a>
- <%= image_tag attachment.url %>
+ <%= image_tag attachment.url, alt: attachment.filename %>
+ <%= link_to t('media_magick.remove'), "javascript://", method: "delete", confirm: t('media_magick.confirm_removal'), class: "remove btn btn-mini btn-danger" %>
</li>
@@ -1,14 +1,12 @@
-<div class="newAttachments">
- <dl class="attachmentQueue">
- <dt>file queue</dt>
- </dl>
+<div class="newAttachments <%= newAttachments.class %>">
+ <ul class="attachmentQueue">
+ </ul>
<div class="dropAttachments"></div>
- <a class="pickAttachments btn" href="javascript://">select files</a>
- <a class="uploadAttachments btn" href="javascript://">upload files</a>
+ <a class="pickAttachments btn" href="javascript://"><%= t('media_magick.select') %></a>
+ <a class="uploadAttachments btn" href="javascript://"><%= t('media_magick.upload') %></a>
</div>
-
-<ul class="loadedAttachments">
+<ul class="loadedAttachments <%= loadedAttachments.class %>">
<% for attachment in model.send(relations).each do %>
<% if attachment.class::TYPE.to_s == 'file' %>
<%= render :partial => "/file", :locals => { :attachment => attachment } %>
@@ -2,21 +2,12 @@
describe MediaMagickHelper do
describe 'attachmentUploader' do
- it 'should create a div.attachmentUploader' do
+ it 'should create a div.attachmentUploader.photos' do
album = Album.new
album.stub(id: '12345678')
helper.attachment_container(album, :photos) do
- end.should eq('<div class="attachmentUploader" data-id="12345678" data-model="album" data-relation="photos" id="album-photos"></div>')
- end
- end
-
- describe 'attachment_item' do
- it 'should create a attachment_item' do
- album = Album.new
- album.stub(id: '12345678')
-
- helper.attachment_item(:div, album, class: 'album').should eq('<div class="album attachment" data-id="12345678"></div>')
+ end.should eq('<div class="attachmentUploader photos" data-id="12345678" data-model="album" data-relation="photos" id="album-photos"></div>')
end
end
end

0 comments on commit 9817e58

Please sign in to comment.