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

Commit

Permalink
Bug 880624 - [MMS/SMS] The dialog when tapping on a contact into ‘To’…
Browse files Browse the repository at this point in the history
… field is not correct
  • Loading branch information
arcturus committed Jun 27, 2013
1 parent ecc7830 commit 8b41ee9
Show file tree
Hide file tree
Showing 15 changed files with 525 additions and 47 deletions.
5 changes: 2 additions & 3 deletions apps/sms/index.html
Expand Up @@ -33,7 +33,6 @@
<!--
<script defer src="shared/js/l10n_date.js"></script>
<script defer src="shared/js/async_storage.js"></script>
<script defer src="shared/js/custom_dialog.js"></script>
<script defer src="shared/js/notification_helper.js"></script>
<script defer src="shared/js/gesture_detector.js"></script>
-->
Expand Down Expand Up @@ -201,7 +200,7 @@ <h1 id="messages-edit-mode" data-l10n-id="editMode">Edit mode</h1>
<div id="messages-contact-tmpl" class="hide">
<!--
<a class="suggestion"
data-number="${number}" data-source="contacts" data-name="${name}">
data-number="${number}" data-source="contacts" data-name="${name}" data-display="${type}${separator}${carrier}${number}">
<p class="name">${nameHTML}</p>
<p>
${type}${separator}${carrier}${numberHTML}
Expand Down Expand Up @@ -271,7 +270,7 @@ <h1 id="messages-edit-mode" data-l10n-id="editMode">Edit mode</h1>
<!--
<span class="recipient" x-inputmode="verbatim"
contenteditable="${editable}"
data-number="${number}" data-source="${source}" data-name="${name}">
data-number="${number}" data-source="${source}" data-name="${name}" data-display="${display}">
${name}
</span>
-->
Expand Down
145 changes: 145 additions & 0 deletions apps/sms/js/dialog.js
@@ -0,0 +1,145 @@
'use strict';

/*
Generic confirm screen. Only 'cancel/default' is mandatory. For having l10n
you should define the key value and you have to set l10n to 'true'. Options
should follow the following structure:
{
title: {
value: 'foo Title',
l10n: false
},
body: {
value: 'foo Body',
l10n: false
},
options: {
// Cancel is a mandatory option. You need to define at least the text
cancel: {
text: {
value: 'cancel',
l10n: true
}
},
// Confirm is an optional one. As in cancel, you could add as well a method
// with params
confirm: {
text: {
value: 'remove',
l10n: true
},
method: function(params) {
fooFunction(params);
},
params: [arg1, arg2,....]
}
}
*/


var Dialog = function(params) {
// We need, at least, one cancel option string
if (!params || !params.options || !params.options.cancel) {
return;
}
var _ = navigator.mozL10n.get;
var handlers = new WeakMap();
// Create the structure
this.form = document.createElement('form');
this.form.dataset.type = 'confirm';
this.form.setAttribute('role', 'dialog');

// We fill the main info

// The title should take into account localization as well
var titleDOM = document.createElement('strong');
var title = (!params.title.l10n) ? params.title.value : _(params.title.value);
titleDOM.textContent = title;
if (params.title.l10n) {
titleDOM.dataset.l10nId = params.title.value;
}
// We make the same for the body
var bodyDOM = document.createElement('small');
var body = (!params.body.l10n) ? params.body.value : _(params.body.value);
bodyDOM.textContent = body;
if (params.body.l10n) {
bodyDOM.dataset.l10nId = params.body.value;
}

// Adding this elements to the DOM
var infoSection = document.createElement('section');
// We create the info container
var infoContainer = document.createElement('p');
infoContainer.appendChild(titleDOM);
infoContainer.appendChild(bodyDOM);
// We append to the section
infoSection.appendChild(infoContainer);
// At the end we have to append to the form
this.form.appendChild(infoSection);

// Adding options. In this case we have a maximum of 2, with different styles
// per button
var menu = document.createElement('menu');
// Default button (Cancel button). It's mandatory
var cancelButton = document.createElement('button');
var cancelOption = params.options.cancel;
var cancel = !cancelOption.text.l10n ?
cancelOption.text.value : _(cancelOption.text.value);
cancelButton.textContent = cancel;
if (cancelOption.text.l10n) {
cancelButton.dataset.l10nId = cancelOption.text.value;
}
handlers.set(cancelButton, cancelOption);
menu.appendChild(cancelButton);

if (params.options.confirm) {
var confirmOption = params.options.confirm;
var confirmButton = document.createElement('button');
var confirm = !confirmOption.text.l10n ?
confirmOption.text.value : _(confirmOption.text.value);
confirmButton.textContent = confirm;
confirmButton.className = 'recommend';
if (confirmOption.text.l10n) {
confirmButton.dataset.l10nId = confirmOption.text.value;
}
handlers.set(confirmButton, confirmOption);
menu.appendChild(confirmButton);
} else {
// If there is only one item, we take the 100% of the space available
cancelButton.style.width = '100%';
}

this.form.addEventListener('submit', function(event) {
event.preventDefault();
});

menu.addEventListener('click', function(event) {
var action = handlers.get(event.target);

if (!action) {
return;
}

var method = (action && action.method) || function() {};

// Delegate operation to target method. This allows
// for a custom "Cancel" to be provided by calling program
method.apply(null, action.params || []);

// Hide action menu when click is received
this.hide();

}.bind(this));
// Appending the action menu to the form
this.form.appendChild(menu);
};

