From 86552ffc8f0f76651747a1faaed9bbda6d015f98 Mon Sep 17 00:00:00 2001
From: Thomas Bruederli <thomas@roundcube.net>
Date: Thu, 07 Feb 2013 09:35:30 -0500
Subject: [PATCH] Finish hierarchical groups browsing in LDAP address books; add according UI elements and styles to the skins; adapt habavior of the compose address book widget

---
 program/js/app.js |   84 +++++++++++++++++++++++++++++++----------
 1 files changed, 63 insertions(+), 21 deletions(-)

diff --git a/program/js/app.js b/program/js/app.js
index 0445004..31a96b5 100644
--- a/program/js/app.js
+++ b/program/js/app.js
@@ -251,7 +251,7 @@
           }
         }
         else if (this.env.action == 'compose') {
-          this.env.compose_commands = ['send-attachment', 'remove-attachment', 'send', 'cancel', 'toggle-editor', 'list-adresses', 'search', 'reset-search', 'extwin'];
+          this.env.compose_commands = ['send-attachment', 'remove-attachment', 'send', 'cancel', 'toggle-editor', 'list-adresses', 'pushgroup', 'search', 'reset-search', 'extwin'];
 
           if (this.env.drafts_mailbox)
             this.env.compose_commands.push('savedraft')
@@ -323,6 +323,8 @@
 
         this.enable_command('add', 'import', this.env.writable_source);
         this.enable_command('list', 'listgroup', 'pushgroup', 'listsearch', 'advanced-search', true);
+
+        this.env.address_group_stack = [];
 
         if (this.gui_objects.contactslist) {
           this.contact_list = new rcube_list_widget(this.gui_objects.contactslist,
@@ -1081,7 +1083,11 @@
         break;
 
       case 'pushgroup':
-        // TODO: so some magic stuff here
+        // add group ID to stack
+        this.env.address_group_stack.push(props.id);
+        if (obj && event)
+          rcube_event.cancel(event);
+
       case 'listgroup':
         this.reset_qsearch();
         this.list_contacts(props.source, props.id);
@@ -3061,7 +3067,13 @@
 
   this.compose_recipient_select = function(list)
   {
-    this.enable_command('add-recipient', list.selection.length > 0);
+    var id, n, recipients = 0;
+    for (n=0; n < list.selection.length; n++) {
+      id = list.selection[n];
+      if (this.env.contactdata[id])
+        recipients++;
+    }
+    this.enable_command('add-recipient', recipients);
   };
 
   this.compose_add_recipient = function(field)
@@ -4030,7 +4042,7 @@
     if (this.preview_timer)
       clearTimeout(this.preview_timer);
 
-    var n, id, sid, ref = this, writable = false,
+    var n, id, sid, contact, ref = this, writable = false,
       source = this.env.source ? this.env.address_sources[this.env.source] : null;
 
     if (id = list.get_single_selection())
@@ -4044,29 +4056,35 @@
       // we'll also need to know sources used in selection for copy
       // and group-addmember operations (drag&drop)
       this.env.selection_sources = [];
-      if (!source) {
-        for (n in list.selection) {
+
+      if (source) {
+        this.env.selection_sources.push(this.env.source);
+      }
+
+      for (n in list.selection) {
+        contact = list.data[list.selection[n]];
+        if (!source) {
           sid = String(list.selection[n]).replace(/^[^-]+-/, '');
           if (sid && this.env.address_sources[sid]) {
-            writable = writable || !this.env.address_sources[sid].readonly;
+            writable = writable || (!this.env.address_sources[sid].readonly && !contact.readonly);
             this.env.selection_sources.push(sid);
           }
         }
-        this.env.selection_sources = $.unique(this.env.selection_sources);
+        else {
+          writable = writable || (!source.readonly && !contact.readonly);
+        }
       }
-      else {
-        this.env.selection_sources.push(this.env.source);
-        writable = !source.readonly;
-      }
+
+      this.env.selection_sources = $.unique(this.env.selection_sources);
     }
 
     // if a group is currently selected, and there is at least one contact selected
     // thend we can enable the group-remove-selected command
-    this.enable_command('group-remove-selected', this.env.group && list.selection.length > 0);
+    this.enable_command('group-remove-selected', this.env.group && list.selection.length > 0 && writable);
     this.enable_command('compose', this.env.group || list.selection.length > 0);
     this.enable_command('export-selected', list.selection.length > 0);
     this.enable_command('edit', id && writable);
-    this.enable_command('delete', list.selection.length && writable);
+    this.enable_command('delete', list.selection.length > 0 && writable);
 
     return false;
   };
@@ -4094,10 +4112,28 @@
     else if (!this.env.search_request)
       folder = group ? 'G'+src+group : src;
 
-    this.select_folder(folder, '', true);
-
     this.env.source = src;
     this.env.group = group;
+
+    // truncate groups listing stack
+    var index = $.inArray(this.env.group, this.env.address_group_stack);
+    if (index < 0)
+      this.env.address_group_stack = [];
+    else
+      this.env.address_group_stack = this.env.address_group_stack.slice(0,index);
+
+    // make sure the current group is on top of the stack
+    if (this.env.group) {
+      this.env.address_group_stack.push(this.env.group);
+
+      // mark the first group on the stack as selected in the directory list
+      folder = 'G'+src+this.env.address_group_stack[0];
+    }
+    else if (this.gui_objects.addresslist_title) {
+        $(this.gui_objects.addresslist_title).html(this.get_label('contacts'));
+    }
+
+    this.select_folder(folder, '', true);
 
     // load contacts remotely
     if (this.gui_objects.contactslist) {
@@ -4160,15 +4196,19 @@
     this.enable_command('compose', this.env.group ? true : false);
   };
 
+  this.set_group_prop = function(prop)
+  {
+    if (this.gui_objects.addresslist_title)
+      $(this.gui_objects.addresslist_title).html(prop.name);
+
+    this.triggerEvent('groupupdate', prop);
+  };
+
   // load contact record
   this.load_contact = function(cid, action, framed)
   {
     var win, url = {}, target = window,
       rec = this.contact_list.data[cid];
-
-    if (rec && rec.type == 'group') {
-      alert('group ' + cid)
-    }
 
     if (win = this.get_frame_window(this.env.contentframe)) {
       url._framed = 1;
@@ -4178,7 +4218,9 @@
       // load dummy content, unselect selected row(s)
       if (!cid)
         this.contact_list.clear_selection();
-      this.enable_command('delete', 'compose', 'export-selected', cid);
+
+      this.enable_command('compose', rec.email);
+      this.enable_command('export-selected', rec._type != 'group');
     }
     else if (framed)
       return false;

--
Gitblit v1.9.1