mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2026-11-21 10:50:37 -05:00
Leave other plugins' features to hooks
Refund emails and PDFs take the shop name and mail settings from :qbo_mail_settings instead of reading redmine_qbo_reminders' settings; the customer page's ticked boxes use generic data-ticked-field/data-ticked-params instead of knowing redmine_qbo_calendar's Add appointment link; and Create issues carries the params plugins name in :qbo_billing_issue_carry_params instead of appointment_id. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0552e2f1a3
commit
ae0ffc7c1c
10 files changed
+69
-39
No files matched your search
@@ -21,16 +21,16 @@ class QboRefundMailer < ActionMailer::Base
|
||||
def refund_summary(refund, email)
|
||||
@refund = refund
|
||||
@customer = refund.customer
|
||||
reminders = defined?(RedmineQboReminders::Settings) ? RedmineQboReminders::Settings.current : nil
|
||||
@shop_name = reminders&.[]('shop_name').to_s.presence || Setting.app_title
|
||||
delivery = reminders ? reminders.delivery_options : {}
|
||||
settings = RedmineQboBilling.mail_settings
|
||||
@shop_name = settings[:shop_name].presence || Setting.app_title
|
||||
delivery = settings[:delivery] || {}
|
||||
if delivery.empty? && !ActionMailer::Base.perform_deliveries
|
||||
raise DeliveryOff, I18n.t(:text_refund_email_off)
|
||||
end
|
||||
|
||||
options = { to: email, from: reminders&.from.presence || Setting.mail_from.to_s,
|
||||
options = { to: email, from: settings[:from].presence || Setting.mail_from.to_s,
|
||||
subject: I18n.t(:text_refund_email_subject, shop: @shop_name, amount: RedmineQboBilling::RefundWriter.money(refund.refund_amount)) }
|
||||
options[:reply_to] = reminders.reply_to if reminders&.reply_to
|
||||
options[:reply_to] = settings[:reply_to] if settings[:reply_to]
|
||||
message = mail(options.merge(delivery)) do |format|
|
||||
format.text
|
||||
end
|
||||
|
||||
@@ -1,40 +1,33 @@
|
||||
<%#
|
||||
Adds what's ticked on the customer page to its links: "New issue" (#dynamic-new-issue-link in the contextual area)
|
||||
and redmine_qbo_calendar's "Add appointment" (#appointment_link). A checkbox takes part with
|
||||
data-new-issue-param="issue[field]" (New issue) and data-appointment-param="field" (Add appointment); one is
|
||||
ticked per field: this plugin's estimates (estimate_id), and other plugins' lists (e.g. redmine_qbo_vehicles'
|
||||
vehicle_id).
|
||||
Adds what's ticked on the customer page to its links. A checkbox takes part with data-ticked-field="field"
|
||||
(one is ticked per field), e.g. this plugin's estimates (estimate_id) and other plugins' lists. A link takes
|
||||
part with data-ticked-params, how each field is named in its URL: "issue[%s]" for New issue
|
||||
(#dynamic-new-issue-link), "%s" for a plain param. Other plugins' links on the page work the same way.
|
||||
%>
|
||||
<script>
|
||||
(function () {
|
||||
var LINKS = [['dynamic-new-issue-link', 'data-new-issue-param'], ['appointment_link', 'data-appointment-param']];
|
||||
var ANY = 'input[data-new-issue-param], input[data-appointment-param]';
|
||||
var BOX = 'input[data-ticked-field]';
|
||||
|
||||
function boxes(attr, param) {
|
||||
return Array.prototype.filter.call(document.querySelectorAll('input[' + attr + ']'), function (cb) {
|
||||
return !param || cb.getAttribute(attr) === param;
|
||||
function boxes(field) {
|
||||
return Array.prototype.filter.call(document.querySelectorAll(BOX), function (cb) {
|
||||
return !field || cb.getAttribute('data-ticked-field') === field;
|
||||
});
|
||||
}
|
||||
|
||||
// Boxes for the same field (the same estimate list, the same vehicle list)
|
||||
function sameField(box) {
|
||||
for (var i = 0; i < LINKS.length; i++) {
|
||||
var attr = LINKS[i][1], param = box.getAttribute(attr);
|
||||
if (param) return boxes(attr, param);
|
||||
}
|
||||
return [box];
|
||||
function fields() {
|
||||
return boxes().map(function (cb) { return cb.getAttribute('data-ticked-field'); })
|
||||
.filter(function (field, i, all) { return all.indexOf(field) === i; });
|
||||
}
|
||||
|
||||
function updateLinks() {
|
||||
LINKS.forEach(function (pair) {
|
||||
var link = document.getElementById(pair[0]);
|
||||
if (!link) return;
|
||||
Array.prototype.forEach.call(document.querySelectorAll('a[data-ticked-params]'), function (link) {
|
||||
// Cache the pristine base URL on first run
|
||||
if (!link.dataset.baseUrl) link.dataset.baseUrl = link.getAttribute('href');
|
||||
var url = new URL(link.dataset.baseUrl, window.location.origin);
|
||||
boxes(pair[1]).forEach(function (cb) {
|
||||
var param = cb.getAttribute(pair[1]);
|
||||
var ticked = boxes(pair[1], param).filter(function (b) { return b.checked; })[0];
|
||||
var format = link.getAttribute('data-ticked-params');
|
||||
fields().forEach(function (field) {
|
||||
var param = format.replace('%s', field);
|
||||
var ticked = boxes(field).filter(function (b) { return b.checked; })[0];
|
||||
if (ticked) {
|
||||
url.searchParams.set(param, ticked.value);
|
||||
} else {
|
||||
@@ -48,9 +41,9 @@
|
||||
// One box per field: ticking one unticks the others for the same field
|
||||
document.addEventListener('change', function (event) {
|
||||
var box = event.target;
|
||||
if (!box.matches || !box.matches(ANY)) return;
|
||||
if (!box.matches || !box.matches(BOX)) return;
|
||||
if (box.checked) {
|
||||
sameField(box).forEach(function (cb) { if (cb !== box) cb.checked = false; });
|
||||
boxes(box.getAttribute('data-ticked-field')).forEach(function (cb) { if (cb !== box) cb.checked = false; });
|
||||
}
|
||||
updateLinks();
|
||||
});
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<div class="contextual qbo-under-title">
|
||||
<%# New issue for this customer; picks up what's ticked on this page (an estimate, other plugins' items) %>
|
||||
<%= link_to sprite_icon('add', l(:label_new_issue)), new_issue_path(issue: { customer_id: @customer.id }),
|
||||
id: 'dynamic-new-issue-link', class: 'icon icon-add', target: :_blank %>
|
||||
id: 'dynamic-new-issue-link', class: 'icon icon-add', target: :_blank, data: { ticked_params: 'issue[%s]' } %>
|
||||
<%# Plugins add their customer actions here (e.g. redmine_qbo_calendar's Add appointment) %>
|
||||
<%= call_hook :view_customers_show_contextual, { customer: @customer } %>
|
||||
<%# Estimates, invoices and payments are handled here, each shown to users with its permission; Open in
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
<% estimates.sort.reverse.each do |estimate| %>
|
||||
<%# One cell each (qbo_estimates/_status_styles lines them up in columns, so the icons line up) %>
|
||||
<div class="row">
|
||||
<%# Ticking an estimate adds it to the customer page's New issue and Add appointment links (customers/_new_issue_link_script) %>
|
||||
<span class="qbo-list-check"><%= check_box_tag "estimate_ids[]", estimate.id, false, data: { new_issue_param: 'issue[estimate_id]', appointment_param: 'estimate_id' }, class: "estimate-checkbox" if local_assigns[:new_issue_checkboxes] %></span>
|
||||
<%# Ticking an estimate adds it to the customer page's links (customers/_new_issue_link_script) %>
|
||||
<span class="qbo-list-check"><%= check_box_tag "estimate_ids[]", estimate.id, false, data: { ticked_field: 'estimate_id' }, class: "estimate-checkbox" if local_assigns[:new_issue_checkboxes] %></span>
|
||||
<b class="qbo-list-number"><%= link_to "##{estimate.doc_number}", estimate_path(estimate), target: :_blank %></b>
|
||||
<span class="qbo-list-date"><%= estimate.txn_date %></span>
|
||||
<%# QuickBooks status, cached by the estimate sync (kept current by the webhook) %>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<% html_title l(:button_create_estimate_issues) %>
|
||||
<%# Extra params to carry through (e.g. appointment_id from redmine_qbo_calendar) %>
|
||||
<% carry = request.query_parameters.merge(request.request_parameters).slice('appointment_id') %>
|
||||
<%# Params other plugins carry through the page (:qbo_billing_issue_carry_params, e.g. redmine_qbo_calendar's appointment) %>
|
||||
<% carry = request.query_parameters.merge(request.request_parameters).slice(*Redmine::Hook.call_hook(:qbo_billing_issue_carry_params, {}).flatten.compact.map(&:to_s)) %>
|
||||
|
||||
<div class="contextual">
|
||||
<%= link_to sprite_icon('angle-left', @return_label), @return_path, class: 'icon icon-angle-left' %>
|
||||
|
||||
Reference in new issue
Block a user