Feature #588 » change_timelog_project.patch
| app/views/timelog/_form.html.erb | ||
|---|---|---|
| 2 | 2 |
<%= back_url_hidden_field_tag %> |
| 3 | 3 | |
| 4 | 4 |
<div class="box tabular"> |
| 5 |
<% if @time_entry.new_record? %> |
|
| 6 |
<% if params[:project_id] %> |
|
| 7 |
<%= hidden_field_tag 'project_id', params[:project_id] %> |
|
| 8 |
<% elsif params[:issue_id] %> |
|
| 9 |
<%= hidden_field_tag 'issue_id', params[:issue_id] %> |
|
| 10 |
<% else %> |
|
| 11 |
<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> |
|
| 12 |
<% end %> |
|
| 5 |
<% if @time_entry.new_record? && params[:project_id] %> |
|
| 6 |
<%= hidden_field_tag 'project_id', params[:project_id] %> |
|
| 7 |
<% elsif @time_entry.new_record? && params[:issue_id] %> |
|
| 8 |
<%= hidden_field_tag 'issue_id', params[:issue_id] %> |
|
| 9 |
<% else %> |
|
| 10 |
<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> |
|
| 13 | 11 |
<% end %> |
| 12 | ||
| 14 | 13 |
<p> |
| 15 | 14 |
<%= f.text_field :issue_id, :size => 6, :required => Setting.timelog_required_fields.include?('issue_id') %>
|
| 16 | 15 |
<span id="time_entry_issue"> |
| ... | ... | |
| 29 | 28 | |
| 30 | 29 |
<%= javascript_tag do %> |
| 31 | 30 |
$(document).ready(function(){
|
| 31 |
$('#time_entry_project_id').change(function(){
|
|
| 32 |
$('#time_entry_issue_id').val('');
|
|
| 33 |
}); |
|
| 32 | 34 |
$('#time_entry_project_id, #time_entry_issue_id').change(function(){
|
| 33 | 35 |
$.ajax({
|
| 34 | 36 |
url: '<%= escape_javascript(@time_entry.new_record? ? new_time_entry_path(:format => 'js') : edit_time_entry_path(:format => 'js')) %>', |
| ... | ... | |
| 45 | 47 |
term: request.term |
| 46 | 48 |
}; |
| 47 | 49 |
var project_id; |
| 48 |
<% if @project %> |
|
| 49 |
project_id = '<%= @project.id %>';
|
|
| 50 |
<% if @time_entry.new_record? && @project %>
|
|
| 51 |
project_id = '<%= @project.id %>'; |
|
| 50 | 52 |
<% else %> |
| 51 |
project_id = $('#time_entry_project_id').val();
|
|
| 53 |
project_id = $('#time_entry_project_id').val();
|
|
| 52 | 54 |
<% end %> |
| 53 | 55 |
if(project_id){
|
| 54 | 56 |
data['project_id'] = project_id; |
| app/views/timelog/bulk_edit.html.erb | ||
|---|---|---|
| 12 | 12 |
<div class="box tabular"> |
| 13 | 13 |
<div> |
| 14 | 14 |
<p> |
| 15 |
<label><%= l(:field_project) %></label> |
|
| 16 |
<%= select_tag('time_entry[project_id]',
|
|
| 17 |
project_tree_options_for_select(Project.allowed_to(:log_time).to_a, |
|
| 18 |
:include_blank => l(:label_no_change_option), |
|
| 19 |
:selected => @target_project)) %> |
|
| 20 |
</p> |
|
| 21 | ||
| 22 |
<p> |
|
| 15 | 23 |
<label><%= l(:field_issue) %></label> |
| 16 | 24 |
<%= text_field :time_entry, :issue_id, :size => 6 %> |
| 17 | 25 |
</p> |
| app/views/timelog/edit.js.erb | ||
|---|---|---|
| 1 |
$('#time_entry_activity_id').html('<%= escape_javascript options_for_select(activity_collection_for_select_options(@time_entry), @time_entry.activity_id) %>');
|
|
| 1 | 2 |
$('#time_entry_issue').html('<%= escape_javascript link_to_issue(@time_entry.issue) if @time_entry.issue.try(:visible?) %>');
|
| test/functional/timelog_controller_test.rb | ||
|---|---|---|
| 125 | 125 |
assert_select 'option', :text => '--- Please select ---' |
| 126 | 126 |
end |
| 127 | 127 | |
| 128 |
def test_get_edit_should_show_projects_select |
|
| 129 |
@request.session[:user_id] = 2 |
|
| 130 |
get :edit, :params => {:id => 2, :project_id => nil}
|
|
| 131 |
assert_response :success |
|
| 132 | ||
| 133 |
assert_select 'select[name=?]', 'time_entry[project_id]' |
|
| 134 |
end |
|
| 135 | ||
| 128 | 136 |
def test_post_create |
| 129 | 137 |
@request.session[:user_id] = 3 |
| 130 | 138 |
assert_difference 'TimeEntry.count' do |
| ... | ... | |
| 489 | 497 |
assert_select_error /Issue is invalid/ |
| 490 | 498 |
end |
| 491 | 499 | |
| 500 |
def test_update_should_allow_to_change_project |
|
| 501 |
entry = TimeEntry.generate!(:project_id => 1) |
|
| 502 | ||
| 503 |
@request.session[:user_id] = 1 |
|
| 504 |
put :update, :params => {
|
|
| 505 |
:id => entry.id, |
|
| 506 |
:time_entry => {
|
|
| 507 |
:project_id => '2' |
|
| 508 |
} |
|
| 509 |
} |
|
| 510 |
assert_response 302 |
|
| 511 |
entry.reload |
|
| 512 | ||
| 513 |
assert_equal 2, entry.project_id |
|
| 514 |
end |
|
| 515 | ||
| 516 |
def test_update_should_fail_with_issue_from_another_project |
|
| 517 |
entry = TimeEntry.generate!(:project_id => 1, :issue_id => 1) |
|
| 518 | ||
| 519 |
@request.session[:user_id] = 1 |
|
| 520 |
put :update, :params => {
|
|
| 521 |
:id => entry.id, |
|
| 522 |
:time_entry => {
|
|
| 523 |
:project_id => '2' |
|
| 524 |
} |
|
| 525 |
} |
|
| 526 | ||
| 527 |
assert_response :success |
|
| 528 |
assert_select_error /Issue is invalid/ |
|
| 529 |
end |
|
| 530 | ||
| 492 | 531 |
def test_get_bulk_edit |
| 493 | 532 |
@request.session[:user_id] = 2 |
| 494 | 533 | |
- « Previous
- 1
- …
- 6
- 7
- 8
- Next »