Implement functionality to assigne Licenses to Packages and show existing Licenses (#17)

Co-authored-by: Tim Lorsbach <tim@lorsba.ch>
Reviewed-on: enviPath/enviPy#17
This commit is contained in:
2025-07-03 06:28:49 +12:00
parent 9950112311
commit 4e58a1fad7
5 changed files with 231 additions and 10 deletions

View File

@ -6,6 +6,10 @@
<a role="button" data-toggle="modal" data-target="#edit_package_permissions_modal">
<i class="glyphicon glyphicon-user"></i> Edit Permissions</a>
</li>
<li>
<a role="button" data-toggle="modal" data-target="#set_license_modal">
<i class="glyphicon glyphicon-duplicate"></i> License</a>
</li>
<li>
<a class="button" data-toggle="modal" data-target="#delete_package_modal">
<i class="glyphicon glyphicon-trash"></i> Delete Package</a>

View File

@ -0,0 +1,153 @@
<div class="modal fade"
tabindex="-1"
id="set_license_modal"
role="dialog"
aria-labelledby="set_license_modal"
aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button"
class="close"
data-dismiss="modal">
<span aria-hidden="true">&times;</span>
<span class="sr-only">Close</span>
</button>
<h3 class="modal-title">Set License</h3>
</div>
<div class="modal-body">
<div class="row">
<div class="col-md-9">
<p>
Set the license for all data in this package:
<br> <br>
(For more information please visit our <a target="#"
href="https://wiki.envipath.org/index.php/License">wiki</a>.)
</p>
</div>
<div class="col-md-3">
<div id="ccfig"></div>
</div>
</div>
<form id="set_license_form" accept-charset="UTF-8" action="" data-remote="true" method="post">
{% csrf_token %}
<div class="input-group">
<div class="radio">
<label><input type="radio" name="optlicense" onclick="cc()" id="ccradio">Creative commons license</label>
</div>
<div>
<div class="checkbox">
<label><input type="checkbox" value="" onclick="cc()" id="ccremix" disabled>Allow adaptations of your work to be shared</label>
</div>
<div class="checkbox">
<label><input type="checkbox" value="" onclick="cc()" id="ccnocom" disabled>Prohibit commercial use</label>
</div>
<div class="checkbox">
<label><input type="checkbox" value="" onclick="cc()" id="ccalike" disabled>Share only if others share alike</label>
</div>
</div>
<div class="radio">
<label><input type="radio" name="optlicense" onclick="cc()" id="noccradio">No creative commons license, contact package owner for license information</label>
</div>
</div>
<input type="hidden" id="license" name="license">
<input type="hidden" id="license-link" name="license-link">
<input type="hidden" id="license-image-link" name="license-image-link">
</form>
</div>
<div class="modal-footer">
<button id="set_license_form_submit" class="btn btn-primary">Submit</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
</div>
</div>
</div>
</div>
<script>
function ccstring(ccremix, ccnocom, ccalike){
var ccstring = "by";
if(ccnocom){
ccstring +="-nc";
}
if(!ccremix){
ccstring +="-nd";
} else{
if(ccalike){
ccstring +="-sa";
}
}
return ccstring;
}
function cc() {
var nocc = $('#noccradio').prop('checked')
var iscc = $('#ccradio').prop('checked');
if(nocc) {
$('#ccradio').prop('checked', false);
$('#ccremix').prop('checked', false);
$('#ccnocom').prop('checked', false);
$('#ccalike').prop('checked', false);
$('#ccremix').prop('disabled', true);
$('#ccnocom').prop('disabled', true);
$('#ccalike').prop('disabled', true);
} else if (iscc) {
$('#ccremix').prop('disabled', false);
$('#ccnocom').prop('disabled', false);
if ($('#ccremix').prop('checked')) {
$('#ccalike').prop('disabled', false);
} else {
$('#ccalike').prop('disabled', true);
}
}
var remix = $('#ccremix').prop('checked');
var nocom = $('#ccnocom').prop('checked');
var alike = $('#ccalike').prop('checked');
if(nocc) {
$('#set_license_form_submit').prop('disabled', false);
$('#ccfig').empty();
$('#license').val('no-license')
} else if(iscc) {
$('#set_license_form_submit').prop('disabled', false);
$('#ccfig').empty();
var ccstr = ccstring(remix, nocom, alike)
var link = `https://creativecommons.org/licenses/${ccstr}/4.0/`;
var imageLink = `https://licensebuttons.net/l/${ccstr}/4.0/88x31.png`;
var img_tpl = `<a href='${link}' target="_blank">
<img src='${imageLink}'>
</a>`;
$('#ccfig').append(img_tpl);
$('#license').val(ccstr);
$('#license-link').val(link);
$('#license-image-link').val(imageLink);
} else {
$('#ccfig').empty();
$('#set_license_form_submit').prop('disabled', true);
$('#license').val('no-license')
}
}
$(function() {
// Disable by default as nothing is selected
cc();
$('#set_license_form_submit').prop('disabled', true);
$('#set_license_form_submit').on('click', function (e) {
e.preventDefault();
$('#set_license_form').submit();
});
});
</script>

View File

@ -5,6 +5,7 @@
{% block action_modals %}
{% include "modals/objects/edit_package_modal.html" %}
{% include "modals/objects/edit_package_permissions_modal.html" %}
{% include "modals/objects/set_license_modal.html" %}
{% include "modals/objects/delete_package_modal.html" %}
{% endblock action_modals %}
@ -50,5 +51,24 @@
</ul>
</div>
{% if package.license %}
<p></p>
<div class="panel-group" id="license_accordion">
<div class="panel panel-default list-group-item" style="background-color:#f5f5f5">
<div class="panel-title">
<a data-toggle="collapse" data-parent="#licence_accordion" href="#license">License</a>
</div>
</div>
<div id="license" class="panel-collapse collapse in">
<div class="panel-body list-group-item">
<a target="_blank" href="{{ package.license.link }}">
<img src="{{ package.license.image_link }}">
</a>
</div>
</div>
</div>
{% endif %}
</div>
{% endblock content %}