Diff
Modified: trunk/app/controllers/packs_controller.rb (2926 => 2927)
--- trunk/app/controllers/packs_controller.rb 2012-02-03 11:30:34 UTC (rev 2926)
+++ trunk/app/controllers/packs_controller.rb 2012-02-10 13:55:28 UTC (rev 2927)
@@ -357,20 +357,20 @@
format.html { render :action ="" "show" }
else
errors, type, entry = @pack.resolve_link(uri, request.host, request.port.to_s, current_user)
-
+
+ entry.comment = params[:comment]
+ @contributable = entry.contributable
+
# By this point, we either have errors, or have an entry that needs saving.
- if errors.empty?
- unless entry.save
- copy_errors(entry.errors, errors)
- end
- end
-
- if errors.empty?
+ if errors.empty? && entry.save
flash[:notice] = 'Item succesfully added to pack.'
format.html { redirect_to pack_url(@pack) }
+ format.js { render :layout => false }
else
+ copy_errors(entry.errors, errors)
flash.now[:error] = 'Failed to add item. See error(s) below.'
@error_message = errors.full_messages.to_sentence(:connector => '')
+ format.js { render :layout => false, :status => :unprocessable_entity }
format.html { render :action ="" "show" }
end
end
Modified: trunk/app/views/contributions/_in_packs_box.rhtml (2926 => 2927)
--- trunk/app/views/contributions/_in_packs_box.rhtml 2012-02-03 11:30:34 UTC (rev 2926)
+++ trunk/app/views/contributions/_in_packs_box.rhtml 2012-02-10 13:55:28 UTC (rev 2927)
@@ -1,5 +1,5 @@
-<% packs = Pack.packs_with_contributable(contributable) -%>
-<div class="contribution_section_box">
+<div class="contribution_section_box" id="in_packs_box">
+ <% packs = Pack.packs_with_contributable(contributable) -%>
<p class="heading">
<%= info_icon_with_tooltip("All the Packs that this item (or versions of this item [[if available]]) is referred to in") -%>
Featured In Packs <span class="count_text">(<%= packs.length -%>)</span>
@@ -25,29 +25,40 @@
<% end %>
<% if logged_in? -%>
- <% user_packs = current_user.packs -%>
- <% unless user_packs.empty? -%>
- <div class="fold">
- <div class="foldTitle">Add to your Pack</div>
- <div class="foldContent" style="display: none;">
- <form return false;" style="text-align: center;">
- <p>
- <select id="add_to_pack_selection" style="width: 99%;">
- <% user_packs.each do |p| -%>
- <% show = (contributable.class.to_s == 'Pack' ? (p.id != contributable.id) : true) -%>
- <% if show -%>
- <option value="<%= url_for(:controller => 'packs', :action ="" 'new_item', :id => p.id, :uri => contributable_url) -%>">
- <%= h(p.title) -%>
- </option>
- <% end -%>
- <% end -%>
- </select>
- </p>
- <%= submit_tag "Next" -%>
- </form>
- </div>
- </div>
- <% end -%>
+ <% user_packs = current_user.packs
+ potential_packs = (user_packs - packs)
+ potential_packs.delete(contributable) if contributable.kind_of?(Pack) %>
+
+ <% unless potential_packs.empty? -%>
+ <div class="error_text" id="add_to_pack_errors" style="display:none"></div>
+ <div class="fold" id="add_to_pack_fold">
+ <div class="foldTitle">Add to your Pack</div>
+ <div class="foldContent" style="display: none;">
+ <% form_remote_tag :url ="" quick_add_pack_url(potential_packs.first),
+ :method => :post,
+ :loading => "$('pack_add_spinner').show();",
+ :complete => "$('pack_add_spinner').hide();",
+ :id => "add_to_pack_form" do %>
+ <p>
+ <select style="width: 99%" = $(this).options[this.selectedIndex].value; return false">
+ <% potential_packs.each do |p| -%>
+ <option value="<%= quick_add_pack_url(p) -%>">
+ <%= h(p.title) -%>
+ </option>
+ <% end -%>
+ </select>
+ </p>
+ <p>
+ Comment:
+ <%= text_area_tag :comment, nil, :style => "width: 98%" %>
+ </p>
+ <%= hidden_field_tag :uri, polymorphic_url(contributable) %>
+ <%= submit_tag "Next" -%>
+ <img id="pack_add_spinner" src="" style="display:none; vertical-align: middle;"/>
+ <% end %>
+ </div>
+ </div>
+ <% end %>
<% else -%>
<p><small><b><%= link_to "Log in", new_session_url -%></b> to add to one of your Packs</small></p>
<% end -%>
Added: trunk/app/views/packs/quick_add.js.erb (0 => 2927)
--- trunk/app/views/packs/quick_add.js.erb (rev 0)
+++ trunk/app/views/packs/quick_add.js.erb 2012-02-10 13:55:28 UTC (rev 2927)
@@ -0,0 +1,10 @@
+<% if @error_message %>
+ alert('Error: <%= @error_message -%>');
+<% end %>
+
+$('in_packs_box').replace("<%= escape_javascript(render(:partial => "contributions/in_packs_box",
+ :locals => {:contributable => @contributable})) %>");
+
+//To re-apply fold style
+$('add_to_pack_fold').titleHTML = 'Add to your Pack';
+foldUpdate($('add_to_pack_fold'));