2011-11-05 17:04:10 +00:00
|
|
|
'use strict';
|
|
|
|
|
2012-02-21 10:11:01 +00:00
|
|
|
pandora.ui.eventsDialog = function(options) {
|
|
|
|
// options can be {id: '...'} or {name: '...'}
|
2011-09-24 23:09:48 +00:00
|
|
|
var height = Math.round((window.innerHeight - 48) * 0.9),
|
|
|
|
width = Math.round(window.innerWidth * 0.9),
|
|
|
|
that = Ox.Dialog({
|
|
|
|
buttons: [
|
2011-10-11 16:30:06 +00:00
|
|
|
Ox.Button({
|
|
|
|
id: 'managePlaces',
|
2013-05-09 10:13:58 +00:00
|
|
|
title: Ox._('Manage Places...')
|
2011-10-11 16:30:06 +00:00
|
|
|
}).bindEvent({
|
|
|
|
click: function() {
|
2012-03-23 09:02:55 +00:00
|
|
|
that.close();
|
|
|
|
(pandora.$ui.placesDialog || (
|
|
|
|
pandora.$ui.placesDialog = pandora.ui.placesDialog()
|
|
|
|
)).open();
|
2011-10-11 16:30:06 +00:00
|
|
|
}
|
|
|
|
}),
|
|
|
|
{},
|
2013-08-14 18:22:12 +00:00
|
|
|
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});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}),
|
2011-09-24 23:09:48 +00:00
|
|
|
Ox.Button({
|
|
|
|
id: 'done',
|
2013-05-09 10:13:58 +00:00
|
|
|
title: Ox._('Done'),
|
2011-10-11 18:13:51 +00:00
|
|
|
width: 48
|
2011-09-24 23:09:48 +00:00
|
|
|
}).bindEvent({
|
|
|
|
click: function() {
|
|
|
|
that.close();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
],
|
|
|
|
closeButton: true,
|
2013-11-20 08:12:59 +00:00
|
|
|
content: Ox.LoadingScreen().start(),
|
2011-09-24 23:09:48 +00:00
|
|
|
height: height,
|
|
|
|
maximizeButton: true,
|
|
|
|
minHeight: 256,
|
|
|
|
minWidth: 512,
|
|
|
|
padding: 0,
|
2013-05-09 10:13:58 +00:00
|
|
|
title: Ox._('Manage Events'),
|
2011-09-24 23:09:48 +00:00
|
|
|
width: width
|
2011-10-11 09:17:43 +00:00
|
|
|
})
|
|
|
|
.bindEvent({
|
|
|
|
resize: function(data) {
|
|
|
|
// setting width would cause an expensive calendar redraw
|
2012-04-19 06:51:29 +00:00
|
|
|
$content && $content.options({
|
|
|
|
height: data.height
|
|
|
|
});
|
2011-10-11 09:17:43 +00:00
|
|
|
},
|
|
|
|
resizeend: function(data) {
|
2012-04-19 06:51:29 +00:00
|
|
|
$content && $content.options({
|
|
|
|
height: data.height, width: data.width
|
|
|
|
});
|
2011-10-11 09:17:43 +00:00
|
|
|
}
|
|
|
|
}),
|
|
|
|
$content;
|
2011-10-03 16:38:07 +00:00
|
|
|
|
|
|
|
pandora.api.findEvents({
|
2011-10-29 17:46:46 +00:00
|
|
|
query: {conditions: [], operator: '&'}
|
2011-10-03 16:38:07 +00:00
|
|
|
}, function(result) {
|
|
|
|
pandora.api.findEvents({
|
|
|
|
query: {conditions: [], operator: '&'},
|
|
|
|
keys: [],
|
|
|
|
range: [0, result.data.items],
|
|
|
|
sort: [{key: 'name', operator: '+'}]
|
|
|
|
}, function(result) {
|
|
|
|
that.options({
|
2012-06-05 08:25:45 +00:00
|
|
|
content: $content = Ox.CalendarEditor({
|
2011-10-09 21:12:50 +00:00
|
|
|
addEvent: function(event, callback) {
|
|
|
|
pandora.api.addEvent(event, function(result) {
|
|
|
|
Ox.Request.clearCache(); // fixme: remove
|
|
|
|
callback(result);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
editEvent: function(event, callback) {
|
|
|
|
pandora.api.editEvent(event, function(result) {
|
|
|
|
Ox.Request.clearCache(); // fixme: remove
|
|
|
|
callback(result);
|
|
|
|
});
|
|
|
|
},
|
2011-10-03 16:38:07 +00:00
|
|
|
events: result.data.items,
|
2012-02-20 18:31:26 +00:00
|
|
|
hasMatches: true,
|
2012-02-15 20:02:59 +00:00
|
|
|
height: height,
|
2012-02-20 18:31:26 +00:00
|
|
|
mode: pandora.site.calendar == 'auto' ? 'add' : 'define',
|
2011-10-09 21:12:50 +00:00
|
|
|
removeEvent: function(event, callback) {
|
|
|
|
pandora.api.removeEvent(event, function(result) {
|
|
|
|
Ox.Request.clearCache(); // fixme: remove
|
|
|
|
callback(result);
|
|
|
|
});
|
|
|
|
},
|
2012-02-21 10:11:01 +00:00
|
|
|
selected: options ? options.id : '',
|
2011-10-31 12:46:17 +00:00
|
|
|
showControls: pandora.user.ui.showCalendarControls,
|
2011-10-03 16:38:07 +00:00
|
|
|
width: width
|
|
|
|
})
|
|
|
|
});
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2011-09-24 23:09:48 +00:00
|
|
|
return that;
|
|
|
|
};
|
|
|
|
|