Skip to content

Commit 1cd2a98

Browse files
committed
Merge pull request mozilla-b2g#2705 from albertopq/contacts-bugfixing
[Contacts] Moving favorite button to the "contact details" view
2 parents d59fff1 + 0779ba2 commit 1cd2a98

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

apps/contacts/index.html

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ <h1 id='org-title'></h1>
163163
<!-- Iterating mails, phones, addresses adn comments here -->
164164
</ul>
165165
</div>
166+
<hr/>
167+
<button onclick='Contacts.toggleFavorite(); return false;' id='toggle-favorite' class="fillflow-row action action-add">
168+
<b>Add as favorite</b>
169+
</button>
166170
</section>
167171
</div>
168172
</article>
@@ -329,11 +333,6 @@ <h1 id='contact-form-title'></h1>
329333
<span role="button" class="icon-add"></span>
330334
<b>Add comment</b>
331335
</button>
332-
333-
<hr/>
334-
<button onclick='Contacts.toggleFavorite(); return false;' id='toggle-favorite' class="fillflow-row action action-add">
335-
<b>Add as favorite</b>
336-
</button>
337336
</form>
338337

339338
<button id='delete-contact' class="hide fillflow-row action action-delete">

apps/contacts/js/contacts.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ var Contacts = (function() {
323323
//
324324
var reloadContactDetails = function reloadContactDetails() {
325325
var contact = currentContact;
326+
toggleFavoriteMessage(isFavorite(currentContact));
326327
detailsName.textContent = contact.name;
327328
if (contact.category && contact.category.indexOf('favorite') != -1) {
328329
detailsName.innerHTML += '<sup></sup>';
@@ -459,7 +460,6 @@ var Contacts = (function() {
459460
numberEmails++;
460461
}
461462

462-
toggleFavoriteMessage(isFavorite(currentContact));
463463
for (var adr in currentContact.adr) {
464464
var currentAddress = currentContact.adr[adr];
465465
var default_type = TAG_OPTIONS['address-type'][0].value;
@@ -657,6 +657,21 @@ var Contacts = (function() {
657657
delete currentContact.category[pos];
658658
}
659659
}
660+
661+
var request = navigator.mozContacts.save(currentContact);
662+
request.onsuccess = function onsuccess() {
663+
var cList = contacts.List;
664+
cList.getContactById(currentContact.id, function onSuccess(savedContact) {
665+
currentContact = savedContact;
666+
contactsList.refresh(currentContact);
667+
reloadContactDetails();
668+
}, function onError() {
669+
console.error('Error reloading contact');
670+
});
671+
};
672+
request.onerror = function onerror() {
673+
console.error('Error saving favorite');
674+
};
660675
};
661676

662677
var toggleFavoriteMessage = function toggleFavMessage(isFav) {

0 commit comments

Comments
 (0)