diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index d0a34d7b..02be772a 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -22,7 +22,7 @@ class IssuesController < ApplicationController before_filter :find_issue, :only => [:show, :edit, :reply] before_filter :find_issues, :only => [:bulk_edit, :move, :destroy] before_filter :find_project, :only => [:new, :update_form, :preview] - before_filter :authorize, :except => [:index, :changes, :gantt, :calendar, :preview, :update_form, :context_menu] + before_filter :authorize, :except => [:index, :changes, :gantt, :calendar, :preview, :context_menu] before_filter :find_optional_project, :only => [:index, :changes, :gantt, :calendar] accept_key_auth :index, :show, :changes @@ -429,8 +429,17 @@ class IssuesController < ApplicationController end def update_form - @issue = Issue.new(params[:issue]) - render :action => :new, :layout => false + if params[:id] + @issue = @project.issues.visible.find(params[:id]) + else + @issue = Issue.new + @issue.project = @project + end + @issue.attributes = params[:issue] + @allowed_statuses = ([@issue.status] + @issue.status.find_new_statuses_allowed_to(User.current.roles_for_project(@project), @issue.tracker)).uniq + @priorities = IssuePriority.all + + render :partial => 'attributes' end def preview diff --git a/app/models/issue.rb b/app/models/issue.rb index cfc2a1bc..658c8efb 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -127,6 +127,11 @@ class Issue < ActiveRecord::Base self.priority = nil write_attribute(:priority_id, pid) end + + def tracker_id=(tid) + self.tracker = nil + write_attribute(:tracker_id, tid) + end def estimated_hours=(h) write_attribute :estimated_hours, (h.is_a?(String) ? h.to_hours : h) @@ -152,6 +157,13 @@ class Issue < ActiveRecord::Base errors.add_to_base I18n.t(:error_can_not_reopen_issue_on_closed_version) end end + + # Checks that the issue can not be added/moved to a disabled tracker + if project && (tracker_id_changed? || project_id_changed?) + unless project.trackers.include?(tracker) + errors.add :tracker_id, :inclusion + end + end end def validate_on_create diff --git a/app/views/issues/_attributes.rhtml b/app/views/issues/_attributes.rhtml new file mode 100644 index 00000000..cfa14d52 --- /dev/null +++ b/app/views/issues/_attributes.rhtml @@ -0,0 +1,34 @@ +<% fields_for :issue, @issue, :builder => TabularFormBuilder do |f| %> + +
<%= f.select :status_id, (@allowed_statuses.collect {|p| [p.name, p.id]}), :required => true %>
+<% else %> +<%= @issue.status.name %>
+<% end %> + +<%= f.select :priority_id, (@priorities.collect {|p| [p.name, p.id]}), :required => true %>
+<%= f.select :assigned_to_id, (@issue.assignable_users.collect {|m| [m.name, m.id]}), :include_blank => true %>
+<% unless @project.issue_categories.empty? %> +<%= f.select :category_id, (@project.issue_categories.collect {|c| [c.name, c.id]}), :include_blank => true %> +<%= prompt_to_remote(l(:label_issue_category_new), + l(:label_issue_category_new), 'category[name]', + {:controller => 'projects', :action => 'add_issue_category', :id => @project}, + :class => 'small', :tabindex => 199) if authorize_for('projects', 'add_issue_category') %>
+<% end %> +<% unless @issue.assignable_versions.empty? %> +<%= f.select :fixed_version_id, (@issue.assignable_versions.collect {|v| [v.name, v.id]}), :include_blank => true %>
+<% end %> +<%= f.text_field :start_date, :size => 10 %><%= calendar_for('issue_start_date') %>
+<%= f.text_field :due_date, :size => 10 %><%= calendar_for('issue_due_date') %>
+<%= f.text_field :estimated_hours, :size => 3 %> <%= l(:field_hours) %>
+<%= f.select :done_ratio, ((0..10).to_a.collect {|r| ["#{r*10} %", r*10] }) %>
+<%= f.select :tracker_id, @project.trackers.collect {|t| [t.name, t.id]}, :required => true %>
-<%= observe_field :issue_tracker_id, :url => { :action => :new }, - :update => :content, - :with => "Form.serialize('issue-form')" %> -<%= f.select :tracker_id, @project.trackers.collect {|t| [t.name, t.id]}, :required => true %>
+<%= observe_field :issue_tracker_id, :url => { :action => :update_form, :project_id => @project, :id => @issue }, + :update => :attributes, + :with => "Form.serialize('issue-form')" %> +<%= f.text_field :subject, :size => 80, :required => true %>
<%= f.text_area :description, :cols => 60, @@ -15,37 +12,8 @@ :class => 'wiki-edit' %>
<%= f.select :status_id, (@allowed_statuses.collect {|p| [p.name, p.id]}), :required => true %>
-<% else %> -<%= @issue.status.name %>
-<% end %> - -<%= f.select :priority_id, (@priorities.collect {|p| [p.name, p.id]}), :required => true %>
-<%= f.select :assigned_to_id, (@issue.assignable_users.collect {|m| [m.name, m.id]}), :include_blank => true %>
-<% unless @project.issue_categories.empty? %> -<%= f.select :category_id, (@project.issue_categories.collect {|c| [c.name, c.id]}), :include_blank => true %> -<%= prompt_to_remote(l(:label_issue_category_new), - l(:label_issue_category_new), 'category[name]', - {:controller => 'projects', :action => 'add_issue_category', :id => @project}, - :class => 'small', :tabindex => 199) if authorize_for('projects', 'add_issue_category') %>
-<% end %> -<% unless @issue.assignable_versions.empty? %> -<%= f.select :fixed_version_id, (@issue.assignable_versions.collect {|v| [v.name, v.id]}), :include_blank => true %>
-<% end %> -<%= f.text_field :start_date, :size => 10 %><%= calendar_for('issue_start_date') %>
-<%= f.text_field :due_date, :size => 10 %><%= calendar_for('issue_due_date') %>
-<%= f.text_field :estimated_hours, :size => 3 %> <%= l(:field_hours) %>
-<%= f.select :done_ratio, ((0..10).to_a.collect {|r| ["#{r*10} %", r*10] }) %>
-