Skip to content

Commit adf22aa

Browse files
author
SPRINX0\prochazka
committed
collectiong emails from downloads
1 parent 4de23bf commit adf22aa

File tree

5 files changed

+178
-9
lines changed

5 files changed

+178
-9
lines changed

assets/js/main.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
import "./app";
2+
import "./modal";
23

34
console.log("This site was generated by Hugo.");

assets/js/modal.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
document.addEventListener("DOMContentLoaded", () => {
2+
// Functions to open and close a modal
3+
function openModal($el) {
4+
$el.classList.add("is-active");
5+
}
6+
7+
function closeModal($el) {
8+
$el.classList.remove("is-active");
9+
}
10+
11+
function closeAllModals() {
12+
(document.querySelectorAll(".modal") || []).forEach(($modal) => {
13+
closeModal($modal);
14+
});
15+
}
16+
17+
// Add a click event on buttons to open a specific modal
18+
(document.querySelectorAll(".js-modal-trigger") || []).forEach(($trigger) => {
19+
const modal = $trigger.dataset.target;
20+
const $target = document.getElementById(modal);
21+
22+
$trigger.addEventListener("click", () => {
23+
openModal($target);
24+
});
25+
});
26+
27+
// Add a click event on various child elements to close the parent modal
28+
(
29+
document.querySelectorAll(
30+
".modal-background, .modal-close, .modal-card-head .delete, .modal-card-foot .button"
31+
) || []
32+
).forEach(($close) => {
33+
const $target = $close.closest(".modal");
34+
35+
$close.addEventListener("click", () => {
36+
closeModal($target);
37+
});
38+
});
39+
40+
// Add a keyboard event to close all modals
41+
document.addEventListener("keydown", (event) => {
42+
if (event.key === "Escape") {
43+
closeAllModals();
44+
}
45+
});
46+
});

data/download.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
icon: fas fa-external-link-alt
4343
link: https://flathub.org/apps/org.dbgate.DbGate
4444
event: download-linux-flathub
45+
isLink: true
4546
- text: MacOS
4647
icon: fab fa-apple
4748
items:
@@ -67,14 +68,17 @@
6768
icon: fab fa-docker
6869
link: https://hub.docker.com/r/dbgate/dbgate
6970
event: download-docker
71+
isLink: true
7072
- text: NPM
7173
icon: fas fa-external-link-alt
7274
link: https://www.npmjs.com/package/dbgate-serve
7375
event: download-npm
76+
isLink: true
7477
- text: Source code
7578
icon: fas fa-code
7679
items:
7780
- text: GitHub
7881
icon: fab fa-github
7982
link: https://github.com/dbgate/dbgate
8083
event: download-github
84+
isLink: true

layouts/shortcodes/download.html

Lines changed: 126 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
<h2>Download DbGate Premium</h2>
22
<p>
3-
For professional usage, we recommend DbGate Premium. It includes all features and support.
3+
For professional usage, we recommend DbGate Premium. It includes all features and support.
44
</p>
55
<p>
6-
A <strong>30-day free trial period</strong> is available.
6+
A <strong>30-day free trial period</strong> is available.
77
</p>
88

9-
<a class="button is-medium is-primary" href="https://dbgate.io/download" data-goatcounter-click="button-download-premium" data-goatcounter-title="Button: Download from dbgate.io">
9+
<a class="button is-medium is-primary" href="https://dbgate.io/download"
10+
data-goatcounter-click="button-download-premium" data-goatcounter-title="Button: Download from dbgate.io">
1011
<i class="fas fa-external-link-alt mr-2"></i>
1112
Download from dbgate.io
1213
</a>
@@ -15,13 +16,15 @@ <h2>Download DbGate Premium</h2>
1516
<h2>Download DbGate Community</h2>
1617
<p>DbGate Community is <strong>free</strong> and open-source</p>
1718
<p>
18-
Download the most recent stable version of DbGate. <br />
19-
Older releases or BETA versions could be found on <a href='https://github.com/dbgate/dbgate/releases' target="_blank">github releases</a> page
20-
</p>
21-
19+
Download the most recent stable version of DbGate. <br />
20+
Older releases or BETA versions could be found on <a href='https://github.com/dbgate/dbgate/releases'
21+
target="_blank">github releases</a> page
22+
</p>
23+
2224
{{ $items := index .Site.Data.download }}
2325

