##// END OF EJS Templates
Update activities list when changing project/issue id on the time entry form (#19656)....
Jean-Philippe Lang -
r13905:216a153421b0
parent child
Show More
@@ -0,0 +1,1
1 $('#time_entry_activity_id').html('<%= escape_javascript options_for_select(activity_collection_for_select_options(@time_entry), @time_entry.activity_id) %>');
@@ -0,0 +1,44
1 # Redmine - project management software
2 # Copyright (C) 2006-2015 Jean-Philippe Lang
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18 require File.expand_path('../base', __FILE__)
19
20 class Redmine::UiTest::TimelogTest < Redmine::UiTest::Base
21 fixtures :projects, :users, :email_addresses, :roles, :members, :member_roles,
22 :trackers, :projects_trackers, :enabled_modules, :issue_statuses, :issues,
23 :enumerations, :custom_fields, :custom_values, :custom_fields_trackers
24
25 def test_changing_project_should_update_activities
26 project = Project.find(1)
27 TimeEntryActivity.create!(:name => 'Design', :project => project, :parent => TimeEntryActivity.find_by_name('Design'), :active => false)
28
29 log_user 'jsmith', 'jsmith'
30 visit '/time_entries/new'
31 within 'select#time_entry_activity_id' do
32 assert has_content?('Development')
33 assert has_content?('Design')
34 end
35
36 within 'form#new_time_entry' do
37 select 'eCookbook', :from => 'Project'
38 end
39 within 'select#time_entry_activity_id' do
40 assert has_content?('Development')
41 assert !has_content?('Design')
42 end
43 end
44 end
@@ -38,6 +38,7 module TimelogHelper
38 # is optional and will be used to check if the selected TimeEntryActivity
38 # is optional and will be used to check if the selected TimeEntryActivity
39 # is active.
39 # is active.
40 def activity_collection_for_select_options(time_entry=nil, project=nil)
40 def activity_collection_for_select_options(time_entry=nil, project=nil)
41 project ||= time_entry.try(:project)
41 project ||= @project
42 project ||= @project
42 if project.nil?
43 if project.nil?
43 activities = TimeEntryActivity.shared.active
44 activities = TimeEntryActivity.shared.active
@@ -26,9 +26,22
26 </div>
26 </div>
27
27
28 <%= javascript_tag do %>
28 <%= javascript_tag do %>
29 <% if @time_entry.new_record? %>
30 $(document).ready(function(){
31 $('#time_entry_project_id, #time_entry_issue_id').change(function(){
32 $.ajax({
33 url: '<%= escape_javascript new_time_entry_path(:format => 'js') %>',
34 type: 'post',
35 data: $('#new_time_entry').serialize()
36 });
37 });
38 });
39 <% end %>
40
29 observeAutocompleteField('time_entry_issue_id', '<%= escape_javascript auto_complete_issues_path(:project_id => @project, :scope => (@project ? nil : 'all'))%>', {
41 observeAutocompleteField('time_entry_issue_id', '<%= escape_javascript auto_complete_issues_path(:project_id => @project, :scope => (@project ? nil : 'all'))%>', {
30 select: function(event, ui) {
42 select: function(event, ui) {
31 $('#time_entry_issue').text(ui.item.label);
43 $('#time_entry_issue').text(ui.item.label);
44 $('#time_entry_issue_id').blur();
32 }
45 }
33 });
46 });
34 <% end %>
47 <% end %>
@@ -215,6 +215,8 Rails.application.routes.draw do
215 match '/time_entries/:id', :to => 'timelog#destroy', :via => :delete, :id => /\d+/
215 match '/time_entries/:id', :to => 'timelog#destroy', :via => :delete, :id => /\d+/
216 # TODO: delete /time_entries for bulk deletion
216 # TODO: delete /time_entries for bulk deletion
217 match '/time_entries/destroy', :to => 'timelog#destroy', :via => :delete
217 match '/time_entries/destroy', :to => 'timelog#destroy', :via => :delete
218 # Used to update the new time entry form
219 post '/time_entries/new', :to => 'timelog#new'
218
220
219 get 'projects/:id/activity', :to => 'activities#index', :as => :project_activity
221 get 'projects/:id/activity', :to => 'activities#index', :as => :project_activity
220 get 'activity', :to => 'activities#index'
222 get 'activity', :to => 'activities#index'
@@ -95,6 +95,13 class TimelogControllerTest < ActionController::TestCase
95 assert_select 'option', :text => 'Inactive Activity', :count => 0
95 assert_select 'option', :text => 'Inactive Activity', :count => 0
96 end
96 end
97
97
98 def test_post_new_as_js_should_update_activity_options
99 @request.session[:user_id] = 3
100 post :new, :time_entry => {:project_id => 1}, :format => 'js'
101 assert_response :success
102 assert_include '#time_entry_activity_id', response.body
103 end
104
98 def test_get_edit_existing_time
105 def test_get_edit_existing_time
99 @request.session[:user_id] = 2
106 @request.session[:user_id] = 2
100 get :edit, :id => 2, :project_id => nil
107 get :edit, :id => 2, :project_id => nil
@@ -23,6 +23,7 class RoutingTimelogsTest < Redmine::RoutingTest
23 should_route 'GET /time_entries.csv' => 'timelog#index', :format => 'csv'
23 should_route 'GET /time_entries.csv' => 'timelog#index', :format => 'csv'
24 should_route 'GET /time_entries.atom' => 'timelog#index', :format => 'atom'
24 should_route 'GET /time_entries.atom' => 'timelog#index', :format => 'atom'
25 should_route 'GET /time_entries/new' => 'timelog#new'
25 should_route 'GET /time_entries/new' => 'timelog#new'
26 should_route 'POST /time_entries/new' => 'timelog#new'
26 should_route 'POST /time_entries' => 'timelog#create'
27 should_route 'POST /time_entries' => 'timelog#create'
27
28
28 should_route 'GET /time_entries/22/edit' => 'timelog#edit', :id => '22'
29 should_route 'GET /time_entries/22/edit' => 'timelog#edit', :id => '22'
General Comments 0
You need to be logged in to leave comments. Login now