move-copy-1.0.4.patch

Brian Lindahl, 2011-01-25 20:08

Download (6.15 KB)

View differences:

redmine-1.0.4-enhanced-move-copy/app/controllers/issue_moves_controller.rb 2011-01-25 10:30:38.585414500 -0700
3 3
  before_filter :find_issues
4 4
  before_filter :authorize
5 5
  
6
  helper :issue_relations
7
  include IssueRelationsHelper
8
  
6 9
  def new
7 10
    prepare_for_issue_move
8 11
    render :layout => false if request.xhr?
......
13 16

  
14 17
    if request.post?
15 18
      new_tracker = params[:new_tracker_id].blank? ? nil : @target_project.trackers.find_by_id(params[:new_tracker_id])
19
      relation_type = params[:relation_type].blank? ? nil : params[:relation_type]
16 20
      unsaved_issue_ids = []
17 21
      moved_issues = []
18 22
      @issues.each do |issue|
......
20 24
        issue.init_journal(User.current)
21 25
        issue.current_journal.notes = @notes if @notes.present?
22 26
        call_hook(:controller_issues_move_before_save, { :params => params, :issue => issue, :target_project => @target_project, :copy => !!@copy })
23
        if r = issue.move_to_project(@target_project, new_tracker, {:copy => @copy, :attributes => extract_changed_attributes_for_move(params)})
27
        if r = issue.move_to_project(@target_project, new_tracker, {:copy => @copy, :relation_type => relation_type, :attributes => extract_changed_attributes_for_move(params)})
24 28
          moved_issues << r
25 29
        else
26 30
          unsaved_issue_ids << issue.id
......
51 55
    @target_project ||= @project    
52 56
    @trackers = @target_project.trackers
53 57
    @available_statuses = Workflow.available_statuses(@project)
58
    @fixed_versions = @target_project.shared_versions.open
59
    @categories = @target_project.issue_categories
54 60
    @notes = params[:notes]
55 61
    @notes ||= ''
56 62
  end
57 63

  
58 64
  def extract_changed_attributes_for_move(params)
59 65
    changed_attributes = {}
60
    [:assigned_to_id, :status_id, :start_date, :due_date, :priority_id].each do |valid_attribute|
66
    [:assigned_to_id, :status_id, :fixed_version_id, :category_id, :start_date, :due_date, :priority_id].each do |valid_attribute|
61 67
      unless params[valid_attribute].blank?
62 68
        changed_attributes[valid_attribute] = (params[valid_attribute] == 'none' ? nil : params[valid_attribute])
63 69
      end
redmine-1.0.4-enhanced-move-copy/app/models/issue.rb 2011-01-25 10:36:45.758484200 -0700
158 158
          end
159 159
        end
160 160
      end
161
      if options[:relation_type]
162
        relation = IssueRelation.new(
163
          :relation_type => options[:relation_type], 
164
          :issue_from => self,
165
          :issue_to => issue)
166
        unless relation.save
167
          issue.destroy
168
          return false
169
        end
170
      end
161 171
    else
162 172
      return false
163 173
    end
redmine-1.0.4-enhanced-move-copy/app/views/issue_moves/new.rhtml 2011-01-25 10:29:49.163223200 -0700
10 10
<%= @issues.collect {|i| hidden_field_tag('ids[]', i.id)}.join %>
11 11

  
12 12
<div class="box tabular">
13
<p><label for="new_project_id"><%=l(:field_project)%>:</label>
13

  
14
<fieldset>
15

  
16
<p><label for="new_project_id"><%=l(:field_project)%></label>
14 17
<%= select_tag "new_project_id",
15 18
               project_tree_options_for_select(@allowed_projects, :selected => @target_project),
16 19
               :onchange => remote_function(:url => { :action => 'new' },
......
18 21
                                            :update => 'content',
19 22
                                            :with => "Form.serialize('move_form')") %></p>
20 23

  
21
<p><label for="new_tracker_id"><%=l(:field_tracker)%>:</label>
24
<p><label for="new_tracker_id"><%=l(:field_tracker)%></label>
22 25
<%= select_tag "new_tracker_id", "<option value=\"\">#{l(:label_no_change_option)}</option>" + options_from_collection_for_select(@trackers, "id", "name") %></p>
23 26

  
27
<% if @copy && (@project == @target_project || Setting.cross_project_issue_relations?) %>
28
  <p>
29
    <label for="relation_type"><%= l(:label_relation_new) %></label>
30
    <%= select_tag('relation_type', "<option value=\"\">#{l(:label_none)}</option>" + options_for_select(collection_for_relation_type_select)) %>
31
  </p>
32
<% end %>
33

  
34
</fieldset>
35

  
36
<fieldset><legend><%= l(:label_attribute_plural) %></legend>
37

  
38
<div class="splitcontentleft">
39

  
24 40
<p>
25 41
  <label><%= l(:field_assigned_to) %></label>
26 42
  <%= select_tag('assigned_to_id', content_tag('option', l(:label_no_change_option), :value => '') +
......
28 44
                                   options_from_collection_for_select(@target_project.assignable_users, :id, :name)) %>
29 45
</p>
30 46

  
47
<% if !@categories.empty? %>
48
<p>
49
  <label><%= l(:field_category) %></label>
50
  <%= select_tag('category_id', "<option value=\"\">#{l(:label_no_change_option)}</option>" + options_from_collection_for_select(@categories, :id, :name)) %>
51
</p>
52
<% end %>
53

  
54
<% if !@fixed_versions.empty? %>
55
<p>
56
  <label><%=l(:field_fixed_version) %></label>
57
  <%= select_tag('fixed_version_id', "<option value=\"\">#{l(:label_no_change_option)}</option>" + options_from_collection_for_select(@fixed_versions, :id, :name)) %>
58
</p>
59
<% end %>
60

  
61
</div>
62

  
63
<div class="splitcontentright">
64

  
31 65
<p>
32 66
  <label><%= l(:field_status) %></label>
33 67
  <%= select_tag('status_id', "<option value=\"\">#{l(:label_no_change_option)}</option>" + options_from_collection_for_select(@available_statuses, :id, :name)) %>
......
48 82
  <%= text_field_tag 'due_date', '', :size => 10 %><%= calendar_for('due_date') %>
49 83
</p>
50 84

  
85
</div>
86
</fieldset>
87

  
51 88
<fieldset><legend><%= l(:field_notes) %></legend>
52 89
<%= text_area_tag 'notes', @notes, :cols => 60, :rows => 10, :class => 'wiki-edit' %>
53 90
<%= wikitoolbar_for 'notes' %>