2426
{{ range $items }}
27+
{{ $osname := .text }}
2528
<div class="columns mb-6 ">
2629
<div class="column is-3">
2730
<button class="button is-medium is-static mr-5 is-fullwidth">
@@ -32,8 +35,12 @@ <h2>Download DbGate Community</h2>
3235
<div class="column">
3336
<div class="columns is-multiline">
3437
{{ range .items }}
38+
3539
<div class="column is-4">
36-
<a class="button is-medium is-primary is-fullwidth" href="{{ .link }}" onClick="sendDownloadEventToGoatCounter('{{ .event }}')">
40+
<a class="button is-medium is-primary is-fullwidth" {{ if .isLink }} href="{{ .link }}"
41+
onClick="sendDownloadEventToGoatCounter('{{ .event }}')" {{ else }}
42+
onClick="openDownloadModal('{{ .link }}', '{{ .event }}', '{{ .icon }}', '{{ $osname }}', '{{ .text }}', '{{ .platform }}')"
43+
{{ end }}>
3744
<i class="{{ .icon }} mr-2"></i>
3845
{{ .text }}
3946
{{ if .platform }}
@@ -49,3 +56,114 @@ <h2>Download DbGate Community</h2>
4956
</div>
5057
</div>
5158
{{ end }}
59+
60+
61+
62+
<div id="download-modal" class="modal">
63+
<div class="modal-background"></div>
64+
65+
<div class="modal-content">
66+
<div class="box">
67+
<h2>Please provide your e-mail address</h2>
68+
69+
<div class="field">
70+
<label class="label">Email</label>
71+
<div class="control has-icons-left has-icons-right">
72+
<input class="input" type="email" placeholder="Your e-mail" oninput="emailChanged()"
73+
id="email-input" />
74+
<span class="icon is-small is-left">
75+
<i class="fas fa-envelope"></i>
76+
</span>
77+
<!-- <span class="icon is-small is-right">
78+
<i class="fas fa-exclamation-triangle"></i>
79+
</span> -->
80+
</div>
81+
<!-- <p class="help is-danger">This email is invalid</p> -->
82+
</div>
83+
84+
85+
<div class="field">
86+
<label class="label">Job title - optional</label>
87+
<div class="control">
88+
<div class="select">
89+
<select id="job-title-select">
90+
<option value="">(Choose)</option>
91+
<option value="developer">Developer</option>
92+
<option value="analyst">Analyst</option>
93+
<option value="data-scientist">Data Scientist</option>
94+
<option value="tester">Tester</option>
95+
<option value="project-manager">Project/Product Manager</option>
96+
<option value="database-administrator">Database Administrator</option>
97+
<option value="other">Other</option>
98+
</select>
99+
</div>
100+
</div>
101+
</div>
102+
103+
<div class='is-flex is-flex-direction-row is-justify-content-space-between is-align-items-end'>
104+
<a class="button is-medium is-primary is-static" id="download-button">
105+
Download
106+
</a>
107+
108+
<p>
109+
<a id="download-no-email">Continue without e-mail</a>
110+
</p>
111+
</div>
112+
</div>
113+
</div>
114+
115+
<button class="modal-close is-large" aria-label="close"></button>
116+
</div>
117+
118+
<script lang="text/javascript">
119+
function openDownloadModal(link, event, icon, osname, title, platform) {
120+
const doDownload = () => {
121+
sendDownloadEventToGoatCounter(event);
122+
const modal = document.getElementById('download-modal');
123+
modal.classList.remove('is-active');
124+
const data = {
125+
email: document.getElementById('email-input').value,
126+
osname: osname,
127+
bundle: title,
128+
platform,
129+
link,
130+
job_title: document.getElementById('job-title-select').value,
131+
event,
132+
}
133+
134+
fetch(
135+
'https://api.dbgate.io/download/community',
136+
{
137+
method: 'POST',
138+
headers: {
139+
'Content-Type': 'application/json',
140+
},
141+
body: JSON.stringify(data),
142+
}
143+
);
144+
145+
}
146+
const modal = document.getElementById('download-modal');
147+
modal.classList.add('is-active');
148+
const button = document.getElementById('download-button');
149+
button.href = link;
150+
button.onclick = doDownload;
151+
button.innerHTML = `<i class="${icon} mr-2"></i> Download DbGate for ${osname} - ${title}`;
152+
if (platform) {
153+
button.innerHTML += ` (${platform})`;
154+
}
155+
const linkButton = document.getElementById('download-no-email');
156+
linkButton.href = link;
157+
linkButton.onclick = doDownload;
158+
}
159+
160+
function emailChanged() {
161+
const input = document.getElementById('email-input');
162+
const button = document.getElementById('download-button');
163+
if (input.value && input.value.includes('@')) {
164+
button.classList.remove('is-static');
165+
} else {
166+
button.classList.add('is-static');
167+
}
168+
}
169+
</script>

layouts/shortcodes/newsletter.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ <h2>Join our newsletter</h2>
4747
body: JSON.stringify(data),
4848
}
4949
);
50-
alert('Thank you for joining our newslette.');
50+
alert('Thank you for joining our newsletter.');
5151
} catch (error) {
5252
console.error('Error:', error);
5353
alert('An error occurred while sending data.');

0 commit comments

Comments
 (0)