Hide install button if we don't have all require files

This commit is contained in:
Julien Duponchelle 2015-09-04 17:08:23 +02:00
parent e73b3d0dfc
commit 1efe06d9f4
2 changed files with 31 additions and 12 deletions

View File

@ -12,6 +12,8 @@ function download(appliance, md5sum) {
return false;
}
var installable_versions = gns3.installableVersions("{{appliance|jsonify|b64encode}}");
{% endblock %}
{% block body %}
@ -54,9 +56,11 @@ function download(appliance, md5sum) {
{{ key }}: {{ appliance["qemu"][key] }}<br />
{% endfor %}
{% endif %}
{% for version in appliance["versions"] | reverse %}
<h2>{{ appliance["name"] }} {{version["name"]}}</h2>
<button class="btn btn-primary btn-lg" type="button" onclick='gns3_button(function() { return gns3.install("{{appliance|jsonify|b64encode}}", "{{version["name"]}}") })'>Install</button>
<button class="btn btn-primary btn-lg" id="download_button_{{loop.index}}" type="button">Install</button>
<script>gns3_show_if("#download_button_{{loop.index}}", installable_versions.indexOf("{{version["name"]}}") != -1)</script>
<h3>Require files</h3>
{% for image in version.images.values() %}
<h4>{{image["filename"]}}</h4>

View File

@ -27,15 +27,12 @@
</style>
<script>
if (gns3.marketplace_api_version() != 1) {
alert("Your client is out of date please update it");
}
function gns3_notif(type, msg) {
var notif = $("#notif")
notif.append("<div class=\"alert alert-" + type + " alert-dismissible fade in\" role=\"alert\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-label=\"Close\"><span aria-hidden=\"true\">×</span></button>" + msg + "</div>")
}
if (typeof gns3 !== "undefined") {
gns3.error.connect(function(msg) {
gns3_notif("danger", msg);
});
@ -44,6 +41,11 @@
gns3_notif("success", msg);
});
if (gns3.marketplaceApiVersion() != 1) {
alert("Your client is out of date please update it");
}
}
/*
Deactivate the button after success click
*/
@ -61,12 +63,25 @@
}
}
/*
* Show or hide element depending of the test
*/
gns3_show_if = function(id, test) {
if (test) {
$(id).show();
}
else {
$(id).hide();
}
}
function humanFileSize(bytes) {
var exp = Math.log(bytes) / Math.log(1024) | 0;
var result = (bytes / Math.pow(1024, exp)).toFixed(2);
return result + ' ' + (exp == 0 ? 'bytes': 'KMGTPEZY'[exp - 1] + 'B');
}
</script>
<script>