Project

General

Profile

Feature #5577 » category_watchers_patch-20120202-tags_1.3.0.patch

patch for tags/1.3.0 - Nayuta Taga, 2012-02-02 10:00

View differences:

app/models/issue_category.rb (working copy)
belongs_to :assigned_to, :class_name => 'Principal', :foreign_key => 'assigned_to_id'
has_many :issues, :foreign_key => 'category_id', :dependent => :nullify
acts_as_watchable
validates_presence_of :name
validates_uniqueness_of :name, :scope => [:project_id]
validates_length_of :name, :maximum => 30
app/controllers/issue_categories_controller.rb (working copy)
def new
@category = @project.issue_categories.build(params[:issue_category])
assign_watchers_from_params
end
verify :method => :post, :only => :create
def create
@category = @project.issue_categories.build(params[:issue_category])
assign_watchers_from_params
if @category.save
respond_to do |format|
format.html do
......
verify :method => :put, :only => :update
def update
assign_watchers_from_params
if @category.update_attributes(params[:issue_category])
respond_to do |format|
format.html {
......
rescue ActiveRecord::RecordNotFound
render_404
end
def assign_watchers_from_params
if params[:issue_category].is_a?(Hash)
@category.watcher_user_ids = params[:issue_category]['watcher_user_ids']
end
end
end
app/controllers/watchers_controller.rb (working copy)
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class WatchersController < ApplicationController
before_filter :find_project
before_filter :find_project, :except => [:show]
before_filter :require_login, :check_project_privacy, :only => [:watch, :unwatch]
before_filter :authorize, :only => [:new, :destroy]
......
set_watcher(User.current, false)
end
def show
p params
respond_to do |format|
format.api {
result = Watcher.find(:all, :conditions => [ "watchable_type = ? and watchable_id = ?", params['watchable_type'].classify, params['watchable_id'].to_i])
render :json => result
}
end
end
def new
@watcher = Watcher.new(params[:watcher])
@watcher.watchable = @watched
app/views/issues/_form.html.erb (working copy)
<% if @issue.new_record? && User.current.allowed_to?(:add_issue_watchers, @project) -%>
<p id="watchers_form"><label><%= l(:label_issue_watchers) %></label>
<% @issue.project.users.sort.each do |user| -%>
<label class="floating"><%= check_box_tag 'issue[watcher_user_ids][]', user.id, @issue.watched_by?(user) %> <%=h user %></label>
<label class="floating watchers_label"><%= check_box_tag 'issue[watcher_user_ids][]', user.id, @issue.watched_by?(user)%> <%=h user %></label>
<% end -%>
</p>
<%= javascript_tag "setupNewIssueWatchersByCategory('#{j(url_for :controller => 'watchers', :action => 'show', :watchable_type => 'issue_category', :watchable_id => 'watchable_id', :format => 'json')}')" %>
<% end %>
<%= call_hook(:view_issues_form_details_bottom, { :issue => @issue, :form => f }) %>
app/views/issue_categories/_form.html.erb (working copy)
<div class="box">
<p><%= f.text_field :name, :size => 30, :required => true %></p>
<p><%= f.select :assigned_to_id, principals_options_for_select(@project.assignable_users, @category.assigned_to), :include_blank => true %></p>
<p id="watchers_form"><label><%= l(:label_issue_watchers) %></label>
<% @project.users.sort.each do |user| -%>
<label class="floating"><%= check_box_tag 'issue_category[watcher_user_ids][]', user.id, @category.watched_by?(user) %> <%=h user %></label>
<% end -%>
</div>
public/javascripts/application.js (working copy)
}
Event.observe(window, 'load', hideOnLoad);
function setupNewIssueWatchersByCategory(url_pattern) {
issue_category_id = $('issue_category_id');
if (!issue_category_id) {
return;
}
function reset() {
$$('#watchers_form .watchers_default input').each(function(el){
el.checked = false;
el.parentNode.removeClassName('watchers_default');
});
}
function f() {
if (0 < issue_category_id.value.length) {
url = url_pattern.replace(/watchable_id/, issue_category_id.value);
new Ajax.Request(url, {
onSuccess: function (request) {
eval("result="+ request.responseText);
reset();
$$('#watchers_form .watchers_label input').each(function(el){
user_id = parseInt(el.value);
result.each(function(watcher){
if (user_id === watcher.user_id) {
el.checked = true;
el.parentNode.addClassName('watchers_default');
throw $break;
}
});
});
}
});
} else {
reset();
}
}
Event.observe(issue_category_id, 'change', f);
f();
}
public/stylesheets/application.css (working copy)
height:1px;
overflow:hidden;
}
#watchers_form .watchers_default {
color: #080;
font-weight:bold;
}
config/locales/en.yml (working copy)
label_issue_category: Issue category
label_issue_category_plural: Issue categories
label_issue_category_new: New category
label_issue_category_watchers: Default watchers
label_custom_field: Custom field
label_custom_field_plural: Custom fields
label_custom_field_new: New custom field
config/locales/ja.yml (working copy)
label_issue_category: チケットのカテゴリ
label_issue_category_plural: チケットのカテゴリ
label_issue_category_new: 新しいカテゴリ
label_issue_category_watchers: デフォルトウォッチャー
label_custom_field: カスタムフィールド
label_custom_field_plural: カスタムフィールド
label_custom_field_new: 新しいカスタムフィールドを作成
config/routes.rb (working copy)
# Destroy uses a get request to prompt the user before the actual DELETE request
map.project_destroy_confirm 'projects/:id/destroy', :controller => 'projects', :action => 'destroy', :conditions => {:method => :get}
map.connect 'watchers/:action/:watchable_type/:watchable_id.:format', :controller => 'watchers'
# TODO: port to be part of the resources route(s)
map.with_options :controller => 'projects' do |project_mapper|
project_mapper.with_options :conditions => {:method => :get} do |project_views|
(2-2/6)