]> err.no Git - scalable-opengroupware.org/blobdiff - UI/WebServerResources/ContactsUI.js
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1305 d1b88da0-ebda-0310...
[scalable-opengroupware.org] / UI / WebServerResources / ContactsUI.js
index 8b449799ce4ffa3e12c4fc62555f7369f027a3f8..21c9872f293df3add7507a16c1b3451bcb4e6d00 100644 (file)
@@ -310,20 +310,20 @@ function onMenuEditContact(event) {
 }
 
 function onMenuWriteToContact(event) {
-   var contactId = document.menuTarget.getAttribute('id');
-   var contactRow = $(contactId);
-   var emailCell = contactRow.down('td', 1);
+  var contactId = document.menuTarget.getAttribute('id');
+  var contactRow = $(contactId);
+  var emailCell = contactRow.down('td', 1);
 
-   if (!emailCell.firstChild) { // .nodeValue is the contact email address
-     window.alert(labels["The selected contact has no email address."]);
-     return false;
-   }
+  if (!emailCell.firstChild) { // .nodeValue is the contact email address
+    window.alert(labels["The selected contact has no email address."]);
+    return false;
+  }
 
-   openMailComposeWindow(ApplicationBaseURL + currentContactFolder
-                        + "/" + contactId + "/write");
+  openMailComposeWindow(ApplicationBaseURL + currentContactFolder
+                       + "/" + contactId + "/write");
 
-   if (document.body.hasClassName("popup"))
-     window.close();
+  if (document.body.hasClassName("popup"))
+    window.close();
 }
 
 function onMenuDeleteContact(event) {
@@ -334,6 +334,11 @@ function onToolbarEditSelectedContacts(event) {
   var contactsList = $('contactsList');
   var rows = contactsList.getSelectedRowsId();
 
+  if (rows.length == 0) {
+    window.alert(labels["Please select a contact."]);
+    return false;
+  }
+
   for (var i = 0; i < rows.length; i++) {
     openContactWindow(URLForFolderID(currentContactFolder)
                       + "/" + rows[i] + "/edit", rows[i]);
@@ -347,8 +352,10 @@ function onToolbarWriteToSelectedContacts(event) {
   var rows = contactsList.getSelectedRowsId();
   var rowsWithEmail = 0;
 
-  if (rows.length == 0)
+  if (rows.length == 0) {
+    openMailComposeWindow(ApplicationBaseURL + "Mail/compose");
     return false;
+  }
 
   for (var i = 0; i < rows.length; i++) {
     var emailCell = $(rows[i]).down('td', 1);
@@ -373,6 +380,11 @@ function uixDeleteSelectedContacts(sender) {
   var contactsList = $('contactsList');
   var rows = contactsList.getSelectedRowsId();
 
+  if (rows.length == 0) {
+    window.alert(labels["Please select a contact."]);
+    return false;
+  }
+
   var contactView = $('contactView');
   contactView.innerHTML = '';
 
@@ -520,19 +532,40 @@ function onAddressBookNew(event) {
 }
 
 function appendAddressBook(name, folder) {
-  if (folder)
+  var owner;
+  var result = true;
+
+  if (folder) {
+    owner = getSubscribedFolderOwner(folder);
     folder = accessToSubscribedFolder(folder);
+  }
   else
     folder = "/" + name;
+  
+  if (!owner)
+    owner = UserLogin;
+
   if ($(folder))
-    window.alert(clabels["You have already subscribed to that folder!"]);
+    result = false;
   else {
+    var contactFolders = $("contactFolders");
+    var items = contactFolders.childNodesWithTag("li");
     var li = document.createElement("li");
-    $("contactFolders").appendChild(li);
+
+    // Add the calendar to the proper place
+    var i = getListIndexForFolder(items, owner, name);
+    if (i != items.length) // User is subscribed to other calendars of the same owner
+      contactFolders.insertBefore(li, items[i]);
+    else 
+      contactFolders.appendChild(li);
+
     li.setAttribute("id", folder);
+    li.setAttribute("owner", owner);
     li.appendChild(document.createTextNode(name));
     setEventsOnContactFolder(li);
   }
+
+  return result;
 }
 
 function newFolderCallback(http) {
@@ -746,12 +779,18 @@ function onContactFoldersMenuPrepareVisibility() {
 
   if (selected.length > 0) {
     var folderOwner = selected[0].getAttribute("owner");
+    var modifyOption = $(this).down("ul").childElements().first();
     var sharingOption = $(this).down("ul").childElements().last();
-    // Disable the "Sharing" option when address book is not owned by user
-    if (folderOwner == UserLogin || IsSuperUser)
+    // Disable the "Sharing" and "Modify" options when address book
+    // is not owned by user
+    if (folderOwner == UserLogin || IsSuperUser) {
+      modifyOption.removeClassName("disabled");
       sharingOption.removeClassName("disabled");
-    else
+    }
+    else {
+      modifyOption.addClassName("disabled");
       sharingOption.addClassName("disabled");
+    }
   }
 }