mirror of
https://github.com/cwinfo/powerdns-admin.git
synced 2024-11-09 23:20:27 +00:00
Fix domain template record modification #346
This commit is contained in:
parent
615413ae90
commit
c7689e7ce7
@ -108,7 +108,7 @@
|
|||||||
<li class="{{ 'active' if active_page == 'dashboard' else '' }}">
|
<li class="{{ 'active' if active_page == 'dashboard' else '' }}">
|
||||||
<a href="{{ url_for('dashboard') }}"><i class="fa fa-dashboard"></i> Dashboard</a>
|
<a href="{{ url_for('dashboard') }}"><i class="fa fa-dashboard"></i> Dashboard</a>
|
||||||
</li>
|
</li>
|
||||||
{% if SETTING.get('allow_user_create_domain') %}
|
{% if SETTING.get('allow_user_create_domain') or current_user.role.name in ['Administrator', 'Operator'] %}
|
||||||
<li class="{{ 'active' if active_page == 'new_domain' else '' }}">
|
<li class="{{ 'active' if active_page == 'new_domain' else '' }}">
|
||||||
<a href="{{ url_for('domain_add') }}"><i class="fa fa-plus"></i> New Domain</a>
|
<a href="{{ url_for('domain_add') }}"><i class="fa fa-plus"></i> New Domain</a>
|
||||||
</li>
|
</li>
|
||||||
|
@ -156,7 +156,7 @@
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block extrascripts %}
|
{% block extrascripts %}
|
||||||
<script>
|
<script>
|
||||||
PDNS_VERSION = '{{ SETTING.get("pdns_version") }}'
|
PDNS_VERSION = '{{ SETTING.get("pdns_version") }}';
|
||||||
// set up history data table
|
// set up history data table
|
||||||
$("#tbl_history").DataTable({
|
$("#tbl_history").DataTable({
|
||||||
"paging" : false,
|
"paging" : false,
|
||||||
|
@ -104,7 +104,6 @@
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block extrascripts %}
|
{% block extrascripts %}
|
||||||
<script>
|
<script>
|
||||||
PDNS_VERSION = '{{ SETTING.get("pdns_version") }}'
|
|
||||||
// superglobals
|
// superglobals
|
||||||
window.records_allow_edit = {{ editable_records|tojson }};
|
window.records_allow_edit = {{ editable_records|tojson }};
|
||||||
window.nEditing = null;
|
window.nEditing = null;
|
||||||
|
@ -115,12 +115,23 @@
|
|||||||
"lengthMenu": " _MENU_ records"
|
"lengthMenu": " _MENU_ records"
|
||||||
},
|
},
|
||||||
"retrieve" : true,
|
"retrieve" : true,
|
||||||
"columnDefs": [{
|
"columnDefs": [
|
||||||
"targets": [ 7 ],
|
{
|
||||||
"visible": false,
|
type: 'natural',
|
||||||
"searchable": false
|
targets: [0, 4]
|
||||||
}]
|
},
|
||||||
|
{
|
||||||
|
// hidden column so that we can add new records on top
|
||||||
|
// regardless of whatever sorting is done
|
||||||
|
visible: false,
|
||||||
|
targets: [ 7 ]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
className: "length-break",
|
||||||
|
targets: [ 4 ]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"orderFixed": [[7, 'asc']]
|
||||||
});
|
});
|
||||||
|
|
||||||
// handle delete button
|
// handle delete button
|
||||||
@ -132,15 +143,19 @@
|
|||||||
var nRow = $(this).parents('tr')[0];
|
var nRow = $(this).parents('tr')[0];
|
||||||
var info = "Are you sure you want to delete " + record + "?";
|
var info = "Are you sure you want to delete " + record + "?";
|
||||||
modal.find('.modal-body p').text(info);
|
modal.find('.modal-body p').text(info);
|
||||||
modal.find('#button_delete_confirm').click(function() {
|
|
||||||
table.row(nRow).remove().draw();
|
|
||||||
modal.modal('hide');
|
|
||||||
})
|
|
||||||
modal.modal('show');
|
modal.modal('show');
|
||||||
|
|
||||||
|
$("#button_delete_confirm").unbind().one('click', function(e) {
|
||||||
|
table.row(nRow).remove().draw();
|
||||||
|
modal.modal('hide');
|
||||||
});
|
});
|
||||||
// handle edit button
|
|
||||||
$(document.body).on("click", ".button_edit, .row_record", function(e) {
|
$("#button_delete_cancel").unbind().one('click', function(e) {
|
||||||
|
modal.modal('hide');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
// handle edit button and record click
|
||||||
|
$(document.body).on("click", ".button_edit{% if quick_edit %}, .row_record{% endif %}", function(e) {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
if ($(this).is('tr')) {
|
if ($(this).is('tr')) {
|
||||||
var nRow = $(this)[0];
|
var nRow = $(this)[0];
|
||||||
@ -176,7 +191,9 @@
|
|||||||
var template = $(this).prop('id');
|
var template = $(this).prop('id');
|
||||||
var info = "Are you sure you want to apply your changes?";
|
var info = "Are you sure you want to apply your changes?";
|
||||||
modal.find('.modal-body p').text(info);
|
modal.find('.modal-body p').text(info);
|
||||||
modal.find('#button_apply_confirm').click(function() {
|
|
||||||
|
// following unbind("click") is to avoid multiple times execution
|
||||||
|
modal.find('#button_apply_confirm').unbind("click").click(function() {
|
||||||
var data = getTableData(table);
|
var data = getTableData(table);
|
||||||
applyChanges(data, '/template/' + template + '/apply', true);
|
applyChanges(data, '/template/' + template + '/apply', true);
|
||||||
modal.modal('hide');
|
modal.modal('hide');
|
||||||
@ -188,15 +205,19 @@
|
|||||||
// handle add record button
|
// handle add record button
|
||||||
$(document.body).on("click", ".button_add_record", function (e) {
|
$(document.body).on("click", ".button_add_record", function (e) {
|
||||||
if (nNew || nEditing) {
|
if (nNew || nEditing) {
|
||||||
// TODO: replace this alert with modal
|
var modal = $("#modal_error");
|
||||||
alert("Previous record not saved. Please save it before adding more record.")
|
modal.find('.modal-body p').text("Previous record not saved. Please save it before adding more record.");
|
||||||
|
modal.modal('show');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var table = $("#tbl_records").DataTable();
|
// clear search first
|
||||||
|
$("#tbl_records").DataTable().search('').columns().search('').draw();
|
||||||
|
|
||||||
var aiNew = table.row.add(['', 'A', 'Active', 3600, '', '', '', '']).draw();
|
// add new row
|
||||||
var nRow = aiNew.index();
|
var default_type = records_allow_edit[0]
|
||||||
editRow(table, nRow);
|
var nRow = jQuery('#tbl_records').dataTable().fnAddData(['', default_type, 'Active', 3600, '', '', '', '0']);
|
||||||
|
editRow($("#tbl_records").DataTable(), nRow);
|
||||||
|
document.getElementById("edit-row-focus").focus();
|
||||||
nEditing = nRow;
|
nEditing = nRow;
|
||||||
nNew = true;
|
nNew = true;
|
||||||
});
|
});
|
||||||
@ -229,20 +250,50 @@
|
|||||||
$(document.body).on("focus", "#current_edit_record_data", function (e) {
|
$(document.body).on("focus", "#current_edit_record_data", function (e) {
|
||||||
var record_type = $(this).parents("tr").find('#record_type').val();
|
var record_type = $(this).parents("tr").find('#record_type').val();
|
||||||
var record_data = $(this);
|
var record_data = $(this);
|
||||||
if (record_type == "MX") {
|
if (record_type == "CAA") {
|
||||||
|
var modal = $("#modal_custom_record");
|
||||||
|
if (record_data.val() == "") {
|
||||||
|
var form = " <label for=\"caa_flag\">CAA Flag</label> \
|
||||||
|
<input type=\"text\" class=\"form-control\" name=\"caa_flag\" id=\"caa_flag\" placeholder=\"0\"> \
|
||||||
|
<label for=\"caa_tag\">CAA Tag</label> \
|
||||||
|
<input type=\"text\" class=\"form-control\" name=\"caa_tag\" id=\"caa_tag\" placeholder=\"issue\"> \
|
||||||
|
<label for=\"caa_value\">CAA Value</label> \
|
||||||
|
<input type=\"text\" class=\"form-control\" name=\"caa_value\" id=\"caa_value\" placeholder=\"eg. letsencrypt.org\"> \
|
||||||
|
";
|
||||||
|
} else {
|
||||||
|
var parts = record_data.val().split(" ");
|
||||||
|
var form = " <label for=\"caa_flag\">CAA Flag</label> \
|
||||||
|
<input type=\"text\" class=\"form-control\" name=\"caa_flag\" id=\"caa_flag\" placeholder=\"0\" value=\"" + parts[0] + "\"> \
|
||||||
|
<label for=\"caa_tag\">CAA Tag</label> \
|
||||||
|
<input type=\"text\" class=\"form-control\" name=\"caa_tag\" id=\"caa_tag\" placeholder=\"issue\" value=\"" + parts[1] + "\"> \
|
||||||
|
<label for=\"caa_value\">CAA Value</label> \
|
||||||
|
<input type=\"text\" class=\"form-control\" name=\"caa_value\" id=\"caa_value\" placeholder=\"eg. letsencrypt.org\" value=\"" + parts[2] + "\"> \
|
||||||
|
";
|
||||||
|
}
|
||||||
|
modal.find('.modal-body p').html(form);
|
||||||
|
modal.find('#button_save').click(function() {
|
||||||
|
caa_flag = modal.find('#caa_flag').val();
|
||||||
|
caa_tag = modal.find('#caa_tag').val();
|
||||||
|
caa_value = modal.find('#caa_value').val();
|
||||||
|
data = caa_flag + " " + caa_tag + " " + '"' + caa_value + '"';
|
||||||
|
record_data.val(data);
|
||||||
|
modal.modal('hide');
|
||||||
|
})
|
||||||
|
modal.modal('show');
|
||||||
|
} else if (record_type == "MX") {
|
||||||
var modal = $("#modal_custom_record");
|
var modal = $("#modal_custom_record");
|
||||||
if (record_data.val() == "") {
|
if (record_data.val() == "") {
|
||||||
var form = " <label for=\"mx_priority\">MX Priority</label> \
|
var form = " <label for=\"mx_priority\">MX Priority</label> \
|
||||||
<input type=\"text\" class=\"form-control\" name=\"mx_priority\" id=\"mx_priority\" placeholder=\"10\"> \
|
<input type=\"text\" class=\"form-control\" name=\"mx_priority\" id=\"mx_priority\" placeholder=\"eg. 10\"> \
|
||||||
<label for=\"mx_server\">MX Server</label> \
|
<label for=\"mx_server\">MX Server</label> \
|
||||||
<input type=\"text\" class=\"form-control\" name=\"mx_server\" id=\"mx_server\" placeholder=\"postfix.example.com\"> \
|
<input type=\"text\" class=\"form-control\" name=\"mx_server\" id=\"mx_server\" placeholder=\"eg. postfix.example.com\"> \
|
||||||
";
|
";
|
||||||
} else {
|
} else {
|
||||||
var parts = record_data.val().split(" ");
|
var parts = record_data.val().split(" ");
|
||||||
var form = " <label for=\"mx_priority\">MX Priority</label> \
|
var form = " <label for=\"mx_priority\">MX Priority</label> \
|
||||||
<input type=\"text\" class=\"form-control\" name=\"mx_priority\" id=\"mx_priority\" placeholder=\"10\" value=\"" + parts[0] + "\"> \
|
<input type=\"text\" class=\"form-control\" name=\"mx_priority\" id=\"mx_priority\" placeholder=\"eg. 10\" value=\"" + parts[0] + "\"> \
|
||||||
<label for=\"mx_server\">MX Server</label> \
|
<label for=\"mx_server\">MX Server</label> \
|
||||||
<input type=\"text\" class=\"form-control\" name=\"mx_server\" id=\"mx_server\" placeholder=\"postfix.example.com\" value=\"" + parts[1] + "\"> \
|
<input type=\"text\" class=\"form-control\" name=\"mx_server\" id=\"mx_server\" placeholder=\"eg. postfix.example.com\" value=\"" + parts[1] + "\"> \
|
||||||
";
|
";
|
||||||
}
|
}
|
||||||
modal.find('.modal-body p').html(form);
|
modal.find('.modal-body p').html(form);
|
||||||
@ -360,7 +411,7 @@
|
|||||||
<p></p>
|
<p></p>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<button type="button" class="btn btn-flat btn-default pull-left"
|
<button type="button" class="btn btn-flat btn-default pull-left" id="button_delete_cancel"
|
||||||
data-dismiss="modal">Close</button>
|
data-dismiss="modal">Close</button>
|
||||||
<button type="button" class="btn btn-flat btn-danger" id="button_delete_confirm">Delete</button>
|
<button type="button" class="btn btn-flat btn-danger" id="button_delete_confirm">Delete</button>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1017,6 +1017,7 @@ def edit_template(template):
|
|||||||
try:
|
try:
|
||||||
t = DomainTemplate.query.filter(DomainTemplate.name == template).first()
|
t = DomainTemplate.query.filter(DomainTemplate.name == template).first()
|
||||||
records_allow_to_edit = Setting().get_records_allow_to_edit()
|
records_allow_to_edit = Setting().get_records_allow_to_edit()
|
||||||
|
quick_edit = Setting().get('record_quick_edit')
|
||||||
if t is not None:
|
if t is not None:
|
||||||
records = []
|
records = []
|
||||||
for jr in t.records:
|
for jr in t.records:
|
||||||
@ -1024,9 +1025,10 @@ def edit_template(template):
|
|||||||
record = DomainTemplateRecord(name=jr.name, type=jr.type, status='Disabled' if jr.status else 'Active', ttl=jr.ttl, data=jr.data)
|
record = DomainTemplateRecord(name=jr.name, type=jr.type, status='Disabled' if jr.status else 'Active', ttl=jr.ttl, data=jr.data)
|
||||||
records.append(record)
|
records.append(record)
|
||||||
|
|
||||||
return render_template('template_edit.html', template=t.name, records=records, editable_records=records_allow_to_edit)
|
return render_template('template_edit.html', template=t.name, records=records, editable_records=records_allow_to_edit, quick_edit=quick_edit)
|
||||||
except:
|
except Exception as e:
|
||||||
logging.error(traceback.format_exc())
|
logging.error('Cannot open domain template page. DETAIL: {0}'.format(e))
|
||||||
|
logging.debug(traceback.format_exc())
|
||||||
return redirect(url_for('error', code=500))
|
return redirect(url_for('error', code=500))
|
||||||
return redirect(url_for('templates'))
|
return redirect(url_for('templates'))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user