Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #30833 from mancas/bug1178891
Browse files Browse the repository at this point in the history
Bug 1178891 - Eliminate "Link contact" button in Contact detail screen
  • Loading branch information
mancas committed Jul 10, 2015
2 parents c0b8dc1 + de25997 commit c194888
Show file tree
Hide file tree
Showing 10 changed files with 9 additions and 480 deletions.
17 changes: 0 additions & 17 deletions apps/communications/contacts/elements/details.html
Expand Up @@ -32,23 +32,6 @@ <h2>

<li data-social class="social-actions" id="social-template-#i#" data-template role="region">
<h2 data-l10n-id="social-network" id="social-label">Social Network</h2>
<div class="fillflow-twocols">
<button id="msg_button" data-l10n-id="msg-send" class="activity icon icon-message">
Message
</button>
<button id="wall_button" data-l10n-id="wall-post" class="activity icon icon-email">
Wall Post
</button>
</div>

<button id="profile_button" data-l10n-id="show-fb-profile" class="fillflow-row activity icon icon-fb-profile">
View Facebook profile
</button>

<button id="link_button" class="activity icon icon-link">
#action#
</button>

<button id="share_button" data-l10n-id="share-contact" class="activity icon icon-share">
Share
</button>
Expand Down
201 changes: 1 addition & 200 deletions apps/communications/contacts/js/service_extensions.js
@@ -1,36 +1,19 @@
'use strict';
/* global utils */
/* global ConfirmDialog */
/* global fb */
/* exported extServices*/

