Added tag list refreshing on tag edits

Result: suggestions etc. gets updated without the need to refresh the
page
This commit is contained in:
Marcin Kurczewski 2014-11-03 13:08:58 +01:00
parent 703cc4724a
commit 150d585860
4 changed files with 20 additions and 14 deletions

1
TODO
View file

@ -5,7 +5,6 @@ first major release.
- posts/upload: ability to paste many urls (unsure) - posts/upload: ability to paste many urls (unsure)
- posts/listing: add buttons for toggling safety - posts/listing: add buttons for toggling safety
- users: add user-configurable "about me" (should support Markdown) - users: add user-configurable "about me" (should support Markdown)
- tags: refresh tags.json when editing post
- tags: add tag merging - tags: add tag merging
- tags: add tag descriptions - tags: add tag descriptions
- tags: add tag edit snapshots (backed-only) - tags: add tag edit snapshots (backed-only)

View file

@ -5,7 +5,8 @@ App.Presenters.PostEditPresenter = function(
util, util,
promise, promise,
api, api,
auth) { auth,
tagList) {
var $target; var $target;
var post; var post;
@ -132,6 +133,7 @@ App.Presenters.PostEditPresenter = function(
promise.wait(api.put('/posts/' + post.id, formData)) promise.wait(api.put('/posts/' + post.id, formData))
.then(function(response) { .then(function(response) {
tagList.refreshTags();
if (typeof(updateCallback) !== 'undefined') { if (typeof(updateCallback) !== 'undefined') {
updateCallback(post = response.json); updateCallback(post = response.json);
} }
@ -153,4 +155,4 @@ App.Presenters.PostEditPresenter = function(
}; };
App.DI.register('postEditPresenter', ['util', 'promise', 'api', 'auth'], App.Presenters.PostEditPresenter); App.DI.register('postEditPresenter', ['util', 'promise', 'api', 'auth', 'tagList'], App.Presenters.PostEditPresenter);

View file

@ -8,6 +8,7 @@ App.Presenters.TagPresenter = function(
promise, promise,
auth, auth,
api, api,
tagList,
router, router,
keyboard, keyboard,
topNavigationPresenter, topNavigationPresenter,
@ -117,6 +118,7 @@ App.Presenters.TagPresenter = function(
tag = response.json; tag = response.json;
render(); render();
renderPosts(posts); renderPosts(posts);
tagList.refreshTags();
}).fail(function(response) { }).fail(function(response) {
window.alert(response.json && response.json.error || 'An error occured.'); window.alert(response.json && response.json.error || 'An error occured.');
}); });
@ -147,4 +149,4 @@ App.Presenters.TagPresenter = function(
}; };
App.DI.register('tagPresenter', ['_', 'jQuery', 'util', 'promise', 'auth', 'api', 'router', 'keyboard', 'topNavigationPresenter', 'messagePresenter'], App.Presenters.TagPresenter); App.DI.register('tagPresenter', ['_', 'jQuery', 'util', 'promise', 'auth', 'api', 'tagList', 'router', 'keyboard', 'topNavigationPresenter', 'messagePresenter'], App.Presenters.TagPresenter);

View file

@ -4,22 +4,25 @@ App.Services = App.Services || {};
App.Services.TagList = function(jQuery) { App.Services.TagList = function(jQuery) {
var tags = []; var tags = [];
jQuery.ajax({ function refreshTags() {
success: function(data, textStatus, xhr) { jQuery.ajax({
tags = data; success: function(data, textStatus, xhr) {
}, tags = data;
error: function(xhr, textStatus, errorThrown) { },
console.log(new Error(errorThrown)); error: function(xhr, textStatus, errorThrown) {
}, console.log(new Error(errorThrown));
type: 'GET', },
url: '/data/tags.json', type: 'GET',
}); url: '/data/tags.json',
});
}
function getTags() { function getTags() {
return tags; return tags;
} }
return { return {
refreshTags: refreshTags,
getTags: getTags, getTags: getTags,
}; };
}; };