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

Commit

Permalink
Bug 1187668 - Update Settings to be ready for L10n API v3
Browse files Browse the repository at this point in the history
  • Loading branch information
Zibi Braniecki committed Jul 28, 2015
1 parent 85e86cc commit 3b31a39
Show file tree
Hide file tree
Showing 63 changed files with 658 additions and 792 deletions.
8 changes: 5 additions & 3 deletions apps/download/js/pick.js
Expand Up @@ -102,9 +102,11 @@
var pInfo = document.createElement('p');
pInfo.classList.add('info');
DownloadFormatter.getDate(download, (date) => {
navigator.mozL10n.setAttributes(pInfo, 'summary', {
date: date,
status: DownloadFormatter.getTotalSize(download)
DownloadFormatter.getTotalSize(download).then(totalSize => {
navigator.mozL10n.setAttributes(pInfo, 'summary', {
date: date,
status: totalSize
});
});
});

Expand Down
6 changes: 3 additions & 3 deletions apps/settings/elements/firefox_accounts.html
Expand Up @@ -29,14 +29,14 @@ <h2 data-l10n-id="fxa-confirm-account">Confirm Your Account</h2>
</header>
<ul>
<li class="description">
<p data-l10n-id="fxa-verification-email-sent-msg" id="fxa-unverified-text">
<p id="fxa-unverified-text">
We will send an email to: foo@bar.com
</p>
<p data-l10n-id="fxa-please-verify">
Click the verification link in your email to confirm your account.
</p>
<p id="fxa-resend-email">
Don't see an email? <a href="#">Resend</a>.
<p id="fxa-resend-email" data-l10n-id="fxa-dont-see-email-resend">
Don't see an email? <a href="#" id="fxa-resend">Resend</a>.
</p>
</li>
<li>
Expand Down
59 changes: 35 additions & 24 deletions apps/settings/js/bluetooth.js
Expand Up @@ -2,14 +2,13 @@
'use strict';

// handle Bluetooth settings
navigator.mozL10n.once(function bluetoothSettings() {
(function bluetoothSettings() {
// Service ID for profiles
var Profiles = {
'HFP': 0x111E,
'A2DP': 0x110D
};

var _ = navigator.mozL10n.get;
var settings = Settings.mozSettings;
var bluetooth = navigator.mozBluetooth;
var defaultAdapter = null;
Expand Down Expand Up @@ -104,12 +103,15 @@ navigator.mozL10n.once(function bluetoothSettings() {
nameEntered = nameEntered.replace(/^\s+|\s+$/g, '');

if (nameEntered.length > MAX_DEVICE_NAME_LENGTH) {
var wantToRetry = window.confirm(_('bluetooth-name-maxlength-alert',
{ length: MAX_DEVICE_NAME_LENGTH }));

if (!wantToRetry) {
updateNameDialog.hidden = true;
}
navigator.mozL10n.formatValue('bluetooth-name-maxlength-alert', {
length: MAX_DEVICE_NAME_LENGTH
}).then((value) => {
var wantToRetry = window.confirm(value);

if (!wantToRetry) {
updateNameDialog.hidden = true;
}
});
return;
}

Expand Down Expand Up @@ -664,13 +666,14 @@ navigator.mozL10n.once(function bluetoothSettings() {
}
} else {
// show pair process fail.
var msg = _('error-pair-title');
var l10nId = 'error-pair-title';
if (errorMessage === 'Repeated Attempts') {
msg = msg + '\n' + _('error-pair-toofast');
l10nId = 'error-pair-toofast';
} else if (errorMessage === 'Authentication Failed') {
msg = msg + '\n' + _('error-pair-pincode');
l10nId = 'error-pair-pincode';
}
window.alert(msg);
navigator.mozL10n.formatValue(l10nId).then(
msg => window.alert(msg));

// rollback device status
if (openList.index[workingAddress]) {
Expand All @@ -685,18 +688,25 @@ navigator.mozL10n.once(function bluetoothSettings() {
}

function setDeviceUnpair(device) {
function unpairDevice() {
// backend takes responsibility to disconnect first.
var req = defaultAdapter.unpair(device.address);
req.onerror = function bt_pairError() {
showDevicePaired(true, null);
};
}

if (device.address === connectedAddress) {
var msg = _('unpair-title') + '\n' + _('unpair-msg');
if (!window.confirm(msg)) {
return;
}
connectedAddress = null;
navigator.mozL10n.formatValue('unpair-confirm').then(msg => {
if (!window.confirm(msg)) {
return;
}
connectedAddress = null;
unpairDevice();
});
} else {
unpairDevice();
}
// backend takes responsibility to disconnect first.
var req = defaultAdapter.unpair(device.address);
req.onerror = function bt_pairError() {
showDevicePaired(true, null);
};
}

function setDeviceDisconnect(device, callback) {
Expand Down Expand Up @@ -741,7 +751,8 @@ navigator.mozL10n.once(function bluetoothSettings() {
small.removeAttribute('data-l10n-id');
small.textContent = '';
connectingAddress = null;
window.alert(_('error-connect-msg'));
navigator.mozL10n.formatValue('error-connect-msg').then(msg =>
window.alert(msg));
}
};

Expand Down Expand Up @@ -927,4 +938,4 @@ navigator.mozL10n.once(function bluetoothSettings() {
gBluetoothCheckBox.removeAttribute('disabled'); // enable UI toggle
defaultAdapter = null; // clear defaultAdapter
});
});
})();
32 changes: 21 additions & 11 deletions apps/settings/js/downloads/download_item.js
Expand Up @@ -87,9 +87,10 @@ window.DownloadItem = (function DownloadItem() {
// Update the state properly in the element
domElement.dataset.state = state;
// Update content
updateContent(domNodes, download);
return updateContent(domNodes, download).then(() => {
return domElement;
});

return domElement;
};

// Update the content of the elements according to the download
Expand All @@ -98,29 +99,38 @@ window.DownloadItem = (function DownloadItem() {
// elements accesible by name
// @param {DomDownload} Download object
var updateContent = function updateContent(domNodes, download) {
var _ = navigator.mozL10n.get;
var state = getDownloadState(download);
if (state === 'downloading') {
domNodes.progress.value =
DownloadFormatter.getPercentage(download);

navigator.mozL10n.setAttributes(domNodes.info, 'partialResult', {
partial: DownloadFormatter.getDownloadedSize(download),
total: DownloadFormatter.getTotalSize(download)
return Promise.all([
DownloadFormatter.getDownloadedSize(download),
DownloadFormatter.getTotalSize(download)
]).then(([partial, total]) => {
navigator.mozL10n.setAttributes(domNodes.info, 'partialResult', {
partial: partial,
total: total
});
});

} else {
var status = '';
var statusPromise;

switch (state) {
case 'stopped':
case 'failed':
status = _('download-' + state);
statusPromise = navigator.mozL10n.formatValue('download-' + state);
break;
case 'succeeded':
status = DownloadFormatter.getTotalSize(download);
statusPromise = DownloadFormatter.getTotalSize(download);
break;
default:
statusPromise = Promise.resolve();
}
DownloadFormatter.getDate(download, function(date) {
return Promise.all([
DownloadFormatter.getDate(download),
statusPromise
]).then(function([date, status]) {
navigator.mozL10n.setAttributes(domNodes.info, 'summary', {
date: date,
status: status
Expand Down
63 changes: 35 additions & 28 deletions apps/settings/js/downloads/downloads_list.js
Expand Up @@ -46,11 +46,12 @@
}

function _newDownload(download) {
_prepend(download);
if (isEditMode) {
numberOfDownloads++;
_updateButtonsStatus();
}
_prepend(download).then(() => {
if (isEditMode) {
numberOfDownloads++;
_updateButtonsStatus();
}
});
}

function _render(downloads, oncomplete) {
Expand All @@ -65,9 +66,9 @@
// Clean before rendering
downloadsContainer.innerHTML = '';
// Render
downloads.forEach(_append);

oncomplete && oncomplete();
Promise.all(downloads.map(_append)).then(() => {
oncomplete && oncomplete();
});
}

function _onerror() {
Expand All @@ -76,33 +77,39 @@
}

function _create(download) {
var li = DownloadItem.create(download);
if (download.state === 'downloading') {
download.onstatechange = _onDownloadStateChange;
}
li.addEventListener('click', _onDownloadAction);
return li;
return DownloadItem.create(download).then((li) => {
if (download.state === 'downloading') {
download.onstatechange = _onDownloadStateChange;
}
li.addEventListener('click', _onDownloadAction);
return li;
});
}

function _prepend(download) {
if (downloadsContainer.children.length === 0) {
_append(download);
_checkEmptyList();
_append(download).then(() => {
_checkEmptyList();
});
return;
}

downloadsContainer.insertBefore(
_create(download),
downloadsContainer.firstChild
);
_checkEmptyList();
_create(download).then((li) => {
downloadsContainer.insertBefore(
li,
downloadsContainer.firstChild
);
_checkEmptyList();
});
}

function _append(download) {
downloadsContainer.appendChild(_create(download));
if (download.state === 'downloading') {
download.onstatechange = _onDownloadStateChange;
}
return _create(download).then((li) => {
downloadsContainer.appendChild(li);
if (download.state === 'downloading') {
download.onstatechange = _onDownloadStateChange;
}
});
}

function _getElementForId(id) {
Expand Down Expand Up @@ -191,7 +198,8 @@
// succeeded.
}, function onError() {
// This error is fired when a download restarted is paused
console.error(navigator.mozL10n.get('restart_download_error'));
navigator.mozL10n.formatValue('restart_download_error').then(msg =>
console.error(msg));
});
}
};
Expand Down Expand Up @@ -457,5 +465,4 @@
}(window));

// startup
navigator.mozL10n.once(DownloadsList.init.bind(DownloadsList));

DownloadsList.init();
23 changes: 11 additions & 12 deletions apps/settings/js/findmydevice.js
Expand Up @@ -78,9 +78,10 @@ define('findmydevice', ['modules/settings_utils', 'shared/settings_listener'
if (this._loginButton.disabled) {
return;
}
var _ = navigator.mozL10n.get;
if (!window.navigator.onLine) {
return window.alert(_('findmydevice-enable-network'));
navigator.mozL10n.formatValue('findmydevice-enable-network').then(
(msg) => window.alert(msg));
return;
}
this._interactiveLogin = true;
var self = this;
Expand Down Expand Up @@ -142,13 +143,13 @@ define('findmydevice', ['modules/settings_utils', 'shared/settings_listener'
_onCheckboxChanged: function fmd_on_checkbox_changed(event) {
event.preventDefault();

var _ = navigator.mozL10n.get;
if (!window.navigator.onLine) {
setTimeout(function() {
// XXX(ggp) do this later so that the visual change in the
// checkbox is properly prevented.
window.alert(_('findmydevice-enable-network'));
});
// XXX(ggp) do this later so that the visual change in the
// checkbox is properly prevented.
// formatValue is asynchronous so we don't need an artificial
// setTimeout here.
navigator.mozL10n.formatValue('findmydevice-enable-network').then(
msg => window.alert(msg));
return;
}

Expand All @@ -168,8 +169,6 @@ define('findmydevice', ['modules/settings_utils', 'shared/settings_listener'
return FindMyDevice;
});

navigator.mozL10n.once(function() {
require(['findmydevice'], function(FindMyDevice) {
FindMyDevice.init();
});
require(['findmydevice'], function(FindMyDevice) {
FindMyDevice.init();
});
30 changes: 14 additions & 16 deletions apps/settings/js/firefox_accounts/menu_loader.js
Expand Up @@ -3,20 +3,18 @@
'use strict';

require(['shared/lazy_loader'], function(LazyLoader) {
navigator.mozL10n.once(function loadWhenIdle() {
var idleObserver = {
time: 4,
onidle: function() {
navigator.removeIdleObserver(idleObserver);
LazyLoader.load([
'/shared/js/fxa_iac_client.js',
'/shared/js/text_normalizer.js',
'js/firefox_accounts/menu.js'
], function fxa_menu_loaded() {
FxaMenu.init(FxAccountsIACHelper);
});
}
};
navigator.addIdleObserver(idleObserver);
});
var idleObserver = {
time: 4,
onidle: function() {
navigator.removeIdleObserver(idleObserver);
LazyLoader.load([
'/shared/js/fxa_iac_client.js',
'/shared/js/text_normalizer.js',
'js/firefox_accounts/menu.js'
], function fxa_menu_loaded() {
FxaMenu.init(FxAccountsIACHelper);
});
}
};
navigator.addIdleObserver(idleObserver);
});

0 comments on commit 3b31a39

Please sign in to comment.