2016-01-18 20:45:07 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2016 Lukas Metzger <developer@lukas-metzger.com>.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2016-01-20 19:46:14 +00:00
|
|
|
var sort = {
|
|
|
|
field: "",
|
|
|
|
order: 1
|
|
|
|
}
|
|
|
|
|
2016-01-18 20:45:07 +00:00
|
|
|
$(document).ready(function() {
|
|
|
|
|
|
|
|
$('#soa button[type=submit]').click(function(){
|
|
|
|
if(validateSoaData()) {
|
2016-01-20 20:48:17 +00:00
|
|
|
saveSoaData();
|
|
|
|
$('#soa button[type=submit]').prop("disabled", true);
|
2016-01-18 20:45:07 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-01-20 20:48:17 +00:00
|
|
|
$('#soa input').bind("paste keyup change", function() {
|
|
|
|
$('#soa button[type=submit]').prop("disabled", false);
|
|
|
|
});
|
|
|
|
|
2016-01-18 20:45:07 +00:00
|
|
|
$('#soa form input').bind("paste keyup change", function() {
|
|
|
|
var regex = new RegExp($(this).attr('data-regex'));
|
|
|
|
if(!regex.test($(this).val()) && $(this).val().length > 0) {
|
|
|
|
$(this).parent().addClass("has-error");
|
|
|
|
} else {
|
|
|
|
$(this).parent().removeClass("has-error");
|
|
|
|
}
|
|
|
|
});
|
2016-01-20 19:46:14 +00:00
|
|
|
|
|
|
|
$('#searchType').select2({
|
|
|
|
placeholder: "Filter..."
|
|
|
|
});
|
2016-01-18 20:45:07 +00:00
|
|
|
|
2016-01-20 19:46:14 +00:00
|
|
|
$('#table-records>thead>tr>td span.glyphicon').click(function() {
|
|
|
|
var field = $(this).siblings('strong').text().toLowerCase();
|
|
|
|
if(sort.field == field) {
|
|
|
|
if(sort.order == 1) sort.order = 0;
|
|
|
|
else sort.field = "";
|
|
|
|
} else {
|
|
|
|
sort.field = field;
|
|
|
|
sort.order = 1;
|
|
|
|
}
|
|
|
|
$('#table-records>thead>tr>td span').removeClass("glyphicon-sort-by-attributes glyphicon-sort-by-attributes-alt");
|
|
|
|
|
|
|
|
if(sort.field == field) {
|
|
|
|
if(sort.order == 1) $(this).addClass("glyphicon-sort-by-attributes");
|
|
|
|
else $(this).addClass("glyphicon-sort-by-attributes-alt");
|
|
|
|
}
|
|
|
|
requestRecordData();
|
|
|
|
});
|
2016-01-18 20:45:07 +00:00
|
|
|
|
2016-01-20 19:46:14 +00:00
|
|
|
$('#searchName, #searchContent').bind("paste keyup", function() {
|
|
|
|
requestRecordData();
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#searchType').change(function() {
|
|
|
|
requestRecordData();
|
|
|
|
});
|
|
|
|
|
|
|
|
requestRecordData();
|
2016-01-20 20:48:17 +00:00
|
|
|
requestSoaData();
|
2016-01-20 19:46:14 +00:00
|
|
|
|
2016-01-18 20:45:07 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
function validateSoaData() {
|
|
|
|
|
|
|
|
var error = 0;
|
|
|
|
|
|
|
|
$('#soa form input:not(#soa-serial)').each(function() {
|
|
|
|
if($(this).val().length <= 0 || $(this).parent().hasClass('has-error')) {
|
|
|
|
error++;
|
|
|
|
$(this).parent().addClass('has-error');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return error<=0;
|
|
|
|
}
|
|
|
|
|
|
|
|
function recreateTable(data) {
|
2016-01-20 19:46:14 +00:00
|
|
|
$('#table-records>tbody').empty();
|
2016-01-18 20:45:07 +00:00
|
|
|
|
|
|
|
$.each(data, function(index,item) {
|
2016-01-20 19:46:14 +00:00
|
|
|
$('<tr></tr>').appendTo('#table-records>tbody')
|
2016-01-18 20:45:07 +00:00
|
|
|
.append('<td>' + item.id + '</td>')
|
|
|
|
.append('<td>' + item.name + '</td>')
|
|
|
|
.append('<td>' + item.type + '</td>')
|
2016-01-20 19:46:14 +00:00
|
|
|
.append('<td>' + item.content + '</td>')
|
|
|
|
.append('<td>' + item.priority + '</td>')
|
|
|
|
.append('<td>' + item.ttl + '</td>')
|
|
|
|
.append('<td><span class="glyphicon glyphicon-pencil cursor-pointer "></span></td>')
|
|
|
|
.append('<td><span class="glyphicon glyphicon-trash cursor-pointer "></span></td>');
|
2016-01-18 20:45:07 +00:00
|
|
|
|
|
|
|
});
|
2016-01-20 19:46:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function requestRecordData() {
|
|
|
|
var restrictions = {};
|
2016-01-18 20:45:07 +00:00
|
|
|
|
2016-01-20 19:46:14 +00:00
|
|
|
restrictions.sort = sort;
|
|
|
|
|
|
|
|
var searchName = $('#searchName').val();
|
|
|
|
if(searchName.length > 0) {
|
|
|
|
restrictions.name = searchName;
|
|
|
|
}
|
|
|
|
|
|
|
|
var searchType = $('#searchType').val();
|
|
|
|
if(searchType != null && searchType.length > 0) {
|
|
|
|
restrictions.type = searchType;
|
|
|
|
}
|
|
|
|
|
|
|
|
var searchContent = $('#searchContent').val();
|
|
|
|
if(searchContent.length > 0) {
|
|
|
|
restrictions.content = searchContent;
|
|
|
|
}
|
|
|
|
|
|
|
|
restrictions.action = "getRecords";
|
|
|
|
|
|
|
|
restrictions.domain = location.hash.substring(1);
|
|
|
|
|
|
|
|
$.post(
|
|
|
|
"api/edit-master.php",
|
|
|
|
JSON.stringify(restrictions),
|
|
|
|
function(data) {
|
|
|
|
recreateTable(data);
|
|
|
|
},
|
|
|
|
"json"
|
|
|
|
);
|
2016-01-20 20:48:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function requestSoaData() {
|
|
|
|
var data = {
|
|
|
|
action: "getSoa"
|
|
|
|
};
|
|
|
|
|
|
|
|
data.domain = location.hash.substring(1);
|
|
|
|
|
|
|
|
$.post(
|
|
|
|
"api/edit-master.php",
|
|
|
|
JSON.stringify(data),
|
|
|
|
function(data) {
|
|
|
|
$('#soa-primary').val(data.primary);
|
|
|
|
$('#soa-mail').val(data.email);
|
|
|
|
$('#soa-refresh').val(data.refresh);
|
|
|
|
$('#soa-retry').val(data.retry);
|
|
|
|
$('#soa-expire').val(data.expire);
|
|
|
|
$('#soa-ttl').val(data.ttl);
|
|
|
|
$('#soa-serial').val(data.serial);
|
|
|
|
},
|
|
|
|
"json"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function saveSoaData() {
|
|
|
|
|
2016-01-18 20:45:07 +00:00
|
|
|
}
|