This repository has been archived by the owner on Nov 3, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20290 from EverythingMe/1020961-indications
Bug 1020961 - [Collection app] Loading progress indicator and Connectivity message
- Loading branch information
1 parent
4e8b16a
commit a0f537b
Showing
6 changed files
with
218 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
'use strict'; | ||
/* global eme */ | ||
|
||
(function(exports) { | ||
|
||
function ViewApps(collection) { | ||
|
||
var grid = document.getElementById('grid'); | ||
var elements = { | ||
offline: document.getElementById('offline'), | ||
offlineMessage: document.getElementById('offline-message') | ||
}; | ||
var requestParams = { | ||
query: collection.query, | ||
categoryId: collection.categoryId, | ||
iconFormat: getIconFormat() | ||
}; | ||
|
||
// render pinned apps first | ||
collection.render(grid); | ||
|
||
if (navigator.onLine) { | ||
makeRequest(); | ||
} else { | ||
onOffline(); | ||
} | ||
|
||
addListeners(); | ||
|
||
function onOffline() { | ||
loading(false); | ||
|
||
var msg = navigator.mozL10n.get('offline-webresults', { | ||
collectionName: collection.name | ||
}); | ||
elements.offlineMessage.innerHTML = msg; | ||
elements.offline.classList.add('show'); | ||
} | ||
|
||
function makeRequest() { | ||
loading(); | ||
|
||
eme.api.Apps.search(requestParams) | ||
.then(function success(searchResponse) { | ||
var results = []; | ||
|
||
searchResponse.response.apps.forEach(function each(webapp) { | ||
results.push({ | ||
id: webapp.id, // e.me app id (int) | ||
name: webapp.name, | ||
url: webapp.appUrl, | ||
icon: webapp.icon, | ||
clipIcon: true | ||
}); | ||
}); | ||
|
||
onResponse(); | ||
|
||
grid.clientLeft; // force layout or else grid isn't displayed | ||
collection.webResults = results; | ||
collection.render(grid); | ||
|
||
}, onResponse); | ||
} | ||
|
||
function loading(should) { | ||
document.body.dataset.loading = should !== false; | ||
elements.offline.classList.remove('show'); | ||
} | ||
|
||
function onResponse() { | ||
loading(false); | ||
removeListeners(); | ||
} | ||
|
||
function addListeners() { | ||
window.addEventListener('online', makeRequest); | ||
window.addEventListener('offline', onOffline); | ||
} | ||
|
||
function removeListeners() { | ||
window.removeEventListener('online', makeRequest); | ||
window.removeEventListener('offline', onOffline); | ||
} | ||
|
||
function getIconFormat() { | ||
return 20; | ||
} | ||
} | ||
|
||
exports.ViewApps = ViewApps; | ||
|
||
}(window)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
'use strict'; | ||
/* global eme */ | ||
|
||
(function(exports) { | ||
|
||
function ViewBGImage(requestParams) { | ||
|
||
var elements = { | ||
content: document.getElementById('content') | ||
}; | ||
|
||
if (navigator.onLine) { | ||
onOnline(); | ||
} else { | ||
addListeners(); | ||
} | ||
|
||
function onOnline() { | ||
eme.api.Search.bgimage(requestParams) | ||
.then(function success(bgResponse) { | ||
removeListeners(); | ||
|
||
var image = bgResponse.response.image; | ||
if (image) { | ||
var src = image.data; | ||
if (/image\//.test(image.MIMEType)) { // base64 image data | ||
src = 'data:' + image.MIMEType + ';base64,' + image.data; | ||
} | ||
|
||
elements.content.style.backgroundImage = 'url(' + src + ')'; | ||
} else { | ||
// TODO show default image? | ||
} | ||
}); | ||
} | ||
|
||
function addListeners() { | ||
window.addEventListener('online', onOnline); | ||
} | ||
|
||
function removeListeners() { | ||
window.removeEventListener('online', onOnline); | ||
} | ||
} | ||
|
||
exports.ViewBGImage = ViewBGImage; | ||
|
||
}(window)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.