| |
| |
| |
| |
| |
| (function(){ |
| 'use strict'; |
|
|
| |
| window.__VAI_BLOB_ALL = window.__VAI_BLOB_ALL || { blobs: [], isUn: false }; |
| var REG = window.__VAI_BLOB_ALL; |
|
|
| |
| function cleanup() { REG.isUn = true; REG.blobs.forEach(function(e) { try { URL.revokeObjectURL(e.url); } catch(r) {} }); REG.blobs = []; } |
| window.addEventListener('pagehide', cleanup); |
| window.addEventListener('beforeunload', cleanup); |
|
|
| |
| if (!window.__VAI_REV_DONE) { |
| var _o = URL.revokeObjectURL; |
| URL.revokeObjectURL = function(u) { |
| if (REG.isUn || !u || typeof u !== 'string' || u.indexOf('blob:') !== 0) return _o.call(this, u); |
| var exist = REG.blobs.find(function(e) { return e.url === u; }); |
| if (!exist) REG.blobs.push({ url: u, revoked: false }); |
| return; |
| }; |
| window.__VAI_REV_DONE = true; |
| } |
|
|
| |
| function dl(blob, name) { |
| var url = URL.createObjectURL(blob); |
| REG.blobs.push({ url: url }); |
| var a = document.createElement('a'); |
| a.href = url; a.download = name; a.style.cssText = 'position:absolute;left:-9999px'; |
| document.body.appendChild(a); |
| a.click(); |
| setTimeout(function() { try { document.body.removeChild(a); } catch(r) {} }, 100); |
| } |
|
|
| |
| document.addEventListener('click', function(e) { |
| var btn = e.target.closest('button, a'); |
| if (!btn) return; |
| |
| var txt = (btn.textContent || '').toLowerCase(); |
| var activeEl = document.activeElement; |
| |
| |
| if (txt.includes('excel') && !txt.includes('gh') && !txt.includes('giao hàng')) { |
| e.preventDefault(); |
| e.stopPropagation(); |
| |
| |
| if (activeEl && activeEl.dataset.vaiExporting === '1') return; |
| |
| |
| if (activeEl) { |
| activeEl.dataset.vaiExporting = '1'; |
| activeEl.dataset.vaiHTML = activeEl.innerHTML; |
| activeEl.innerHTML = '<span style="opacity:0.7">⏳</span>'; |
| } |
| |
| |
| setTimeout(function() { |
| if (typeof window.exportExcel === 'function') { |
| window.exportExcel().then(function() { |
| if (activeEl) { |
| activeEl.dataset.vaiExporting = '0'; |
| activeEl.innerHTML = activeEl.dataset.vaiHTML || '💾 Excel'; |
| } |
| if (typeof showToast === 'function') showToast('✅ Excel OK'); |
| }).catch(function(err) { |
| if (activeEl) { |
| activeEl.dataset.vaiExporting = '0'; |
| activeEl.innerHTML = activeEl.dataset.vaiHTML || '💾 Excel'; |
| } |
| alert('❌ Lỗi: ' + (err && err.message ? err.message : err)); |
| }); |
| } else { |
| |
| console.log('[VAI] Export function not ready, waiting...'); |
| var wait = setInterval(function() { |
| if (typeof window.exportExcel === 'function') { |
| clearInterval(wait); |
| window.exportExcel().then(function() { |
| if (activeEl) { |
| activeEl.dataset.vaiExporting = '0'; |
| activeEl.innerHTML = activeEl.dataset.vaiHTML || '💾 Excel'; |
| } |
| }); |
| } |
| }, 500); |
| } |
| }, 10); |
| |
| return false; |
| } |
| |
| |
| if ((txt.includes('giao hàng') || txt.includes('gh')) && txt.includes('excel')) { |
| e.preventDefault(); |
| e.stopPropagation(); |
| |
| if (activeEl && activeEl.dataset.vaiExporting === '1') return; |
| |
| if (activeEl) { |
| activeEl.dataset.vaiExporting = '1'; |
| activeEl.dataset.vaiHTML = activeEl.innerHTML; |
| activeEl.innerHTML = '<span style="opacity:0.7">⏳</span>'; |
| } |
| |
| setTimeout(function() { |
| if (typeof window.exportDeliveryExcel === 'function') { |
| window.exportDeliveryExcel().then(function() { |
| if (activeEl) { |
| activeEl.dataset.vaiExporting = '0'; |
| activeEl.innerHTML = activeEl.dataset.vaiHTML || 'GH Excel'; |
| } |
| }); |
| } |
| }, 10); |
| |
| return false; |
| } |
| }, true); |
|
|
| console.log('[VAI CLICK] Handler attached - Excel click ready'); |
| })(); |