From e1913a1d05a748b1eb82377ba7719aa8b3895c49 Mon Sep 17 00:00:00 2001 From: rolux Date: Wed, 14 Aug 2013 18:22:12 +0000 Subject: [PATCH] add export dialog; use it in manage places/events/users --- static/js/eventsDialog.js | 29 ++++++++++++++++++++++ static/js/exportDialog.js | 51 +++++++++++++++++++++++++++++++++++++++ static/js/placesDialog.js | 32 ++++++++++++++++++++++++ static/js/usersDialog.js | 40 ++++++++++-------------------- 4 files changed, 125 insertions(+), 27 deletions(-) create mode 100644 static/js/exportDialog.js diff --git a/static/js/eventsDialog.js b/static/js/eventsDialog.js index 041be0c7..2b11c144 100644 --- a/static/js/eventsDialog.js +++ b/static/js/eventsDialog.js @@ -20,6 +20,35 @@ pandora.ui.eventsDialog = function(options) { } }), {}, + Ox.Button({ + id: 'exportEvents', + title: Ox._('Export Events...') + }).bindEvent({ + click: function() { + var $button = this, + keys = ['name', 'alternativeNames', 'start', 'end']; + $button.options({disabled: true}); + pandora.api.findEvents({ + query: {conditions: [], operator: '&'}, + keys: keys, + range: [0, 1000000], + sort: [{key: 'name', operator: '+'}] + }, function(result) { + pandora.ui.exportDialog({ + data: JSON.stringify(result.data.items.map(function(item) { + Object.keys(item).filter(function(key) { + return !Ox.contains(keys, key); + }).forEach(function(key) { + delete item[key]; + }); + return item; + }), null, ' '), + title: Ox._('Events') + }).open(); + $button.options({disabled: false}); + }); + } + }), Ox.Button({ id: 'done', title: Ox._('Done'), diff --git a/static/js/exportDialog.js b/static/js/exportDialog.js new file mode 100644 index 00000000..04226a94 --- /dev/null +++ b/static/js/exportDialog.js @@ -0,0 +1,51 @@ +'use strict'; + +pandora.ui.exportDialog = function(options) { + + var $content = Ox.Input({ + height: 256, + style: 'square', + type: 'textarea', + value: options.data, + width: 512 - Ox.UI.SCROLLBAR_SIZE + }), + + that = Ox.Dialog({ + buttons: [ + Ox.Button({ + title: Ox._('Select All') + }) + .bindEvent({ + click: function() { + $content.focusInput(true); + } + }), + {}, + Ox.Button({ + title: Ox._('Close') + }) + .bindEvent({ + click: function() { + that.close(); + } + }) + ], + content: $content, + fixedSize: true, + height: 256, + removeOnClose: true, + title: options.title, + width: 512 + }); + + that.superOpen = that.open; + that.open = function() { + that.superOpen(); + that.find('.OxContent').css({overflow: 'hidden'}); + $content.find('textarea').addClass('OxMonospace'); + $content.focusInput(true); + }; + + return that; + +}; \ No newline at end of file diff --git a/static/js/placesDialog.js b/static/js/placesDialog.js index 10412397..df8ffdae 100644 --- a/static/js/placesDialog.js +++ b/static/js/placesDialog.js @@ -89,6 +89,38 @@ pandora.ui.placesDialog = function(options) { } }), {}, + Ox.Button({ + id: 'exportPlaces', + title: Ox._('Export Places...') + }).bindEvent({ + click: function() { + var $button = this, + keys = [ + 'name', 'alternativeNames', 'geoname', + 'lat', 'lng', 'south', 'west', 'north', 'east' + ]; + $button.options({disabled: true}); + pandora.api.findPlaces({ + query: {conditions: [], operator: '&'}, + keys: keys, + range: [0, 1000000], + sort: [{key: 'name', operator: '+'}] + }, function(result) { + pandora.ui.exportDialog({ + data: JSON.stringify(result.data.items.map(function(item) { + Object.keys(item).filter(function(key) { + return !Ox.contains(keys, key); + }).forEach(function(key) { + delete item[key]; + }); + return item; + }), null, ' '), + title: Ox._('Places') + }).open(); + $button.options({disabled: false}); + }); + } + }), Ox.Button({ id: 'done', title: Ox._('Done'), diff --git a/static/js/usersDialog.js b/static/js/usersDialog.js index 138ec0ac..609754f0 100644 --- a/static/js/usersDialog.js +++ b/static/js/usersDialog.js @@ -517,43 +517,29 @@ pandora.ui.usersDialog = function() { }), {}, Ox.Button({ - title: Ox._('Export E-Mail Addresses') + title: Ox._('Export E-Mail Addresses...') }) .css({margin: '4px 4px 4px 0'}) .bindEvent({ 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) { - var $dialog = Ox.Dialog({ - buttons: [ - Ox.Button({ - title: Ox._('Close') - }) - .bindEvent({ - click: function() { - $dialog.close(); - } - }) - ], - content: Ox.Element() - .addClass('OxSelectable') - .css({margin: '16px'}) - .html( - result.data.items.filter(function(item) { - return item.email; - }).map(function(item) { - return Ox.encodeHTMLEntities(item.username) - + ' <' + item.email + '>'; - }).join(', ') - ), - removeOnClose: true, - title: Ox._('E-Mail Addresses') - }) - .open(); + pandora.ui.exportDialog({ + data: result.data.items.filter(function(item) { + return item.email; + }).map(function(item) { + return Ox.encodeHTMLEntities(item.username) + + ' <' + item.email + '>'; + }).join(', '), + title: Ox._('E-Mail Addresses') + }).open(); + $button.options({disabled: false}); }); } }),