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 #16659 from jmcanterafonseca/birthday_take2
Browse files Browse the repository at this point in the history
Bug 935045 - Allow the user to enter birth date in contact add and conta...
  • Loading branch information
jmcanterafonseca committed Mar 5, 2014
2 parents 63fd017 + edae471 commit 3b84e00
Show file tree
Hide file tree
Showing 20 changed files with 681 additions and 90 deletions.
33 changes: 16 additions & 17 deletions apps/communications/contacts/elements/details.html
Expand Up @@ -28,22 +28,6 @@ <h2 data-l10n-id="#type_l10n_id#">#type#</h2>
</div>
</li>

<li id="birthday-template-#i#" data-template>
<h2 data-l10n-id="birthday">Birthday</h2>
<p><strong>#bday#</strong></p>
</li>

<li data-mail id='email-details-template-#i#' data-template>
<h2 data-l10n-id="#type_l10n_id#">#type#</h2>
<div class="item">
<div class="item-body-exp">
<button id="email-or-pick-#i#" class="activity icon icon-email">
<b>#value#</b>
</button>
</div>
</div>
</li>

<li data-social class="social-actions" id="social-template-#i#" data-template>
<h2 data-l10n-id="social-network" id="social-label">Social Network</h2>
<div class="fillflow-twocols">
Expand Down Expand Up @@ -88,6 +72,22 @@ <h2 data-l10n-id="#type_l10n_id#">#type#</h2>
</div>
</li>

<li data-mail id='email-details-template-#i#' data-template>
<h2 data-l10n-id="#type_l10n_id#">#type#</h2>
<div class="item">
<div class="item-body-exp">
<button id="email-or-pick-#i#" class="activity icon icon-email">
<b>#value#</b>
</button>
</div>
</div>
</li>

<li id="dates-template-#i#" data-template>
<h2>#type#</h2>
<p><strong>#date#</strong></p>
</li>

<p data-comment id='note-details-template-#i#' data-template class="comment-notes">#note#</p>
<div id='contact-detail-inner'>
<h1 id='org-title'></h1>
Expand All @@ -105,4 +105,3 @@ <h1 id='org-title'></h1>
</article>
</template>
</element>

27 changes: 26 additions & 1 deletion apps/communications/contacts/elements/form.html
Expand Up @@ -67,6 +67,22 @@ <h1 id='contact-form-title' data-l10n-id="addContact">Add contact</h1>
</fieldset>
</div>

<div id='add-date-#i#' data-template class='date-template' data-exclusive="true" data-custom="false" data-index="#i#">
<fieldset class="fillflow-row">
<legend class="action">
<span data-taglist="date-type" name="date[#i#][type]" data-value="#type_value#" id="date_type_#i#" data-field="type" data-l10n-id="#type_l10n_id#">#type#</span>
</legend>
<section>
<p class="setbox-item">
<span id="date-text_#i#" data-l10n-id="date.placeholder" class="datetime placeholder">
Date
</span>
<input placeholder="date" data-l10n-id="date" name="date[#i#][value]" class="textfield hidden-input" type="date" id="date_#i#">
</p>
</section>
</fieldset>
</div>

<div id='add-note-#i#' data-template class='note-template' data-index="#i#">
<dl class="setbox fillflow-row">
<dd class="setbox-body">
Expand Down Expand Up @@ -140,6 +156,16 @@ <h1 id='contact-form-title' data-l10n-id="addContact">Add contact</h1>
</button>
</li>

<li>
<section>
<div id="contacts-form-dates"></div>
</section>

<button data-field-type="date" id='add-new-date' data-l10n-id="addDate" class="fillflow-row action action-add icon icon-add">
Add Date
</button>
</li>

<li>
<section>
<div id="contacts-form-notes"></div>
Expand All @@ -161,4 +187,3 @@ <h1 id='contact-form-title' data-l10n-id="addContact">Add contact</h1>
</article>
</template>
</element>

