Add key shortcut to add to favgroup
This commit is contained in:
44
app/assets/javascripts/favorite_groups.js
Normal file
44
app/assets/javascripts/favorite_groups.js
Normal file
@@ -0,0 +1,44 @@
|
||||
(function() {
|
||||
Danbooru.FavoriteGroup = {};
|
||||
|
||||
Danbooru.FavoriteGroup.initialize_all = function() {
|
||||
if ($("#c-posts").length && $("#a-show").length) {
|
||||
this.initialize_add_to_favgroup_dialog();
|
||||
$(document).bind("keydown", "1 2 3 4 5 6 7 8 9 0", Danbooru.FavoriteGroup.add_to_favgroup);
|
||||
}
|
||||
}
|
||||
|
||||
Danbooru.FavoriteGroup.initialize_add_to_favgroup_dialog = function() {
|
||||
$("#add-to-favgroup-dialog").dialog({
|
||||
autoOpen: false,
|
||||
width: 500,
|
||||
buttons: {
|
||||
"Cancel": function() {
|
||||
$(this).dialog("close");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$(document).bind("keydown", "g", function(e) {
|
||||
if ($(".add-to-favgroup").length === 1) {
|
||||
// If the user only has one favorite group we don't need to ask which group to add the post to.
|
||||
$(".add-to-favgroup").click();
|
||||
} else if ($(".add-to-favgroup").length > 1) {
|
||||
$("#add-to-favgroup-dialog").dialog("open");
|
||||
}
|
||||
e.preventDefault();
|
||||
});
|
||||
}
|
||||
|
||||
Danbooru.FavoriteGroup.add_to_favgroup = function(e) {
|
||||
var favgroup_index = String.fromCharCode(e.which);
|
||||
var link = $("#add-to-favgroup-" + favgroup_index + ":visible");
|
||||
if (link.length) {
|
||||
link.click();
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
||||
$(function() {
|
||||
Danbooru.FavoriteGroup.initialize_all();
|
||||
});
|
||||
@@ -1,6 +1,6 @@
|
||||
class FavoriteGroupsController < ApplicationController
|
||||
before_filter :member_only, :except => [:index, :show]
|
||||
respond_to :html, :xml, :json
|
||||
respond_to :html, :xml, :json, :js
|
||||
|
||||
def index
|
||||
@favorite_groups = FavoriteGroup.search(params[:search]).order("updated_at desc").paginate(params[:page], :limit => params[:limit], :search_count => params[:search])
|
||||
@@ -59,6 +59,13 @@ class FavoriteGroupsController < ApplicationController
|
||||
redirect_to favorite_groups_path
|
||||
end
|
||||
|
||||
def add_post
|
||||
@favorite_group = FavoriteGroup.find(params[:id])
|
||||
check_privilege(@favorite_group)
|
||||
@post = Post.find(params[:post_id])
|
||||
@favorite_group.add!(@post)
|
||||
end
|
||||
|
||||
private
|
||||
def check_privilege(favgroup)
|
||||
raise User::PrivilegeError unless favgroup.editable_by?(CurrentUser.user)
|
||||
|
||||
@@ -256,7 +256,7 @@ class User < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def favorite_groups
|
||||
FavoriteGroup.for_creator(CurrentUser.user.id)
|
||||
FavoriteGroup.for_creator(CurrentUser.user.id).order("updated_at desc")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
11
app/views/favorite_groups/_add_to_favgroup_dialog.html.erb
Normal file
11
app/views/favorite_groups/_add_to_favgroup_dialog.html.erb
Normal file
@@ -0,0 +1,11 @@
|
||||
<p>Select a favorite group to add this post to:</p>
|
||||
|
||||
<% 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 %>
|
||||
</div>
|
||||
<% end %>
|
||||
1
app/views/favorite_groups/add_post.js.erb
Normal file
1
app/views/favorite_groups/add_post.js.erb
Normal file
@@ -0,0 +1 @@
|
||||
Danbooru.notice("Added post to favorite group <%= escape_javascript(@favorite_group.pretty_name) %>");
|
||||
@@ -133,6 +133,10 @@
|
||||
<div id="add-commentary-dialog" title="Add artist commentary" style="display: none;">
|
||||
<%= render "artist_commentaries/form", :artist_commentary => @post.artist_commentary %>
|
||||
</div>
|
||||
|
||||
<div id="add-to-favgroup-dialog" title="Add to favorite group" style="display: none;">
|
||||
<%= render "favorite_groups/add_to_favgroup_dialog", :post => @post %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<% content_for(:page_title) do %>
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
<li><kbd class="key">a</kbd> Previous post</li>
|
||||
<li><kbd class="key">d</kbd> Next post</li>
|
||||
<li><kbd class="key">f</kbd> Favorite post</li>
|
||||
<li><kbd class="key">g</kbd> Add post to favorite group</li>
|
||||
<li><kbd class="key">r</kbd> Go to random post</li>
|
||||
<li><kbd class="key">v</kbd> Toggle between sample and full size</li>
|
||||
</ul>
|
||||
|
||||
@@ -110,6 +110,9 @@ Rails.application.routes.draw do
|
||||
resource :dtext_preview, :only => [:create]
|
||||
resources :favorites
|
||||
resources :favorite_groups do
|
||||
member do
|
||||
put :add_post
|
||||
end
|
||||
resource :order, :only => [:edit], :controller => "favorite_group_orders"
|
||||
end
|
||||
resources :forum_posts do
|
||||
|
||||
Reference in New Issue
Block a user