sharedrop/app/scripts/app.js
2014-03-10 09:32:01 +01:00

64 lines
1.5 KiB
JavaScript

window.ShareDrop.App = Ember.Application.create();
ShareDrop.App.deferReadiness();
// Check if everything we need is available
(function () {
checkWebRTCSupport()
.then(clearFileSystem)
.catch(function (error) {
ShareDrop.App.error = error;
})
.then(function () {
ShareDrop.App.advanceReadiness();
});
function checkWebRTCSupport() {
return new Promise(function (resolve, reject) {
if (('webkitRTCPeerConnection' in window) && util.supports.sctp) {
resolve();
} else {
reject('browser_unsupported');
}
});
}
function clearFileSystem() {
return new Promise(function (resolve, reject) {
ShareDrop.File.removeAll()
.then(function () {
resolve();
})
.catch(function () {
reject('filesystem_unavailable');
});
});
}
})();
ShareDrop.App.IndexRoute = Ember.Route.extend({
beforeModel: function() {
if (ShareDrop.App.error) {
throw new Error(ShareDrop.App.error);
}
},
renderTemplate: function () {
this.render();
this.render('about_you', {
into: 'application',
outlet: 'about_you'
});
}
});
ShareDrop.App.ErrorRoute = Ember.Route.extend({
renderTemplate: function(controller, error) {
var name = 'errors/' + error.message,
template = Ember.TEMPLATES[name];
if (template) this.render(name);
}
});