devshort

private self-hosted shortlink service
git clone https://git.clttr.info/devshort.git
Log (Feed) | Files | Refs (Tags) | README | LICENSE

commit 1176183d6493cb77ed7b6525f707acd125133c2b
parent e80d04006d6e1a5fd134893e02eb0b044f9a8867
Author: Florian Kaldowski <flokX@users.noreply.github.com>
Date:   Sat,  6 Apr 2019 14:29:25 +0200

Update main.js
Diffstat:
Madmin/main.js | 28+++++++++++++++++-----------
1 file changed, 17 insertions(+), 11 deletions(-)

diff --git a/admin/main.js b/admin/main.js @@ -1,19 +1,22 @@ var currentDate = new Date(); var startDate = new Date(new Date().setFullYear(currentDate.getFullYear() - 1)); +var spinner = document.getElementById('spinner'); +var chartsDiv = document.getElementById('charts'); $.ajaxSetup({ cache: false }); $('button#add-shortlink').click(function (event) { + 'use strict'; event.preventDefault(); - $('div#spinner').show(); + spinner.style.display = ''; $.post('index.php?add', { - name: $('input#name').val(), - link: $('input#link').val() + name: document.getElementById('name').value, + link: document.getElementById('link').value }, function (data) { if (data === '{"status": "successful"}') { - $('input#name').val(''); - $('input#link').val(''); + document.getElementById('name').value = ''; + document.getElementById('link').value = ''; getCharts(); } else if (data === '{"status": "unvalid-url"}') { document.getElementById('status').innerHTML = '<div class="alert alert-danger" role="alert">Unvalid URL. Please provide a valid URL.</div>'; @@ -21,20 +24,23 @@ $('button#add-shortlink').click(function (event) { document.getElementById('status').innerHTML = '<div class="alert alert-danger" role="alert">Error. Please try again.</div>'; } }); - $('div#spinner').hide(); + spinner.style.display = 'none'; }); $('a#refresh').click(function (event) { + 'use strict'; event.preventDefault(); getCharts(); }); function getCharts() { 'use strict'; - $('div#spinner').show(); - $('div#charts').empty(); + spinner.style.display = ''; + while (chartsDiv.firstChild) { + chartsDiv.firstChild.remove(); + } $.getJSON('stats.json', function (json) { $.each(json, function (name, data) { - $('div#charts').append('<div id="card-' + name + '" class="card mb-3"><div class="card-body"><div id="heatmap-' + name + '" class="heatmap"></div></div><div class="card-footer text-center text-muted"><a id="export-' + name + '" href="#download" class="card-link">Download chart</a><a id="delete-' + name + '" href="#delete" class="card-link">Delete shortlink and dataset</a></div></div>'); + chartsDiv.insertAdjacentHTML('beforeend', '<div id="card-' + name + '" class="card mb-3"><div class="card-body"><div id="heatmap-' + name + '" class="heatmap"></div></div><div class="card-footer text-center text-muted"><a id="export-' + name + '" href="#download" class="card-link">Download chart</a><a id="delete-' + name + '" href="#delete" class="card-link">Delete shortlink and dataset</a></div></div>'); let heatmap = new frappe.Chart('div#heatmap-' + name, { type: 'heatmap', title: 'Access statistics for ' + name, @@ -54,10 +60,10 @@ function getCharts() { $.post('index.php?delete', { name: name }); - $('div#card-' + name).remove(); + document.getElementById('card-' + name).remove(); }); }); - $('div#spinner').hide(); + spinner.style.display = 'none'; }); }