// We prototype functions to show/hide the UI of action-menu
Dialog.prototype.show = function() {
document.body.appendChild(this.form);
};

Dialog.prototype.hide = function() {
document.body.removeChild(this.form);
};
22 changes: 16 additions & 6 deletions apps/sms/js/message_manager.js
Expand Up @@ -211,15 +211,25 @@ var MessageManager = {
return;
}

if (activity.number || activity.contact) {
var recipient = activity.contact || {
number: activity.number,
source: 'manual'
// Choose the appropiate contact resolver, if we
// have a contact object, and no number,just use a dummy source,
// and return the contact, if not, if we have a number, use
// one of the functions to get a contact based on a number
var contactSource = Contacts.findByPhoneNumber.bind(Contacts);
var phoneNumber = activity.number;
if (activity.contact && !phoneNumber) {
contactSource = function dummySource(contact, cb) {
cb(activity.contact);
};

ThreadUI.recipients.add(recipient);
phoneNumber = activity.contact.number || activity.contact.tel[0].value;
}

Utils.getContactDisplayInfo(contactSource, phoneNumber,
(function onData(data) {
data.source = 'contacts';
ThreadUI.recipients.add(data);
}).bind(this));

// If the message has a body, use it to populate the input field.
if (activity.body) {
ThreadUI.setMessageBody(
Expand Down
55 changes: 44 additions & 11 deletions apps/sms/js/recipients.js
Expand Up @@ -22,6 +22,7 @@
this.email = opts.email || '';
this.editable = opts.editable || 'true';
this.source = opts.source || 'manual';
this.display = opts.display || '';
}
/**
* set
Expand Down Expand Up @@ -704,7 +705,12 @@
//
// 1.a Delete Mode
//
Recipients.View.prompts.remove(target, function(result) {
var recipientWrapper = {
target: target,
recipient: recipient
};
Recipients.View.prompts.remove(recipientWrapper,
function(result) {
if (result.isConfirmed) {
owner.remove(
relation.get(target)
Expand Down Expand Up @@ -896,20 +902,47 @@
};

Recipients.View.prompts = {
remove: function(candidate, callback) {
remove: function(params, callback) {
var response = {
isConfirmed: false,
recipient: candidate
recipient: params.target
};
var message = navigator.mozL10n.get('recipientRemoval', {
recipient: candidate.textContent.trim()
});
// If it's a contact we should ask to remove
if (confirm(message)) {
response.isConfirmed = true;
}

callback(response);
var dialog = new Dialog(
{
title: {
value: params.recipient.name || params.recipient.number,
l10n: false
},
body: {
value: params.recipient.display,
l10n: false
},
options: {
cancel: {
text: {
value: 'cancel',
l10n: true
}
},
confirm: {
text: {
value: 'remove',
l10n: true
},
method: function(callback, response) {
if (response) {
response.isConfirmed = true;
if (callback && typeof callback === 'function') {
callback(response);
}
}
},
params: [callback, response]
}
}
});
dialog.show();
}
};

Expand Down
3 changes: 1 addition & 2 deletions apps/sms/js/startup.js
Expand Up @@ -6,9 +6,9 @@
var lazyLoadFiles = [
'shared/js/async_storage.js',
'shared/js/l10n_date.js',
'shared/js/custom_dialog.js',
'shared/js/notification_helper.js',
'shared/js/gesture_detector.js',
'js/dialog.js',
'js/blacklist.js',
'js/contacts.js',
'js/recipients.js',
Expand All @@ -34,7 +34,6 @@ var lazyLoadFiles = [
'shared/style/switches.css',
'shared/style/confirm.css',
'shared/style_unstable/progress_activity.css',
'style/custom_dialog.css',
'shared/style/action_menu.css',
'shared/style/responsive.css',
'style/notification.css'
Expand Down
29 changes: 8 additions & 21 deletions apps/sms/js/thread_ui.js
Expand Up @@ -440,13 +440,12 @@ var ThreadUI = global.ThreadUI = {
});

activity.onsuccess = (function() {
var details = Utils.getContactDetails('', activity.result);

this.recipients.add({
name: details.title || details.number || activity.result.name[0],
number: details.number || activity.result.number,
source: 'contacts'
});
Utils.getContactDisplayInfo(Contacts.findByPhoneNumber.bind(Contacts),
activity.result.number,
(function onData(data) {
data.source = 'contacts';
this.recipients.add(data);
}).bind(this));
}).bind(this);

activity.onerror = (function(e) {
Expand Down Expand Up @@ -1584,21 +1583,9 @@ var ThreadUI = global.ThreadUI = {
continue;
}

var number = current.value;
var title = details.title || number;
var type = current.type && current.type.length ? current.type[0] : '';
var carrier = current.carrier ? (current.carrier + ', ') : '';
var separator = type || carrier ? ' | ' : '';
var li = document.createElement('li');
var data = {
name: title,
number: number,
type: type,
carrier: carrier,
separator: separator,
nameHTML: '',
numberHTML: ''
};

var data = Utils.getDisplayObject(details.title, current);

['name', 'number'].forEach(function(key) {
var escapedData = Utils.escapeHTML(data[key]);
Expand Down

0 comments on commit 8b41ee9

Please sign in to comment.