From 47b181d8cf71fd9e6bb3905f758061f5faacd2d5 Mon Sep 17 00:00:00 2001 From: rolux Date: Thu, 22 Jan 2015 14:37:17 +0530 Subject: [PATCH] users dialog: export selected emails only (if one or more users are selected) --- static/js/usersDialog.js | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/static/js/usersDialog.js b/static/js/usersDialog.js index e586fcaa..4455d547 100644 --- a/static/js/usersDialog.js +++ b/static/js/usersDialog.js @@ -525,14 +525,9 @@ pandora.ui.usersDialog = function() { click: function() { var $button = this; $button.options({disabled: true}); - pandora.api.findUsers({ - query: {conditions: [], operator: '&'}, - keys: ['email', 'username'], - range: [0, numberOfUsers], - sort: [{key: 'username', operator: '+'}] - }, function(result) { + getEmailAddresses(function(items) { pandora.ui.exportDialog({ - data: result.data.items.filter(function(item) { + data: items.filter(function(item) { return item.email; }).map(function(item) { return Ox.encodeHTMLEntities(item.username) @@ -588,6 +583,25 @@ pandora.ui.usersDialog = function() { that.superClose(); }; + function getEmailAddresses(callback) { + pandora.api.findUsers({ + query: {conditions: [ + {key: 'level', value: 'guest', operator: '!='}, + {key: 'level', value: 'robot', operator: '!='} + ], operator: '&'}, + keys: ['id', 'username', 'email'], + range: [0, 1000000], + sort: [{key: 'username', operator: '+'}] + }, function(result) { + var selected = $list.options('selected'); + callback(result.data.items.filter(function(user) { + return !selected.length || Ox.contains(selected, user.id); + }).map(function(user) { + return {username: user.username, email: user.email}; + })); + }); + } + function getFormItemById(id) { var ret; Ox.forEach((