diff --git a/ajax/categories/list.php b/ajax/categories/list.php index 1af6a8b5..77557396 100644 --- a/ajax/categories/list.php +++ b/ajax/categories/list.php @@ -32,6 +32,10 @@ OCP\JSON::success(array( 'data' => array( 'categories' => $categories, 'favorites' => $favorites, + 'lastgroup' => OCP\Config::getUserValue( + OCP\User::getUser(), + 'contacts', + 'lastgroup', 'all'), ) ) ); diff --git a/css/contacts.css b/css/contacts.css index ce0dbb7e..13fc122d 100644 --- a/css/contacts.css +++ b/css/contacts.css @@ -196,7 +196,7 @@ input.propertytype { float: left; font-size: .8em; width: 8em !important; direct /* contact list */ #contactlist { position: relative; top: 0; left: 0; right: 0; width: 100%; } -#contactlist tr { height: 3em; } +#contactlist tr { height: 3em; display: none; } #contactlist tr.active, #contactlist tr:hover { background-color: #eee; } #contactlist tr > td { border-bottom: 1px solid #DDDDDD; font-weight: normal; text-align: left; overflow: hidden; text-overflow: ellipsis; vertical-align: middle; white-space: nowrap; } #contactlist tr > td:hover { overflow: inherit; text-overflow: inherit; background-color: #fff; z-index: 200; } diff --git a/js/app.js b/js/app.js index 59cb92cd..79410cb1 100644 --- a/js/app.js +++ b/js/app.js @@ -98,6 +98,20 @@ OC.notify = function(params) { var GroupList = function(groupList, listItemTmpl) { this.$groupList = groupList; + var self = this; + this.$groupList.on('click', 'h3', function(event) { + if(wrongKey(event)) { + return; + } + self.$groupList.find('h3').removeClass('active'); + $(this).addClass('active'); + self.lastgroup = $(this).data('id'); + $(document).trigger('status.group.selected', { + id: self.lastgroup, + type: $(this).data('type'), + contacts: $(this).data('contacts'), + }); + }); this.$groupListItemTemplate = listItemTmpl; this.categories = []; } @@ -114,6 +128,10 @@ GroupList.prototype.isFavorite = function(contactid) { return this.inGroup(contactid, 'fav'); } +GroupList.prototype.selectGroup = function(groupid) { + console.log('selectGroup', groupid); +} + GroupList.prototype.inGroup = function(contactid, groupid) { var $groupelem = this.findById(groupid); var contacts = $groupelem.data('contacts'); @@ -301,6 +319,7 @@ GroupList.prototype.loadGroups = function(numcontacts, cb) { tmpl.octemplate({id: 'all', type: 'all', num: numcontacts, name: t('contacts', 'All')}).appendTo($groupList); $.getJSON(OC.filePath('contacts', 'ajax', 'categories/list.php'), {}, function(jsondata) { if (jsondata && jsondata.status == 'success') { + self.lastgroup = jsondata.data.lastgroup; // Favorites var contacts = $.map(jsondata.data.favorites, function(c) {return parseInt(c)}); var $elem = tmpl.octemplate({ @@ -329,6 +348,13 @@ GroupList.prototype.loadGroups = function(numcontacts, cb) { $elem.data('id', category.id) $elem.appendTo($groupList); }); + var $elem = self.findById(self.lastgroup); + $elem.addClass('active'); + $(document).trigger('status.group.selected', { + id: self.lastgroup, + type: $elem.data('type'), + contacts: $elem.data('contacts'), + }); } // TODO: else if(typeof cb === 'function') { cb(); @@ -568,6 +594,32 @@ OC.Contacts = OC.Contacts || { } }); }); + // Group selected, only show contacts from that group + $(document).bind('status.group.selected', function(e, result) { + console.log('status.group.selected', result); + self.currentgroup = result.id; + // Close any open contact. + if(self.currentid) { + var id = self.currentid; + self.closeContact(id); + self.Contacts.jumpToContact(id); + } + self.$contactList.show(); + self.$toggleAll.show(); + self.showActions(['add', 'delete']); + if(result.type === 'category' || result.type === 'fav') { + console.log('contacts', $(this).data('contacts')); + self.Contacts.showContacts(result.contacts); + } else { + self.Contacts.showContacts(self.currentgroup); + } + $.post(OC.filePath('contacts', 'ajax', 'setpreference.php'), {'key':'lastgroup', 'value':self.currentgroup}, function(jsondata) { + if(jsondata.status !== 'success') { + OC.notify({message: jsondata.data.message}); + } + }); + self.$rightContent.scrollTop(0); + }); // mark items whose title was hid under the top edge as read /*this.$rightContent.scroll(function() { // prevent too many scroll requests; @@ -727,36 +779,6 @@ OC.Contacts = OC.Contacts || { }); console.log('groups', $opt.parent().data('action'), $opt.val(), $opt.text()); }); - // Group selected, only show contacts from that group - this.$groupList.on('click', 'h3', function() { - self.currentgroup = $(this).data('id'); - console.log('Group click', $(this).data('id'), $(this).data('type')); - // Close any open contact. - if(self.currentid) { - var id = self.currentid; - self.closeContact(id); - self.Contacts.jumpToContact(id); - } - self.$groupList.find('h3').removeClass('active'); - self.$contactList.show(); - self.$toggleAll.show(); - self.showActions(['add', 'delete']); - $(this).addClass('active'); - var gtype = $(this).data('type'); - var gid = $(this).data('id'); - if(gtype === 'category' || gtype === 'fav') { - console.log('contacts', $(this).data('contacts')); - self.Contacts.showContacts($(this).data('contacts')); - } else { - self.Contacts.showContacts(gid); - } - $.post(OC.filePath('contacts', 'ajax', 'setpreference.php'), {'key':'lastgroup', 'value':gid}, function(jsondata) { - if(jsondata.status !== 'success') { - OC.notify({message: jsondata.data.message}); - } - }); - self.$rightContent.scrollTop(0); - }); // Contact list. Either open a contact or perform an action (mailto etc.) this.$contactList.on('click', 'tr', function(event) { if($(event.target).is('input')) {