Defect #34922 ยป 34922.patch
app/views/timelog/_form.html.erb | ||
---|---|---|
1 | 1 |
<%= error_messages_for 'time_entry' %> |
2 | 2 |
<%= back_url_hidden_field_tag %> |
3 | 3 | |
4 |
<div class="box tabular">
|
|
4 |
<%= labelled_fields_for :time_entry, @time_entry do |f| %>
|
|
5 | 5 |
<% if @time_entry.new_record? && params[:project_id] %> |
6 | 6 |
<%= hidden_field_tag 'project_id', params[:project_id] %> |
7 | 7 |
<% elsif @time_entry.new_record? && params[:issue_id] %> |
... | ... | |
36 | 36 |
<% end %> |
37 | 37 |
<% end %> |
38 | 38 |
<%= call_hook(:view_timelog_edit_form_bottom, { :time_entry => @time_entry, :form => f }) %> |
39 |
</div>
|
|
39 |
<% end %>
|
|
40 | 40 | |
41 | 41 |
<%= javascript_tag do %> |
42 | 42 |
$(document).ready(function(){ |
... | ... | |
44 | 44 |
$('#time_entry_issue_id').val(''); |
45 | 45 |
}); |
46 | 46 |
$('#time_entry_project_id, #time_entry_issue_id').change(function(){ |
47 |
$.ajax({ |
|
48 |
url: '<%= escape_javascript(@time_entry.new_record? ? new_time_entry_path(:format => 'js') : edit_time_entry_path(:format => 'js')) %>', |
|
49 |
type: 'post', |
|
50 |
data: $(this).closest('form').serialize() |
|
51 |
}); |
|
47 |
updateTimeEntryForm('<%= escape_javascript(@time_entry.new_record? ? new_time_entry_path(:format => 'js') : edit_time_entry_path(:format => 'js')) %>'); |
|
52 | 48 |
}); |
53 | 49 |
}); |
54 | 50 |
app/views/timelog/edit.html.erb | ||
---|---|---|
1 | 1 |
<h2><%= l(:label_spent_time) %></h2> |
2 | 2 | |
3 |
<%= labelled_form_for @time_entry, :url => time_entry_path(@time_entry), :html => {:multipart => true} do |f| %> |
|
3 |
<%= labelled_form_for @time_entry, :url => time_entry_path(@time_entry), :html => {:id =>'time-entry-form', :multipart => true} do |f| %> |
|
4 |
<div class="box tabular" id="all_attributes"> |
|
4 | 5 |
<%= render :partial => 'form', :locals => {:f => f} %> |
6 |
</div> |
|
5 | 7 |
<%= submit_tag l(:button_save) %> |
6 | 8 |
<%= cancel_button_tag_for_time_entry(@project) %> |
7 | 9 |
<% end %> |
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) %>'); |
|
2 |
$('#time_entry_issue').html('<%= escape_javascript link_to_issue(@time_entry.issue) if @time_entry.issue.try(:visible?) %>'); |
|
1 |
replaceTimeEntryFormWith('<%= escape_javascript(render :partial => 'form') %>'); |
app/views/timelog/new.html.erb | ||
---|---|---|
1 | 1 |
<h2><%= l(:label_spent_time) %></h2> |
2 | 2 | |
3 |
<%= labelled_form_for @time_entry, :url => time_entries_path, :html => {:multipart => true} do |f| %> |
|
3 |
<%= labelled_form_for @time_entry, :url => time_entries_path, :html => {:id =>'time-entry-form', :multipart => true} do |f| %> |
|
4 |
<div class="box tabular" id="all_attributes"> |
|
4 | 5 |
<%= render :partial => 'form', :locals => {:f => f} %> |
6 |
</div> |
|
5 | 7 |
<%= submit_tag l(:button_create) %> |
6 | 8 |
<%= submit_tag l(:button_create_and_continue), :name => 'continue' %> |
7 | 9 |
<%= cancel_button_tag_for_time_entry(@project) %> |
app/views/timelog/new.js.erb | ||
---|---|---|
1 |
$('#time_entry_activity_id').html('<%= escape_javascript options_for_select(activity_collection_for_select_options(@time_entry), @time_entry.activity_id) %>'); |
|
2 |
$('#time_entry_issue').html('<%= escape_javascript link_to_issue(@time_entry.issue) if @time_entry.issue.try(:visible?) %>'); |
|
1 |
replaceTimeEntryFormWith('<%= escape_javascript(render :partial => 'form') %>'); |
public/javascripts/application.js | ||
---|---|---|
634 | 634 |
}); |
635 | 635 |
} |
636 | 636 | |
637 |
function updateTimeEntryForm(url) { |
|
638 |
$('#all_attributes input, #all_attributes textarea, #all_attributes select').each(function(){ |
|
639 |
$(this).data('valuebeforeupdate', $(this).val()); |
|
640 |
}); |
|
641 |
return $.ajax({ |
|
642 |
url: url, |
|
643 |
type: 'post', |
|
644 |
data: $('#time-entry-form').serialize() |
|
645 |
}); |
|
646 |
} |
|
647 | ||
648 |
function replaceTimeEntryFormWith(html){ |
|
649 |
var replacement = $(html); |
|
650 |
$('#all_attributes input, #all_attributes textarea, #all_attributes select').each(function(){ |
|
651 |
var object_id = $(this).attr('id'); |
|
652 |
if (object_id && $(this).data('valuebeforeupdate')!=$(this).val()) { |
|
653 |
replacement.find('#'+object_id).val($(this).val()); |
|
654 |
} |
|
655 |
}); |
|
656 |
$('#all_attributes').empty(); |
|
657 |
$('#all_attributes').prepend(replacement); |
|
658 |
} |
|
659 | ||
637 | 660 |
function observeAutocompleteField(fieldId, url, options) { |
638 | 661 |
$(document).ready(function() { |
639 | 662 |
$('#'+fieldId).autocomplete($.extend({ |
test/application_system_test_case.rb | ||
---|---|---|
81 | 81 |
assert_equal '/my/page', current_path |
82 | 82 |
end |
83 | 83 | |
84 |
def wait_for_ajax |
|
85 |
Timeout.timeout(Capybara.default_max_wait_time) do |
|
86 |
loop until page.evaluate_script("jQuery.active").zero? |
|
87 |
end |
|
88 |
end |
|
89 | ||
84 | 90 |
def clear_downloaded_files |
85 | 91 |
FileUtils.rm downloaded_files |
86 | 92 |
end |
test/functional/timelog_controller_test.rb | ||
---|---|---|
143 | 143 |
@request.session[:user_id] = 3 |
144 | 144 |
post :new, :params => {:time_entry => {:project_id => 1}, :format => 'js'} |
145 | 145 |
assert_response :success |
146 |
assert_include '#time_entry_activity_id', response.body
|
|
146 |
assert_include 'id=\"time_entry_activity_id\"', response.body
|
|
147 | 147 |
end |
148 | 148 | |
149 | 149 |
def test_get_edit_existing_time |
test/system/timelog_test.rb | ||
---|---|---|
38 | 38 |
assert has_content?('Design') |
39 | 39 |
end |
40 | 40 | |
41 |
within 'form#new_time_entry' do
|
|
41 |
within 'form#time-entry-form' do
|
|
42 | 42 |
select 'eCookbook', :from => 'Project' |
43 | 43 |
end |
44 |
wait_for_ajax |
|
44 | 45 |
within 'select#time_entry_activity_id' do |
45 | 46 |
assert has_content?('Development') |
46 | 47 |
assert !has_content?('Design') |
47 | 48 |
end |
48 | 49 |
end |
49 | 50 | |
51 |
def test_changing_project_should_switch_show_or_hide_custom_fields_depending_on_roles |
|
52 |
project1 = Project.find(1) # eCookbook |
|
53 |
project2 = Project.find(2) # OnlineStore |
|
54 |
project2.enable_module!(:time_tracking) |
|
55 |
user = User.find(2) # jsmith |
|
56 |
assert_equal [1], user.roles_for_project(project1).collect(&:id).sort |
|
57 |
assert_equal [2], user.roles_for_project(project2).collect(&:id).sort |
|
58 |
custom_field = TimeEntryCustomField.find(10) # Overtime |
|
59 |
custom_field.visible = 0 |
|
60 |
custom_field.role_ids = [1] |
|
61 |
custom_field.save! |
|
62 | ||
63 |
log_user 'jsmith', 'jsmith' |
|
64 |
visit '/time_entries/new' |
|
65 | ||
66 |
within 'form#time-entry-form' do |
|
67 |
assert has_no_content?('Overtime') |
|
68 | ||
69 |
select 'eCookbook', from: 'Project' |
|
70 |
wait_for_ajax |
|
71 |
assert has_content?('Overtime') |
|
72 | ||
73 |
select 'OnlineStore', from: 'Project' |
|
74 |
wait_for_ajax |
|
75 |
assert has_no_content?('Overtime') |
|
76 |
end |
|
77 |
end |
|
78 | ||
50 | 79 |
def test_bulk_edit |
51 | 80 |
log_user 'jsmith', 'jsmith' |
52 | 81 |
visit '/time_entries/bulk_edit?ids[]=1&ids[]=2&ids[]=3' |