PluginProbe
Easy Invoice – Invoice Generator, PDF Quotes & Payments / 2.3.6
Easy Invoice – Invoice Generator, PDF Quotes & Payments v2.3.6
2.4.0 2.4.1 2.3.8 2.3.7 2.3.6 2.3.5 2.3.4 2.3.3 2.3.2 2.3.1 2.2.0 2.1.21 2.1.20 2.1.19 2.1.18 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 2.1.15 2.1.16 2.1.2 All 57 releases
easy-invoice / assets / js / bulk-send-email-teaser.js

bulk-send-email-teaser.js in Easy Invoice – Invoice Generator, PDF Quotes & Payments 2.3.6, at assets/js/bulk-send-email-teaser.js

105 lines 4.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /* global jQuery, easyInvoiceBulkSendTeaser, EasyInvoiceConfirmation, EasyInvoiceToast */
2 /**
3 * Free-side Pro bulk-action teaser
4 *
5 * Owns two bulk-action options on the Invoice and Quote listings:
6 * • send_email — "Send Email (Pro)"
7 * • export — "Export Selected (Pro)"
8 *
9 * Both options are visible to ALL users (Free + Pro) so the feature is
10 * discoverable. When Pro is INACTIVE we intercept submit and open the
11 * EasyInvoiceConfirmation upgrade dialog. When Pro IS active this script
12 * does nothing — the Pro plugin's own handlers take over.
13 *
14 * The send_email option is injected by this script (Free templates never
15 * shipped it). The export option is already in the Free templates (it pre-
16 * dates this work), so we only re-label it with the (Pro) suffix via the
17 * <option> tag in the template and intercept its submit here.
18 */
19 (function ($) {
20 'use strict';
21
22 if (typeof easyInvoiceBulkSendTeaser === 'undefined') {
23 return;
24 }
25
26 var cfg = easyInvoiceBulkSendTeaser;
27 var t = cfg.i18n || {};
28
29 // If Pro is active, Pro's own JS handles everything.
30 if (cfg.hasPro) {
31 return;
32 }
33
34 // Map of Pro-gated bulk actions → upgrade-dialog copy. Easy to extend
35 // when more Pro-only bulk actions land.
36 var PRO_ACTIONS = {
37 send_email: {
38 featureName: t.send_email_feature_name || 'Bulk Send Email',
39 description: t.send_email_feature_description ||
40 'Select multiple invoices or quotes and send the configured "Available" email to every selected document\'s client in a single click.'
41 },
42 export: {
43 featureName: t.export_feature_name || 'Bulk Export Selected',
44 description: t.export_feature_description ||
45 'Export your selected invoices or quotes to a clean CSV — perfect for accounting tools, audit trails, or migration to another system.'
46 }
47 };
48
49 $(function () {
50 var $form = $('#bulk-action-form');
51 if (!$form.length) {
52 return;
53 }
54
55 var $select = $form.find('select[name="bulk_action"]');
56 if (!$select.length) {
57 return;
58 }
59
60 // Inject the Send Email option (the templates don't ship it).
61 if (!$select.find('option[value="send_email"]').length) {
62 $select.append(
63 $('<option>', {
64 value: 'send_email',
65 'data-requires-pro': '1'
66 }).text(t.send_email_label || 'Send Email (Pro)')
67 );
68 }
69
70 // Hijack submit only when one of our Pro actions is selected. Attach
71 // with native addEventListener in CAPTURE PHASE so we run BEFORE the
72 // listing template's own inline jQuery submit handler (especially on
73 // the Quote listing, which AJAX-routes every bulk action). Without
74 // capture-phase, the user would briefly see the listing's generic
75 // confirm dialog before our upgrade popup ever fires.
76 $form[0].addEventListener('submit', function (e) {
77 var action = $select.val();
78 if (!action || !PRO_ACTIONS[action]) {
79 return;
80 }
81 e.preventDefault();
82 e.stopImmediatePropagation();
83 e.stopPropagation();
84 showUpgradePrompt(PRO_ACTIONS[action]);
85 }, true);
86 });
87
88 function showUpgradePrompt(feature) {
89 if (window.EasyInvoiceConfirmation && typeof window.EasyInvoiceConfirmation.showUpgradeDialog === 'function') {
90 window.EasyInvoiceConfirmation.showUpgradeDialog({
91 featureName: feature.featureName,
92 description: feature.description,
93 onUpgrade: function () {
94 window.open(cfg.upgradeUrl || 'https://matrixaddons.com/plugins/easy-invoice/#pricing', '_blank');
95 }
96 });
97 } else if (window.EasyInvoiceToast) {
98 window.EasyInvoiceToast.warning(
99 (t.upgrade_required || 'This action requires Easy Invoice Pro.')
100 );
101 window.open(cfg.upgradeUrl || 'https://matrixaddons.com/plugins/easy-invoice/#pricing', '_blank');
102 }
103 }
104 })(jQuery);
105