mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-05-08 21:15:27 +00:00
Monotone-Parent: 6303f532fa4bb3c36fe2f298f62f659c4fc71b18
Monotone-Revision: c111ae7ec8c39efb8d0cc56ff4627bb958ff0cc8 Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2012-04-18T20:03:07
This commit is contained in:
@@ -1203,25 +1203,180 @@ function onMonthOverview() {
|
||||
return _ensureView("monthview");
|
||||
}
|
||||
|
||||
function onCalendarReload() {
|
||||
function refreshEventsAndTasks() {
|
||||
refreshEvents();
|
||||
refreshTasks();
|
||||
reloadWebCalendars();
|
||||
}
|
||||
|
||||
function onCalendarReload() {
|
||||
if (!reloadWebCalendars()) {
|
||||
refreshEventsAndTasks();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function reloadWebCalendars() {
|
||||
var url = ApplicationBaseURL + "reloadWebCalendars";
|
||||
if (document.reloadWebCalAjaxRequest) {
|
||||
document.reloadWebCalAjaxRequest.aborted = true;
|
||||
document.reloadWebCalAjaxRequest.abort();
|
||||
log("* reloadWebCalendars");
|
||||
var hasWebCalendars = false;
|
||||
|
||||
var remaining = [];
|
||||
var refreshOperations = { "remaining": remaining };
|
||||
if (UserSettings['Calendar']
|
||||
&& UserSettings['Calendar']['WebCalendars']) {
|
||||
var webCalendars = UserSettings['Calendar']['WebCalendars'];
|
||||
|
||||
var folders = $("calendarList");
|
||||
var calendarNodes = folders.childNodesWithTag("li");
|
||||
for (var i = 0; i < calendarNodes.length; i++) {
|
||||
var current = calendarNodes[i];
|
||||
var calendarID = current.getAttribute("id");
|
||||
var owner = current.getAttribute("owner");
|
||||
var realID = owner + ":Calendar/" + calendarID.substr(1);
|
||||
if (webCalendars[realID]) { /* is web calendar ? */
|
||||
remaining.push(realID);
|
||||
reloadWebCalendar(realID, refreshOperations);
|
||||
}
|
||||
}
|
||||
}
|
||||
document.reloadWebCalAjaxRequest
|
||||
= triggerAjaxRequest(url, reloadWebCalendarsCallback);
|
||||
|
||||
return (remaining.length > 0);
|
||||
}
|
||||
|
||||
function reloadWebCalendarsCallback (http) {
|
||||
changeCalendarDisplay(null, currentView);
|
||||
var calendarReloadErrors = { "invalid-calendar-content":
|
||||
_("the returned content was not valid calendar"
|
||||
+ " data"),
|
||||
"http-error": _("an unknown http error occurred"
|
||||
+ " during the load operation"),
|
||||
"bad-url": _("the url in use is invalid or the"
|
||||
+ " host is currently unreachable"),
|
||||
"invalid-url": _("the url being used is invalid"
|
||||
+ " or not handled") };
|
||||
|
||||
function reloadWebCalendar(folderID, refreshOperations) {
|
||||
var url = URLForFolderID(folderID) + "/reload";
|
||||
var cbData = { "folderID": folderID };
|
||||
if (refreshOperations) {
|
||||
cbData["refreshOperations"] = refreshOperations;
|
||||
}
|
||||
triggerAjaxRequest(url, reloadWebCalendarCallback, cbData);
|
||||
}
|
||||
|
||||
function reloadWebCalendarCallback(http) {
|
||||
var cbData = http.callbackData;
|
||||
if (http.status == 200) {
|
||||
var result = http.responseText.evalJSON(true);
|
||||
var requireAuth = false;
|
||||
var success = false;
|
||||
if (result.status) {
|
||||
if (result.status == 401) {
|
||||
requireAuth = true;
|
||||
}
|
||||
else {
|
||||
if (result.status == 200) {
|
||||
success = true;
|
||||
}
|
||||
else {
|
||||
var errorMessage = _("An error occurred while importing calendar.");
|
||||
if (result["error"]) {
|
||||
var message = calendarReloadErrors[result["error"]];
|
||||
errorMessage = (_("An error occurred while loading remote"
|
||||
+ " calendar: %{0}.").formatted(message));
|
||||
}
|
||||
showAlertDialog (errorMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
var errorMessage = _("An error occurred while importing calendar.");
|
||||
if (result["error"]) {
|
||||
var message = calendarReloadErrors[result["error"]];
|
||||
errorMessage = (_("An error occurred while loading remote"
|
||||
+ " calendar: %{0}.").formatted(message));
|
||||
}
|
||||
showAlertDialog (errorMessage);
|
||||
}
|
||||
|
||||
if (requireAuth) {
|
||||
reauthenticateWebCalendar(cbData["folderID"], cbData);
|
||||
}
|
||||
else {
|
||||
var refreshOperations = cbData["refreshOperations"];
|
||||
if (refreshOperations) {
|
||||
var remaining = refreshOperations["remaining"];
|
||||
var calIdx = remaining.indexOf(cbData["folderID"]);
|
||||
remaining.splice(calIdx, 1);
|
||||
if (remaining.length == 0) {
|
||||
refreshEventsAndTasks();
|
||||
changeCalendarDisplay(null, currentView);
|
||||
}
|
||||
else {
|
||||
var newFolderID = remaining[0];
|
||||
reloadWebCalendar(newFolderID, refreshOperations);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (success) {
|
||||
refreshEventsAndTasks();
|
||||
changeCalendarDisplay(null, currentView);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
showAlertDialog(_("An error occurred while importing calendar."));
|
||||
var refreshOperations = cbData["refreshOperations"];
|
||||
if (refreshOperations) {
|
||||
var remaining = refreshOperations["remaining"];
|
||||
var calIdx = remaining.indexOf(cbData["folderID"]);
|
||||
remaining.splice(calIdx, 1);
|
||||
if (remaining.length > 0) {
|
||||
var newFolderID = remaining[0];
|
||||
reloadWebCalendar(newFolderID, refreshOperations);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function reauthenticateWebCalendar(folderID, refreshCBData) {
|
||||
var remoteURL = null;
|
||||
if (UserSettings['Calendar'] && UserSettings['Calendar']['WebCalendars']) {
|
||||
var webCalendars = UserSettings['Calendar']['WebCalendars'];
|
||||
remoteURL = webCalendars[folderID];
|
||||
}
|
||||
var parts = remoteURL.split("/");
|
||||
var hostname = parts[2];
|
||||
function authenticate(username, password) {
|
||||
disposeDialog();
|
||||
var url = URLForFolderID(folderID) + "/set-credentials";
|
||||
var parameters = ("username=" + encodeURIComponent(username)
|
||||
+ "&password=" + encodeURIComponent(password));
|
||||
triggerAjaxRequest(url, authenticateWebCalendarCallback, refreshCBData, parameters,
|
||||
{ "Content-type": "application/x-www-form-urlencoded" });
|
||||
}
|
||||
showAuthenticationDialog(_("Please identify yourself to \"%{0}\"...")
|
||||
.formatted(hostname),
|
||||
authenticate);
|
||||
}
|
||||
|
||||
function authenticateWebCalendarCallback(http) {
|
||||
var cbData = http.callbackData;
|
||||
var folderID = cbData["folderID"];
|
||||
var refreshOperations = cbData["refreshOperations"];
|
||||
if (isHttpStatus204(http.status)) {
|
||||
reloadWebCalendar(folderID, refreshOperations);
|
||||
}
|
||||
else {
|
||||
if (refreshOperations) {
|
||||
var remaining = refreshOperations["remaining"];
|
||||
var calIdx = remaining.indexOf(folderID);
|
||||
remaining.splice(calIdx, 1);
|
||||
if (remaining.length > 0) {
|
||||
var newFolderID = remaining[0];
|
||||
reloadWebCalendar(newFolderID, refreshOperations);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function scrollDayView(scrollEvent) {
|
||||
@@ -2567,29 +2722,51 @@ function onCalendarWebAdd(event) {
|
||||
}
|
||||
|
||||
function onCalendarWebAddConfirm() {
|
||||
disposeDialog();
|
||||
var calendarUrl = this.value;
|
||||
if (calendarUrl) {
|
||||
if (document.addWebCalendarRequest) {
|
||||
document.addWebCalendarRequest.aborted = true;
|
||||
document.addWebCalendarRequest.abort ();
|
||||
}
|
||||
var url = ApplicationBaseURL + "/addWebCalendar?url=" + escape (calendarUrl);
|
||||
document.addWebCalendarRequest =
|
||||
triggerAjaxRequest (url, addWebCalendarCallback);
|
||||
var url = ApplicationBaseURL + "/addWebCalendar"
|
||||
var parameters = "url=" + calendarUrl;
|
||||
triggerAjaxRequest(url, addWebCalendarCallback, calendarUrl, parameters,
|
||||
{ "Content-type": "application/x-www-form-urlencoded" });
|
||||
}
|
||||
disposeDialog();
|
||||
}
|
||||
function addWebCalendarCallback (http) {
|
||||
var data = http.responseText.evalJSON(true);
|
||||
if (data.imported >= 0) {
|
||||
appendCalendar(data.displayname, "/" + data.name);
|
||||
refreshEvents();
|
||||
refreshTasks();
|
||||
changeCalendarDisplay();
|
||||
|
||||
function addWebCalendarCallback(http) {
|
||||
if (http.status == 200) {
|
||||
var data = http.responseText.evalJSON(true);
|
||||
if (!data || data["error"] || !data["name"] || !data["folderID"]) {
|
||||
showAlertDialog (_("An error occurred while importing calendar."));
|
||||
}
|
||||
else {
|
||||
if (UserSettings['Calendar']) {
|
||||
var webCalendars = UserSettings['Calendar']['WebCalendars'];
|
||||
if (!webCalendars) {
|
||||
webCalendars = {};
|
||||
UserSettings['Calendar']['WebCalendars'] = webCalendars;
|
||||
}
|
||||
webCalendars[data["folderID"]] = http.callbackData;
|
||||
}
|
||||
|
||||
appendCalendar(data["name"], data["folderID"]);
|
||||
reloadWebCalendar(data["folderID"]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
showAlertDialog (_("An error occurred while importing calendar."));
|
||||
}
|
||||
|
||||
// if (data.imported) {
|
||||
// appendCalendar(data.displayname, "/" + data.name);
|
||||
// refreshEvents();
|
||||
// refreshTasks();
|
||||
// changeCalendarDisplay();
|
||||
// }
|
||||
// else if (data.status && data.status == 401) {
|
||||
// reauthenticateWebCalendar(data.name, data.url);
|
||||
// }
|
||||
// else {
|
||||
// }
|
||||
}
|
||||
|
||||
function onCalendarExport(event) {
|
||||
|
||||
Reference in New Issue
Block a user