pandora/static/js/placesDialog.js

151 lines
6 KiB
JavaScript
Raw Normal View History

2011-11-05 17:04:10 +00:00
'use strict';
2012-01-15 15:05:37 +00:00
pandora.ui.placesDialog = function(options) {
// options can be {id: '...'} or {name: '...'}
2011-08-17 11:39:55 +00:00
var height = Math.round((window.innerHeight - 48) * 0.9),
2011-06-02 07:01:29 +00:00
width = Math.round(window.innerWidth * 0.9),
$content = Ox.MapEditor({
addPlace: function(place, callback) {
pandora.api.addPlace(place, function(result) {
Ox.Request.clearCache(); // fixme: remove
callback(result);
});
},
editPlace: function(place, callback) {
pandora.api.editPlace(place, function(result) {
Ox.Request.clearCache(); // fixme: remove
callback(result);
});
},
2011-10-30 14:59:54 +00:00
getMatches: function(names, callback) {
// fixme: the results of this are of course
// not identical to actual place matches
2013-02-27 11:36:54 +00:00
var conditions = [], keys, operator;
if (names.length == 0) {
callback(0);
} else {
2013-02-27 11:36:54 +00:00
keys = pandora.site.layers.filter(function(layer) {
2012-01-02 15:29:43 +00:00
return layer.type == 'place' || layer.hasPlaces;
}).map(function(layer) {
return layer.id;
2013-02-27 11:36:54 +00:00
});
keys.forEach(function(key) {
operator = Ox.getObjectById(
pandora.site.layers, key
).type == 'place' ? '==' : '=';
names.forEach(function(name) {
conditions.push({key: key, value: name, operator: operator});
});
});
pandora.api.findClips({
query: {
2013-02-27 11:36:54 +00:00
conditions: conditions,
operator: conditions.length == 1 ? '&' : '|'
}
}, function(result) {
callback(result.data.items);
});
}
2011-10-30 14:59:54 +00:00
},
2012-02-20 18:31:26 +00:00
hasMatches: true, // FIXME: getMatches is enough
height: height - 48,
mode: pandora.site.map == 'auto' ? 'add' : 'define',
2012-01-15 15:05:37 +00:00
names: pandora.hasPlacesLayer ? function(callback) {
pandora.api.getPlaces(function(result) {
2012-01-15 15:05:37 +00:00
callback(result.data.items);
});
} : null,
places: function(data, callback) {
2012-02-04 14:02:48 +00:00
data.keys && data.keys.push('matches');
2012-01-15 15:05:37 +00:00
return pandora.api.findPlaces(Ox.extend({
query: {conditions: [], operator: ''}
}, data), callback);
},
removePlace: function(place, callback) {
pandora.api.removePlace(place, function(result) {
Ox.Request.clearCache(); // fixme: remove
callback(result);
});
},
2012-02-20 18:31:26 +00:00
selected: options ? options.id : '',
showControls: pandora.user.ui.showMapControls,
showLabels: pandora.user.ui.showMapLabels,
showTypes: true,
width: width
}),
2011-06-19 17:49:25 +00:00
that = Ox.Dialog({
2011-05-25 19:42:45 +00:00
buttons: [
2011-10-11 16:30:06 +00:00
Ox.Button({
id: 'manageEvents',
2013-05-09 10:13:58 +00:00
title: Ox._('Manage Events...')
2011-10-11 16:30:06 +00:00
}).bindEvent({
click: function() {
that.close();
(pandora.$ui.eventsDialog || (
pandora.$ui.eventsDialog = pandora.ui.eventsDialog()
)).open();
2011-10-11 16:30:06 +00:00
}
}),
{},
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});
});
}
}),
2011-06-19 17:49:25 +00:00
Ox.Button({
2011-05-25 19:42:45 +00:00
id: 'done',
2013-05-09 10:13:58 +00:00
title: Ox._('Done'),
width: 48
2011-05-25 19:42:45 +00:00
}).bindEvent({
click: function() {
that.close();
}
})
],
2011-08-17 11:39:55 +00:00
closeButton: true,
content: $content,
2011-05-25 19:42:45 +00:00
height: height,
2011-08-17 11:39:55 +00:00
maximizeButton: true,
minHeight: 256,
minWidth: 512,
2011-06-02 08:03:41 +00:00
//keys: {enter: 'done', escape: 'done'},
2011-05-25 19:42:45 +00:00
padding: 0,
2013-05-09 10:13:58 +00:00
title: Ox._('Manage Places'),
2011-05-25 19:42:45 +00:00
width: width
})
.bindEvent({
resize: function(data) {
2012-01-30 23:29:04 +00:00
$content.options({width: width, height: height});
}
2011-05-25 19:42:45 +00:00
});
return that;
};