-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
194 lines (174 loc) · 6.73 KB
/
index.html
File metadata and controls
194 lines (174 loc) · 6.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>GHL Bulk Delete Email Templates Tool</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" />
<style>
body {
background-color: #f9fafb;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
.main-header {
text-align: center;
font-size: 2.5rem;
font-weight: bold;
color: #2c3e50;
margin-bottom: 2rem;
}
label {
font-weight: 500;
color: #34495e;
}
.form-control {
border-radius: 0.5rem;
}
.btn {
border-radius: 0.5rem;
}
#results {
background: #ffffff;
padding: 1rem;
border-radius: 1rem;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.05);
}
.badge {
font-size: 1rem;
}
</style>
</head>
<body>
<div class="container py-5">
<h1 class="main-header">📧 GHL Bulk Delete Email Templates Tool</h1>
<div class="row g-4 justify-content-center mb-4">
<div class="col-md-4">
<label for="locationId">Subaccount ID</label>
<input type="text" id="locationId" class="form-control" placeholder="Location ID" required>
</div>
<div class="col-md-4">
<label>Private Integration Key</label>
<input type="text" id="authToken" class="form-control" placeholder="Integration Key" required>
</div>
</div>
<div class="row g-4 justify-content-center mb-4">
<div class="col-md-3">
<label>Templates Limit</label>
<input type="number" id="limit" class="form-control" placeholder="Limit" value="100">
</div>
<div class="col-md-3">
<label>Delete Delay (sec)</label>
<input type="number" id="delay" class="form-control" placeholder="Delay (sec)" value="2">
</div>
<div class="col-md-3 d-flex align-items-end gap-3">
<button class="btn btn-primary w-100" id="fetchBtn">Fetch Templates</button>
</div>
<div class="col-md-3 d-flex align-items-end">
<button id="clearBtn" class="btn btn-outline-danger w-100">Clear Data</button>
</div>
</div>
<div id="results" class="mt-4"></div>
</div>
<script>
let templates = [];
let ghlDeletedCount = 0;
document.getElementById('fetchBtn').addEventListener('click', async () => {
const locationId = document.getElementById('locationId').value.trim();
const authToken = document.getElementById('authToken').value.trim();
const limit = document.getElementById('limit').value.trim() || 100;
if (!locationId || !authToken) return alert('Please fill Location ID and Authorization Token.');
try {
const res = await fetch(`https://services.leadconnectorhq.com/emails/builder?locationId=${locationId}&limit=${limit}`, {
method: 'GET',
headers: {
Authorization: `Bearer ${authToken}`,
Version: '2021-07-28',
Accept: 'application/json'
}
});
const data = await res.json();
templates = (data.builders || []);
if (!templates.length) return alert('No templates found.');
renderTable();
} catch (err) {
console.error(err);
alert('Failed to fetch templates. See console for details.');
}
});
function renderTable() {
const rows = templates.map((t, i) => `
<tr>
<td><input type="checkbox" class="form-check-input template-checkbox" data-id="${t.id}"></td>
<td>${i + 1}</td>
<td>${t.id}</td>
<td>${t.name}</td>
<td>${new Date(t.lastUpdated).toLocaleString()}</td>
</tr>
`).join('');
document.getElementById('results').innerHTML = `
<div class="d-flex flex-wrap gap-3 mb-3">
<button class="btn btn-outline-danger" id="deleteSelected">🧹 Delete Selection (Memory)</button>
<span id="totalCount" class="badge bg-secondary d-flex align-items-center">Total: ${templates.length}</span>
<button class="btn btn-danger" id="deleteFromGHL">🚨 Delete from GHL</button>
<span id="ghlDeleteCount" class="badge bg-danger d-flex align-items-center">GHL Deleted: ${ghlDeletedCount}</span>
</div>
<div class="table-responsive">
<table class="templatesTable table table-bordered table-striped">
<thead class="table-light">
<tr>
<th><input type="checkbox" id="selectAll"></th>
<th>#</th>
<th>ID</th>
<th>Name</th>
<th>Last Updated</th>
</tr>
</thead>
<tbody>${rows}</tbody>
</table>
</div>`;
document.getElementById('selectAll').addEventListener('change', (e) => {
document.querySelectorAll('.template-checkbox').forEach(cb => cb.checked = e.target.checked);
});
document.getElementById('deleteSelected').addEventListener('click', () => {
const selectedIds = Array.from(document.querySelectorAll('.template-checkbox:checked')).map(cb => cb.dataset.id);
templates = templates.filter(t => !selectedIds.includes(t.id));
renderTable();
});
document.getElementById('deleteFromGHL').addEventListener('click', async () => {
const locationId = document.getElementById('locationId').value.trim();
const authToken = document.getElementById('authToken').value.trim();
const delay = parseInt(document.getElementById('delay').value) * 1000 || 2000;
const selectedIds = Array.from(document.querySelectorAll('.template-checkbox:checked')).map(cb => cb.dataset.id);
for (let i = 0; i < selectedIds.length; i++) {
const id = selectedIds[i];
try {
const res = await fetch(`https://services.leadconnectorhq.com/emails/builder/${locationId}/${id}`, {
method: 'DELETE',
headers: {
Authorization: `Bearer ${authToken}`,
Version: '2021-07-28',
Accept: 'application/json'
}
});
const result = await res.json();
if (result) {
templates = templates.filter(t => t.id !== id);
ghlDeletedCount++;
renderTable();
}
} catch (err) {
console.error('Failed to delete:', id, err);
}
await new Promise(res => setTimeout(res, delay));
}
alert('GHL Deletion complete!');
});
}
document.getElementById('clearBtn').addEventListener('click', () => {
templates = [];
ghlDeletedCount = 0;
document.getElementById('results').innerHTML = '';
});
</script>
</body>
</html>