add export dialog; use it in manage places/events/users

This commit is contained in:
rolux 2013-08-14 18:22:12 +00:00
parent 4754f86909
commit e1913a1d05
4 changed files with 125 additions and 27 deletions

View file

@ -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({ Ox.Button({
id: 'done', id: 'done',
title: Ox._('Done'), title: Ox._('Done'),

51
static/js/exportDialog.js Normal file
View file

@ -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;
};

View file

@ -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({ Ox.Button({
id: 'done', id: 'done',
title: Ox._('Done'), title: Ox._('Done'),

View file

@ -517,43 +517,29 @@ pandora.ui.usersDialog = function() {
}), }),
{}, {},
Ox.Button({ Ox.Button({
title: Ox._('Export E-Mail Addresses') title: Ox._('Export E-Mail Addresses...')
}) })
.css({margin: '4px 4px 4px 0'}) .css({margin: '4px 4px 4px 0'})
.bindEvent({ .bindEvent({
click: function() { click: function() {
var $button = this;
$button.options({disabled: true});
pandora.api.findUsers({ pandora.api.findUsers({
query: {conditions: [], operator: '&'}, query: {conditions: [], operator: '&'},
keys: ['email', 'username'], keys: ['email', 'username'],
range: [0, numberOfUsers], range: [0, numberOfUsers],
sort: [{key: 'username', operator: '+'}] sort: [{key: 'username', operator: '+'}]
}, function(result) { }, function(result) {
var $dialog = Ox.Dialog({ pandora.ui.exportDialog({
buttons: [ data: result.data.items.filter(function(item) {
Ox.Button({ return item.email;
title: Ox._('Close') }).map(function(item) {
}) return Ox.encodeHTMLEntities(item.username)
.bindEvent({ + ' <' + item.email + '>';
click: function() { }).join(', '),
$dialog.close(); title: Ox._('E-Mail Addresses')
} }).open();
}) $button.options({disabled: false});
],
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)
+ ' &lt;' + item.email + '&gt;';
}).join(', ')
),
removeOnClose: true,
title: Ox._('E-Mail Addresses')
})
.open();
}); });
} }
}), }),