]> source.dussan.org Git - redmine.git/commitdiff
Timelog move between projects (#588).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Mon, 3 Apr 2017 09:33:27 +0000 (09:33 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Mon, 3 Apr 2017 09:33:27 +0000 (09:33 +0000)
Patch by Marius BALTEANU.

git-svn-id: http://svn.redmine.org/redmine/trunk@16450 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/views/timelog/_form.html.erb
app/views/timelog/edit.js.erb
test/functional/timelog_controller_test.rb

index 2d1134c4cbb6c0c14e0865e14c246b3e84ca4123..aa62ffc786dcac9567f32ebc31c5e90a31cbe52e 100644 (file)
@@ -2,15 +2,14 @@
 <%= back_url_hidden_field_tag %>
 
 <div class="box tabular">
-  <% if @time_entry.new_record? %>
-    <% if params[:project_id] %>
-      <%= hidden_field_tag 'project_id', params[:project_id] %>
-    <% elsif params[:issue_id] %>
-      <%= hidden_field_tag 'issue_id', params[:issue_id] %>
-    <% else %>
-      <p><%= f.select :project_id, project_tree_options_for_select(Project.allowed_to(:log_time).to_a, :selected => @time_entry.project, :include_blank => true), :required => true %></p>
-    <% end %>
+  <% if @time_entry.new_record? && params[:project_id] %>
+    <%= hidden_field_tag 'project_id', params[:project_id] %>
+  <% elsif @time_entry.new_record? && params[:issue_id] %>
+    <%= hidden_field_tag 'issue_id', params[:issue_id] %>
+  <% else %>
+    <p><%= f.select :project_id, project_tree_options_for_select(Project.allowed_to(:log_time).to_a, :selected => @time_entry.project, :include_blank => true), :required => true %></p>
   <% end %>
+
   <p>
     <%= f.text_field :issue_id, :size => 6, :required => Setting.timelog_required_fields.include?('issue_id') %>
     <span id="time_entry_issue">
@@ -29,6 +28,9 @@
 
 <%= javascript_tag do %>
   $(document).ready(function(){
+    $('#time_entry_project_id').change(function(){
+      $('#time_entry_issue_id').val('');
+    });
     $('#time_entry_project_id, #time_entry_issue_id').change(function(){
       $.ajax({
         url: '<%= escape_javascript(@time_entry.new_record? ? new_time_entry_path(:format => 'js') : edit_time_entry_path(:format => 'js')) %>',
         term: request.term
       };
       var project_id;
-      <% if @project %>
-        project_id = '<%= @project.id %>';
+      <% if @time_entry.new_record? && @project %>
+      project_id = '<%= @project.id %>';
       <% else %>
-        project_id = $('#time_entry_project_id').val();
+      project_id = $('#time_entry_project_id').val();
       <% end %>
       if(project_id){
         data['project_id'] = project_id;
index cd7861140b0db07a25972d27bd74704364e486e1..4cba8cfe6c6c234d84c7f60b1b0b0946202a4143 100644 (file)
@@ -1 +1,2 @@
+$('#time_entry_activity_id').html('<%= escape_javascript options_for_select(activity_collection_for_select_options(@time_entry), @time_entry.activity_id) %>');
 $('#time_entry_issue').html('<%= escape_javascript link_to_issue(@time_entry.issue) if @time_entry.issue.try(:visible?) %>');
index baad0c95db2e87b8044b5ab52e7ca271ca4fd003..ead919006e4bf35799cd78c528bedeff4bd16530 100644 (file)
@@ -125,6 +125,14 @@ class TimelogControllerTest < Redmine::ControllerTest
     assert_select 'option', :text => '--- Please select ---'
   end
 
+  def test_get_edit_should_show_projects_select
+    @request.session[:user_id] = 2
+    get :edit, :params => {:id => 2, :project_id => nil}
+    assert_response :success
+
+    assert_select 'select[name=?]', 'time_entry[project_id]'
+  end
+
   def test_post_create
     @request.session[:user_id] = 3
     assert_difference 'TimeEntry.count' do
@@ -489,6 +497,37 @@ class TimelogControllerTest < Redmine::ControllerTest
     assert_select_error /Issue is invalid/
   end
 
+  def test_update_should_allow_to_change_project
+    entry = TimeEntry.generate!(:project_id => 1)
+
+    @request.session[:user_id] = 1
+    put :update, :params => {
+      :id => entry.id,
+      :time_entry => {
+        :project_id => '2'
+      }
+    }
+    assert_response 302
+    entry.reload
+
+    assert_equal 2, entry.project_id
+  end
+
+  def test_update_should_fail_with_issue_from_another_project
+    entry = TimeEntry.generate!(:project_id => 1, :issue_id => 1)
+
+    @request.session[:user_id] = 1
+    put :update, :params => {
+      :id => entry.id,
+      :time_entry => {
+        :project_id => '2'
+      }
+    }
+
+    assert_response :success
+    assert_select_error /Issue is invalid/
+  end
+
   def test_get_bulk_edit
     @request.session[:user_id] = 2