bep40 commited on
Commit
61aa615
·
verified ·
1 Parent(s): fdebcf6

Upload quote-ui.js

Browse files
Files changed (1) hide show
  1. quote-ui.js +154 -0
quote-ui.js ADDED
@@ -0,0 +1,154 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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';
10
+
11
+ var ACCESS_CODE='V.AISTUDIO';
12
+
13
+ function isUnlocked(){
14
+ return document.body.classList.contains('vas-unlocked');
15
+ }
16
+
17
+ function unlock(){
18
+ document.body.classList.add('vas-unlocked');
19
+ console.log('[Quote UI v7] ✅ Unlocked');
20
+ setTimeout(addProtectedButtons,200);
21
+ }
22
+
23
+ function lock(){
24
+ document.body.classList.remove('vas-unlocked');
25
+ removeProtectedButtons();
26
+ }
27
+
28
+ // === NÚT LƯU (LUÔN HIỆN) ===
29
+ function hasSaveButton(){
30
+ return !!document.querySelector('[data-vai-save-btn]');
31
+ }
32
+
33
+ function addSaveButton(){
34
+ if(hasSaveButton())return;
35
+ var actionsArea=document.querySelector('.quote-actions');
36
+ if(!actionsArea)return;
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) ===
58
+ function hasProtectedButtons(){
59
+ return !!document.querySelector('[data-vai-protected-btn]');
60
+ }
61
+
62
+ function removeProtectedButtons(){
63
+ document.querySelectorAll('[data-vai-protected-btn]').forEach(function(b){b.remove();});
64
+ }
65
+
66
+ function addProtectedButtons(){
67
+ if(!isUnlocked())return;
68
+ if(hasProtectedButtons())return;
69
+ var actionsArea=document.querySelector('.quote-actions');
70
+ if(!actionsArea)return;
71
+
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
+ ];
79
+
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(){
95
+ var ov=document.querySelector('.quote-overlay');
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;
103
+ if(accessInput.getAttribute('data-vai-access'))return true;
104
+ accessInput.setAttribute('data-vai-access','1');
105
+
106
+ function checkCode(){
107
+ var val=(accessInput.value||'').trim();
108
+ if(val===ACCESS_CODE||val.toUpperCase()===ACCESS_CODE){
109
+ if(!isUnlocked())unlock();
110
+ }else{
111
+ if(isUnlocked())lock();
112
+ }
113
+ }
114
+
115
+ accessInput.addEventListener('input',checkCode);
116
+ accessInput.addEventListener('change',checkCode);
117
+ accessInput.addEventListener('blur',checkCode);
118
+ accessInput.addEventListener('keypress',function(e){if(e.key==='Enter')checkCode();});
119
+ return true;
120
+ }
121
+
122
+ // === OBSERVER ===
123
+ var observer=new MutationObserver(function(){
124
+ bindAccessCodeInput();
125
+ if(isQuoteOpen()){
126
+ if(!hasSaveButton())setTimeout(addSaveButton,200);
127
+ if(isUnlocked()&&!hasProtectedButtons())setTimeout(addProtectedButtons,300);
128
+ }
129
+ if(!isQuoteOpen()){
130
+ if(hasSaveButton())document.querySelectorAll('[data-vai-save-btn]').forEach(function(b){b.remove();});
131
+ if(hasProtectedButtons())removeProtectedButtons();
132
+ }
133
+ if(!isUnlocked()&&hasProtectedButtons())removeProtectedButtons();
134
+ });
135
+ observer.observe(document.body,{childList:true,subtree:true,attributes:true,attributeFilter:['class','style']});
136
+
137
+ setInterval(function(){
138
+ bindAccessCodeInput();
139
+ if(isQuoteOpen()){
140
+ if(!hasSaveButton())addSaveButton();
141
+ if(isUnlocked()&&!hasProtectedButtons())addProtectedButtons();
142
+ }
143
+ if(!isQuoteOpen()){
144
+ if(hasSaveButton())document.querySelectorAll('[data-vai-save-btn]').forEach(function(b){b.remove();});
145
+ if(hasProtectedButtons())removeProtectedButtons();
146
+ }
147
+ if(!isUnlocked()&&hasProtectedButtons())removeProtectedButtons();
148
+ },2000);
149
+
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
+ })();