mirror of
https://github.com/rickbarrette/stopwatch.git
synced 2026-04-02 01:41:58 -04:00
time entry form fixes
- issue selection selects the project accordingly - issue / project selection updates available activities - move project / issue selector to top. more logical this way, since making a selection there may change the available activities
This commit is contained in:
@@ -73,6 +73,17 @@ class StopwatchTimersController < ApplicationController
|
||||
render json: @timer.to_json
|
||||
end
|
||||
|
||||
def update_form
|
||||
if id = params[:time_entry_id].presence
|
||||
@time_entry = TimeEntry.visible.find id
|
||||
else
|
||||
@time_entry = TimeEntry.new
|
||||
end
|
||||
@time_entry.safe_attributes = params[:time_entry]
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
head 404
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_timer
|
||||
@@ -82,7 +93,6 @@ class StopwatchTimersController < ApplicationController
|
||||
|
||||
def find_time_entry
|
||||
@time_entry = time_entries.find params[:id]
|
||||
|
||||
end
|
||||
|
||||
def load_todays_entries
|
||||
|
||||
@@ -2,16 +2,15 @@
|
||||
|
||||
<fieldset class="box tabular">
|
||||
<legend><%= t @time_entry.new_record? ? '.legend_new' : '.legend_edit' %></legend>
|
||||
<p><%= f.select :activity_id, activity_collection_for_select_options(@time_entry), :required => true %></p>
|
||||
|
||||
<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>
|
||||
|
||||
<p><label for="stopwatch_time_entry_project_id"><%= l :field_project %><span class="required"> *</span></label><%= f.select :project_id, project_tree_options_for_select(Project.allowed_to(:log_time).to_a, :selected => @time_entry.project, :include_blank => true), { no_label: true }, id: 'stopwatch_time_entry_project_id' %></p>
|
||||
<p>
|
||||
<%= f.text_field :issue_id, :size => 6, :required => Setting.timelog_required_fields.include?('issue_id') %>
|
||||
<span id="time_entry_issue">
|
||||
<span id="stopwatch_time_entry_issue">
|
||||
<%= link_to_issue(@time_entry.issue) if @time_entry.issue.try(:visible?) %>
|
||||
</span>
|
||||
</p>
|
||||
<p><label for="stopwatch_time_entry_activity_id"><%= l :field_activity %><span class="required"> *</span></label><%= f.select :activity_id, activity_collection_for_select_options(@time_entry), { no_label: true }, id: 'stopwatch_time_entry_activity_id' %></p>
|
||||
<!--
|
||||
<p><%= f.date_field :spent_on, :size => 10, :required => true %><%= calendar_for('time_entry_spent_on') %></p>
|
||||
-->
|
||||
@@ -30,7 +29,7 @@
|
||||
});
|
||||
$('#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(@time_entry, format: 'js')) %>',
|
||||
url: '<%= j update_form_stopwatch_timers_path(time_entry_id: @time_entry.id, format: 'js') %>',
|
||||
type: 'post',
|
||||
data: $(this).closest('form').serialize()
|
||||
});
|
||||
|
||||
5
app/views/stopwatch_timers/update_form.js.erb
Normal file
5
app/views/stopwatch_timers/update_form.js.erb
Normal file
@@ -0,0 +1,5 @@
|
||||
$('#stopwatch_time_entry_activity_id').html('<%= escape_javascript options_for_select(activity_collection_for_select_options(@time_entry), @time_entry.activity_id) %>');
|
||||
$('#stopwatch_time_entry_issue').html('<%= escape_javascript link_to_issue(@time_entry.issue) if @time_entry.issue.try(:visible?) %>');
|
||||
$('#stopwatch_time_entry_project_id').html('<%= escape_javascript project_tree_options_for_select(Project.allowed_to(:log_time).to_a, :selected => @time_entry.project, :include_blank => true) %>');
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
resources :stopwatch_timers, only: %i(new create edit update) do
|
||||
collection do
|
||||
get :current
|
||||
post :update_form
|
||||
end
|
||||
member do
|
||||
put :start
|
||||
|
||||
Reference in New Issue
Block a user