From e7431d4d5bf4d1e6ccedf1081b0d7de01ccd29e3 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Wed, 12 Feb 2014 11:40:02 +0000 Subject: [PATCH] use findUsers to get newsletter status of selected users, fixes #2276 --- pandora/user/views.py | 3 +- static/js/usersDialog.js | 102 +++++++++++++++++++++------------------ 2 files changed, 58 insertions(+), 47 deletions(-) diff --git a/pandora/user/views.py b/pandora/user/views.py index 2a3d59d6..b3f8e04c 100644 --- a/pandora/user/views.py +++ b/pandora/user/views.py @@ -415,7 +415,7 @@ actions.register(findUser) def parse_query(data, user): query = {} query['range'] = [0, 100] - query['sort'] = [{'key':'name', 'operator':'+'}] + query['sort'] = [{'key':'username', 'operator':'+'}] for key in ('keys', 'range', 'sort', 'query'): if key in data: query[key] = data[key] @@ -441,6 +441,7 @@ def order_query(qs, sort): 'system': 'system', 'timesseen': 'timesseen', 'useragent': 'useragent', + 'user': 'username', 'username': 'username', 'numberoflists': 'numberoflists', 'windowsize': 'windowsize', diff --git a/static/js/usersDialog.js b/static/js/usersDialog.js index 609754f0..dc19127e 100644 --- a/static/js/usersDialog.js +++ b/static/js/usersDialog.js @@ -600,15 +600,23 @@ pandora.ui.usersDialog = function() { return ret; }; - function getTo() { - return $list.options('selected').map(function(id) { - return $list.value(id); - }).filter(function(user) { - return ['guest', 'robot'].indexOf(user.level) == -1 && ( - $mailForm.values().include == 'users' || user.newsletter - ); - }).map(function(user) { - return user.username; + function getTo(callback) { + pandora.api.findUsers({ + query: {conditions: [ + {key: 'level', value: 'guest', operator: '!='}, + {key: 'level', value: 'robot', operator: '!='} + ], 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) { + return user.username; + })); }); } @@ -766,8 +774,7 @@ pandora.ui.usersDialog = function() { }) .bindEvent({ change: function() { - setTo(); - setSend(); + setTo(setSend); } }), Ox.Input({ @@ -835,8 +842,7 @@ pandora.ui.usersDialog = function() { $form.append($editForm = renderEditForm()); } } else { - setTo(); - setSend(); + setTo(setSend); setWidth(); $editForm && $editForm.remove(); $form.append($mailForm); @@ -858,40 +864,41 @@ pandora.ui.usersDialog = function() { $form.append($editForm = renderEditForm()); } } else { - setTo(); - setSend(); + setTo(setSend); } } function sendMail() { $sendButton.options({title: Ox._('Sending'), disabled: true}); - pandora.api.mail({ - to: getTo(), - subject: getFormItemById('subject').value(), - message: getFormItemById('message').value(), - receipt: getFormItemById('receipt').value() - }, function(result) { - var $dialog = pandora.ui.iconDialog({ - buttons: [ - Ox.Button({ - id: 'close', - title: Ox._('Close') - }) - .bindEvent({ - click: function() { - $dialog.close(); - } - }) - ], - content: result.status.code == 200 - ? Ox._('Your message has been sent.') - : Ox._('Your message could not be sent. Please try again.'), - keys: {enter: 'close', escape: 'close'}, - title: result.status.code == 200 - ? Ox._('Message Sent') - : Ox._('Application Error') - }).open(); - $sendButton.options({title: Ox._('Send'), disabled: false}); + getTo(function(to) { + pandora.api.mail({ + to: to, + subject: getFormItemById('subject').value(), + message: getFormItemById('message').value(), + receipt: getFormItemById('receipt').value() + }, function(result) { + var $dialog = pandora.ui.iconDialog({ + buttons: [ + Ox.Button({ + id: 'close', + title: Ox._('Close') + }) + .bindEvent({ + click: function() { + $dialog.close(); + } + }) + ], + content: result.status.code == 200 + ? Ox._('Your message has been sent.') + : Ox._('Your message could not be sent. Please try again.'), + keys: {enter: 'close', escape: 'close'}, + title: result.status.code == 200 + ? Ox._('Message Sent') + : Ox._('Application Error') + }).open(); + $sendButton.options({title: Ox._('Send'), disabled: false}); + }); }); } @@ -927,10 +934,13 @@ pandora.ui.usersDialog = function() { }); } - function setTo() { - var recipients = getTo().length; - $mailForm.values({ - to: Ox.formatCount(recipients, 'recipient').replace('no', 'No') + function setTo(callback) { + getTo(function(to) { + var recipients = to.length; + $mailForm.values({ + to: Ox.formatCount(recipients, 'recipient').replace('no', 'No') + }); + callback(); }); }