refactored javascripts

This commit is contained in:
albert
2011-03-10 12:58:09 -05:00
parent 4af5c5c38f
commit efa6856b4a
27 changed files with 385 additions and 359 deletions

View File

@@ -3,7 +3,7 @@ class TagAliasesController < ApplicationController
respond_to :html, :xml, :json
def new
@tag_alias = TagAlias.new
@tag_alias = TagAlias.new(params[:tag_alias])
respond_with(@tag_alias)
end

View File

@@ -2,6 +2,7 @@ class WikiPagesController < ApplicationController
respond_to :html, :xml, :json
before_filter :member_only, :except => [:index, :show]
before_filter :moderator_only, :only => [:destroy]
before_filter :normalize_search_params, :only => [:index]
def new
@wiki_page = WikiPage.new
@@ -53,4 +54,12 @@ class WikiPagesController < ApplicationController
@wiki_page.revert_to!(@version)
respond_with(@wiki_page)
end
private
def normalize_search_params
if params[:title]
params[:search] ||= {}
params[:search][:title_equals] = params.delete(:title)
end
end
end

View File

@@ -34,7 +34,7 @@ module ApplicationHelper
end
def wait_image(html_id)
('<img src="/images/wait.gif" style="display: none;" id="' + html_id + '">').html_safe
('<img src="/images/wait.gif" style="display: none;" class="wait" id="' + html_id + '">').html_safe
end
protected

View File

@@ -29,6 +29,14 @@ class TagAlias < ActiveRecord::Base
self.creator_id = CurrentUser.user.id
end
def antecedent_tag
Tag.find_by_name(antecedent_name)
end
def consequent_tag
Tag.find_by_name(consequent_name)
end
def absence_of_transitive_relation
# We don't want a -> b && b -> c chains
if self.class.exists?(["antecedent_name = ?", consequent_name]) || self.class.exists?(["consequent_name = ?", antecedent_name])

View File

