Converted record management page to new template.

This commit is contained in:
Ivan Filippov 2016-04-26 20:44:22 -06:00
parent 4164f34fa4
commit 887263342f
2 changed files with 293 additions and 147 deletions

View File

@ -43,3 +43,74 @@ function getTableData(table) {
});
return records
}
function saveRow(oTable, nRow) {
var jqInputs = $(oTable.row(nRow).node()).find("input");
var jqSelect = $(oTable.row(nRow).node()).find("select");
if (jqSelect[1].value == 'false') {
status = 'Active';
} else {
status = 'Disabled';
}
oTable.cell(nRow,0).data(jqInputs[0].value);
oTable.cell(nRow,1).data(jqSelect[0].value);
oTable.cell(nRow,2).data(status);
oTable.cell(nRow,3).data(jqSelect[2].value);
oTable.cell(nRow,4).data(jqInputs[1].value);
var record = jqInputs[0].value;
var button_edit = "<button type=\"button\" class=\"btn btn-flat btn-warning button_edit\" id=\"" + record + "\">Edit&nbsp;<i class=\"fa fa-edit\"></i></button>"
var button_delete = "<button type=\"button\" class=\"btn btn-flat btn-danger button_edit\" id=\"" + record + "\">Delete&nbsp;<i class=\"fa fa-trash\"></i></button>"
oTable.cell(nRow,5).data(button_edit);
oTable.cell(nRow,6).data(button_delete);
oTable.draw();
}
function restoreRow(oTable, nRow) {
var aData = oTable.row(nRow).data();
var jqTds = $('>td', nRow);
oTable.row(nRow).data(aData);
oTable.draw();
}
function editRow(oTable, nRow) {
var aData = oTable.row(nRow).data();
var jqTds = oTable.cells(nRow,'').nodes();
var record_types = "";
for(var i = 0; i < records_allow_edit.length; i++) {
var record_type = records_allow_edit[i];
record_types += "<option value=\"" + record_type + "\">" + record_type + "</option>";
}
jqTds[0].innerHTML = '<input type="text" class="form-control input-small" value="' + aData[0] + '">';
//jqTds[1].innerHTML = '<select class="form-control" id="record_type" name="record_type" value="' + aData[1] + '"' + '><option value="A">A</option><option value="AAAA">AAAA</option><option value="NS">NS</option><option value="CNAME">CNAME</option><option value="DNAME">DNAME</option><option value="MR">MR</option><option value="PTR">PTR</option><option value="HINFO">HINFO</option><option value="MX">MX</option><option value="TXT">TXT</option><option value="RP">RP</option><option value="AFSDB">AFSDB</option><option value="SIG">SIG</option><option value="KEY">KEY</option><option value="LOC">LOC</option><option value="SRV">SRV</option><option value="CERT">CERT</option><option value="NAPTR">NAPTR</option><option value="DS">DS</option><option value="SSHFP">SSHFP</option><option value="RRSIG">RRSIG</option><option value="NSEC">NSEC</option><option value="DNSKEY">DNSKEY</option><option value="NSEC3">DSEC3</option><option value="NSEC3PARAM">NSEC3PARAM</option><option value="TLSA">TLSA</option><option value="SPF">SPF</option><option value="DL">DL</option><option value="SOA">SOA</option></select>';
jqTds[1].innerHTML = '<select class="form-control" id="record_type" name="record_type" value="' + aData[1] + '"' + '>' + record_types + '</select>';
jqTds[2].innerHTML = '<select class="form-control" id="record_status" name="record_status" value="' + aData[2] + '"' + '><option value="false">Active</option><option value="true">Disabled</option></select>';
jqTds[3].innerHTML = '<select class="form-control" id="record_ttl" name="record_ttl" value="' + aData[3] + '"' + '><option value="60">1 minute</option><option value="300">5 minutes</option><option value="1800">30 minutes</option><option value="3600">60 minutes</option><option value="86400">24 hours</option></select>';
jqTds[4].innerHTML = '<input type="text" style="display:table-cell; width:100% !important" class="form-control input-small advance-data" value="' + aData[4].replace(/\"/g,"&quot;") + '">';
jqTds[5].innerHTML = '<button type="button" class="btn btn-flat btn-primary button_save">Save</button>';
jqTds[6].innerHTML = '<button type="button" class="btn btn-flat btn-primary button_cancel">Cancel</button>';
// set current value of dropdows column
if (aData[2] == 'Active'){
isDisabled = 'false';
}
else {
isDisabled = 'true';
}
SelectElement('record_type', aData[1]);
SelectElement('record_status', isDisabled);
SelectElement('record_ttl', aData[3]);
}
function SelectElement(elementID, valueToSelect)
{
var element = document.getElementById(elementID);
element.value = valueToSelect;
}

View File

@ -1,126 +1,52 @@
{% extends "base.html" %}
{% block head %}
{{ super() }}
<!-- BEGIN PAGE LEVEL PLUGIN STYLES -->
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='global/plugins/select2/select2.css') }}"/>
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='global/plugins/datatables/plugins/bootstrap/dataTables.bootstrap.css') }}"/>
<!-- END PAGE LEVEL PLUGIN STYLES -->
<!-- BEGIN THEME STYLES -->
<!-- DOC: To use 'rounded corners' style just load 'components-rounded.css' stylesheet instead of 'components.css' in the below style tag -->
<link href="{{ url_for('static', filename='global/css/components-md.css') }}" id="style_components" rel="stylesheet" type="text/css"/>
<link href="{{ url_for('static', filename='global/css/plugins-md.css') }}" rel="stylesheet" type="text/css"/>
<link href="{{ url_for('static', filename='admin/layout2/css/layout.css') }}" rel="stylesheet" type="text/css"/>
<link href="{{ url_for('static', filename='admin/layout2/css/themes/grey.css') }}" rel="stylesheet" type="text/css" id="style_color"/>
<link href="{{ url_for('static', filename='admin/layout2/css/custom.css') }}" rel="stylesheet" type="text/css"/>
<!-- END THEME STYLES -->
{% endblock %}
{% block title %}<title>DNS Control Panel - DOMAIN</title>{% endblock %}
{% block dashboard_stat %}
<!-- BEGIN PAGE HEADER-->
<h3 class="page-title">
Domain</h3>
<div class="page-bar">
<ul class="page-breadcrumb">
<li>
<i class="fa fa-home"></i>
<a href="{{ url_for('dashboard') }}">Home</a>
<i class="fa fa-angle-right"></i>
</li>
<li>
<a href="{{ url_for('dashboard') }}">Domain</a>
<i class="fa fa-angle-right"></i>
</li>
<li>
<a href="">{{ domain.name }}</a>
</li>
</ul>
</div>
<!-- END PAGE HEADER-->
<section class="content-header">
<h1>
Manage domain <small>{{ domain.name }}</small>
</h1>
<ol class="breadcrumb">
<li><a href="{{ url_for('dashboard') }}"><i
class="fa fa-dashboard"></i> Home</a></li>
<li>Domain</li>
<li class="active">{{ domain.name }}</li>
</ol>
</section>
{% endblock %}
{% block content %}
<div class="clearfix">
</div>
<section class="content">
<div class="row">
<div class="col-md-12">
<!-- BEGIN RECORD TABLE-->
<div class="portlet box blue">
<div class="portlet-title">
<div class="caption">
<i class="fa fa-globe"></i> {{ domain.name }}
<input type="hidden" id="domainname" value="{{ domain.name }}">
<div class="col-xs-12">
<div class="box">
<div class="box-header">
<h3 class="box-title">Manage Records for {{ domain.name }}</h3>
</div>
<div class="tools">
<a href="javascript:;" class="collapse">
</a>
<a href="javascript:;" class="reload">
</a>
</div>
</div>
<div class="portlet-body">
{% if domain.type != 'Slave' %}
<div class="table-toolbar">
<div class="row">
<div class="col-md-6">
<div class="btn-group">
<button id="tbl_record_manage_new" class="btn green">
Add Record <i class="fa fa-plus"></i>
<div class="box-body">
<button type="button" class="btn btn-flat btn-primary pull-left button_add_record" id="{{ domain.name }}">
Add Record&nbsp;<i class="fa fa-plus"></i>
</button>
<button type="button" class="btn btn-flat btn-primary pull-right button_apply_changes" id="{{ domain.name }}">
Apply Changes&nbsp;<i class="fa fa-floppy-o"></i>
</button>
</div>
</div>
<div class="col-md-6">
<div class="btn-group pull-right">
<button id="tbl_record_manage_apply" class="btn green">
<i class="fa fa-save"></i>Apply Changes
</button>
</div>
</div>
</div>
</div>
{% else %}
<div class="table-toolbar">
<div class="row">
<div class="col-md-6">
<div class="btn-group">
<button id="tbl_record_update_from_master" class="btn green">
Update from Master <i class="fa fa-download"></i>
</button>
</div>
</div>
</div>
</div>
{% endif %}
<table class="table table-striped table-hover table-bordered" id="tbl_record_manage">
<div class="box-body">
<table id="tbl_records" class="table table-bordered table-striped">
<thead>
<tr>
<th>
Name
</th>
<th>
Type
</th>
<th>
Status
</th>
<th>
TTL
</th>
<th>
Data
</th>
<th>
Edit
</th>
<th>
Delete
</th>
<th>Name</th>
<th>Type</th>
<th>Status</th>
<th>TTL</th>
<th>Data</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
{% for record in records %}
<tr class="odd gradeX">
<tr class="odd">
<td>
{{ (record.name,domain.name)|display_record_name }}
</td>
@ -139,18 +65,25 @@
{% if domain.type != 'Slave' %}
<td width="6%">
{% if record.is_allowed() %}
<a class="btn default btn-xs purple edit" href="javascript:;"> <i class="fa fa-edit"></i></a>
<button type="button" class="btn btn-flat btn-warning button_edit" id="{{ (record.name,domain.name)|display_record_name }}">
Edit&nbsp;<i class="fa fa-edit"></i>
</button>
{% else %}
<!-- TODO: replace this link for slave records -->
<a href="#" class="btn default btn-xs purple"> <i class="fa fa-exclamation-circle"></i></a>
{% endif %}
</td>
<td width="6%">
{% if record.is_allowed() %}
<a class="btn default btn-xs red delete" href="javascript:;"> <i class="fa fa-trash"></i></a>
<button type="button" class="btn btn-flat btn-danger button_delete" id="{{ (record.name,domain.name)|display_record_name }}">
Delete&nbsp;<i class="fa fa-trash"></i>
</button>
{% else %}
<!-- TODO: replace this link for slave records -->
<a href="#" class="btn default btn-xs red"> <i class="fa fa-exclamation-circle"></i></a>
{% endif %}
{% else %}
<!-- TODO: replace these links for slave records -->
<td width="6%">
<a href="#" class="btn default btn-xs purple"> <i class="fa fa-exclamation-circle"></i></a>
</td>
@ -164,33 +97,175 @@
</tbody>
</table>
</div>
<!-- /.box-body -->
</div>
<!-- END RECORD TABLE-->
<!-- /.box -->
</div>
<!-- /.col -->
</div>
<!-- /.row -->
</section>
{% endblock %}
{% block scripts %}
{{ super() }}
<!-- BEGIN PAGE LEVEL SCRIPTS -->
<script src="{{ url_for('static', filename='global/scripts/metronic.js') }}" type="text/javascript"></script>
<script src="{{ url_for('static', filename='admin/layout2/scripts/layout.js') }}" type="text/javascript"></script>
<script src="{{ url_for('static', filename='global/plugins/bootbox/bootbox.min.js') }}" type="text/javascript"></script>
<!-- END PAGE LEVEL SCRIPTS -->
<!-- TABLE PLUGINS -->
<script type="text/javascript" src="{{ url_for('static', filename='global/plugins/select2/select2.min.js') }}"></script>
<script type="text/javascript" src="{{ url_for('static', filename='global/plugins/datatables/media/js/jquery.dataTables.min.js') }}"></script>
<script type="text/javascript" src="{{ url_for('static', filename='global/plugins/datatables/plugins/bootstrap/dataTables.bootstrap.js') }}"></script>
<script src="{{ url_for('static', filename='admin/pages/scripts/table-editable.js') }}"></script>
<!-- END TABLE PLUGINS -->
{% block extrascripts %}
<script>
jQuery(document).ready(function() {
// superglobals
window.records_allow_edit = {{ editable_records|tojson }};
Metronic.init(); // init metronic core componets
Layout.init(); // init layout
TableEditable.init();
});
window.nEditing = null;
window.nNew = false;
// set up user data table
$("#tbl_records").DataTable({
"paging" : true,
"lengthChange" : true,
"searching" : true,
"ordering" : true,
"info" : true,
"autoWidth" : false,
"lengthMenu": [ [5, 15, 20, -1],
[5, 15, 20, "All"]],
"pageLength": 15,
"language": {
"lengthMenu": " _MENU_ records"
},
"retrieve" : true
});
// handle delete button
$(document).on("click", ".button_delete", function() {
var modal = $("#modal_delete");
var table = $("#tbl_records").DataTable();
var record = $(this).prop('id');
var info = "Are you sure you want to delete " + record + "?";
modal.find('.modal-body p').text(info);
modal.find('#button_delete_confirm').click(function() {
table.row($(this).parents('tr')[0]).remove().draw();
modal.modal('hide');
})
modal.modal('show');
});
// handle edit button
$(document).on("click", ".button_edit", function() {
var nRow = $(this).parents('tr')[0];
var table = $("#tbl_records").DataTable();
if (nEditing !== null && nEditing != nRow && nNew == false) {
/* Currently editing - but not this row - restore the old before continuing to edit mode */
restoreRow(table, nEditing);
editRow(table, nRow);
nEditing = nRow;
} else if (nNew == true) {
/* adding a new row, delete it and start editing */
table.row(nEditing).remove().draw();
nNew = false;
editRow(table, nRow);
nEditing = nRow;
} else {
/* No edit in progress - let's start one */
editRow(table, nRow);
nEditing = nRow;
}
});
// handle apply changes button
$(document).on("click",".button_apply_changes", function() {
var modal = $("#modal_apply_changes");
var table = $("#tbl_records").DataTable();
var domain = $(this).prop('id');
var info = "Are you sure you want to apply your changes?";
modal.find('.modal-body p').text(info);
modal.find('#button_apply_confirm').click(function() {
var data = getTableData(table);
applyChanges(data, '/domain/' + domain + '/apply', true);
modal.modal('hide');
})
modal.modal('show');
});
// handle add record button
$(document).on("click", ".button_add_record", function (e) {
if (nNew || nEditing) {
// TODO: replace this alert with modal
alert("Previous record not saved. Please save it before adding more record.")
return;
}
var table = $("#tbl_records").DataTable();
var aiNew = table.row.add(['', 'A', 'Active', 3600, '', '', '']).draw();
var nRow = aiNew.index();
editRow(table, nRow);
nEditing = nRow;
nNew = true;
});
//handle cancel button
$(document).on("click", ".button_cancel", function (e) {
var oTable = $("#tbl_records").DataTable();
if (nNew) {
oTable.row(nEditing).remove().draw();
nEditing = null;
nNew = false;
} else {
restoreRow(oTable, nEditing);
nEditing = null;
}
});
//handle save button
$(document).on("click", ".button_save", function (e) {
var table = $("#tbl_records").DataTable();
saveRow(table, nEditing);
nEditing = null;
});
</script>
<!-- END JAVASCRIPTS -->
{% endblock %}
{% block modals %}
<div class="modal fade modal-warning" id="modal_delete">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"
aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
<h4 class="modal-title">Confirmation</h4>
</div>
<div class="modal-body">
<p></p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default pull-left"
data-dismiss="modal">Close</button>
<button type="button" class="btn btn-danger" id="button_delete_confirm">Delete</button>
</div>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div>
<div class="modal fade modal-primary" id="modal_apply_changes">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"
aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
<h4 class="modal-title">Confirmation</h4>
</div>
<div class="modal-body">
<p></p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-flat btn-default pull-left"
data-dismiss="modal">Close</button>
<button type="button" class="btn btn-flat btn-primary" id="button_apply_confirm">Apply</button>
</div>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div>
{% endblock %}