PluginProbe
Easy Invoice – Invoice Generator, PDF Quotes & Payments / 2.1.0
Easy Invoice – Invoice Generator, PDF Quotes & Payments v2.1.0
2.4.3 2.4.4 2.4.2 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 All 60 releases
easy-invoice / templates / invoices / live-preview.php

live-preview.php in Easy Invoice – Invoice Generator, PDF Quotes & Payments 2.1.0, at templates/invoices/live-preview.php

196 lines 8.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <!-- Right Panel - Live Preview -->
2 <div class="bg-white shadow rounded-lg" style="padding: 10px;">
3
4 <div class="px-6 py-5 border-b border-gray-200" style="margin-bottom: 10px;">
5 <div class="flex justify-between items-center">
6 <div class="flex items-center">
7 <div class="flex-shrink-0 bg-indigo-100 rounded-lg p-3">
8 <i class="fas fa-eye text-indigo-600 text-xl"></i>
9 </div>
10 <div class="ml-4">
11 <h2 class="text-lg font-medium text-gray-900">Invoice Preview</h2>
12 <p class="mt-1 text-sm text-gray-500">Live preview of your invoice</p>
13 </div>
14 </div>
15 <?php if($invoice_id > 0 ){ ?>
16 <a href="<?php echo get_permalink($invoice_id); ?>" target="_blank" class="inline-flex items-center px-4 py-2 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500">
17 <i class="fas fa-external-link-alt mr-2"></i>
18 Full Preview
19 </a>
20 <?php } ?>
21 </div>
22 </div>
23
24 <?php
25 // Get the current template (default to 'standard')
26 $current_template = $invoice ? $invoice->getTemplate() : 'standard';
27 if (empty($current_template)) {
28 $current_template = 'standard';
29 }
30 $template_class = 'template-' . $current_template;
31
32 // Initialize formatter for the invoice templates
33 $formatter = new \EasyInvoice\Helpers\InvoiceFormatter($invoice);
34 ?>
35
36 <div id="invoice-container" class="invoice-container">
37 <?php
38 // Dynamically load the selected template
39 $template_file = EASY_INVOICE_PLUGIN_DIR . 'templates/invoice-templates/' . $current_template . '.php';
40 if (file_exists($template_file)) {
41 include_once $template_file;
42 } else {
43 // Show template not found message
44 ?>
45 <div class="template-not-found">
46 <div class="template-not-found-icon">
47 <i class="fas fa-exclamation-circle"></i>
48 </div>
49 <h3>Template Not Found</h3>
50 <p>The selected template "<?php echo esc_html($current_template); ?>" does not exist.</p>
51 <p>Please select a different template or contact support if you believe this is an error.</p>
52 </div>
53 <style>
54 .template-not-found {
55 text-align: center;
56 padding: 40px;
57 background: #fff;
58 border-radius: 8px;
59 box-shadow: 0 2px 4px rgba(0,0,0,0.1);
60 }
61 .template-not-found-icon {
62 font-size: 48px;
63 color: #dc3545;
64 margin-bottom: 20px;
65 }
66 .template-not-found h3 {
67 font-size: 24px;
68 color: #32325d;
69 margin-bottom: 10px;
70 }
71 .template-not-found p {
72 color: #8898aa;
73 margin-bottom: 10px;
74 }
75 </style>
76 <?php
77 }
78 ?>
79 </div>
80 </div>
81
82 <style>
83 /* Loading state styles */
84 .loading-overlay {
85 position: absolute;
86 top: 0;
87 left: 0;
88 right: 0;
89 bottom: 0;
90 background: rgba(255, 255, 255, 0.9);
91 display: flex;
92 justify-content: center;
93 align-items: center;
94 z-index: 1000;
95 }
96
97 .loading-spinner {
98 text-align: center;
99 }
100
101 .invoice-container.loading .loading-overlay {
102 display: flex;
103 }
104
105 /* (Resize logic removed per request) */
106 </style>
107
108 <script>
109 // Localize easyInvoice object for this page
110 window.easyInvoice = window.easyInvoice || {};
111 window.easyInvoice.isPro = <?php echo easy_invoice_has_pro() ? 'true' : 'false'; ?>;
112 window.easyInvoice.ajaxUrl = '<?php echo admin_url('admin-ajax.php'); ?>';
113 window.easyInvoice.nonce = '<?php echo wp_create_nonce('easy_invoice_nonce'); ?>';
114
115 jQuery(document).ready(function($) {
116 // Function to update the live preview
117 function updateLivePreview(templateId) {
118 // Show loading state
119 $('#invoice-container').addClass('loading');
120
121 // Make AJAX call to load the template
122 $.ajax({
123 url: window.easyInvoice.ajaxUrl,
124 type: 'POST',
125 data: {
126 action: 'easy_invoice_load_template',
127 template: templateId,
128 invoice_id: '<?php echo esc_js($invoice_id); ?>',
129 nonce: window.easyInvoice.nonce
130 },
131 success: function(response) {
132 if (response.success) {
133 // Update the preview content
134 $('#invoice-container').html(response.data.html);
135 } else {
136 // Show error message
137 $('#invoice-container').html(`
138 <div class="template-not-found">
139 <div class="template-not-found-icon">
140 <i class="fas fa-exclamation-circle"></i>
141 </div>
142 <h3>Template Not Found</h3>
143 <p>The selected template "${templateId}" does not exist.</p>
144 <p>Please select a different template or contact support if you believe this is an error.</p>
145 </div>
146 `);
147 }
148 },
149 error: function(xhr, status, error) {
150 // Show error message
151 $('#invoice-container').html(`
152 <div class="template-not-found">
153 <div class="template-not-found-icon">
154 <i class="fas fa-exclamation-circle"></i>
155 </div>
156 <h3>Error Loading Template</h3>
157 <p>There was an error loading the template. Please try again.</p>
158 </div>
159 `);
160 },
161 complete: function() {
162 // Remove loading state
163 $('#invoice-container').removeClass('loading');
164 }
165 });
166 }
167
168 // Listen for template changes from the template cards
169 $('.template-card').on('click', function(e) {
170 const templateId = $(this).data('template-id');
171
172 // Check if this is a premium template in free version
173 const isPremium = $(this).attr('data-is-premium') === 'true';
174 const isFreeVersion = !window.easyInvoice || !window.easyInvoice.isPro;
175 if (isPremium && isFreeVersion) {
176 // Show premium upgrade modal instead of selecting the template
177 if (typeof EasyInvoiceConfirmation !== 'undefined' && EasyInvoiceConfirmation.showFeatureUpgrade) {
178 EasyInvoiceConfirmation.showFeatureUpgrade('<?php _e('Premium Templates', 'easy-invoice'); ?>', '<?php _e('Access all premium templates including Modern, Professional, Classic, and more to give your invoices a unique and professional look.', 'easy-invoice'); ?>');
179 } else {
180 alert('<?php _e('This is a premium feature. Please upgrade to Pro to access all templates.', 'easy-invoice'); ?>');
181 }
182 return;
183 }
184
185 updateLivePreview(templateId);
186 });
187
188 // Listen for template changes from the gallery
189 $('.gallery-template-card').on('click', function() {
190 const templateId = $(this).data('template-id');
191 updateLivePreview(templateId);
192 });
193
194
195 });
196 </script>