19 changes: 18 additions & 1 deletion apps/communications/contacts/js/contacts.js
Expand Up @@ -85,7 +85,7 @@ var Contacts = (function() {
null, params['fromUpdateActivity']);
showApp();
}, function onError() {
console.log('Error retrieving contact to be edited');
console.error('Error retrieving contact to be edited');
contactsForm.render(null, goToForm);
showApp();
});
Expand Down Expand Up @@ -171,6 +171,10 @@ var Contacts = (function() {
{type: 'current', value: _('current')},
{type: 'home', value: _('home')},
{type: 'work', value: _('work')}
],
'date-type': [
{type: 'birthday', value: _('birthday')},
{type: 'anniversary', value: _('anniversary')}
]
};
};
Expand Down Expand Up @@ -356,6 +360,13 @@ var Contacts = (function() {
var selectedTagType = contactTag.dataset.taglist;
var options = TAG_OPTIONS[selectedTagType];

var type = selectedTagType.split('-')[0];
var isCustomTagVisible = (document.querySelector(
'[data-template]' + '.' + type + '-' +
'template').dataset.custom != 'false');

options = ContactsTag.filterTags(type, contactTag, options);

if (!customTag) {
customTag = document.querySelector('#custom-tag');
customTag.addEventListener('keydown', handleCustomTag);
Expand All @@ -377,7 +388,13 @@ var Contacts = (function() {
for (var i in options) {
options[i].value = _(options[i].type);
}

ContactsTag.setCustomTag(customTag);
// Set whether the custom tag is visible or not
// This is needed for dates as we only support bday and anniversary
// and not custom dates
ContactsTag.setCustomTagVisibility(isCustomTagVisible);

ContactsTag.fillTagOptions(tagsList, contactTag, options);

navigation.go('view-select-tag', 'right-left');
Expand Down
7 changes: 6 additions & 1 deletion apps/communications/contacts/js/contacts_merger.js
Expand Up @@ -64,6 +64,7 @@ contacts.Merger = (function() {

mergedContact.photo = masterContact.photo || [];
mergedContact.bday = masterContact.bday;
mergedContact.anniversary = masterContact.anniversary;

mergedContact.adr = masterContact.adr || [];

Expand Down Expand Up @@ -151,6 +152,9 @@ contacts.Merger = (function() {
if (!mergedContact.bday && theMatchingContact.bday) {
mergedContact.bday = theMatchingContact.bday;
}
if (!mergedContact.anniversary && theMatchingContact.anniversary) {
mergedContact.anniversary = theMatchingContact.anniversary;
}

if (isDefined(theMatchingContact.org) && mergedContact.org.length === 0) {
mergedContact.org = theMatchingContact.org;
Expand Down Expand Up @@ -305,7 +309,8 @@ contacts.Merger = (function() {

function fillMasterContact(masterContact, mergedContact, mergedPhoto, done) {
var fields = ['familyName', 'givenName', 'name', 'org', 'email', 'tel',
'bday', 'adr', 'category', 'url', 'note', 'photo'];
'bday', 'anniversary', 'adr', 'category',
'url', 'note', 'photo'];

fields.forEach(function(aField) {
masterContact[aField] = mergedContact[aField];
Expand Down
48 changes: 47 additions & 1 deletion apps/communications/contacts/js/contacts_tag.js
Expand Up @@ -9,6 +9,19 @@ var ContactsTag = (function() {
customTag = element;
};

var setCustomTagVisibility = function setCustomTagVisibility(value) {
if (!customTag) {
return;
}

if (value) {
customTag.classList.remove('hide');
}
else {
customTag.classList.add('hide');
}
};

var touchCustomTag = function touchCustomTag(callback) {
if (selectedTag) {
selectedTag.removeAttribute('class');
Expand Down Expand Up @@ -85,10 +98,43 @@ var ContactsTag = (function() {
}
};

// Filter tags to be shown when selecting an item type (work, birthday, etc)
// This is particularly useful for dates as we cannot have multiple instances
// of them (only one birthday, only one anniversary)
function filterTags(type, currentNode, tags) {
var element = document.querySelector(
'[data-template]' + '.' + type + '-' + 'template');
if (!element || !element.dataset.exclusive) {
return tags;
}

// If the type is exclusive the tag options are filtered according to
// the existing ones
var newOptions = tags.slice(0);

var sameType = document.querySelectorAll('.' + type + '-template');
if (sameType.length > 1) {
for (var j = 0; j < sameType.length; j++) {
var itemSame = sameType.item(j);
var tagNode = itemSame.querySelector('[data-field="type"]');
if (tagNode !== currentNode &&
!itemSame.classList.contains('removed')) {
newOptions = newOptions.filter(function(ele) {
return ele.type != tagNode.dataset.value;
});
}
}
}

return newOptions;
}

return {
'setCustomTag': setCustomTag,
'touchCustomTag': touchCustomTag,
'fillTagOptions': fillTagOptions,
'clickDone': clickDone
'clickDone': clickDone,
'setCustomTagVisibility': setCustomTagVisibility,
'filterTags': filterTags
};
})();
13 changes: 12 additions & 1 deletion apps/communications/contacts/js/fb/fb_contact_utils.js
Expand Up @@ -9,6 +9,8 @@ fb.PROFILE_PHOTO_URI = 'fb_profile_photo';
fb.FRIEND_URI = 'fb_friend';
fb.DEFAULT_PHONE_TYPE = 'other';
fb.DEFAULT_EMAIL_TYPE = 'other';
// This year indicates that the year can be ignored (yearless date)
fb.FLAG_YEAR_IGNORED = 9996;

fb.CONTACTS_APP_ORIGIN = location.origin;

Expand Down Expand Up @@ -141,7 +143,7 @@ fb.getWorksAt = function(fbdata) {
*
*/
fb.getBirthDate = function getBirthDate(sbday) {
var out = new Date();
var out = new Date(0);

var imonth = sbday.indexOf('/');
var smonth = sbday.substring(0, imonth);
Expand All @@ -160,6 +162,15 @@ fb.getBirthDate = function getBirthDate(sbday) {
if (syear && syear.length > 0) {
out.setUTCFullYear(parseInt(syear, 10));
}
else {
// 9996 is the year that flags a not known year
out.setUTCFullYear(fb.FLAG_YEAR_IGNORED);
}

out.setUTCHours(0);
out.setUTCMinutes(0);
out.setUTCSeconds(0);
out.setUTCMilliseconds(0);

return out;
};
Expand Down
46 changes: 46 additions & 0 deletions apps/communications/contacts/js/utilities/misc.js
Expand Up @@ -12,4 +12,50 @@ if (!utils.misc) {
}
return outContact;
};

utils.misc.formatDate = function formatDate(date) {
// This year indicates that the year can be ignored
var FLAG_YEAR_IGNORED = 9996;
var _ = navigator.mozL10n.get;

var year = date.getFullYear();
if (year === FLAG_YEAR_IGNORED) {
year = '';
}
var dateFormat = _('dateFormat') || '%B %e';
var f = new navigator.mozL10n.DateTimeFormat();
try {
var offset = date.getTimezoneOffset() * 60 * 1000;
var normalizedDate = new Date(date.getTime() + offset);
var dayMonthString = f.localeFormat(normalizedDate, dateFormat);
var dateString = _('dateOutput', {
dayMonthFormatted: dayMonthString,
year: year
});
} catch (err) {
console.error('Error parsing date: ', err);
throw err;
}

return dateString;
};

// Normalizes the contact date in UTC TZ
utils.misc.normalizeDate = function normalizeDate(filledDate) {
var normalizedDate;

if (filledDate) {
normalizedDate = new Date(0);
normalizedDate.setUTCDate(filledDate.getDate());
normalizedDate.setUTCMonth(filledDate.getMonth());
normalizedDate.setUTCFullYear(filledDate.getFullYear());

normalizedDate.setUTCHours(0);
normalizedDate.setUTCMinutes(0);
normalizedDate.setUTCSeconds(0);
normalizedDate.setUTCMilliseconds(0);
}

return normalizedDate;
};
}

0 comments on commit 3b84e00

Please sign in to comment.