Improve firmware generation JS

This commit is contained in:
Kumi 2019-02-09 16:24:41 +00:00
parent d402b1b0ac
commit 97d045c063
3 changed files with 29 additions and 4 deletions

@ -1 +1 @@
Subproject commit de6e1ff2eac0281ea8c3f312aaaaa337c22f9768
Subproject commit 5a2882f08e30e4e9b8945d84e53c228ed2cfbeff

View file

@ -1,3 +1,26 @@
function urlStatus(url, cb){
$.ajax({
url: url,
dataType: 'text',
type: 'GET',
complete: function(xhr){
if(typeof cb === 'function')
cb.apply(this, [xhr.status]);
}
});
}
function checkDownload(url){
urlStatus(url, function(status) {
if (status === 200){
document.getElementById("download").src=url;
}
else {
checkDownload(url);
}
});
}
function timeSince(obj) {
last = new Date(Number(obj));
var seconds = Math.floor((new Date() - last) / 1000);
@ -74,8 +97,9 @@ function askreboot(device_id) {
if (confirm("Are you sure you want to reboot this Device?")) window.location.href = "/devices/" + device_id + "/reboot";
};
function downloadnotice() {
alert("Your file is being prepared. This might take a minute or two. You may close this page and click the download button again later when the file has been generated or if your browser stops trying to load the file.");
function downloadnotice(device_id) {
alert("Your file is being prepared. This might take a minute or two, the download will start automatically when the file is ready. You may close this page and click the download button again later to pick the file up we will store it for you.");
checkDownload('/devices/' + device_id + '/download');
};
function showdevices() {

View file

@ -40,7 +40,7 @@
<td id="{{ device.id }}-name">{% if device.name %}{{ device.name }}{% endif %}</td>
<td id="{{ device.id }}-network">{{ device.network }}</td>
<td><div style="display:inline;" id="{{ device.id }}-ip">{% if device.curip %}{{ device.curip }} (at {{ device.lasttime }}){% endif %}</div></td>
<td><a href="/devices/{{ device.id }}/edit"><i class="fas fa-edit" title="Edit Device"></i></a> <a href="#"><i style="color: green;" onclick="askreboot({{ device.id }});" class="fas fa-sync" title="Reboot Device"></i></a>{% if user.is_staff %} <a onclick="downloadnotice();" href="/devices/{{ device.id }}/download"><i class="fas fa-download" title="Download Configuration"></i></a>{% endif %}{% if user.is_superuser %} <a href="#"><i style="color: darkred;" onclick="askdelete({{ device.id }});" class="fas fa-trash-alt" title="Delete Device"></i></a>{% endif %}</td>
<td><a href="/devices/{{ device.id }}/edit"><i class="fas fa-edit" title="Edit Device"></i></a> <a href="#"><i style="color: green;" onclick="askreboot({{ device.id }});" class="fas fa-sync" title="Reboot Device"></i></a>{% if user.is_staff %} <i onclick="downloadnotice({{ device.id }});" class="fas fa-download" title="Download Configuration"></i></a>{% endif %}{% if user.is_superuser %} <a href="#"><i style="color: darkred;" onclick="askdelete({{ device.id }});" class="fas fa-trash-alt" title="Delete Device"></i></a>{% endif %}</td>
</tr>
{% endfor %}
@ -157,5 +157,6 @@
</div>
{% endif %}
<iframe id="download" width="1" height="1" style="display:none"></iframe>
<script src="/js/devices.js"></script>
{% endblock %}