use findUsers to get newsletter status of selected users, fixes #2276
This commit is contained in:
parent
1b6a535456
commit
e7431d4d5b
2 changed files with 58 additions and 47 deletions
|
@ -415,7 +415,7 @@ actions.register(findUser)
|
||||||
def parse_query(data, user):
|
def parse_query(data, user):
|
||||||
query = {}
|
query = {}
|
||||||
query['range'] = [0, 100]
|
query['range'] = [0, 100]
|
||||||
query['sort'] = [{'key':'name', 'operator':'+'}]
|
query['sort'] = [{'key':'username', 'operator':'+'}]
|
||||||
for key in ('keys', 'range', 'sort', 'query'):
|
for key in ('keys', 'range', 'sort', 'query'):
|
||||||
if key in data:
|
if key in data:
|
||||||
query[key] = data[key]
|
query[key] = data[key]
|
||||||
|
@ -441,6 +441,7 @@ def order_query(qs, sort):
|
||||||
'system': 'system',
|
'system': 'system',
|
||||||
'timesseen': 'timesseen',
|
'timesseen': 'timesseen',
|
||||||
'useragent': 'useragent',
|
'useragent': 'useragent',
|
||||||
|
'user': 'username',
|
||||||
'username': 'username',
|
'username': 'username',
|
||||||
'numberoflists': 'numberoflists',
|
'numberoflists': 'numberoflists',
|
||||||
'windowsize': 'windowsize',
|
'windowsize': 'windowsize',
|
||||||
|
|
|
@ -600,15 +600,23 @@ pandora.ui.usersDialog = function() {
|
||||||
return ret;
|
return ret;
|
||||||
};
|
};
|
||||||
|
|
||||||
function getTo() {
|
function getTo(callback) {
|
||||||
return $list.options('selected').map(function(id) {
|
pandora.api.findUsers({
|
||||||
return $list.value(id);
|
query: {conditions: [
|
||||||
}).filter(function(user) {
|
{key: 'level', value: 'guest', operator: '!='},
|
||||||
return ['guest', 'robot'].indexOf(user.level) == -1 && (
|
{key: 'level', value: 'robot', operator: '!='}
|
||||||
$mailForm.values().include == 'users' || user.newsletter
|
], operator: '&'},
|
||||||
);
|
keys: ['id', 'username', 'newsletter'],
|
||||||
}).map(function(user) {
|
range: [0, numberOfUsers],
|
||||||
return user.username;
|
sort: [{key: 'username', operator: '+'}]
|
||||||
|
}, function(result) {
|
||||||
|
var selected = $list.options('selected');
|
||||||
|
callback(result.data.items.filter(function(user) {
|
||||||
|
return selected.indexOf(user.id) > -1
|
||||||
|
&& ($mailForm.values().include == 'users' || user.newsletter);
|
||||||
|
}).map(function(user) {
|
||||||
|
return user.username;
|
||||||
|
}));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -766,8 +774,7 @@ pandora.ui.usersDialog = function() {
|
||||||
})
|
})
|
||||||
.bindEvent({
|
.bindEvent({
|
||||||
change: function() {
|
change: function() {
|
||||||
setTo();
|
setTo(setSend);
|
||||||
setSend();
|
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
Ox.Input({
|
Ox.Input({
|
||||||
|
@ -835,8 +842,7 @@ pandora.ui.usersDialog = function() {
|
||||||
$form.append($editForm = renderEditForm());
|
$form.append($editForm = renderEditForm());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
setTo();
|
setTo(setSend);
|
||||||
setSend();
|
|
||||||
setWidth();
|
setWidth();
|
||||||
$editForm && $editForm.remove();
|
$editForm && $editForm.remove();
|
||||||
$form.append($mailForm);
|
$form.append($mailForm);
|
||||||
|
@ -858,40 +864,41 @@ pandora.ui.usersDialog = function() {
|
||||||
$form.append($editForm = renderEditForm());
|
$form.append($editForm = renderEditForm());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
setTo();
|
setTo(setSend);
|
||||||
setSend();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendMail() {
|
function sendMail() {
|
||||||
$sendButton.options({title: Ox._('Sending'), disabled: true});
|
$sendButton.options({title: Ox._('Sending'), disabled: true});
|
||||||
pandora.api.mail({
|
getTo(function(to) {
|
||||||
to: getTo(),
|
pandora.api.mail({
|
||||||
subject: getFormItemById('subject').value(),
|
to: to,
|
||||||
message: getFormItemById('message').value(),
|
subject: getFormItemById('subject').value(),
|
||||||
receipt: getFormItemById('receipt').value()
|
message: getFormItemById('message').value(),
|
||||||
}, function(result) {
|
receipt: getFormItemById('receipt').value()
|
||||||
var $dialog = pandora.ui.iconDialog({
|
}, function(result) {
|
||||||
buttons: [
|
var $dialog = pandora.ui.iconDialog({
|
||||||
Ox.Button({
|
buttons: [
|
||||||
id: 'close',
|
Ox.Button({
|
||||||
title: Ox._('Close')
|
id: 'close',
|
||||||
})
|
title: Ox._('Close')
|
||||||
.bindEvent({
|
})
|
||||||
click: function() {
|
.bindEvent({
|
||||||
$dialog.close();
|
click: function() {
|
||||||
}
|
$dialog.close();
|
||||||
})
|
}
|
||||||
],
|
})
|
||||||
content: result.status.code == 200
|
],
|
||||||
? Ox._('Your message has been sent.')
|
content: result.status.code == 200
|
||||||
: Ox._('Your message could not be sent. Please try again.'),
|
? Ox._('Your message has been sent.')
|
||||||
keys: {enter: 'close', escape: 'close'},
|
: Ox._('Your message could not be sent. Please try again.'),
|
||||||
title: result.status.code == 200
|
keys: {enter: 'close', escape: 'close'},
|
||||||
? Ox._('Message Sent')
|
title: result.status.code == 200
|
||||||
: Ox._('Application Error')
|
? Ox._('Message Sent')
|
||||||
}).open();
|
: Ox._('Application Error')
|
||||||
$sendButton.options({title: Ox._('Send'), disabled: false});
|
}).open();
|
||||||
|
$sendButton.options({title: Ox._('Send'), disabled: false});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -927,10 +934,13 @@ pandora.ui.usersDialog = function() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function setTo() {
|
function setTo(callback) {
|
||||||
var recipients = getTo().length;
|
getTo(function(to) {
|
||||||
$mailForm.values({
|
var recipients = to.length;
|
||||||
to: Ox.formatCount(recipients, 'recipient').replace('no', 'No')
|
$mailForm.values({
|
||||||
|
to: Ox.formatCount(recipients, 'recipient').replace('no', 'No')
|
||||||
|
});
|
||||||
|
callback();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue