From e8fd39d12b4649d94d63d220d2201169b6dece08 Mon Sep 17 00:00:00 2001
From: Thomas Bruederli <thomas@roundcube.net>
Date: Tue, 05 Feb 2013 11:30:01 -0500
Subject: [PATCH] Fix inserting a new contact group when list is still empty

---
 program/js/treelist.js |   12 +++++++-----
 program/js/app.js      |    5 ++++-
 2 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/program/js/app.js b/program/js/app.js
index 7c6dba8..57ef903 100644
--- a/program/js/app.js
+++ b/program/js/app.js
@@ -4438,7 +4438,10 @@
       this.name_input_li = $('<li>').addClass(type).append(this.name_input);
 
       var li = type == 'contactsearch' ? $('li:last', this.gui_objects.folderlist) : $('ul.groups li:last', this.get_folder_li(this.env.source,'',true));
-      this.name_input_li.insertAfter(li);
+      if (li.length)
+        this.name_input_li.insertAfter(li);
+      else
+        this.name_input_li.appendTo(type == 'contactsearch' ? this.gui_objects.folderlist : $('ul.groups', this.get_folder_li(this.env.source,'',true)));
     }
 
     this.name_input.select().focus();
diff --git a/program/js/treelist.js b/program/js/treelist.js
index 4beaada..d6d50e4 100644
--- a/program/js/treelist.js
+++ b/program/js/treelist.js
@@ -263,7 +263,7 @@
 		if (sibling) {
 			li.insertAfter(sibling);
 		}
-		else {
+		else if (first.id != myid) {
 			li.insertBefore(first);
 		}
 
@@ -380,18 +380,20 @@
 	{
 		var result = [];
 		ul.children('li').each(function(i,e){
-			var li = $(e);
+			var li = $(e), sublist = li.children('ul');
 			var node = {
 				id: dom2id(li),
 				classes: li.attr('class').split(' '),
 				virtual: li.hasClass('virtual'),
 				html: li.children().first().get(0).outerHTML,
-				children: walk_list(li.children('ul'))
+				children: walk_list(sublist)
 			}
 
+			if (sublist.length) {
+				node.childlistclass = sublist.attr('class');
+			}
 			if (node.children.length) {
-				node.childlistclass = li.children('ul').attr('class');
-				node.collapsed = li.children('ul').css('display') == 'none';
+				node.collapsed = sublist.css('display') == 'none';
 			}
 			if (li.hasClass('selected')) {
 				selection = node.id;

--
Gitblit v1.9.1