diff --git a/app/controllers/customers_controller.rb b/app/controllers/customers_controller.rb index c2d9731..fe602db 100644 --- a/app/controllers/customers_controller.rb +++ b/app/controllers/customers_controller.rb @@ -188,6 +188,21 @@ class CustomersController < ApplicationController end end + def add_apointment + estimate = params[:estimate_id] + invoice = params[:invoice_id] + output = "" + logger.debug "Calling :add_apointment hook" + results = Redmine::Hook.call_hook :add_apointment, { customer: customer } + unless results.nil? + results.each do |r| + output.concat "%0A" if output.length > 0 + output.concat r unless r.nil? + end + end + redirect_to "https://calendar.google.com/calendar/render?action=TEMPLATE&text=#{@customer.name}+-&details=#{ link_to t(:customer_details), "https://#{Setting.host_name}#{customer_path @customer.id}"}%0A#{@customer.primary_phone}%0A#{output}&dates=#{Time.now.strftime("%Y%m%d")}T090000/#{Time.now.strftime("%Y%m%d")}T170000", target: :_blank + end + private # redmine permission - add customers diff --git a/app/views/customers/_actions.html.erb b/app/views/customers/_actions.html.erb index ab1bf78..c06aef9 100644 --- a/app/views/customers/_actions.html.erb +++ b/app/views/customers/_actions.html.erb @@ -1,5 +1,6 @@ -<%= link_to t(:label_appointment), "https://calendar.google.com/calendar/render?action=TEMPLATE&text=#{@customer.name}+-&details=#{ link_to t(:customer_details), "https://#{Setting.host_name}#{customer_path @customer.id}"}%0A#{@customer.primary_phone}&dates=#{Time.now.strftime("%Y%m%d")}T090000/#{Time.now.strftime("%Y%m%d")}T170000", target: :_blank %> +<%= link_to t(:label_appointment), "https://calendar.google.com/calendar/render?action=TEMPLATE&text=#{@customer.name}+-&details=#{ link_to t(:customer_details), "https://#{Setting.host_name}#{customer_path @customer.id}"}%0A#{@customer.primary_phone}&dates=#{Time.now.strftime("%Y%m%d")}T090000/#{Time.now.strftime("%Y%m%d")}T170000", target: :_blank, id: :appointment_link %> +

diff --git a/assets/javascripts/application.js b/assets/javascripts/application.js index f240bcc..809c0dd 100644 --- a/assets/javascripts/application.js +++ b/assets/javascripts/application.js @@ -1,11 +1,30 @@ -$(function() { - $("input#issue_customer_id").on("change", function() { - - $.ajax({ - url: "/filter_estimates_by_customer", - type: "GET", - data: { selected_customer: $("input#issue_customer_id").val() } - }); - }); - -}); +function updateLink() { + + const selectedIds = getSelectedInvoiceIds(); + + + const extra = `%0A${selectedIds}`; + + const linkElement = document.getElementById("appointment_link"); + const absoluteUrl = linkElement.href; + let result = absoluteUrl.replace(/&dates/g, `${extra}&dates`); + + linkElement.href = result; + linkElement.textContent = "New Appointment Link"; +} + +function getSelectedInvoiceIds() { + // Select all checkboxes with the class 'invoice-checkbox' + const checkboxes = document.querySelectorAll('.invoice-checkbox'); + + // Use Array.from to convert NodeList to an array and then filter and map + const selectedIds = Array.from(checkboxes) + .filter(checkbox => checkbox.checked) // Keep only checked checkboxes + .map(checkbox => checkbox.value); // Extract the value (invoice ID) + + // Display the result (for demonstration) + console.log(JSON.stringify(selectedIds)); + + // You can return the array or use it as needed + return selectedIds; +}