From 8e6eeab6800fa5860f222fed9730ecdc36cd5126 Mon Sep 17 00:00:00 2001 From: Ricky Barrette Date: Wed, 9 Mar 2022 18:55:44 -0500 Subject: [PATCH] Moved HTML code into partial _from_hook.html.erb --- app/views/issues/_form_hook.html.erb | 14 ++++++++++++++ lib/issues_form_hook_listener.rb | 28 ++++++++++++++++++++-------- 2 files changed, 34 insertions(+), 8 deletions(-) create mode 100644 app/views/issues/_form_hook.html.erb diff --git a/app/views/issues/_form_hook.html.erb b/app/views/issues/_form_hook.html.erb new file mode 100644 index 0000000..c1833dc --- /dev/null +++ b/app/views/issues/_form_hook.html.erb @@ -0,0 +1,14 @@ +

+ + <%= search_customer %> + <%= customer_id %> + <%= link_to_function(t(:label_load_customer), "updateIssueFrom('/issues/#{context[:issue].id}/edit.js', this)") %> +

+ +

+ <%= select_estimate %> +

+ +

+ <%= vehicle %> +

\ No newline at end of file diff --git a/lib/issues_form_hook_listener.rb b/lib/issues_form_hook_listener.rb index 21a62d2..508b233 100644 --- a/lib/issues_form_hook_listener.rb +++ b/lib/issues_form_hook_listener.rb @@ -10,7 +10,7 @@ class IssuesFormHookListener < Redmine::Hook::ViewListener - # Load the javascript + # Load the javascript to support the autocomplete forms def view_layouts_base_html_head(context = {}) js = javascript_include_tag 'application', :plugin => 'redmine_qbo' js += javascript_include_tag 'autocomplete-rails', :plugin => 'redmine_qbo' @@ -18,19 +18,20 @@ class IssuesFormHookListener < Redmine::Hook::ViewListener end # Edit Issue Form - # TODO figure out how to do this with a view + # Here we build the required form components before passing them to a partial view formatting. def view_issues_form_details_bottom(context={}) f = context[:form] - #check project level customer/vehicle ownership first + # check project level customer ownership first + # This is done to preload customer information if the entire project is dedicated to a customer if context[:project] selected_customer = context[:project].customer ? context[:project].customer.id : nil selected_vehicle = context[:project].vehicle ? context[:project].vehicle.id : nil end - # Check to see if there are things attached to the issue - selected_customer = context[:issue].customer ? context[:issue].customer.id : nil - selected_estimate = context[:issue].qbo_estimate ? context[:issue].qbo_estimate.id : nil + # Check to see if the issue already belongs to a customer + selected_customer = context[:issue].customer ? context[:issue].customer.id : nil + selected_estimate = context[:issue].qbo_estimate ? context[:issue].qbo_estimate.id : nil selected_vehicle = context[:issue].vehicles_id ? context[:issue].vehicles_id : nil # Load customer information @@ -64,10 +65,21 @@ class IssuesFormHookListener < Redmine::Hook::ViewListener estimates = [nil].compact end - # Generate the drop down list of quickbooks extimates & vehicles + # Generate the drop down list of quickbooks estimates & vehicles select_estimate = f.select :qbo_estimate_id, estimates, :selected => selected_estimate, include_blank: true vehicle = f.select :vehicles_id, vehicles, :selected => selected_vehicle, include_blank: true - return "

#{search_customer} #{customer_id} #{link_to_function I18n.t(:label_load_customer), "updateIssueFrom('/issues/#{context[:issue].id}/edit.js', this)"}

#{select_estimate}

#{vehicle}

" + # Pass all prebuilt form components to our partial + context[:controller].send(:render_to_string, { + :partial => 'issues/form_hook', + locals: { + search_customer: search_customer, + customer_id: customer_id, + context: context, + select_estimate: select_estimate, + vehicle: vehicle + } + } + ) end end