favgroups: add create new option to add to favgroup dialog.

Add option to create a new favgroup when the user opens the Add to
Favgroup dialog and they don't have any favgroups yet.
This commit is contained in:
evazion
2020-01-15 13:18:25 -06:00
parent 1ce628c31f
commit 7d53af64c1
3 changed files with 22 additions and 19 deletions

View File

@@ -21,15 +21,7 @@ class FavoriteGroupsController < ApplicationController
def create def create
@favorite_group = FavoriteGroup.create(favgroup_params) @favorite_group = FavoriteGroup.create(favgroup_params)
respond_with(@favorite_group) do |format| respond_with(@favorite_group)
format.html do
if @favorite_group.errors.any?
render :action => "new"
else
redirect_to favorite_groups_path
end
end
end
end end
def edit def edit

View File

@@ -1,12 +1,22 @@
<p>Select a favorite group to add this post to:</p> <% if CurrentUser.favorite_groups.empty? %>
<p>Add this post to a new a favorite group (<%= link_to_wiki "help:favorite_groups" %>):</p>
<% CurrentUser.favorite_groups.each_with_index do |favgroup, i| %> <%= edit_form_for(FavoriteGroup.new, html: { class: "one-line-form" }) do |f| %>
<div> <%= f.input :name, as: :string, required: true, input_html: { style: "width: 20em" } %>
<%= i + 1 %>. <%= f.input :post_ids, as: :hidden, input_html: { value: post.id } %>
<%= link_to favgroup.name, <%= f.submit "Create" %>
add_post_favorite_group_path(favgroup, :post_id => post.id, :format => :js), <% end %>
:id => "add-to-favgroup-#{i + 1}", :class => "add-to-favgroup", <% else %>
:method => :put, :remote => true, <p>Select a favorite group to add this post to (<%= link_to_wiki "help:favorite_groups" %>):</p>
:"data-shortcut" => (i + 1) % 10, :"data-shortcut-when" => ":visible" %>
</div> <% CurrentUser.favorite_groups.each_with_index do |favgroup, i| %>
<div>
<%= i + 1 %>.
<%= link_to favgroup.name,
add_post_favorite_group_path(favgroup, post_id: post.id, format: :js),
id: "add-to-favgroup-#{i + 1}", class: "add-to-favgroup", method: :put,
remote: true, "data-shortcut": (i + 1) % 10, "data-shortcut-when": ":visible"
%>
</div>
<% end %>
<% end %> <% end %>

View File

@@ -0,0 +1 @@
location.reload();