diff --git a/public_html/js/Api.js b/public_html/js/Api.js
index cdb26836..5b875d6b 100644
--- a/public_html/js/Api.js
+++ b/public_html/js/Api.js
@@ -1,6 +1,6 @@
var App = App || {};
-App.API = function(jQuery, promise, appState) {
+App.API = function(_, jQuery, promise, appState) {
var baseUrl = '/api/';
@@ -32,13 +32,13 @@ App.API = function(jQuery, promise, appState) {
success: function(data, textStatus, xhr) {
resolve({
status: xhr.status,
- json: data});
+ json: stripMeta(data)});
},
error: function(xhr, textStatus, errorThrown) {
reject({
status: xhr.status,
json: xhr.responseJSON ?
- xhr.responseJSON :
+ stripMeta(xhr.responseJSON) :
{error: errorThrown}});
},
type: method,
@@ -48,6 +48,16 @@ App.API = function(jQuery, promise, appState) {
});
}
+ function stripMeta(data) {
+ var result = {};
+ _.each(data, function(v, k) {
+ if (!k.match(/^__/)) {
+ result[k] = v;
+ }
+ });
+ return result;
+ }
+
return {
get: get,
post: post,
@@ -57,4 +67,4 @@ App.API = function(jQuery, promise, appState) {
};
-App.DI.registerSingleton('api', ['jQuery', 'promise', 'appState'], App.API);
+App.DI.registerSingleton('api', ['_', 'jQuery', 'promise', 'appState'], App.API);
diff --git a/public_html/js/Bootstrap.js b/public_html/js/Bootstrap.js
index 20bb07b9..c48882f6 100644
--- a/public_html/js/Bootstrap.js
+++ b/public_html/js/Bootstrap.js
@@ -2,17 +2,20 @@ var App = App || {};
App.Bootstrap = function(auth, router, promise, presenterManager) {
- promise.wait(
- auth.tryLoginFromCookie(),
- presenterManager.init())
- .then(startRouting)
- .fail(function(error) {
- promise.wait(auth.loginAnonymous())
+ promise.wait(presenterManager.init())
+ .then(function() {
+ promise.wait(auth.tryLoginFromCookie())
.then(startRouting)
- .fail(function(response) {
- console.log(response);
- window.alert('Fatal authentication error: ' + response.json.error);
+ .fail(function(error) {
+ promise.wait(auth.loginAnonymous())
+ .then(startRouting)
+ .fail(function() {
+ console.log(arguments);
+ window.alert('Fatal authentication error');
+ });
});
+ }).fail(function() {
+ console.log(arguments);
});
function startRouting() {
diff --git a/public_html/js/Presenters/GlobalCommentListPresenter.js b/public_html/js/Presenters/GlobalCommentListPresenter.js
index 73722f9e..15bca4f6 100644
--- a/public_html/js/Presenters/GlobalCommentListPresenter.js
+++ b/public_html/js/Presenters/GlobalCommentListPresenter.js
@@ -20,28 +20,29 @@ App.Presenters.GlobalCommentListPresenter = function(
util.promiseTemplate('global-comment-list'),
util.promiseTemplate('global-comment-list-item'),
util.promiseTemplate('post-list-item'))
- .then(function(listTemplate, listItemTemplate, postTemplate)
- {
- templates.list = listTemplate;
- templates.listItem = listItemTemplate;
- templates.post = postTemplate;
+ .then(function(listTemplate, listItemTemplate, postTemplate) {
+ templates.list = listTemplate;
+ templates.listItem = listItemTemplate;
+ templates.post = postTemplate;
- render();
- loaded();
+ render();
+ loaded();
- pagerPresenter.init({
- baseUri: '#/comments',
- backendUri: '/comments',
- $target: $el.find('.pagination-target'),
- updateCallback: function(data, clear) {
- renderPosts(data.entities, clear);
- },
+ pagerPresenter.init({
+ baseUri: '#/comments',
+ backendUri: '/comments',
+ $target: $el.find('.pagination-target'),
+ updateCallback: function(data, clear) {
+ renderPosts(data.entities, clear);
},
- function() {
- reinit(params, function() {});
- });
- })
- .fail(function() { console.log(new Error(arguments)); });
+ },
+ function() {
+ reinit(params, function() {});
+ });
+ }).fail(function() {
+ console.log(arguments);
+ loaded();
+ });
}
diff --git a/public_html/js/Presenters/HomePresenter.js b/public_html/js/Presenters/HomePresenter.js
index d321203e..f344abcc 100644
--- a/public_html/js/Presenters/HomePresenter.js
+++ b/public_html/js/Presenters/HomePresenter.js
@@ -33,7 +33,7 @@ App.Presenters.HomePresenter = function(
templates.postContent = postContentTemplate;
globals = globalsResponse.json;
- post = featuredPostResponse.json;
+ post = featuredPostResponse.json.id ? featuredPostResponse.json : null;
render();
loaded();
diff --git a/public_html/js/Presenters/LoginPresenter.js b/public_html/js/Presenters/LoginPresenter.js
index 954bf75e..0ff86c39 100644
--- a/public_html/js/Presenters/LoginPresenter.js
+++ b/public_html/js/Presenters/LoginPresenter.js
@@ -29,6 +29,9 @@ App.Presenters.LoginPresenter = function(
$el.find('input:eq(0)').focus();
}
loaded();
+ }).fail(function() {
+ console.log(arguments);
+ loaded();
});
}
diff --git a/public_html/js/Presenters/LogoutPresenter.js b/public_html/js/Presenters/LogoutPresenter.js
index b13102ee..90f4bf2b 100644
--- a/public_html/js/Presenters/LogoutPresenter.js
+++ b/public_html/js/Presenters/LogoutPresenter.js
@@ -21,8 +21,8 @@ App.Presenters.LogoutPresenter = function(
var $messageDiv = messagePresenter.showInfo($messages, 'Logged out. Back to main page');
$messageDiv.find('a').click(mainPageLinkClicked);
}).fail(function(response) {
- loaded();
messagePresenter.showError(($messages, response.json && response.json.error || response) + '
Reload the page to continue.');
+ loaded();
});
}
diff --git a/public_html/js/Presenters/PagerPresenter.js b/public_html/js/Presenters/PagerPresenter.js
index 9c7210b6..88296723 100644
--- a/public_html/js/Presenters/PagerPresenter.js
+++ b/public_html/js/Presenters/PagerPresenter.js
@@ -46,6 +46,9 @@ App.Presenters.PagerPresenter = function(
templates.pager = template;
render();
loaded();
+ }).fail(function() {
+ console.log(arguments);
+ loaded();
});
}
diff --git a/public_html/js/Presenters/PostCommentListPresenter.js b/public_html/js/Presenters/PostCommentListPresenter.js
index 5294d986..f4fe4a41 100644
--- a/public_html/js/Presenters/PostCommentListPresenter.js
+++ b/public_html/js/Presenters/PostCommentListPresenter.js
@@ -53,10 +53,15 @@ App.Presenters.PostCommentListPresenter = function(
.then(function(response) {
comments = response.json.data;
render();
+ }).fail(function() {
+ console.log(arguments);
});
}
})
- .fail(function() { console.log(new Error(arguments)); });
+ .fail(function() {
+ console.log(arguments);
+ loaded();
+ });
}
function render() {
diff --git a/public_html/js/Presenters/PostPresenter.js b/public_html/js/Presenters/PostPresenter.js
index a06d33b5..98b22795 100644
--- a/public_html/js/Presenters/PostPresenter.js
+++ b/public_html/js/Presenters/PostPresenter.js
@@ -83,7 +83,10 @@ App.Presenters.PostPresenter = function(
topNavigationPresenter.changeTitle('@' + post.id);
render();
loaded();
- }).fail(loaded);
+ }).fail(function() {
+ console.log(arguments);
+ loaded();
+ });
}
function attachLinksToPostsAround() {
diff --git a/public_html/js/Presenters/PostUploadPresenter.js b/public_html/js/Presenters/PostUploadPresenter.js
index 0911daa6..7ee89089 100644
--- a/public_html/js/Presenters/PostUploadPresenter.js
+++ b/public_html/js/Presenters/PostUploadPresenter.js
@@ -32,6 +32,9 @@ App.Presenters.PostUploadPresenter = function(
templates.upload = template;
render();
loaded();
+ }).fail(function() {
+ console.log(arguments);
+ loaded();
});
}
diff --git a/public_html/js/Presenters/RegistrationPresenter.js b/public_html/js/Presenters/RegistrationPresenter.js
index 9320b514..207fc860 100644
--- a/public_html/js/Presenters/RegistrationPresenter.js
+++ b/public_html/js/Presenters/RegistrationPresenter.js
@@ -21,6 +21,9 @@ App.Presenters.RegistrationPresenter = function(
templates.registration = template;
render();
loaded();
+ }).fail(function() {
+ console.log(arguments);
+ loaded();
});
}
diff --git a/public_html/js/Presenters/TagListPresenter.js b/public_html/js/Presenters/TagListPresenter.js
index 9eec6e99..65b1fbcf 100644
--- a/public_html/js/Presenters/TagListPresenter.js
+++ b/public_html/js/Presenters/TagListPresenter.js
@@ -38,6 +38,9 @@ App.Presenters.TagListPresenter = function(
function() {
reinit(params, function() {});
});
+ }).fail(function() {
+ console.log(arguments);
+ loaded();
});
}
diff --git a/public_html/js/Presenters/TagPresenter.js b/public_html/js/Presenters/TagPresenter.js
index a5a19cef..06df9cc0 100644
--- a/public_html/js/Presenters/TagPresenter.js
+++ b/public_html/js/Presenters/TagPresenter.js
@@ -36,6 +36,9 @@ App.Presenters.TagPresenter = function(
templates.postListItem = postListItemTemplate;
reinit(params, loaded);
+ }).fail(function() {
+ console.log(arguments);
+ loaded();
});
}
diff --git a/public_html/js/Presenters/TopNavigationPresenter.js b/public_html/js/Presenters/TopNavigationPresenter.js
index 8d576535..7f2d2d9f 100644
--- a/public_html/js/Presenters/TopNavigationPresenter.js
+++ b/public_html/js/Presenters/TopNavigationPresenter.js
@@ -19,6 +19,8 @@ App.Presenters.TopNavigationPresenter = function(
render();
loaded();
auth.startObservingLoginChanges('top-navigation', loginStateChanged);
+ }).fail(function() {
+ loaded();
});
}
diff --git a/public_html/js/Presenters/UserAccountRemovalPresenter.js b/public_html/js/Presenters/UserAccountRemovalPresenter.js
index f20d0900..04b731da 100644
--- a/public_html/js/Presenters/UserAccountRemovalPresenter.js
+++ b/public_html/js/Presenters/UserAccountRemovalPresenter.js
@@ -28,6 +28,9 @@ App.Presenters.UserAccountRemovalPresenter = function(
templates.accountRemoval = template;
render();
loaded();
+ }).fail(function() {
+ console.log(arguments);
+ loaded();
});
}
diff --git a/public_html/js/Presenters/UserAccountSettingsPresenter.js b/public_html/js/Presenters/UserAccountSettingsPresenter.js
index 0facc7f5..4aa7e843 100644
--- a/public_html/js/Presenters/UserAccountSettingsPresenter.js
+++ b/public_html/js/Presenters/UserAccountSettingsPresenter.js
@@ -45,6 +45,9 @@ App.Presenters.UserAccountSettingsPresenter = function(
templates.accountRemoval = template;
render();
loaded();
+ }).fail(function() {
+ console.log(arguments);
+ loaded();
});
}
diff --git a/public_html/js/Presenters/UserActivationPresenter.js b/public_html/js/Presenters/UserActivationPresenter.js
index 350379f9..16af4c16 100644
--- a/public_html/js/Presenters/UserActivationPresenter.js
+++ b/public_html/js/Presenters/UserActivationPresenter.js
@@ -36,6 +36,9 @@ App.Presenters.UserActivationPresenter = function(
}
render();
loaded();
+ }).fail(function() {
+ console.log(arguments);
+ loaded();
});
}
diff --git a/public_html/js/Presenters/UserBrowsingSettingsPresenter.js b/public_html/js/Presenters/UserBrowsingSettingsPresenter.js
index f26a69c2..589de54a 100644
--- a/public_html/js/Presenters/UserBrowsingSettingsPresenter.js
+++ b/public_html/js/Presenters/UserBrowsingSettingsPresenter.js
@@ -25,6 +25,9 @@ App.Presenters.UserBrowsingSettingsPresenter = function(
templates.browsingSettings = template;
render();
loaded();
+ }).fail(function() {
+ console.log(arguments);
+ loaded();
});
}
@@ -53,6 +56,8 @@ App.Presenters.UserBrowsingSettingsPresenter = function(
promise.wait(browsingSettings.setSettings(newSettings))
.then(function() {
messagePresenter.showInfo($messages, 'Browsing settings updated!');
+ }).fail(function() {
+ console.log(arguments);
});
}
diff --git a/public_html/js/Presenters/UserListPresenter.js b/public_html/js/Presenters/UserListPresenter.js
index cc0189d0..b7e213be 100644
--- a/public_html/js/Presenters/UserListPresenter.js
+++ b/public_html/js/Presenters/UserListPresenter.js
@@ -39,6 +39,9 @@ App.Presenters.UserListPresenter = function(
function() {
reinit(params, function() {});
});
+ }).fail(function() {
+ console.log(arguments);
+ loaded();
});
}
diff --git a/public_html/js/Presenters/UserPresenter.js b/public_html/js/Presenters/UserPresenter.js
index af1223b0..05774ee2 100644
--- a/public_html/js/Presenters/UserPresenter.js
+++ b/public_html/js/Presenters/UserPresenter.js
@@ -28,6 +28,9 @@ App.Presenters.UserPresenter = function(
$messages = $el.find('.messages');
templates.user = template;
reinit(params, loaded);
+ }).fail(function() {
+ console.log(arguments);
+ loaded();
});
}
diff --git a/public_html/js/Promise.js b/public_html/js/Promise.js
index 9633b690..32877fb9 100644
--- a/public_html/js/Promise.js
+++ b/public_html/js/Promise.js
@@ -20,7 +20,7 @@ App.Promise = function(_, jQuery) {
active.push(promise.promiseId);
- promise.then(function() {
+ promise.always(function() {
if (!_.contains(active, promise.promiseId)) {
throw new Error('Broken promise (promise ID: ' + promise.promiseId + ')');
}
diff --git a/public_html/js/Util.js b/public_html/js/Util.js
index 73c87386..3f2ed4fd 100644
--- a/public_html/js/Util.js
+++ b/public_html/js/Util.js
@@ -124,7 +124,7 @@ App.Util = function(_, jQuery, marked, promise) {
}
function formatUnits(number, base, suffixes, callback) {
- if (!number) {
+ if (!number && number !== 0) {
return NaN;
}
number *= 1.0;
diff --git a/public_html/templates/home.tpl b/public_html/templates/home.tpl
index 8dd3dded..7cb95d68 100644
--- a/public_html/templates/home.tpl
+++ b/public_html/templates/home.tpl
@@ -1,10 +1,10 @@
- Serving <%= globals.postCount %> posts (<%= formatFileSize(globals.postSize) %>) + Serving <%= globals.postCount || 0 %> posts (<%= formatFileSize(globals.postSize || 0) %>)
- <% if (post) { %> + <% if (post && typeof(post) !== 'undefined') { %>