use findUsers to get newsletter status of selected users, fixes #2276

This commit is contained in:
j 2014-02-12 11:40:02 +00:00
parent 1b6a535456
commit e7431d4d5b
2 changed files with 58 additions and 47 deletions

View file

@ -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',

View file

@ -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'],
range: [0, numberOfUsers],
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) { }).map(function(user) {
return user.username; 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,15 +864,15 @@ 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});
getTo(function(to) {
pandora.api.mail({ pandora.api.mail({
to: getTo(), to: to,
subject: getFormItemById('subject').value(), subject: getFormItemById('subject').value(),
message: getFormItemById('message').value(), message: getFormItemById('message').value(),
receipt: getFormItemById('receipt').value() receipt: getFormItemById('receipt').value()
@ -893,6 +899,7 @@ pandora.ui.usersDialog = function() {
}).open(); }).open();
$sendButton.options({title: Ox._('Send'), disabled: false}); $sendButton.options({title: Ox._('Send'), disabled: false});
}); });
});
} }
function setHeight(data) { function setHeight(data) {
@ -927,11 +934,14 @@ pandora.ui.usersDialog = function() {
}); });
} }
function setTo() { function setTo(callback) {
var recipients = getTo().length; getTo(function(to) {
var recipients = to.length;
$mailForm.values({ $mailForm.values({
to: Ox.formatCount(recipients, 'recipient').replace('no', 'No') to: Ox.formatCount(recipients, 'recipient').replace('no', 'No')
}); });
callback();
});
} }
function setWidth() { function setWidth() {