From bc727eeba43c9f60f4d4647d35eb584444f0f40e Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Fri, 26 Oct 2012 01:57:16 +0200 Subject: [PATCH] Make groups sortable. --- ajax/categories/list.php | 4 ++++ js/app.js | 38 +++++++++++++++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/ajax/categories/list.php b/ajax/categories/list.php index dd2937b6..077fa99e 100644 --- a/ajax/categories/list.php +++ b/ajax/categories/list.php @@ -37,6 +37,10 @@ OCP\JSON::success(array( OCP\User::getUser(), 'contacts', 'lastgroup', 'all'), + 'sortorder' => OCP\Config::getUserValue( + OCP\User::getUser(), + 'contacts', + 'groupsort', ''), ) ) ); diff --git a/js/app.js b/js/app.js index 79fd1a81..3754390f 100644 --- a/js/app.js +++ b/js/app.js @@ -338,6 +338,8 @@ GroupList.prototype.loadGroups = function(numcontacts, cb) { $.getJSON(OC.filePath('contacts', 'ajax', 'categories/list.php'), {}, function(jsondata) { if (jsondata && jsondata.status == 'success') { self.lastgroup = jsondata.data.lastgroup; + self.sortorder = $.map(jsondata.data.sortorder.split(','), function(c) {return parseInt(c)}); + console.log('sortorder', self.sortorder); // Favorites var contacts = $.map(jsondata.data.favorites, function(c) {return parseInt(c)}); var $elem = tmpl.octemplate({ @@ -378,6 +380,17 @@ GroupList.prototype.loadGroups = function(numcontacts, cb) { }); $elem.appendTo($groupList); }); + + var elems = $groupList.find('h3[data-type="category"]').get(); + + elems.sort(function(a, b) { + return self.sortorder.indexOf(parseInt($(a).data('id'))) > self.sortorder.indexOf(parseInt($(b).data('id'))); + }); + + $.each(elems, function(index, elem) { + $groupList.append(elem); + }); + // Shared addressbook $.each(jsondata.data.shared, function(c, shared) { var sharedindicator = '