Spaces:
Running
Running
Revert quote-ui.js to bb80fef31b
Browse files- quote-ui.js +15 -35
quote-ui.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
| 1 |
/**
|
| 2 |
* V.AI STUDIO — Quote UI v7
|
| 3 |
*
|
| 4 |
-
* - Nút "💾 Lưu" LUÔN HIỆN (không cần mã truy cập)
|
| 5 |
* - Nút "📋 Đơn hàng", "📦 GH Excel", "📦 GH PDF" ẨN cho đến khi nhập V.AISTUDIO
|
| 6 |
-
* -
|
| 7 |
*/
|
| 8 |
(function(){
|
| 9 |
'use strict';
|
|
@@ -25,29 +25,6 @@ function lock(){
|
|
| 25 |
removeProtectedButtons();
|
| 26 |
}
|
| 27 |
|
| 28 |
-
// Wait for VAI_ORDERS to be available then execute fn
|
| 29 |
-
function waitForOrders(fn,btn){
|
| 30 |
-
if(window.VAI_ORDERS&&typeof window.VAI_ORDERS.openSearch==='function'){
|
| 31 |
-
fn();return;
|
| 32 |
-
}
|
| 33 |
-
// Poll every 500ms for up to 10s
|
| 34 |
-
var originalText=btn?btn.innerHTML:'';
|
| 35 |
-
if(btn)btn.innerHTML='⏳ Đang tải...';
|
| 36 |
-
var attempts=0;
|
| 37 |
-
var poll=setInterval(function(){
|
| 38 |
-
attempts++;
|
| 39 |
-
if(window.VAI_ORDERS&&typeof window.VAI_ORDERS.openSearch==='function'){
|
| 40 |
-
clearInterval(poll);
|
| 41 |
-
if(btn)btn.innerHTML=originalText;
|
| 42 |
-
fn();
|
| 43 |
-
}else if(attempts>20){
|
| 44 |
-
clearInterval(poll);
|
| 45 |
-
if(btn)btn.innerHTML=originalText;
|
| 46 |
-
alert('Không tải được module đơn hàng. Thử refresh trang (Ctrl+Shift+R).');
|
| 47 |
-
}
|
| 48 |
-
},500);
|
| 49 |
-
}
|
| 50 |
-
|
| 51 |
// === NÚT LƯU (LUÔN HIỆN) ===
|
| 52 |
function hasSaveButton(){
|
| 53 |
return !!document.querySelector('[data-vai-save-btn]');
|
|
@@ -60,17 +37,21 @@ function addSaveButton(){
|
|
| 60 |
|
| 61 |
var btn=document.createElement('button');
|
| 62 |
btn.setAttribute('data-vai-save-btn','1');
|
| 63 |
-
btn.className='quote-btn';
|
| 64 |
btn.innerHTML='💾 Lưu';
|
| 65 |
btn.style.cssText='padding:12px 20px;border:none;border-radius:10px;font-weight:700;font-size:.82rem;cursor:pointer;display:flex;align-items:center;gap:6px;transition:all .25s ease;white-space:nowrap;background:#7c3aed;color:#fff';
|
| 66 |
btn.onmouseenter=function(){this.style.background='#6d28d9';};
|
| 67 |
btn.onmouseleave=function(){this.style.background='#7c3aed';};
|
| 68 |
btn.onclick=function(){
|
| 69 |
-
|
| 70 |
window.VAI_ORDERS.save();
|
| 71 |
-
}
|
|
|
|
|
|
|
| 72 |
};
|
|
|
|
| 73 |
actionsArea.insertBefore(btn, actionsArea.firstChild);
|
|
|
|
| 74 |
}
|
| 75 |
|
| 76 |
// === CÁC NÚT BẢO VỆ (ẨN CHO ĐẾN KHI UNLOCK) ===
|
|
@@ -91,9 +72,7 @@ function addProtectedButtons(){
|
|
| 91 |
var btnStyle='padding:12px 20px;border:none;border-radius:10px;font-weight:700;font-size:.82rem;cursor:pointer;display:flex;align-items:center;gap:6px;transition:all .25s ease;white-space:nowrap';
|
| 92 |
|
| 93 |
var buttons=[
|
| 94 |
-
{html:'📋 Đơn hàng',bg:'#2563eb',hover:'#1d4ed8',fn:function(
|
| 95 |
-
waitForOrders(function(){window.VAI_ORDERS.openSearch();},b);
|
| 96 |
-
}},
|
| 97 |
{html:'📦 GH Excel',bg:'#059669',hover:'#047857',fn:function(){if(typeof exportDeliveryExcel==='function')exportDeliveryExcel();}},
|
| 98 |
{html:'📦 GH PDF',bg:'#0d9488',hover:'#0f766e',fn:function(){if(typeof exportDeliveryPDF==='function')exportDeliveryPDF();}}
|
| 99 |
];
|
|
@@ -101,14 +80,15 @@ function addProtectedButtons(){
|
|
| 101 |
buttons.forEach(function(cfg){
|
| 102 |
var btn=document.createElement('button');
|
| 103 |
btn.setAttribute('data-vai-protected-btn','1');
|
| 104 |
-
btn.className='quote-btn checkout-done-btn';
|
| 105 |
btn.innerHTML=cfg.html;
|
| 106 |
btn.style.cssText=btnStyle+';background:'+cfg.bg+';color:#fff';
|
| 107 |
btn.onmouseenter=function(){this.style.background=cfg.hover;};
|
| 108 |
btn.onmouseleave=function(){this.style.background=cfg.bg;};
|
| 109 |
-
btn.onclick=
|
| 110 |
actionsArea.appendChild(btn);
|
| 111 |
});
|
|
|
|
| 112 |
}
|
| 113 |
|
| 114 |
function isQuoteOpen(){
|
|
@@ -116,7 +96,7 @@ function isQuoteOpen(){
|
|
| 116 |
return ov&&(ov.classList.contains('open')||ov.style.display==='flex'||ov.style.display==='block');
|
| 117 |
}
|
| 118 |
|
| 119 |
-
// === BIND mã truy cập input ===
|
| 120 |
function bindAccessCodeInput(){
|
| 121 |
var accessInput=document.getElementById('qcAccessCode');
|
| 122 |
if(!accessInput)return false;
|
|
@@ -170,5 +150,5 @@ setInterval(function(){
|
|
| 170 |
setTimeout(bindAccessCodeInput,1000);
|
| 171 |
setTimeout(bindAccessCodeInput,3000);
|
| 172 |
|
| 173 |
-
console.log('[Quote UI v7] loaded');
|
| 174 |
})();
|
|
|
|
| 1 |
/**
|
| 2 |
* V.AI STUDIO — Quote UI v7
|
| 3 |
*
|
| 4 |
+
* - Nút "💾 Lưu" LUÔN HIỆN (không cần mã truy cập) — lưu đơn cho mọi user
|
| 5 |
* - Nút "📋 Đơn hàng", "📦 GH Excel", "📦 GH PDF" ẨN cho đến khi nhập V.AISTUDIO
|
| 6 |
+
* - Khi Lưu → tự động lưu vào danh sách đơn hàng (VAI_ORDERS)
|
| 7 |
*/
|
| 8 |
(function(){
|
| 9 |
'use strict';
|
|
|
|
| 25 |
removeProtectedButtons();
|
| 26 |
}
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
// === NÚT LƯU (LUÔN HIỆN) ===
|
| 29 |
function hasSaveButton(){
|
| 30 |
return !!document.querySelector('[data-vai-save-btn]');
|
|
|
|
| 37 |
|
| 38 |
var btn=document.createElement('button');
|
| 39 |
btn.setAttribute('data-vai-save-btn','1');
|
| 40 |
+
btn.className='quote-btn'; // KHÔNG có checkout-done-btn → luôn hiện
|
| 41 |
btn.innerHTML='💾 Lưu';
|
| 42 |
btn.style.cssText='padding:12px 20px;border:none;border-radius:10px;font-weight:700;font-size:.82rem;cursor:pointer;display:flex;align-items:center;gap:6px;transition:all .25s ease;white-space:nowrap;background:#7c3aed;color:#fff';
|
| 43 |
btn.onmouseenter=function(){this.style.background='#6d28d9';};
|
| 44 |
btn.onmouseleave=function(){this.style.background='#7c3aed';};
|
| 45 |
btn.onclick=function(){
|
| 46 |
+
if(window.VAI_ORDERS&&window.VAI_ORDERS.save){
|
| 47 |
window.VAI_ORDERS.save();
|
| 48 |
+
}else{
|
| 49 |
+
alert('⏳ Đang tải module đơn hàng...');
|
| 50 |
+
}
|
| 51 |
};
|
| 52 |
+
// Insert as first button in actions
|
| 53 |
actionsArea.insertBefore(btn, actionsArea.firstChild);
|
| 54 |
+
console.log('[Quote UI v7] 💾 Lưu button added (always visible)');
|
| 55 |
}
|
| 56 |
|
| 57 |
// === CÁC NÚT BẢO VỆ (ẨN CHO ĐẾN KHI UNLOCK) ===
|
|
|
|
| 72 |
var btnStyle='padding:12px 20px;border:none;border-radius:10px;font-weight:700;font-size:.82rem;cursor:pointer;display:flex;align-items:center;gap:6px;transition:all .25s ease;white-space:nowrap';
|
| 73 |
|
| 74 |
var buttons=[
|
| 75 |
+
{html:'📋 Đơn hàng',bg:'#2563eb',hover:'#1d4ed8',fn:function(){if(window.VAI_ORDERS)window.VAI_ORDERS.openSearch();else alert('⏳ Đang tải...');}},
|
|
|
|
|
|
|
| 76 |
{html:'📦 GH Excel',bg:'#059669',hover:'#047857',fn:function(){if(typeof exportDeliveryExcel==='function')exportDeliveryExcel();}},
|
| 77 |
{html:'📦 GH PDF',bg:'#0d9488',hover:'#0f766e',fn:function(){if(typeof exportDeliveryPDF==='function')exportDeliveryPDF();}}
|
| 78 |
];
|
|
|
|
| 80 |
buttons.forEach(function(cfg){
|
| 81 |
var btn=document.createElement('button');
|
| 82 |
btn.setAttribute('data-vai-protected-btn','1');
|
| 83 |
+
btn.className='quote-btn checkout-done-btn'; // ẨN cho đến khi vas-unlocked
|
| 84 |
btn.innerHTML=cfg.html;
|
| 85 |
btn.style.cssText=btnStyle+';background:'+cfg.bg+';color:#fff';
|
| 86 |
btn.onmouseenter=function(){this.style.background=cfg.hover;};
|
| 87 |
btn.onmouseleave=function(){this.style.background=cfg.bg;};
|
| 88 |
+
btn.onclick=cfg.fn;
|
| 89 |
actionsArea.appendChild(btn);
|
| 90 |
});
|
| 91 |
+
console.log('[Quote UI v7] Protected buttons injected (Đơn hàng, GH)');
|
| 92 |
}
|
| 93 |
|
| 94 |
function isQuoteOpen(){
|
|
|
|
| 96 |
return ov&&(ov.classList.contains('open')||ov.style.display==='flex'||ov.style.display==='block');
|
| 97 |
}
|
| 98 |
|
| 99 |
+
// === BIND mã truy cập input (#qcAccessCode) ===
|
| 100 |
function bindAccessCodeInput(){
|
| 101 |
var accessInput=document.getElementById('qcAccessCode');
|
| 102 |
if(!accessInput)return false;
|
|
|
|
| 150 |
setTimeout(bindAccessCodeInput,1000);
|
| 151 |
setTimeout(bindAccessCodeInput,3000);
|
| 152 |
|
| 153 |
+
console.log('[Quote UI v7] loaded — Lưu always visible, protected buttons need V.AISTUDIO');
|
| 154 |
})();
|