Project

General

Profile

Defect #34922 ยป 34922.patch

Yuichi HARADA, 2022-01-25 06:33

View differences:

app/views/timelog/_form.html.erb
<%= error_messages_for 'time_entry' %>
<%= back_url_hidden_field_tag %>
<div class="box tabular">
<%= labelled_fields_for :time_entry, @time_entry do |f| %>
<% if @time_entry.new_record? && params[:project_id] %>
<%= hidden_field_tag 'project_id', params[:project_id] %>
<% elsif @time_entry.new_record? && params[:issue_id] %>
......
<% end %>
<% end %>
<%= call_hook(:view_timelog_edit_form_bottom, { :time_entry => @time_entry, :form => f }) %>
</div>
<% end %>
<%= javascript_tag do %>
$(document).ready(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')) %>',
type: 'post',
data: $(this).closest('form').serialize()
});
updateTimeEntryForm('<%= escape_javascript(@time_entry.new_record? ? new_time_entry_path(:format => 'js') : edit_time_entry_path(:format => 'js')) %>');
});
});
app/views/timelog/edit.html.erb
<h2><%= l(:label_spent_time) %></h2>
<%= labelled_form_for @time_entry, :url => time_entry_path(@time_entry), :html => {:multipart => true} do |f| %>
<%= labelled_form_for @time_entry, :url => time_entry_path(@time_entry), :html => {:id =>'time-entry-form', :multipart => true} do |f| %>
<div class="box tabular" id="all_attributes">
<%= render :partial => 'form', :locals => {:f => f} %>
</div>
<%= submit_tag l(:button_save) %>
<%= cancel_button_tag_for_time_entry(@project) %>
<% end %>
app/views/timelog/edit.js.erb
$('#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?) %>');
replaceTimeEntryFormWith('<%= escape_javascript(render :partial => 'form') %>');
app/views/timelog/new.html.erb
<h2><%= l(:label_spent_time) %></h2>
<%= labelled_form_for @time_entry, :url => time_entries_path, :html => {:multipart => true} do |f| %>
<%= labelled_form_for @time_entry, :url => time_entries_path, :html => {:id =>'time-entry-form', :multipart => true} do |f| %>
<div class="box tabular" id="all_attributes">
<%= render :partial => 'form', :locals => {:f => f} %>
</div>
<%= submit_tag l(:button_create) %>
<%= submit_tag l(:button_create_and_continue), :name => 'continue' %>
<%= cancel_button_tag_for_time_entry(@project) %>
app/views/timelog/new.js.erb
$('#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?) %>');
replaceTimeEntryFormWith('<%= escape_javascript(render :partial => 'form') %>');
public/javascripts/application.js
});
}
function updateTimeEntryForm(url) {
$('#all_attributes input, #all_attributes textarea, #all_attributes select').each(function(){
$(this).data('valuebeforeupdate', $(this).val());
});
return $.ajax({
url: url,
type: 'post',
data: $('#time-entry-form').serialize()
});
}
function replaceTimeEntryFormWith(html){
var replacement = $(html);
$('#all_attributes input, #all_attributes textarea, #all_attributes select').each(function(){
var object_id = $(this).attr('id');
if (object_id && $(this).data('valuebeforeupdate')!=$(this).val()) {
replacement.find('#'+object_id).val($(this).val());
}
});
$('#all_attributes').empty();
$('#all_attributes').prepend(replacement);
}
function observeAutocompleteField(fieldId, url, options) {
$(document).ready(function() {
$('#'+fieldId).autocomplete($.extend({
test/application_system_test_case.rb
assert_equal '/my/page', current_path
end
def wait_for_ajax
Timeout.timeout(Capybara.default_max_wait_time) do
loop until page.evaluate_script("jQuery.active").zero?
end
end
def clear_downloaded_files
FileUtils.rm downloaded_files
end
test/functional/timelog_controller_test.rb
@request.session[:user_id] = 3
post :new, :params => {:time_entry => {:project_id => 1}, :format => 'js'}
assert_response :success
assert_include '#time_entry_activity_id', response.body
assert_include 'id=\"time_entry_activity_id\"', response.body
end
def test_get_edit_existing_time
test/system/timelog_test.rb
assert has_content?('Design')
end
within 'form#new_time_entry' do
within 'form#time-entry-form' do
select 'eCookbook', :from => 'Project'
end
wait_for_ajax
within 'select#time_entry_activity_id' do
assert has_content?('Development')
assert !has_content?('Design')
end
end
def test_changing_project_should_switch_show_or_hide_custom_fields_depending_on_roles
project1 = Project.find(1) # eCookbook
project2 = Project.find(2) # OnlineStore
project2.enable_module!(:time_tracking)
user = User.find(2) # jsmith
assert_equal [1], user.roles_for_project(project1).collect(&:id).sort
assert_equal [2], user.roles_for_project(project2).collect(&:id).sort
custom_field = TimeEntryCustomField.find(10) # Overtime
custom_field.visible = 0
custom_field.role_ids = [1]
custom_field.save!
log_user 'jsmith', 'jsmith'
visit '/time_entries/new'
within 'form#time-entry-form' do
assert has_no_content?('Overtime')
select 'eCookbook', from: 'Project'
wait_for_ajax
assert has_content?('Overtime')
select 'OnlineStore', from: 'Project'
wait_for_ajax
assert has_no_content?('Overtime')
end
end
def test_bulk_edit
log_user 'jsmith', 'jsmith'
visit '/time_entries/bulk_edit?ids[]=1&ids[]=2&ids[]=3'
    (1-1/1)