Monotone-Parent: 7f6095f809b62253c184355dc35939b4fe3e2c53

Monotone-Revision: 45efb9e03119e3b3a03e6e1b4b2e0c17f37a7928

Monotone-Author: flachapelle@inverse.ca
Monotone-Date: 2007-10-23T14:39:29
Monotone-Branch: ca.inverse.sogo
This commit is contained in:
Francis Lachapelle 2007-10-23 14:39:29 +00:00
parent 043624b59e
commit 0eb260dacf
2 changed files with 97 additions and 51 deletions

View file

@ -1410,15 +1410,22 @@ function onCalendarAdd(event) {
preventDefault(event); preventDefault(event);
} }
function appendCalendar(folderName, folder) { function appendCalendar(folderName, folderPath) {
if (folder) var owner;
folder = accessToSubscribedFolder(folder);
if (folderPath) {
owner = getSubscribedFolderOwner(folderPath);
folderPath = accessToSubscribedFolder(folderPath);
}
else else
folder = "/" + folderName; folderPath = "/" + folderName;
// log ("append: " + folderName + "; folder: " + folder); if (!owner)
owner = UserLogin;
if ($(folder)) //log ("append name: " + folderName + "; path: " + folderPath + "; owner: " + owner);
if ($(folderPath))
window.alert(clabels["You have already subscribed to that folder!"]); window.alert(clabels["You have already subscribed to that folder!"]);
else { else {
var calendarList = $("calendarList"); var calendarList = $("calendarList");
@ -1427,8 +1434,34 @@ function appendCalendar(folderName, folder) {
//log ("color: " + color); //log ("color: " + color);
var li = document.createElement("li"); var li = document.createElement("li");
calendarList.appendChild(li);
li.setAttribute("id", folder); // Add the calendar to the proper place
for (var i = 0; i < lis.length; i++) {
var currentFolderName = lis[i].lastChild.nodeValue.strip();
if (lis[i].readAttribute('owner') != owner)
continue;
if (currentFolderName > folderName)
break;
}
if (i != lis.length) { // User is subscribed to other calendars of the same owner
calendarList.insertBefore(li, lis[i]);
}
else {
for (var i = 0; i < lis.length; i++) {
if (lis[i].readAttribute('owner') == UserLogin)
continue;
if (lis[i].readAttribute('owner') > owner) {
calendarList.insertBefore(li, lis[i]);
break;
}
}
if (i == lis.length) {
calendarList.appendChild(li);
}
}
li.setAttribute("id", folderPath);
li.setAttribute("owner", owner);
var checkBox = document.createElement("input"); var checkBox = document.createElement("input");
checkBox.setAttribute("type", "checkbox"); checkBox.setAttribute("type", "checkbox");
@ -1453,20 +1486,21 @@ function appendCalendar(folderName, folder) {
Event.observe(checkBox, "click", Event.observe(checkBox, "click",
updateCalendarStatus.bindAsEventListener(checkBox)); updateCalendarStatus.bindAsEventListener(checkBox));
var url = URLForFolderID(folder) + "/canAccessContent"; var url = URLForFolderID(folderPath) + "/canAccessContent";
triggerAjaxRequest(url, calendarEntryCallback, folder); triggerAjaxRequest(url, calendarEntryCallback, folderPath);
// Update CSS for events color
if (!document.styleSheets) return; if (!document.styleSheets) return;
var theRules = new Array(); var theRules = new Array();
var lastSheet = document.styleSheets[document.styleSheets.length - 1]; var lastSheet = document.styleSheets[document.styleSheets.length - 1];
if (lastSheet.insertRule) { // Mozilla if (lastSheet.insertRule) { // Mozilla
lastSheet.insertRule('.calendarFolder' + folder.substr(1) + ' {' lastSheet.insertRule('.calendarFolder' + folderPath.substr(1) + ' {'
+ ' background-color: ' + ' background-color: '
+ color + color
+ ' !important; }', 0); + ' !important; }', 0);
} }
else { // IE else { // IE
lastSheet.addRule('.calendarFolder' + folder.substr(1), lastSheet.addRule('.calendarFolder' + folderPath.substr(1),
' background-color: ' ' background-color: '
+ color + color
+ ' !important; }'); + ' !important; }');
@ -1483,26 +1517,30 @@ function onFolderSubscribeCB(folderData) {
function onFolderUnsubscribeCB(folderId) { function onFolderUnsubscribeCB(folderId) {
var node = $(folderId); var node = $(folderId);
node.parentNode.removeChild(node); node.parentNode.removeChild(node);
refreshEvents(); if (removeFolderRequestCount == 0) {
refreshTasks(); refreshEvents();
changeCalendarDisplay(); refreshTasks();
changeCalendarDisplay();
}
} }
function onCalendarRemove(event) { function onCalendarRemove(event) {
var nodes = $("calendarList").getSelectedNodes(); if (removeFolderRequestCount == 0) {
if (nodes.length > 0) { var nodes = $("calendarList").getSelectedNodes();
nodes[0].deselect(); for (var i = 0; i < nodes.length; i++) {
var folderId = nodes[0].getAttribute("id"); nodes[i].deselect();
var folderIdElements = folderId.split("_"); var folderId = nodes[i].getAttribute("id");
if (folderIdElements.length > 1) { var folderIdElements = folderId.split("_");
unsubscribeFromFolder(folderId, onFolderUnsubscribeCB, folderId); if (folderIdElements.length > 1) {
} unsubscribeFromFolder(folderId, onFolderUnsubscribeCB, folderId);
else { }
var calId = folderIdElements[0].substr(1); else {
deletePersonalCalendar(calId); var calId = folderIdElements[0].substr(1);
} deletePersonalCalendar(calId);
}
}
} }
preventDefault(event); preventDefault(event);
} }
@ -1510,13 +1548,9 @@ function deletePersonalCalendar(folderId) {
var label var label
= labels["Are you sure you want to delete the selected calendar?"]; = labels["Are you sure you want to delete the selected calendar?"];
if (window.confirm(label)) { if (window.confirm(label)) {
if (document.deletePersonalCalendarAjaxRequest) { removeFolderRequestCount++;
document.deletePersonalCalendarAjaxRequest.aborted = true;
document.deletePersonalCalendarAjaxRequest.abort();
}
var url = ApplicationBaseURL + "/" + folderId + "/deleteFolder"; var url = ApplicationBaseURL + "/" + folderId + "/deleteFolder";
document.deletePersonalCalendarAjaxRequest triggerAjaxRequest(url, deletePersonalCalendarCallback, folderId);
= triggerAjaxRequest(url, deletePersonalCalendarCallback, folderId);
} }
} }
@ -1536,11 +1570,13 @@ function deletePersonalCalendarCallback(http) {
else else
i++; i++;
} }
refreshEvents(); removeFolderRequestCount--;
refreshTasks(); if (removeFolderRequestCount == 0) {
changeCalendarDisplay(); refreshEvents();
refreshTasks();
changeCalendarDisplay();
}
} }
document.deletePersonalCalendarAjaxRequest = null;
} }
else else
log ("ajax problem 5: " + http.status); log ("ajax problem 5: " + http.status);

View file

@ -27,7 +27,6 @@ var logWindow = null;
var queryParameters; var queryParameters;
var activeAjaxRequests = 0;
var menus = new Array(); var menus = new Array();
var search = {}; var search = {};
var sorting = {}; var sorting = {};
@ -42,6 +41,10 @@ var allDocumentElements = null;
var userDefaults = null; var userDefaults = null;
var userSettings = null; var userSettings = null;
// Ajax requests counts
var activeAjaxRequests = 0;
var removeFolderRequestCount = 0;
/* a W3C compliant document.all */ /* a W3C compliant document.all */
function getAllScopeElements(scope) { function getAllScopeElements(scope) {
var elements = new Array(); var elements = new Array();
@ -1029,19 +1032,18 @@ function subscribeToFolder(refreshCallback, refreshCallbackData) {
rfCbData); rfCbData);
} }
else else
refreshCallbackData["window"].alert(clabels["You cannot subscribe to a folder that you own!"] refreshCallbackData["window"].alert(clabels["You cannot subscribe to a folder that you own!"]);
);
} }
function folderUnsubscriptionCallback(http) { function folderUnsubscriptionCallback(http) {
if (http.readyState == 4) { if (http.readyState == 4) {
removeFolderRequestCount--;
if (isHttpStatus204(http.status)) { if (isHttpStatus204(http.status)) {
if (http.callbackData) if (http.callbackData)
http.callbackData["method"](http.callbackData["data"]); http.callbackData["method"](http.callbackData["data"]);
} }
else else
window.alert(clabels["Unable to unsubscribe from that folder!"]); window.alert(clabels["Unable to unsubscribe from that folder!"]);
document.unsubscriptionAjaxRequest = null;
} }
} }
@ -1051,19 +1053,16 @@ function unsubscribeFromFolder(folder, refreshCallback, refreshCallbackData) {
refreshCallbackData); refreshCallbackData);
} }
else { else {
var folderData = folder.split("+"); var folderData = folder.split("_");
var username = folderData[0]; var username = folderData[0];
var folderPath = folderData[1]; var folderPath = folderData[1];
if (username.startsWith('/'))
username = username.substring(1);
if (username != UserLogin) { if (username != UserLogin) {
var url = (ApplicationBaseURL + folder + "/unsubscribe"); var url = (ApplicationBaseURL + folder + "/unsubscribe");
if (document.unsubscriptionAjaxRequest) { removeFolderRequestCount++;
document.unsubscriptionAjaxRequest.aborted = true;
document.unsubscriptionAjaxRequest.abort();
}
var rfCbData = { method: refreshCallback, data: refreshCallbackData }; var rfCbData = { method: refreshCallback, data: refreshCallbackData };
document.unsubscriptionAjaxRequest triggerAjaxRequest(url, folderUnsubscriptionCallback, rfCbData);
= triggerAjaxRequest(url, folderUnsubscriptionCallback,
rfCbData);
} }
else else
window.alert(clabels["You cannot unsubscribe from a folder that you own!"]); window.alert(clabels["You cannot unsubscribe from a folder that you own!"]);
@ -1084,6 +1083,17 @@ function accessToSubscribedFolder(serverFolder) {
return folder; return folder;
} }
function getSubscribedFolderOwner(serverFolder) {
var owner;
var parts = serverFolder.split(":");
if (parts.length > 1) {
owner = parts[0];
}
return owner;
}
function listRowMouseDownHandler(event) { function listRowMouseDownHandler(event) {
preventDefault(event); preventDefault(event);
//Event.stop(event); //Event.stop(event);
@ -1414,7 +1424,7 @@ function createFolderCallback(http) {
var data = http.callbackData; var data = http.callbackData;
if (http.status == 201) { if (http.status == 201) {
if (data.okCB) if (data.okCB)
data.okCB(data.name, "/" + http.responseText); data.okCB(data.name, "/" + http.responseText, UserLogin);
} }
else { else {
if (data.notOkCB) if (data.notOkCB)