mirror of
https://github.com/tuxis-ie/nsedit.git
synced 2025-04-19 20:09:14 +03:00
Implement record sorting. Closes #83
This commit is contained in:
parent
d103c7b04f
commit
749478c36a
2 changed files with 43 additions and 2 deletions
|
@ -563,6 +563,7 @@ $(document).ready(function () {
|
||||||
noDataAvailable: 'No records for ' + zone.record.name
|
noDataAvailable: 'No records for ' + zone.record.name
|
||||||
},
|
},
|
||||||
paging: true,
|
paging: true,
|
||||||
|
sorting: true,
|
||||||
pageSize: 20,
|
pageSize: 20,
|
||||||
openChildAsAccordion: true,
|
openChildAsAccordion: true,
|
||||||
actions: {
|
actions: {
|
||||||
|
@ -592,6 +593,7 @@ $(document).ready(function () {
|
||||||
name: {
|
name: {
|
||||||
title: 'Label',
|
title: 'Label',
|
||||||
width: '7%',
|
width: '7%',
|
||||||
|
sorting: true,
|
||||||
create: true,
|
create: true,
|
||||||
display: displayContent('name', zone.record.name),
|
display: displayContent('name', zone.record.name),
|
||||||
inputClass: 'name',
|
inputClass: 'name',
|
||||||
|
@ -648,6 +650,7 @@ $(document).ready(function () {
|
||||||
title: 'Content',
|
title: 'Content',
|
||||||
width: '30%',
|
width: '30%',
|
||||||
create: true,
|
create: true,
|
||||||
|
sorting: true,
|
||||||
display: displayContent('content'),
|
display: displayContent('content'),
|
||||||
inputClass: 'content',
|
inputClass: 'content',
|
||||||
listClass: 'content'
|
listClass: 'content'
|
||||||
|
@ -656,6 +659,7 @@ $(document).ready(function () {
|
||||||
title: 'TTL',
|
title: 'TTL',
|
||||||
width: '2%',
|
width: '2%',
|
||||||
create: true,
|
create: true,
|
||||||
|
sorting: false,
|
||||||
display: displayContent('ttl'),
|
display: displayContent('ttl'),
|
||||||
defaultValue: '<?php echo $defaults['ttl']; ?>',
|
defaultValue: '<?php echo $defaults['ttl']; ?>',
|
||||||
inputClass: 'ttl',
|
inputClass: 'ttl',
|
||||||
|
@ -680,6 +684,7 @@ $(document).ready(function () {
|
||||||
title: 'Disabled',
|
title: 'Disabled',
|
||||||
width: '2%',
|
width: '2%',
|
||||||
create: true,
|
create: true,
|
||||||
|
sorting: false,
|
||||||
display: displayContent('disabled'),
|
display: displayContent('disabled'),
|
||||||
defaultValue: '<?php echo $defaults['disabled'] ? 'No' : 'Yes'; ?>',
|
defaultValue: '<?php echo $defaults['disabled'] ? 'No' : 'Yes'; ?>',
|
||||||
inputClass: 'disabled',
|
inputClass: 'disabled',
|
||||||
|
|
40
zones.php
40
zones.php
|
@ -70,13 +70,31 @@ function rrtype_compare($a, $b) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function record_compare($a, $b) {
|
function record_compare_default($a, $b) {
|
||||||
if ($cmp = compareName($a['name'], $b['name'])) return $cmp;
|
if ($cmp = compareName($a['name'], $b['name'])) return $cmp;
|
||||||
if ($cmp = rrtype_compare($a['type'], $b['type'])) return $cmp;
|
if ($cmp = rrtype_compare($a['type'], $b['type'])) return $cmp;
|
||||||
if ($cmp = strnatcasecmp($a['content'], $b['content'])) return $cmp;
|
if ($cmp = strnatcasecmp($a['content'], $b['content'])) return $cmp;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function record_compare_name($a, $b) {
|
||||||
|
return record_compare_default($a, $b);
|
||||||
|
}
|
||||||
|
|
||||||
|
function record_compare_type($a, $b) {
|
||||||
|
if ($cmp = rrtype_compare($a['type'], $b['type'])) return $cmp;
|
||||||
|
if ($cmp = compareName($a['name'], $b['name'])) return $cmp;
|
||||||
|
if ($cmp = strnatcasecmp($a['content'], $b['content'])) return $cmp;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
function record_compare_content($a, $b) {
|
||||||
|
if ($cmp = strnatcasecmp($a['content'], $b['content'])) return $cmp;
|
||||||
|
if ($cmp = compareName($a['name'], $b['name'])) return $cmp;
|
||||||
|
if ($cmp = rrtype_compare($a['type'], $b['type'])) return $cmp;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
function add_db_zone($zonename, $accountname) {
|
function add_db_zone($zonename, $accountname) {
|
||||||
if (valid_user($accountname) === false) {
|
if (valid_user($accountname) === false) {
|
||||||
jtable_respond(null, 'error', "$accountname is not a valid username");
|
jtable_respond(null, 'error', "$accountname is not a valid username");
|
||||||
|
@ -173,7 +191,25 @@ case "listrecords":
|
||||||
foreach ($records as &$record) {
|
foreach ($records as &$record) {
|
||||||
$record['id'] = json_encode($record);
|
$record['id'] = json_encode($record);
|
||||||
}
|
}
|
||||||
usort($records, "record_compare");
|
if (isset($_GET['jtSorting'])) {
|
||||||
|
list($scolumn, $sorder) = preg_split("/ /", $_GET['jtSorting']);
|
||||||
|
switch ($scolumn) {
|
||||||
|
case "type":
|
||||||
|
usort($records, "record_compare_type");
|
||||||
|
break;
|
||||||
|
case "content":
|
||||||
|
usort($records, "record_compare_content");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
usort($records, "record_compare_name");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if ($sorder == "DESC") {
|
||||||
|
$records = array_reverse($records);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
usort($records, "record_compare_name");
|
||||||
|
}
|
||||||
jtable_respond($records);
|
jtable_respond($records);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue