OLD | NEW |
1 var Settings = {}; | 1 var Settings = {}; |
2 | 2 |
3 Settings.removeCompanyLogo = function () { | 3 Settings.removeCompanyLogo = function () { |
4 var elem = document.getElementById('bewpi-company-logo-wrapper'); | 4 var elem = document.getElementById('bewpi-company-logo-wrapper'); |
5 elem.parentNode.removeChild(elem); | 5 elem.parentNode.removeChild(elem); |
6 document.getElementById('bewpi-company-logo-value').value = ''; | 6 document.getElementById('bewpi-company-logo-value').value = ''; |
7 }; | 7 }; |
8 | 8 |
9 Settings.previewInvoice = function (data) { | 9 Settings.previewInvoice = function (data) { |
10 // construct an HTTP request | 10 // construct an HTTP request |
11 var xhr = new XMLHttpRequest(); | 11 var xhr = new XMLHttpRequest(); |
12 xhr.open("GET", ajax_url + "?action=wpi_preview_invoice&security=" + nonce,
true); | 12 xhr.open("GET", ajax_url + "?action=wpi_preview_invoice&security=" + nonce,
true); |
13 xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8'); | 13 xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8'); |
14 | 14 |
15 xhr.send(); | 15 xhr.send(); |
16 | 16 |
17 xhr.onloadend = function () { | 17 xhr.onloadend = function () { |
18 // done | 18 // done |
19 }; | 19 }; |
20 }; | 20 }; |
21 | 21 |
22 Settings.enableDisableNextInvoiceNumbering = function (elem) { | 22 Settings.enableDisableNextInvoiceNumbering = function (elem) { |
23 var nextInvoiceNumberInput = document.getElementById('bewpi-next-invoice-num
ber'); | 23 var nextInvoiceNumberInput = document.getElementById('bewpi-next-invoice-num
ber'); |
24 ( elem.checked ) ? nextInvoiceNumberInput.disabled = false : nextInvoiceNumb
erInput.disabled = true; | 24 ( elem.checked ) ? nextInvoiceNumberInput.disabled = false : nextInvoiceNumb
erInput.disabled = true; |
25 }; | 25 }; |
| 26 |
| 27 Settings.showHideInvoiceNumberOptions = function (elem) { |
| 28 » // The Element.closest function is new in DOM5, so to be sure, we don't
use it yet |
| 29 » var closest = function(el, tag) { |
| 30 » » for ( ; el && el !== document; el = el.parentNode ) { |
| 31 » » » if ( el.tagName.toLowerCase() === tag ) { |
| 32 » » » » return el; |
| 33 » » » } |
| 34 » » } |
| 35 » » return false; |
| 36 » }; |
| 37 » var showHideControl = function(id, show) { |
| 38 » » var e = document.getElementById(id); |
| 39 » » // Also hide the whole table row |
| 40 » » closest(e, 'tr').style.display = (show) ? '' : 'none'; |
| 41 » }; |
| 42 » if (!elem) return; |
| 43 » var val = (elem.options[elem.selectedIndex].value); |
| 44 » // Show / hide the table rows with controls that do not apply to the cur
rent invoice numbering type |
| 45 » showHideControl('bewpi-reset-counter', val == "sequential_number"); |
| 46 » showHideControl('bewpi-next-invoice-number', val == "sequential_number")
; |
| 47 » showHideControl('bewpi-invoice-number-digits', val != "third_party"); |
| 48 » showHideControl('bewpi-invoice-number-prefix', val != "third_party"); |
| 49 » showHideControl('bewpi-invoice-number-suffix', val != "third_party"); |
| 50 » showHideControl('bewpi-invoice-number-format', val != "third_party"); |
| 51 » showHideControl('bewpi-reset-counter-yearly', val == "sequential_number"
); |
| 52 }; |
| 53 |
| 54 |
OLD | NEW |