1
0
mirror of https://github.com/owncloudarchive/contacts.git synced 2025-02-07 01:54:16 +01:00

Finished implementing favorites.

This commit is contained in:
Thomas Tanghus 2012-10-22 15:35:33 +02:00
parent 3bbf951fda
commit 148c69ac33
5 changed files with 168 additions and 29 deletions

View File

@ -26,4 +26,12 @@ foreach($categories as &$category) {
$category['contacts'] = $ids;
}
OCP\JSON::success(array('data' => array('categories'=>$categories)));
$favorites = $catmgr->getFavorites();
OCP\JSON::success(array(
'data' => array(
'categories' => $categories,
'favorites' => $favorites,
)
)
);

View File

@ -54,10 +54,12 @@ dl.form { display: inline-block; width: auto; margin: 0; padding: 0; cursor: nor
.download { background:url('%webroot%/core/img/actions/download.svg') no-repeat center; }
.cloud { background:url('%webroot%/core/img/places/picture.svg') no-repeat center; }
.globe { background:url('%webroot%/core/img/actions/public.svg') no-repeat center; }
.starred { display: inline-block; height: 22px; width: 22px; padding: 0; margin: 0; background:url('%appswebroot%/contacts/img/starred.png') no-repeat center; }
.transparent{ opacity: 0.6; }
.float { float: left; display: inline-block; width: auto; }
.break { clear: both; }
.loading { background: url('%webroot%/core/img/loading.gif') no-repeat center !important; /*cursor: progress; */ cursor: wait; }
.wait { opacity: cursor: wait; }
.control {
border: 1px solid #DDDDDD;
border-radius: 0.3em;
@ -87,7 +89,7 @@ dl.addresscard .action { float: right; }
/* Properties */
.fullname { font-weight:bold; font-size:1.5em; width: 18em; }
.singleproperties{ display: inline-block; float: left; width: 20em;}
.singleproperties{ display: inline-block; float: left; width: 25em;}
.propertylist li.propertycontainer { white-space: nowrap; min-width: 38em; display: block; clear: both; }
.propertylist li.propertycontainer > .listactions { display: inline-block; position: absolute; clear: none; opacity: 0; }
@ -153,7 +155,9 @@ input.propertytype { float: left; font-size: .8em; width: 8em !important; direct
#phototools li a { float:left; cursor:pointer; width:22px; height:22px; opacity: 0.6; }
#phototools li a:hover { opacity: 0.8; }
#contactphoto_fileupload, #import_fileupload { -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=0)"; filter:alpha(opacity=0); opacity:0; z-index:1001; width:0; height:0;}
.favorite { display: inline-block; float: left; height: 20px; width: 20px; background:url('%appswebroot%/contacts/img/inactive_star.png') no-repeat center; }
.favorite.active, .favorite:hover { background:url('%appswebroot%/contacts/img/active_star.png') no-repeat center; }
.favorite.inactive { background:url('%appswebroot%/contacts/img/inactive_star.png') no-repeat center; }
/* Header */
#contactsheader { position: fixed; padding: 0; margin:0; top:3.5em; left: 32.5em; right: 0; height: 4em; border-bottom: 1px solid #DDDDDD; z-index: 50; }

105
js/app.js
View File

@ -110,10 +110,57 @@ GroupList.prototype.findById = function(id) {
return this.$groupList.find('h3[data-id="' + id + '"]');
}
GroupList.prototype.isFavorite = function(contactid) {
var $groupelem = this.findById('fav');
var contacts = $groupelem.data('contacts');
return (contacts.indexOf(contactid) !== -1);
}
GroupList.prototype.setAsFavorite = function(contactid, state, cb) {
contactid = parseInt(contactid);
var $groupelem = this.findById('fav');
var contacts = $groupelem.data('contacts');
if(state) {
OCCategories.addToFavorites(contactid, 'contact', function(jsondata) {
if(jsondata.status === 'success') {
contacts.push(contactid);
$groupelem.data('contacts', contacts);
$groupelem.find('.numcontacts').text(contacts.length);
if(contacts.length > 0 && $groupelem.is(':hidden')) {
$groupelem.show();
}
}
if(typeof cb === 'function') {
cb(jsondata);
} else if(jsondata.status !== 'success') {
OC.notify({message:t('contacts', jsondata.data.message)});
}
});
} else {
OCCategories.removeFromFavorites(contactid, 'contact', function(jsondata) {
if(jsondata.status === 'success') {
contacts.splice(contacts.indexOf(contactid), 1);
//console.log('contacts', contacts, contacts.indexOf(id), contacts.indexOf(String(id)));
$groupelem.data('contacts', contacts);
$groupelem.find('.numcontacts').text(contacts.length);
if(contacts.length === 0 && $groupelem.is(':visible')) {
$groupelem.hide();
}
}
if(typeof cb === 'function') {
cb(jsondata);
} else if(jsondata.status !== 'success') {
OC.notify({message:t('contacts', jsondata.data.message)});
}
});
}
}
GroupList.prototype.addTo = function(contactid, groupid, cb) {
console.log('GroupList.addTo', contactid, groupid);
var $groupelem = this.findById(groupid);
var contacts = $groupelem.data('contacts');
if(contacts.indexOf(String(contactid)) === -1) {
if(contacts.indexOf(contactid) === -1) {
$.post(OC.filePath('contacts', 'ajax', 'categories/addto.php'), {contactid: contactid, categoryid: groupid},function(jsondata) {
if(!jsondata) {
OC.notify({message:t('contacts', 'Network or server error. Please inform administrator.')});
@ -248,9 +295,22 @@ GroupList.prototype.loadGroups = function(numcontacts, cb) {
var tmpl = this.$groupListItemTemplate;
tmpl.octemplate({id: 'all', type: 'all', num: numcontacts, name: t('contacts', 'All')}).appendTo($groupList);
tmpl.octemplate({id: 'fav', type: 'fav', num: '', name: t('contacts', 'Favorites')}).appendTo($groupList);
$.getJSON(OC.filePath('contacts', 'ajax', 'categories/list.php'), {}, function(jsondata) {
if (jsondata && jsondata.status == 'success') {
// Favorites
var contacts = $.map(jsondata.data.favorites, function(c) {return parseInt(c)});
var $elem = tmpl.octemplate({
id: 'fav',
type: 'fav',
num: contacts.length,
name: t('contacts', 'Favorites')
}).appendTo($groupList);
$elem.data('contacts', contacts).find('.numcontacts').before('<span class="starred" />');
if(contacts.length === 0) {
$elem.hide();
}
console.log('favorites', $elem.data('contacts'));
// Normal groups
$.each(jsondata.data.categories, function(c, category) {
var contacts = $.map(category.contacts, function(c) {return parseInt(c)});
var $elem = (tmpl).octemplate({
@ -258,7 +318,7 @@ GroupList.prototype.loadGroups = function(numcontacts, cb) {
type: 'category',
num: contacts.length,
name: category.name,
})
});
self.categories.push({id: category.id, name: category.name});
$elem.data('contacts', contacts)
$elem.data('name', category.name)
@ -486,6 +546,24 @@ OC.Contacts = OC.Contacts || {
console.log('request.addressbook.activate', result);
self.Contacts.showFromAddressbook(result.id, result.activate);
});
$(document).bind('request.setasfavorite', function(e, result) {
console.log('request.setasfavorite', result);
self.Groups.setAsFavorite(result.id, result.state, function(jsondata) {
if(jsondata.status === 'success') {
$(document).trigger('status.contact.favoritestate', {
status: 'success',
id: result.id,
state: result.state,
});
} else {
OC.notify({message:t('contacts', jsondata.data.message)});
$(document).trigger('status.contact.favoritestate', {
status: 'error',
});
}
});
});
// mark items whose title was hid under the top edge as read
/*this.$rightContent.scroll(function() {
// prevent too many scroll requests;
@ -660,12 +738,19 @@ OC.Contacts = OC.Contacts || {
self.$toggleAll.show();
self.showActions(['add', 'delete']);
$(this).addClass('active');
if($(this).data('type') === 'category') {
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($(this).data('id'));
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.)
@ -853,6 +938,16 @@ OC.Contacts = OC.Contacts || {
this.$contactList.hide();
this.$toggleAll.hide();
var $contactelem = this.Contacts.showContact(this.currentid);
var self = this;
// FIXME: This should (maybe) be an argument to the Contact
setTimeout(function() {
var state = self.Groups.isFavorite(self.currentid);
$(document).trigger('status.contact.favoritestate', {
status: 'success',
id: self.currentid,
state: state,
});
}, 2000);
this.$rightContent.prepend($contactelem);
this.buildGroupSelect();
},

View File

@ -291,6 +291,37 @@ OC.Contacts = OC.Contacts || {};
console.log('change', event);
self.saveProperty({obj:event.target});
});
this.$fullelem.on('click', '.favorite', function(event) {
if(typeof self.is_favorite === 'undefined') {
console.log('Favorite state not set yet.');
self.is_favorite == false;
}
console.log('favorite', event);
$(this).addClass('wait');
$(document).trigger('request.setasfavorite', {
id: self.id,
state: !self.is_favorite,
});
});
$(document).bind('status.contact.favoritestate', function(e, result) {
console.log('status.contact.favoritestate', result);
if(parseInt(result.id) !== parseInt(self.id)) {
console.log(result.id, 'is not me:', self.id);
return;
}
var $favstar = self.$fullelem.find('.favorite');
$favstar.removeClass('wait');
if(result.status === 'success') {
self.is_favorite = result.state;
if(result.state === true) {
$favstar.removeClass('inactive').addClass('active');
} else {
$favstar.removeClass('active').addClass('inactive');
}
} else {
// TODO:...
}
});
this.$fullelem.find('form').on('submit', function(event) {
console.log('submit', this, event);
return false;

View File

@ -120,6 +120,7 @@
<li><a class="svg cloud" title="<?php echo $l->t('Select photo from ownCloud'); ?>"></a></li>
</ul>
</div>
<a class="favorite"></a>
<div class="singleproperties">
<input class="fullname value propertycontainer" data-element="fn" type="text" name="value" value="{name}" />
<dl class="form">