Index: app/models/issue_category.rb =================================================================== --- app/models/issue_category.rb (revision 8748) +++ app/models/issue_category.rb (working copy) @@ -20,6 +20,8 @@ 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 Index: app/controllers/issue_categories_controller.rb =================================================================== --- app/controllers/issue_categories_controller.rb (revision 8748) +++ app/controllers/issue_categories_controller.rb (working copy) @@ -40,11 +40,13 @@ 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 @@ -75,6 +77,7 @@ verify :method => :put, :only => :update def update + assign_watchers_from_params if @category.update_attributes(params[:issue_category]) respond_to do |format| format.html { @@ -122,4 +125,10 @@ 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 Index: app/controllers/watchers_controller.rb =================================================================== --- app/controllers/watchers_controller.rb (revision 8748) +++ app/controllers/watchers_controller.rb (working copy) @@ -16,7 +16,7 @@ # 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] @@ -36,6 +36,16 @@ 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 respond_to do |format| format.js do Index: app/views/issues/new.html.erb =================================================================== --- app/views/issues/new.html.erb (revision 8748) +++ app/views/issues/new.html.erb (working copy) @@ -23,9 +23,10 @@ <% if @issue.safe_attribute? 'watcher_user_ids' -%>

<% @issue.project.users.sort.each do |user| -%> - + <% end -%>

+ <%= javascript_tag "setupNewIssueWatchersByCategory('#{j(url_for :controller => 'watchers', :action => 'show', :watchable_type => 'issue_category', :watchable_id => 'watchable_id', :format => 'json')}')" %> <% end %> Index: app/views/issue_categories/_form.html.erb =================================================================== --- app/views/issue_categories/_form.html.erb (revision 8748) +++ app/views/issue_categories/_form.html.erb (working copy) @@ -3,4 +3,8 @@

<%= f.text_field :name, :size => 30, :required => true %>

<%= f.select :assigned_to_id, principals_options_for_select(@project.assignable_users, @category.assigned_to), :include_blank => true %>

+

+<% @project.users.sort.each do |user| -%> + +<% end -%>

Index: public/javascripts/application.js =================================================================== --- public/javascripts/application.js (revision 8748) +++ public/javascripts/application.js (working copy) @@ -515,3 +515,41 @@ } 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(); +} Index: public/stylesheets/application.css =================================================================== --- public/stylesheets/application.css (revision 8748) +++ public/stylesheets/application.css (working copy) @@ -1048,3 +1048,8 @@ height:1px; overflow:hidden; } + +#watchers_form .watchers_default { + color: #080; + font-weight:bold; +} Index: config/locales/en.yml =================================================================== --- config/locales/en.yml (revision 8748) +++ config/locales/en.yml (working copy) @@ -496,6 +496,7 @@ 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 Index: config/locales/ja.yml =================================================================== --- config/locales/ja.yml (revision 8748) +++ config/locales/ja.yml (working copy) @@ -510,6 +510,7 @@ 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: 新しいカスタムフィールドを作成 Index: config/routes.rb =================================================================== --- config/routes.rb (revision 8748) +++ config/routes.rb (working copy) @@ -140,6 +140,8 @@ map.connect 'watchers/autocomplete_for_user', :controller=> 'watchers', :action => 'autocomplete_for_user', :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 :conditions => {:method => :get} do |project_views| project_views.connect 'projects/:id/settings/:tab',