forked from enviPath/enviPy
## Changes - All text input fields are now cleaned with nh3 to remove html tags. We allow certain html tags under `settings.py/ALLOWED_HTML_TAGS` so we can easily update the tags we allow in the future. - All names and descriptions now use the template tag `nh_safe` in all html files. - Usernames and emails are a small exception and are not allowed any html tags Co-authored-by: Liam Brydon <62733830+MyCreativityOutlet@users.noreply.github.com> Co-authored-by: jebus <lorsbach@envipath.com> Co-authored-by: Tim Lorsbach <tim@lorsba.ch> Reviewed-on: enviPath/enviPy#171 Reviewed-by: jebus <lorsbach@envipath.com> Co-authored-by: liambrydon <lbry121@aucklanduni.ac.nz> Co-committed-by: liambrydon <lbry121@aucklanduni.ac.nz>
76 lines
3.2 KiB
HTML
76 lines
3.2 KiB
HTML
|
|
{% load static %}
|
|
<!-- Copy Object -->
|
|
<div id="generic_copy_object_modal" class="modal" tabindex="-1">
|
|
<div class="modal-dialog">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<h3 class="modal-title">Copy {{ object_type|capfirst }}</h3>
|
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
|
<span aria-hidden="true">×</span>
|
|
</button>
|
|
</div>
|
|
<div class="modal-body">
|
|
<form id="generic-copy-object-modal-form" accept-charset="UTF-8" data-remote="true" method="post">
|
|
{% csrf_token %}
|
|
<label for="target-package">Select the Target Package you want to copy this {{ object_type }}
|
|
into</label>
|
|
<select id="target-package" name="target-package" data-actions-box='true' class="form-control"
|
|
data-width='100%'>
|
|
<option disabled selected>Select Target Package</option>
|
|
{% for p in meta.writeable_packages %}
|
|
<option value="{{ p.url }}">{{ p.name|safe }}</option>`
|
|
{% endfor %}
|
|
</select>
|
|
<input type="hidden" name="hidden" value="copy">
|
|
</form>
|
|
<div id="copy-object-error-message" class="alert alert-danger" role="alert" style="display: none">
|
|
</div>
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
|
|
<button type="button" class="btn btn-primary" id="generic-copy-object-modal-form-submit">
|
|
Copy
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<script>
|
|
$(function () {
|
|
|
|
$('#generic-copy-object-modal-form-submit').click(function (e) {
|
|
e.preventDefault();
|
|
$('#copy-object-error-message').hide()
|
|
|
|
const packageUrl = $('#target-package').find(":selected").val();
|
|
|
|
if (packageUrl === 'Select Target Package' || packageUrl === '' || packageUrl === null || packageUrl === undefined) {
|
|
return;
|
|
}
|
|
const formData = {
|
|
hidden: 'copy',
|
|
object_to_copy: '{{ current_object.url }}',
|
|
}
|
|
|
|
$.ajax({
|
|
type: 'post',
|
|
data: formData,
|
|
url: packageUrl,
|
|
success: function (data, textStatus) {
|
|
window.location.href = data.success;
|
|
},
|
|
error: function (jqXHR, textStatus, errorThrown) {
|
|
if (jqXHR.responseJSON.error.indexOf('to the same package') > -1) {
|
|
$('#copy-object-error-message').append('<p>The target Package is the same as the source Package. Please select another target!</p>');
|
|
} else {
|
|
$('#copy-object-error-message').append('<p>' + jqXHR.responseJSON.error + '</p>');
|
|
}
|
|
$('#copy-object-error-message').show();
|
|
}
|
|
});
|
|
});
|
|
|
|
})
|
|
</script>
|