(function(exports) {
var extServices = {};
var contactId;

// TODO Remove fb- prefixes: Bug 1181469
var extensionFrame = document.querySelector('#fb-extensions');
var oauthFrame = document.querySelector('#fb-oauth');
oauthFrame.src = '/shared/pages/import/oauth.html';
var currentURI, access_token;
var canClose = true, canCloseLogout = true;
var closeRequested = false;

extServices.startLink = function(cid, linked) {
canClose = true;
canCloseLogout = true;
contactId = cid;
if (!linked) {
load('fb_link.html' + '?contactId=' + contactId, 'proposal',
'facebook');
} else {
unlink(contactId);
}
};

extServices.importFB = function(evt) {
loadService('facebook');
};

extServices.importGmail = function(evt) {
loadService('gmail');
};
Expand Down Expand Up @@ -83,180 +66,6 @@
extensionFrame.classList.remove('opening');
}

function openURL(url) {
window.open(url, '', 'dialog');
}

extServices.showProfile = function(cid) {
var req = fb.utils.getContactData(cid);

req.onsuccess = function() {
var fbContact = new fb.Contact(req.result);

var uid = fbContact.uid;
var profileUrl = 'https://m.facebook.com/' + uid;

openURL(fb.utils.getNonCacheableUrl(profileUrl));
};

req.onerror = function() {
window.console.error('Contacts FB Profile: Contact not found');
};
};

extServices.wallPost = function(cid) {
contactId = cid;
fb.msg.ui.wallPost(contactId);
};

extServices.sendPrivateMsg = function(cid) {
contactId = cid;
fb.msg.ui.sendPrivateMsg(contactId);
};

extServices.initEventHandlers = function(socialNode, contact, linked) {
var elements = {
'#msg_button': {
'elems': ['id'],
'callback': onPrivateMsgClick
},
'#wall_button': {
'elems': ['id'],
'callback': onWallClick
},
'#profile_button': {
'elems': ['id'],
'callback': onProfileClick
},
'#link_button': {
'elems': ['id', 'fb_is_linked'],
'callback': onLinkClick
}
};

// Add extra info too
var extras = {};
extras.fb_is_linked = linked;

/* jshint loopfunc:true */
for (var nodeName in elements) {
var node = socialNode.querySelector(nodeName);
var variables = elements[nodeName].elems;
variables.forEach(function appendData(data) {
var value = contact[data] || extras[data];
node.dataset[data] = value;
});
node.addEventListener('click', elements[nodeName].callback);
}
};

function onClickWithId(evt, callback) {
var contactId = evt.target.dataset.id;
callback(contactId);
}

/*
The following functons are similar,
but have been splitted for better reading
and future different handling
*/
function onPrivateMsgClick(evt) {
onClickWithId(evt, extServices.sendPrivateMsg);
}

function onWallClick(evt) {
onClickWithId(evt, extServices.wallPost);
}

function onProfileClick(evt) {
onClickWithId(evt, extServices.showProfile);
}

// Note this is slightly different
function onLinkClick(evt) {
var contactId = evt.target.dataset.id;
var linked = evt.target.dataset.fb_is_linked;

linked = (linked === 'true');
extServices.startLink(contactId, linked);
}

function doLink(fData) {
var uid = fData.uid;
// We need to obtain the mozContact id for the UID
var mozContReq = fb.utils.getMozContact(uid);

mozContReq.onsuccess = function() {
// contactId is the device contact about to be linked
var fbContact = new fb.Contact(null, contactId);

// mozContactReq.result is id in mozContacts for that UID
var originalFbContact = mozContReq.result;

var req = fbContact.linkTo({
uid: uid,
photoUrl: fData.url,
mozContact: originalFbContact
});

req.onsuccess = function success() {
close();

if (originalFbContact && !fb.isFbLinked(originalFbContact)) {
window.Contacts && window.Contacts.List.remove(originalFbContact.id);
}
window.Contacts && window.Contacts.showContactDetail(contactId);
};

req.onerror = function() {
window.console.error('FB: Error while linking contacts', req.error);
};
};

mozContReq.onerror = function() {
window.console.error('FB: Error while linking contacts',
mozContReq.error);
};
}

function unlink(cid) {
var msg = 'social-unlink-confirm-title';
var yesObject = {
title: 'social-unlink-confirm-accept',
isDanger: true,
callback: function onAccept() {
ConfirmDialog.hide();
doUnlink(cid);
}
};

var noObject = {
title: 'cancel',
callback: function onCancel() {
ConfirmDialog.hide();
}
};

ConfirmDialog.show(null, msg, noObject, yesObject);
}

function doUnlink(cid) {
var fbContact = new fb.Contact(null, cid);

var freq = fbContact.unlink();

freq.onsuccess = function() {
window.Contacts && window.Contacts.updateContactDetail(cid);
if (freq.result) {
window.Contacts && window.Contacts.updateContactDetail(cid);
}
};

freq.onerror = function() {
window.console.error('FB: Error while unlinking', freq.error);
};
}

function notifySettings(evtype) {
// Notify observers that a change from FB could have happened
var eventType = evtype || 'fb_changed';
Expand Down Expand Up @@ -344,14 +153,6 @@
}
break;

case 'item_selected':
var fData = data.data;
doLink(fData);

// Not needed to notifySettings as when settings will be open
// the info from FB will be refreshed anyway
break;

case 'messaging_ready':
extensionFrame.contentWindow.postMessage({
type: 'token',
Expand Down
71 changes: 5 additions & 66 deletions apps/communications/contacts/js/views/details.js
Expand Up @@ -18,7 +18,6 @@
/* global TAG_OPTIONS */
/* global utils */
/* global VcardFilename */
/* global ExtServices */
/* global MatchService */
/* global WebrtcClient */
/* global MainNavigation */
Expand Down Expand Up @@ -54,12 +53,6 @@ contacts.Details = (function() {
header,
_;

var socialButtonIds = [
'#profile_button',
'#wall_button',
'#msg_button'
];

var init = function cd_init(currentDom) {
_ = navigator.mozL10n.get;
dom = currentDom || document;
Expand All @@ -79,9 +72,6 @@ contacts.Details = (function() {
favoriteMessage = dom.querySelector('#toggle-favorite');
notesTemplate = dom.querySelector('#note-details-template-\\#i\\#');

window.addEventListener('online', checkOnline);
window.addEventListener('offline', checkOnline);

initPullEffect(cover);

// to avoid race conditions with NFC, we load it before handleDetails
Expand Down Expand Up @@ -317,9 +307,8 @@ contacts.Details = (function() {
renderDates(contact);

renderNotes(contact);
if (fb.isEnabled) {
renderSocial(contact);
}

renderShareButton(contact);

if (!fb.isFbContact(contact) || fb.isFbLinked(contact)) {
renderDuplicate(contact);
Expand Down Expand Up @@ -449,69 +438,19 @@ contacts.Details = (function() {
}
};

var renderSocial = function cd_renderSocial(contact) {
var linked = isFbLinked;

var action = linked ? _('social-unlink') : _('social-link');
var slinked = linked ? 'false' : 'true';

var renderShareButton = function cd_renderShareButton(contact) {
var social = utils.templates.render(socialTemplate, {
i: contact.id,
action: action,
linked: slinked
i: contact.id
});
currentSocial = social;
var linkButton = social.querySelector('#link_button');
var shareButton = social.querySelector('#share_button');

shareButton.addEventListener('click', shareContact);

if (!isFbContact) {
socialButtonIds.forEach(function check(id) {
var button = social.querySelector(id);
if (button) {
button.classList.add('hide');
}
});
// Checking whether link should be enabled or not
doDisableButton(linkButton);
shareButton.classList.remove('hide');
} else {
var socialLabel = social.querySelector('#social-label');
if (socialLabel) {
socialLabel.setAttribute('data-l10n-id', 'facebook');
}
shareButton.classList.add('hide');
}

// If it is a FB Contact but not linked unlink must be hidden
if (isFbContact && !linked) {
linkButton.classList.add('hide');
}

ExtServices.initEventHandlers(social, contact, linked);
shareButton.classList.remove('hide');

listContainer.appendChild(social);
};

var checkOnline = function() {
var socialTemplate = document.querySelector(
':not([data-template])[data-social]');

if (socialTemplate && !isFbContact) {
doDisableButton(socialTemplate.querySelector('#link_button'));
}
};

function doDisableButton(buttonElement) {
if (navigator.onLine === true) {
buttonElement.removeAttribute('disabled');
}
else {
buttonElement.setAttribute('disabled', 'disabled');
}
}

var renderWebrtcClient = function renderWebrtcClient(contact) {
getWebrtcClientResources(function onLoaded() {
WebrtcClient.start(contact);
Expand Down
Expand Up @@ -56,7 +56,6 @@ marionette('Contacts > Details', function() {
client.helper.waitForElement(selectors.listContactFirstText).click();
subject.waitSlideLeft('details');
assertContactData(testContact);
client.findElement(selectors.detailsLinkButton);
});

test('Show contact with picture', function() {
Expand Down
4 changes: 0 additions & 4 deletions apps/communications/contacts/test/marionette/lib/contacts.js
Expand Up @@ -48,11 +48,7 @@ Contacts.Selectors = {
detailsSocialLabel: '#contact-detail-inner #details-list #social-label',
detailsSocialTemplate: '#contact-detail-inner #details-list .social-actions',
detailsCoverImage: '#cover-img',
detailsLinkButton: '#contact-detail-inner #link_button',
detailsShareButton: '#contact-detail-inner #share_button',
fbMsgButton: '#contact-detail-inner #msg_button',
fbWallButton: '#contact-detail-inner #wall_button',
fbProfileButton: '#contact-detail-inner #profile_button',

findDupsButton: '#details-list #find-merge-button',

Expand Down

0 comments on commit c194888

Please sign in to comment.