Lists and Templates overviews refactored to use ajax. Before the refactoring, they behaved and looked a bit different to the other (Ajax) tables. The main difference in the behavior was in the row numbers (1st column) when sort order was switched. The non-ajax tables rearranged the numbers in the 1st column while the ajax-tables didn't.
Some small tweaks in table-helpers to allow selecting which fields are pulled from DB (and how they are renamed).
This commit is contained in:
parent
e5190c9b20
commit
9fdf52674e
12 changed files with 246 additions and 192 deletions
|
@ -673,6 +673,80 @@ router.post('/status/ajax/:id/:status', (req, res) => {
|
|||
});
|
||||
});
|
||||
|
||||
router.post('/clicked/ajax/:id/:linkId', (req, res) => {
|
||||
let linkId = Number(req.params.linkId) || 0;
|
||||
|
||||
campaigns.get(req.params.id, true, (err, campaign) => {
|
||||
if (err || !campaign) {
|
||||
return res.json({
|
||||
error: err && err.message || err || _('Campaign not found'),
|
||||
data: []
|
||||
});
|
||||
}
|
||||
lists.get(campaign.list, (err, list) => {
|
||||
if (err) {
|
||||
return res.json({
|
||||
error: err && err.message || err,
|
||||
data: []
|
||||
});
|
||||
}
|
||||
|
||||
let campaignCid = campaign.cid;
|
||||
let listCid = list.cid;
|
||||
|
||||
let columns = ['#', 'email', 'first_name', 'last_name', 'campaign_tracker__' + campaign.id + '`.`created', 'count'];
|
||||
campaigns.filterClickedSubscribers(campaign, linkId, req.body, columns, (err, data, total, filteredTotal) => {
|
||||
if (err) {
|
||||
return res.json({
|
||||
error: err.message || err,
|
||||
data: []
|
||||
});
|
||||
}
|
||||
|
||||
res.json({
|
||||
draw: req.body.draw,
|
||||
recordsTotal: total,
|
||||
recordsFiltered: filteredTotal,
|
||||
data: data.map((row, i) => [
|
||||
'<a href="/archive/' + encodeURIComponent(campaignCid) + '/' + encodeURIComponent(listCid) + '/' + encodeURIComponent(row.cid) + '?track=no">' + ((Number(req.body.start) || 0) + 1 + i) + '</a>',
|
||||
htmlescape(row.email || ''),
|
||||
htmlescape(row.firstName || ''),
|
||||
htmlescape(row.lastName || ''),
|
||||
row.created && row.created.toISOString ? '<span class="datestring" data-date="' + row.created.toISOString() + '" title="' + row.created.toISOString() + '">' + row.created.toISOString() + '</span>' : 'N/A',
|
||||
row.count,
|
||||
'<span class="glyphicon glyphicon-wrench" aria-hidden="true"></span><a href="/lists/subscription/' + campaign.list + '/edit/' + row.cid + '">' + _('Edit') + '</a>'
|
||||
])
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
router.post('/selection/ajax', (req, res) => {
|
||||
campaigns.filter(req.body, Number(req.query.parent) || false, (err, data, total, filteredTotal) => {
|
||||
if (err) {
|
||||
return res.json({
|
||||
error: err.message || err,
|
||||
data: []
|
||||
});
|
||||
}
|
||||
|
||||
res.json({
|
||||
draw: req.body.draw,
|
||||
recordsTotal: total,
|
||||
recordsFiltered: filteredTotal,
|
||||
data: data.map((row, i) => [
|
||||
'',
|
||||
(Number(req.body.start) || 0) + 1 + i,
|
||||
'<span class="glyphicon glyphicon-inbox" aria-hidden="true"></span> <a href="/campaigns/view/' + row.id + '">' + htmlescape(row.name || '') + '</a>',
|
||||
htmlescape(striptags(row.description) || ''),
|
||||
'<span class="datestring" data-date="' + row.created.toISOString() + '" title="' + row.created.toISOString() + '">' + row.created.toISOString() + '</span>']
|
||||
)
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
router.post('/delete', passport.parseForm, passport.csrfProtection, (req, res) => {
|
||||
campaigns.delete(req.body.id, (err, deleted) => {
|
||||
if (err) {
|
||||
|
|
|
@ -55,23 +55,8 @@ router.all('/*', (req, res, next) => {
|
|||
});
|
||||
|
||||
router.get('/', (req, res) => {
|
||||
let limit = 999999999;
|
||||
let start = 0;
|
||||
|
||||
lists.list(start, limit, (err, rows, total) => {
|
||||
if (err) {
|
||||
req.flash('danger', err.message || err);
|
||||
return res.redirect('/');
|
||||
}
|
||||
|
||||
res.render('lists/lists', {
|
||||
rows: rows.map((row, i) => {
|
||||
row.index = start + i + 1;
|
||||
row.description = striptags(row.description);
|
||||
return row;
|
||||
}),
|
||||
total
|
||||
});
|
||||
res.render('lists/lists', {
|
||||
title: _('Lists')
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -159,6 +144,32 @@ router.post('/delete', passport.parseForm, passport.csrfProtection, (req, res) =
|
|||
});
|
||||
});
|
||||
|
||||
router.post('/ajax', (req, res) => {
|
||||
lists.filter(req.body, Number(req.query.parent) || false, (err, data, total, filteredTotal) => {
|
||||
if (err) {
|
||||
return res.json({
|
||||
error: err.message || err,
|
||||
data: []
|
||||
});
|
||||
}
|
||||
|
||||
res.json({
|
||||
draw: req.body.draw,
|
||||
recordsTotal: total,
|
||||
recordsFiltered: filteredTotal,
|
||||
data: data.map((row, i) => [
|
||||
(Number(req.body.start) || 0) + 1 + i,
|
||||
'<span class="glyphicon glyphicon-list-alt" aria-hidden="true"></span> <a href="/lists/view/' + row.id + '">' + htmlescape(row.name || '') + '</a>',
|
||||
'<code>' + row.cid + '</code>',
|
||||
row.subscribers,
|
||||
htmlescape(striptags(row.description) || ''),
|
||||
'<span class="glyphicon glyphicon-wrench" aria-hidden="true"></span><a href="/lists/edit/' + row.id + '">' + _('Edit') + '</a>' ]
|
||||
)
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
router.post('/ajax/:id', (req, res) => {
|
||||
lists.get(req.params.id, (err, list) => {
|
||||
if (err || !list) {
|
||||
|
|
|
@ -8,6 +8,7 @@ let settings = require('../lib/models/settings');
|
|||
let tools = require('../lib/tools');
|
||||
let helpers = require('../lib/helpers');
|
||||
let striptags = require('striptags');
|
||||
let htmlescape = require('escape-html');
|
||||
let passport = require('../lib/passport');
|
||||
let mailer = require('../lib/mailer');
|
||||
let _ = require('../lib/translate')._;
|
||||
|
@ -22,23 +23,8 @@ router.all('/*', (req, res, next) => {
|
|||
});
|
||||
|
||||
router.get('/', (req, res) => {
|
||||
let limit = 999999999;
|
||||
let start = 0;
|
||||
|
||||
templates.list(start, limit, (err, rows, total) => {
|
||||
if (err) {
|
||||
req.flash('danger', err.message || err);
|
||||
return res.redirect('/');
|
||||
}
|
||||
|
||||
res.render('templates/templates', {
|
||||
rows: rows.map((row, i) => {
|
||||
row.index = start + i + 1;
|
||||
row.description = striptags(row.description);
|
||||
return row;
|
||||
}),
|
||||
total
|
||||
});
|
||||
res.render('templates/templates', {
|
||||
title: _('Templates')
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -164,4 +150,27 @@ router.post('/delete', passport.parseForm, passport.csrfProtection, (req, res) =
|
|||
});
|
||||
});
|
||||
|
||||
router.post('/ajax', (req, res) => {
|
||||
templates.filter(req.body, Number(req.query.parent) || false, (err, data, total, filteredTotal) => {
|
||||
if (err) {
|
||||
return res.json({
|
||||
error: err.message || err,
|
||||
data: []
|
||||
});
|
||||
}
|
||||
|
||||
res.json({
|
||||
draw: req.body.draw,
|
||||
recordsTotal: total,
|
||||
recordsFiltered: filteredTotal,
|
||||
data: data.map((row, i) => [
|
||||
(Number(req.body.start) || 0) + 1 + i,
|
||||
'<span class="glyphicon glyphicon-file" aria-hidden="true"></span> ' + htmlescape(row.name || ''),
|
||||
htmlescape(striptags(row.description) || ''),
|
||||
'<span class="glyphicon glyphicon-wrench" aria-hidden="true"></span><a href="/templates/edit/' + row.id + '">' + _('Edit') + '</a>' ]
|
||||
)
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue