2011-07-29 18:37:11 +00:00
|
|
|
// vim: et:ts=4:sw=4:sts=4:ft=javascript
|
2011-10-03 16:38:07 +00:00
|
|
|
|
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),
|
2012-06-05 08:25:45 +00:00
|
|
|
$content = Ox.MapEditor({
|
2011-10-11 09:17:43 +00:00
|
|
|
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;
|
2012-06-05 08:32:08 +00:00
|
|
|
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});
|
|
|
|
});
|
|
|
|
});
|
2012-06-05 08:32:08 +00:00
|
|
|
pandora.api.findClips({
|
|
|
|
query: {
|
2013-02-27 11:36:54 +00:00
|
|
|
conditions: conditions,
|
|
|
|
operator: conditions.length == 1 ? '&' : '|'
|
2012-06-05 08:32:08 +00:00
|
|
|
}
|
|
|
|
}, 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
|
2012-02-02 12:14:30 +00:00
|
|
|
height: height - 48,
|
|
|
|
mode: pandora.site.map == 'auto' ? 'add' : 'define',
|
2012-01-15 15:05:37 +00:00
|
|
|
names: pandora.hasPlacesLayer ? function(callback) {
|
2014-12-22 10:35:39 +00:00
|
|
|
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);
|
|
|
|
},
|
2011-10-11 09:17:43 +00:00
|
|
|
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 : '',
|
2011-10-31 12:46:17 +00:00
|
|
|
showControls: pandora.user.ui.showMapControls,
|
|
|
|
showLabels: pandora.user.ui.showMapLabels,
|
2011-10-11 09:17:43 +00:00
|
|
|
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() {
|
2012-03-23 09:02:55 +00:00
|
|
|
that.close();
|
|
|
|
(pandora.$ui.eventsDialog || (
|
|
|
|
pandora.$ui.eventsDialog = pandora.ui.eventsDialog()
|
|
|
|
)).open();
|
2011-10-11 16:30:06 +00:00
|
|
|
}
|
|
|
|
}),
|
|
|
|
{},
|
2013-08-14 18:22:12 +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'),
|
2011-10-11 18:13:51 +00:00
|
|
|
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,
|
2011-10-11 09:17:43 +00:00
|
|
|
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
|
2011-10-11 09:17:43 +00:00
|
|
|
})
|
|
|
|
.bindEvent({
|
|
|
|
resize: function(data) {
|
2012-01-30 23:29:04 +00:00
|
|
|
$content.options({width: width, height: height});
|
2011-10-11 09:17:43 +00:00
|
|
|
}
|
2011-05-25 19:42:45 +00:00
|
|
|
});
|
|
|
|
return that;
|
|
|
|
};
|
|
|
|
|