Cleaned up a UX issue with the zone records list editor view.

This commit is contained in:
Matt Scott 2023-02-20 15:50:03 -05:00
parent 3ee63aca8c
commit 4d0cf87338

View File

@ -1,24 +1,17 @@
{% extends "base.html" %} {% extends "base.html" %}
{% block title %}<title>Zone Records - {{ domain.name | pretty_domain_name }} - {{ SITE_NAME }}</title>{% endblock %}
{% block title %}
<title>
{{ domain.name | pretty_domain_name }} - {{ SITE_NAME }}
</title>
{% endblock %}
{% block dashboard_stat %} {% block dashboard_stat %}
<div class="content-header"> <div class="content-header">
<div class="container-fluid"> <div class="container-fluid">
<div class="row mb-2"> <div class="row mb-2">
<div class="col-sm-6"> <div class="col-sm-6">
<h1 class="m-0 text-dark"> <h1 class="m-0 text-dark">Zone Records - {{ domain.name | pretty_domain_name }}</h1>
Domain: <b>{{ domain.name | pretty_domain_name }}</b>
</h1>
</div> </div>
<div class="col-sm-6"> <div class="col-sm-6">
<ol class="breadcrumb float-sm-right"> <ol class="breadcrumb float-sm-right">
<li class="breadcrumb-item"><a href="{{ url_for('dashboard.dashboard') }}">Dashboard</a></li> <li class="breadcrumb-item"><a href="{{ url_for('dashboard.dashboard') }}">Dashboard</a></li>
<li class="breadcrumb-item active">Domain: {{ domain.name | pretty_domain_name }}</li> <li class="breadcrumb-item active">Zone Records - {{ domain.name | pretty_domain_name }}</li>
</ol> </ol>
</div> </div>
</div> </div>
@ -27,42 +20,54 @@
{% endblock %} {% endblock %}
{% block content %} {% block content %}
<section class="content"> <section class="content">
<div class="container-fluid"> <div class="container-fluid">
<div class="row"> <div class="row">
<div class="col-12"> <div class="col-12">
<div class="card"> <div class="card">
<div class="card-header"> <div class="card-header">
{% if domain.type != 'Slave' %} <h3 class="card-title">Zone Editor</h3>
<button type="button" style="position: relative; margin-left: 20px" class="btn btn-primary float-left button_add_record" id="{{ domain.name }}"> <div class="card-tools">
<i class="fa-solid fa-plus"></i>
&nbsp;Add Record
</button>
<button type="button" style="position: relative; margin-left: 20px" class="btn btn-primary float-right button_apply_changes" id="{{ domain.name }}" value="{{ domain.serial }}">
<i class="fa-solid fa-save"></i>
&nbsp;Apply Changes
</button>
{% else %}
<button type="button" style="position: relative; margin-left: 20px" class="btn btn-primary float-left button_update_from_primary" id="{{ domain.name }}">
<i class="fa-solid fa-sync"></i>
&nbsp;Update from Primary
</button>
{% endif %}
{% if current_user.role.name in ['Administrator', 'Operator'] %} {% if current_user.role.name in ['Administrator', 'Operator'] %}
<button type="button" style="position: relative; margin-left: 20px" class="btn btn-primary float-left btn-danger" onclick="window.location.href='{{ url_for('domain.setting', domain_name=domain.name) }}'"> <button type="button" title="Zone Settings"
class="btn btn-primary btn-danger"
onclick="window.location.href='{{ url_for('domain.setting', domain_name=domain.name) }}'">
<i class="fa-solid fa-toolbox"></i> <i class="fa-solid fa-toolbox"></i>
&nbsp;Admin &nbsp;Zone Settings
</button> </button>
{% endif %} {% endif %}
{% if current_user.role.name in ['Administrator', 'Operator'] or SETTING.get('allow_user_view_history') %} {% if current_user.role.name in ['Administrator', 'Operator'] or SETTING.get('allow_user_view_history') %}
<button type="button" style="position: relative; margin-left: 20px" class="btn btn-primary button_changelog" id="{{ domain.name }}"> <button type="button" title="Zone Changelog"
class="btn btn-primary ml-2 button_changelog" id="{{ domain.name }}">
<i class="fa-solid fa-history" aria-hidden="true"></i> <i class="fa-solid fa-history" aria-hidden="true"></i>
&nbsp;Changelog &nbsp;Changelog
</button> </button>
{% endif %} {% endif %}
{% if domain.type != 'Slave' %}
<button type="button" title="Add Record"
class="btn btn-primary ml-2 button_add_record" id="{{ domain.name }}">
<i class="fa-solid fa-plus"></i>
&nbsp;Add Record
</button>
<button type="button" title="Save Changes"
class="btn btn-primary ml-2 button_apply_changes"
id="{{ domain.name }}"
value="{{ domain.serial }}">
<i class="fa-solid fa-save"></i>
&nbsp;Save Changes
</button>
{% else %}
<button type="button" title="Update from Primary"
class="btn btn-primary ml-2 button_update_from_primary"
id="{{ domain.name }}">
<i class="fa-solid fa-sync"></i>
&nbsp;Update from Primary
</button>
{% endif %}
</div> </div>
<div class="card-body"> </div>
<table id="tbl_records" class="table table-bordered table-striped"> <div class="card-body table-responsive">
<table id="tbl_records" class="table table-bordered table-striped table-hover table-sm">
<thead> <thead>
<tr> <tr>
<th>Name</th> <th>Name</th>
@ -75,7 +80,7 @@
<th>Edit</th> <th>Edit</th>
<th>Delete</th> <th>Delete</th>
{% if current_user.role.name in ['Administrator', 'Operator'] or SETTING.get('allow_user_view_history') %} {% if current_user.role.name in ['Administrator', 'Operator'] or SETTING.get('allow_user_view_history') %}
<th >Changelog</th> <th>Changelog</th>
{% endif %} {% endif %}
{% else %} {% else %}
<th>Invisible Sorting Column</th> <th>Invisible Sorting Column</th>
@ -90,29 +95,31 @@
<td>{{ record.status }}</td> <td>{{ record.status }}</td>
<td>{{ record.ttl }}</td> <td>{{ record.ttl }}</td>
<td>{{ record.data | pretty_domain_name }}</td> <td>{{ record.data | pretty_domain_name }}</td>
{% if domain.type != 'Secondary' %} {% if domain.type != 'Slave' %}
<td>{{ record.comment }}</td> <td>{{ record.comment }}</td>
<td width="6%"> <td>
{% if record.is_allowed_edit() %} {% if record.is_allowed_edit() %}
<button type="button" class="btn btn-warning button_edit"> <button type="button" class="btn btn-sm btn-warning button_edit">
<i class="fa-solid fa-edit"></i> <i class="fa-solid fa-edit"></i>
</button> </button>
{% else %} {% else %}
<button type="button" class="btn btn-warning"> <button type="button" class="btn btn-sm btn-warning">
<i class="fa-solid fa-exclamation-circle"></i> <i class="fa-solid fa-exclamation-circle"></i>
</button> </button>
{% endif %} {% endif %}
</td> </td>
<td width="6%"> <td>
{% if record.is_allowed_delete() %} {% if record.is_allowed_delete() %}
<button type="button" class="btn btn-danger button_delete"> <button type="button" class="btn btn-sm btn-danger button_delete">
<i class="fa-solid fa-trash"></i> <i class="fa-solid fa-trash"></i>
</button> </button>
{% endif %} {% endif %}
</td> </td>
{% if current_user.role.name in ['Administrator', 'Operator'] or SETTING.get('allow_user_view_history') %} {% if current_user.role.name in ['Administrator', 'Operator'] or SETTING.get('allow_user_view_history') %}
<td width="6%"> <td>
<button type="button" onclick="show_record_changelog('{{record.name}}','{{record.type}}',event)" class="btn btn-primary"> <button type="button"
onclick="show_record_changelog('{{ record.name }}','{{ record.type }}',event)"
class="btn btn-primary">
<i class="fa-solid fa-history" aria-hidden="true"></i> <i class="fa-solid fa-history" aria-hidden="true"></i>
</button> </button>
</td> </td>
@ -129,11 +136,24 @@
</div> </div>
</div> </div>
</div> </div>
</section> </section>
{% endblock %}
{% block head_styles %}
<style>
/* Page Specific Overrides */
table#tbl_records thead th:nth-child(1),
table#tbl_records thead th:nth-child(2),
table#tbl_records thead th:nth-child(3),
table#tbl_records thead th:nth-child(4) { width: 100px; }
table#tbl_records tbody td { text-align: center; }
table#tbl_records tbody td:nth-child(0n+5),
table#tbl_records tbody td:nth-child(0n+6) { text-align: left; }
</style>
{% endblock %} {% endblock %}
{% block extrascripts %} {% block extrascripts %}
<script> <script>
// superglobals // superglobals
window.records_allow_edit = {{ editable_records | tojson }}; window.records_allow_edit = {{ editable_records | tojson }};
window.ttl_options = {{ ttl_options | tojson }}; window.ttl_options = {{ ttl_options | tojson }};
@ -142,24 +162,24 @@
// set up user data table // set up user data table
$("#tbl_records").DataTable({ $("#tbl_records").DataTable({
"paging" : true, "paging": true,
"lengthChange" : true, "lengthChange": true,
"searching" : true, "searching": true,
"ordering" : true, "ordering": true,
"info" : true, "info": true,
"autoWidth" : false, "autoWidth": false,
{% if SETTING.get('default_record_table_size') | string in ['5','15','20'] %} {% if SETTING.get('default_record_table_size') | string in ['5','15','20'] %}
"lengthMenu": [ [5, 15, 20, -1], "lengthMenu": [[5, 15, 20, -1],
[5, 15, 20, "All"]], [5, 15, 20, "All"]],
{% else %} {% else %}
"lengthMenu": [ [5, 15, 20, {{ SETTING.get('default_record_table_size') }}, -1], "lengthMenu": [[5, 15, 20, {{ SETTING.get('default_record_table_size') }}, -1],
[5, 15, 20, {{ SETTING.get('default_record_table_size') }}, "All"]], [5, 15, 20, {{ SETTING.get('default_record_table_size') }}, "All"]],
{% endif %} {% endif %}
"pageLength": {{ SETTING.get('default_record_table_size') }}, "pageLength": {{ SETTING.get('default_record_table_size') }},
"language": { "language": {
"lengthMenu": " _MENU_ records" "lengthMenu": " _MENU_ records"
}, },
"retrieve" : true, "retrieve": true,
"columnDefs": [ "columnDefs": [
{ {
type: 'natural', type: 'natural',
@ -175,17 +195,13 @@
visible: false, visible: false,
{% if domain.type != 'Slave' %} {% if domain.type != 'Slave' %}
{% if current_user.role.name in ['Administrator', 'Operator'] or SETTING.get('allow_user_view_history') %} {% if current_user.role.name in ['Administrator', 'Operator'] or SETTING.get('allow_user_view_history') %}
targets: [ 9 ] targets: [9]
{% else %} {% else %}
targets: [ 8 ] targets: [8]
{% endif %} {% endif %}
{% else %} {% else %}
targets: [ 5 ] targets: [5]
{% endif %} {% endif %}
},
{
className: "length-break",
targets: [ 4, 5 ]
} }
], ],
{% if domain.type != 'Slave' %} {% if domain.type != 'Slave' %}
@ -204,14 +220,15 @@
e.stopPropagation(); e.stopPropagation();
window.location.href = "/domain/{{domain.name}}/changelog/" + record_name + "./" + record_type; window.location.href = "/domain/{{domain.name}}/changelog/" + record_name + "./" + record_type;
} }
// handle changelog button // handle changelog button
$(document.body).on("click", ".button_changelog", function(e) { $(document.body).on("click", ".button_changelog", function (e) {
e.stopPropagation(); e.stopPropagation();
window.location.href = "/domain/{{domain.name}}/changelog"; window.location.href = "/domain/{{domain.name}}/changelog";
}); });
// handle delete button // handle delete button
$(document.body).on("click", ".button_delete", function(e) { $(document.body).on("click", ".button_delete", function (e) {
e.stopPropagation(); e.stopPropagation();
var modal = $("#modal_delete"); var modal = $("#modal_delete");
var table = $("#tbl_records").DataTable(); var table = $("#tbl_records").DataTable();
@ -221,18 +238,18 @@
modal.find('.modal-body p').text(info); modal.find('.modal-body p').text(info);
modal.modal('show'); modal.modal('show');
$("#button_delete_confirm").unbind().one('click', function(e) { $("#button_delete_confirm").unbind().one('click', function (e) {
table.row(nRow).remove().draw(); table.row(nRow).remove().draw();
modal.modal('hide'); modal.modal('hide');
}); });
$("#button_delete_cancel").unbind().one('click', function(e) { $("#button_delete_cancel").unbind().one('click', function (e) {
modal.modal('hide'); modal.modal('hide');
}); });
}); });
// handle edit button and record click // handle edit button and record click
{% if domain.type != 'Slave' %} {% if domain.type != 'Slave' %}
$(document.body).on("click", ".button_edit{% if quick_edit %}, .row_record{% endif %}", function(e) { $(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];
@ -263,7 +280,7 @@
{% endif %} {% endif %}
// handle apply changes button // handle apply changes button
$(document.body).on("click",".button_apply_changes", function() { $(document.body).on("click", ".button_apply_changes", function () {
if (nNew || nEditing) { if (nNew || nEditing) {
showErrorModal("Previous record not saved. Please save it before applying the changes."); showErrorModal("Previous record not saved. Please save it before applying the changes.");
return; return;
@ -277,7 +294,7 @@
modal.find('.modal-body p').text(info); modal.find('.modal-body p').text(info);
// following unbind("click") is to avoid multiple times execution // following unbind("click") is to avoid multiple times execution
modal.find('#button_apply_confirm').unbind("click").click(function() { modal.find('#button_apply_confirm').unbind("click").click(function () {
var data = {'serial': serial, 'record': getTableData(table), '_csrf_token': '{{ csrf_token() }}'}; var data = {'serial': serial, 'record': getTableData(table), '_csrf_token': '{{ csrf_token() }}'};
applyRecordChanges(data, domain); applyRecordChanges(data, domain);
modal.modal('hide'); modal.modal('hide');
@ -334,7 +351,10 @@
//handle update_from_primary button //handle update_from_primary button
$(document.body).on("click", ".button_update_from_primary", function (e) { $(document.body).on("click", ".button_update_from_primary", function (e) {
var domain = $(this).prop('id'); var domain = $(this).prop('id');
applyChanges({'domain': domain, '_csrf_token': '{{ csrf_token() }}'}, $SCRIPT_ROOT + '/domain/' + domain + '/update', true); applyChanges({
'domain': domain,
'_csrf_token': '{{ csrf_token() }}'
}, $SCRIPT_ROOT + '/domain/' + domain + '/update', true);
}); });
{% if SETTING.get('record_helper') %} {% if SETTING.get('record_helper') %}
@ -363,7 +383,7 @@
"; ";
} }
modal.find('.modal-body p').html(form); modal.find('.modal-body p').html(form);
modal.find('#button_save').click(function() { modal.find('#button_save').click(function () {
caa_flag = modal.find('#caa_flag').val(); caa_flag = modal.find('#caa_flag').val();
caa_tag = modal.find('#caa_tag').val(); caa_tag = modal.find('#caa_tag').val();
caa_value = modal.find('#caa_value').val(); caa_value = modal.find('#caa_value').val();
@ -389,7 +409,7 @@
"; ";
} }
modal.find('.modal-body p').html(form); modal.find('.modal-body p').html(form);
modal.find('#button_save').click(function() { modal.find('#button_save').click(function () {
mx_server = modal.find('#mx_server').val(); mx_server = modal.find('#mx_server').val();
mx_priority = modal.find('#mx_priority').val(); mx_priority = modal.find('#mx_priority').val();
data = mx_priority + " " + mx_server; data = mx_priority + " " + mx_server;
@ -425,7 +445,7 @@
"; ";
} }
modal.find('.modal-body p').html(form); modal.find('.modal-body p').html(form);
modal.find('#button_save').click(function() { modal.find('#button_save').click(function () {
srv_priority = modal.find('#srv_priority').val(); srv_priority = modal.find('#srv_priority').val();
srv_weight = modal.find('#srv_weight').val(); srv_weight = modal.find('#srv_weight').val();
srv_port = modal.find('#srv_port').val(); srv_port = modal.find('#srv_port').val();
@ -475,7 +495,7 @@
"; ";
} }
modal.find('.modal-body p').html(form); modal.find('.modal-body p').html(form);
modal.find('#button_save').click(function() { modal.find('#button_save').click(function () {
soa_primaryns = modal.find('#soa_primaryns').val(); soa_primaryns = modal.find('#soa_primaryns').val();
soa_adminemail = modal.find('#soa_adminemail').val(); soa_adminemail = modal.find('#soa_adminemail').val();
soa_serial = modal.find('#soa_serial').val(); soa_serial = modal.find('#soa_serial').val();
@ -514,7 +534,7 @@
"; ";
} }
modal.find('.modal-body p').html(form); modal.find('.modal-body p').html(form);
modal.find('#button_save').click(function() { modal.find('#button_save').click(function () {
tlsa_certificate_usage = modal.find('#tlsa_certificate_usage').val(); tlsa_certificate_usage = modal.find('#tlsa_certificate_usage').val();
tlsa_selector = modal.find('#tlsa_selector').val(); tlsa_selector = modal.find('#tlsa_selector').val();
tlsa_matching = modal.find('#tlsa_matching').val(); tlsa_matching = modal.find('#tlsa_matching').val();
@ -532,9 +552,9 @@
<textarea style=\"min-width: 100%;color: #333;\" placeholder=\"Your TXT record data\" rows=\"5\" id=\"txt_record\" name=\"txt_record\">" + txt_data + "</textarea> \ <textarea style=\"min-width: 100%;color: #333;\" placeholder=\"Your TXT record data\" rows=\"5\" id=\"txt_record\" name=\"txt_record\">" + txt_data + "</textarea> \
"; ";
modal.find('.modal-body p').html(form); modal.find('.modal-body p').html(form);
modal.find('#button_save').click(function() { modal.find('#button_save').click(function () {
data = modal.find('#txt_record').val(); data = modal.find('#txt_record').val();
if (! /^".*"$/.test(data)) { if (!/^".*"$/.test(data)) {
data = '"' + data + '"'; data = '"' + data + '"';
} }
record_data.val(data); record_data.val(data);
@ -551,10 +571,10 @@
<textarea style=\"min-width: 100%;color: #333;\" placeholder=\"Your LUA snippet\" rows=\"5\" id=\"lua_record\" name=\"lua_record\">" + lua_data + "</textarea> \ <textarea style=\"min-width: 100%;color: #333;\" placeholder=\"Your LUA snippet\" rows=\"5\" id=\"lua_record\" name=\"lua_record\">" + lua_data + "</textarea> \
"; ";
modal.find('.modal-body p').html(form); modal.find('.modal-body p').html(form);
modal.find('#button_save').click(function() { modal.find('#button_save').click(function () {
type = modal.find('#lua_type').val(); type = modal.find('#lua_type').val();
data = modal.find('#lua_record').val(); data = modal.find('#lua_record').val();
if (! /^".*"$/.test(data)) { if (!/^".*"$/.test(data)) {
data = '"' + data + '"'; data = '"' + data + '"';
} }
data = type + ' ' + data; data = type + ' ' + data;
@ -566,11 +586,11 @@
}); });
{% endif %} {% endif %}
window.onload = function() { window.onload = function () {
document.getElementById("loading-spinner").style.display = "none"; document.getElementById("loading-spinner").style.display = "none";
} }
</script> </script>
{% endblock %} {% endblock %}
{% block modals %} {% block modals %}
@ -587,7 +607,8 @@
<p></p> <p></p>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button type="button" class="btn btn-secondary pull-left" id="button_delete_cancel" data-dismiss="modal"> <button type="button" class="btn btn-secondary pull-left" id="button_delete_cancel"
data-dismiss="modal">
<i class="fa-solid fa-window-close"></i>&nbsp;Close <i class="fa-solid fa-window-close"></i>&nbsp;Close
</button> </button>
<button type="button" class="btn btn-danger" id="button_delete_confirm"> <button type="button" class="btn btn-danger" id="button_delete_confirm">