@@ -61,7 +61,7 @@
<td>
<%= link_to h(url.to_s), h(url.to_s) %>
<% if CurrentUser.user.is_moderator? %>
(<%= link_to("mass edit", mass_edit_admin_posts_path(:antecedent => "-#{@artist.name} source:#{ArtistUrl.normalize_for_search(url.to_s)}", :consequent => @artist.name)) %>)
(<%#= link_to("mass edit", mass_edit_admin_posts_path(:antecedent => "-#{@artist.name} source:#{ArtistUrl.normalize_for_search(url.to_s)}", :consequent => @artist.name)) %>)
<% end %>
</td>
</tr>

View File

@@ -35,8 +35,12 @@
<%= nav_link_to("Notes", notes_path) %>
<%= nav_link_to("Artists", artists_path(:order => "date")) %>
<%= nav_link_to("Tags", tags_path(:order => "date")) %>
<% if CurrentUser.is_moderator? %>
<%= nav_link_to("Aliases", tag_aliases_path) %>
<%= nav_link_to("Implications", tag_implications_path) %>
<% end %>
<%= nav_link_to("Pools", pools_path) %>
<%= nav_link_to("Wiki", wiki_pages_path(:search => {:title_equals => "help:home"})) %>
<%= nav_link_to("Wiki", wiki_pages_path(:title => "help:home")) %>
<%= nav_link_to("Forum", forum_topics_path, :class => (CurrentUser.user.has_forum_been_updated? ? "forum-updated" : nil)) %>
<%= nav_link_to("&raquo;".html_safe, site_map_path) %>
</menu>

View File

@@ -1,2 +1,2 @@
Danbooru.Utility.j_error(<%= @exception.message.to_json.html_safe %>);
Danbooru.j_error(<%= @exception.message.to_json.html_safe %>);
$("img#approve-wait").hide();

View File

@@ -1,2 +1,2 @@
Danbooru.Utility.j_error("You have already disapproved this post");
Danbooru.j_error("You have already disapproved this post");
$("img#disapprove-wait").hide();

View File

@@ -0,0 +1,7 @@
<% content_for(:secondary_links) do %>
<menu>
<li><%= link_to "Listing", tag_aliases_path %></li>
<li><%= link_to "Add", new_tag_alias_path %></li>
<li><%= link_to "Help", wiki_pages_path(:title => "help:tag_aliases") %></li>
</menu>
<% end %>

View File

@@ -1,92 +1,42 @@
<div style="margin-bottom: 1em;">
<% form_tag(tag_aliases_path, :method => :get) do %>
<%= text_field_tag "query", params[:query] %>
<%= submit_tag "Search Aliases" %>
<%= submit_tag "Search Implications" %>
<% end %>
</div>
<div id="c-tag-aliases">
<div id="a-index">
<div class="search">
<% form_tag(tag_aliases_path, :method => :get) do %>
<%= text_field_tag "query", params[:query] %>
<%= submit_tag "Search Aliases" %>
<%= submit_tag "Search Implications" %>
<% end %>
</div>
<div id="aliases">
<% form_tag(:action => "update") do %>
<table width="100%" class="highlightable">
<thead>
<tr>
<th width="1%"></th>
<th width="19%">From</th>
<th width="20%">From</th>
<th width="20%">To</th>
<th width="60%">Reason</th>
<th width="20%">Reference</th>
<th width="40%"></th>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="4">
<% if @current_user.is_admin_or_higher? %>
<%= button_to_function "Select pending", "$$('.pending').each(function(x) {x.checked = true})" %>
<%= submit_tag "Approve" %>
<%= button_to_function "Delete", "$('reason-box').show(); $('reason').focus()" %>
<%= submit_tag "Fix" %>
<%= button_to_function "Add", "$('add-box').show().scrollTo(); $('tag_alias_name').focus()" %>
<div id="reason-box" style="display: none; margin-top: 1em;">
<strong>Reason:</strong>
<%= text_field_tag "reason", "", :size => 40 %>
<%= submit_tag "Delete" %>
</div>
<% end %>
</td>
</tr>
</tfoot>
<tbody>
<% @aliases.each do |a| %>
<tr class="<%= cycle 'even', 'odd' %> <%= a.is_pending? ? 'pending-tag' : nil %>">
<td><input type="checkbox" name="aliases[<%= a.id %>]" value="1" <%= a.is_pending? ? 'class="pending"' : nil %>></td>
<td><%= link_to h(a.name), :controller => "post", :action => "index", :tags => a.name %> (<%= Tag.find_by_name(a.name).post_count rescue 0 %>)</td>
<td><%= link_to h(a.alias_name), :controller => "post", :action => "index", :tags => a.alias_name %> (<%= Tag.find(a.alias_id).post_count rescue 0 %>)</td>
<td><%= format_text(a.reason) %></td>
<% @tag_aliases.each do |tag_alias| %>
<tr>
<td><%= link_to tag_alias.antecedent_name, posts_path(:tags => tag_alias.antecedent_name) %> (<%= tag_alias.antecedent_tag.post_count rescue 0 %>)</td>
<td><%= link_to tag_alias.consequent_name, posts_path(:tags => tag_alias.consequent_name) %> (<%= tag_alias.consequent_tag.post_count rescue 0 %>)</td>
<td><%= link_to tag_alias.forum_topic_id, forum_topic_path(tag_alias.forum_topic_id) %></td>
<td>
<% if CurrentUser.is_admin? %>
<%= link_to "Delete", :url => tag_alias_path(tag_alias), :remote => true, :method => :delete, :confirm => "Are you sure you want to delete this alias?" %>
<% end %>
</td>
</tr>
<% end %>
</tbody>
</table>
<% end %>
</div>
<% if @current_user.is_admin_or_higher? %>
<div id="add-box" <% unless params[:to_name] %>style="display: none;"<% end %>>
<% form_tag(:action => "create") do %>
<h4>Add Alias</h4>
<% unless @current_user.is_anonymous? %>
<%= hidden_field_tag "tag_alias[creator_id]", @current_user.id %>
<% end %>
<table>
<tr>
<th><label for="tag_alias_name">Name</label></th>
<td><%= text_field "tag_alias", "name", :size => 40, :value => params[:from_name] %></td>
</tr>
<tr>
<th><label for="tag_alias_alias">Alias to</label></th>
<td><%= text_field "tag_alias", "alias", :size => 40, :value => params[:to_name] %></td>
</tr>
<tr>
<th><label for="tag_alias_reason">Reason</label></th>
<td><%= text_area "tag_alias", "reason", :size => "40x2", :value => params[:reason] %></td>
</tr>
<tr>
<td colspan="2"><%= submit_tag "Submit" %></td>
</tr>
</table>
<% end %>
</div>
<% end %>
</div>
<div id="paginator">
<%= will_paginate(@aliases) %>
</div>
<% content_for("subnavbar") do %>
<li><%= link_to "List", :controller => "tag_alias", :action => "index" %></li>
<li><%= link_to "Add", :controller => "tag_alias", :action => "new" %></li>
<li><%= link_to "Help", :controller => "help", :action => "tag_aliases" %></li>
<% end %>
<%= render "secondary_links" %>

View File

@@ -1,20 +1,13 @@
<% form_tag(:controller => "forum", :action => "create") do %>
<p>You can create a forum thread to suggest the creation of an alias.</p>
<table>
<tr>
<th><label for="tag_alias_name">From</label></th>
<td><%= text_field "tag_alias", "name", :size => 40 %></td>
</tr>
<tr>
<th><label for="tag_alias_alias">To</label></th>
<td><%= text_field "tag_alias", "alias", :size => 40 %></td>
</tr>
<tr>
<th><label for="tag_alias_reason">Reason</label></th>
<td><%= text_area "tag_alias", "reason", :rows => 10, :cols => 60 %></td>
</tr>
<tr>
<td colspan="2"><%= submit_tag "Submit" %></td>
</tr>
</table>
<% end %>
<div id="c-tag-aliases">
<div id="a-new">
<h1>New Tag Alias</h1>
<%= simple_form_for(@tag_alias) do |f| %>
<%= f.input :antecedent_name, :label => "From" %>
<%= f.input :consequent_name, :label => "To" %>
<%= f.input :forum_topic_id, :label => "Forum" %>
<%= f.button :submit %>
<% end %>
</div>
</div>
<%= render "secondary_links" %>

View File

@@ -1,8 +1,8 @@
var errors = <%= @unapproval.errors.full_messages.to_json.html_safe %>;
if (errors.length > 0) {
Danbooru.Utility.j_error(errors.join("; "));
Danbooru.j_error(errors.join("; "));
} else {
Danbooru.Utility.j_alert("Unapproval", "Unapproval successful");
Danbooru.j_alert("Unapproval", "Unapproval successful");
$("a#approve").show();
$("a#disapprove").show();
$("a#unapprove").hide();