public
nobgit
read
NobMail
Based on mailcow: dockerized
Languages
Repository composition by tracked source files.
PHP
49%
JavaScript
35%
HTML
9%
CSS
4%
Shell
2%
Python
1%
Lua
0%
Perl
0%
Ruby
0%
SCSS
0%
Create file
Wiki Documentation
Clone
https://nobgit.com/orgs/nobgit/nobmail.git
ssh://[email protected]:2222/orgs/nobgit/nobmail.git
Commit
Mailboxes datatable - server side processing
Signed-off-by: Kristian Feldsam <[email protected]>
28cec996
data/web/js/site/mailbox.js | 39 +++++++++++++++++++--------------------
data/web/json_api.php | 33 +++++++++++++++++++++++++++++++++
2 files changed, 52 insertions(+), 20 deletions(-)
Diff
diff --git a/data/web/js/site/mailbox.js b/data/web/js/site/mailbox.js
index 5e1ba315..fe6113a8 100644
--- a/data/web/js/site/mailbox.js
+++ b/data/web/js/site/mailbox.js
@@ -869,7 +869,7 @@ jQuery(function($){
var table = $('#mailbox_table').DataTable({
responsive: true,
processing: true,
- serverSide: false,
+ serverSide: true,
stateSave: true,
pageLength: pagination_size,
dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
@@ -878,13 +878,12 @@ jQuery(function($){
language: lang_datatables,
initComplete: function(settings, json){
hideTableExpandCollapseBtn('#tab-mailboxes', '#mailbox_table');
- filterByDomain(json, 8, table);
},
ajax: {
type: "GET",
- url: "/api/v1/get/mailbox/reduced",
+ url: "/api/v1/get/mailbox/datatables",
dataSrc: function(json){
- $.each(json, function (i, item) {
+ $.each(json.data, function (i, item) {
item.quota = {
sortBy: item.quota_used,
value: item.quota
@@ -970,7 +969,7 @@ jQuery(function($){
}
});
- return json;
+ return json.data;
}
},
columns: [
@@ -1000,13 +999,15 @@ jQuery(function($){
{
title: lang.domain_quota,
data: 'quota.value',
+ searchable: false,
responsivePriority: 8,
- defaultContent: '',
- orderData: 23
+ defaultContent: ''
},
{
title: lang.last_mail_login,
data: 'last_mail_login',
+ searchable: false,
+ orderable: false,
defaultContent: '',
responsivePriority: 7,
render: function (data, type) {
@@ -1019,11 +1020,15 @@ jQuery(function($){
{
title: lang.last_pw_change,
data: 'last_pw_change',
+ searchable: false,
+ orderable: false,
defaultContent: ''
},
{
title: lang.in_use,
data: 'in_use.value',
+ searchable: false,
+ orderable: false,
defaultContent: '',
responsivePriority: 9,
className: 'dt-data-w100',
@@ -1092,6 +1097,8 @@ jQuery(function($){
{
title: lang.msg_num,
data: 'messages',
+ searchable: false,
+ orderable: false,
defaultContent: '',
responsivePriority: 5
},
@@ -1116,6 +1123,8 @@ jQuery(function($){
{
title: lang.active,
data: 'active',
+ searchable: false,
+ orderable: false,
defaultContent: '',
responsivePriority: 4,
render: function (data, type) {
@@ -1125,22 +1134,12 @@ jQuery(function($){
{
title: lang.action,
data: 'action',
+ searchable: false,
+ orderable: false,
className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-text-right',
responsivePriority: 6,
defaultContent: ''
- },
- {
- title: "",
- data: 'quota.sortBy',
- defaultContent: '',
- className: "d-none"
- },
- {
- title: "",
- data: 'in_use.sortBy',
- defaultContent: '',
- className: "d-none"
- },
+ }
]
});
diff --git a/data/web/json_api.php b/data/web/json_api.php
index 6c008a60..3077bf7b 100644
--- a/data/web/json_api.php
+++ b/data/web/json_api.php
@@ -1046,6 +1046,39 @@ if (isset($_GET['query'])) {
break;
case "mailbox":
switch ($object) {
+ case "datatables":
+ $table = ['mailbox', 'm'];
+ $primaryKey = 'username';
+ $columns = [
+ ['db' => 'username', 'dt' => 2],
+ ['db' => 'quota', 'dt' => 3],
+ ];
+
+ require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/lib/ssp.class.php';
+ global $pdo;
+ if($_SESSION['mailcow_cc_role'] === 'admin') {
+ $data = SSP::complex($_GET, $pdo, $table, $primaryKey, $columns, null, "(`m`.`kind` = '' OR `m`.`kind` = NULL)");
+ } elseif ($_SESSION['mailcow_cc_role'] === 'domainadmin') {
+ $data = SSP::complex($_GET, $pdo, $table, $primaryKey, $columns,
+ 'INNER JOIN domain_admins as da ON da.domain = m.domain',
+ [
+ 'condition' => "(`m`.`kind` = '' OR `m`.`kind` = NULL) AND `da`.`active` = 1 AND `da`.`username` = :username",
+ 'bindings' => ['username' => $_SESSION['mailcow_cc_username']]
+ ]);
+ }
+
+ if (!empty($data['data'])) {
+ $mailboxData = [];
+ foreach ($data['data'] as $mailbox) {
+ if ($details = mailbox('get', 'mailbox_details', $mailbox[2])) {
+ $mailboxData[] = $details;
+ }
+ }
+ $data['data'] = $mailboxData;
+ }
+
+ process_get_return($data);
+ break;
case "all":
case "reduced":
$tags = null;