diff --git a/data/config.ini b/data/config.ini index d17520ed..aaf74d6c 100644 --- a/data/config.ini +++ b/data/config.ini @@ -68,6 +68,7 @@ changeTagCategory = moderator, administrator changeTagImplications = moderator, administrator changeTagSuggestions = moderator, administrator banTags = moderator, administrator +deleteTags = moderator, administrator listComments = regularUser, powerUser, moderator, administrator addComments = regularUser, powerUser, moderator, administrator diff --git a/public_html/js/Auth.js b/public_html/js/Auth.js index e2d9ed05..dc717965 100644 --- a/public_html/js/Auth.js +++ b/public_html/js/Auth.js @@ -45,6 +45,7 @@ App.Auth = function(_, jQuery, util, api, appState, promise) { editAllComments: 'editAllComments', deleteOwnComments: 'deleteOwnComments', deleteAllComments: 'deleteAllComments', + deleteTags: 'deleteTags', listTags: 'listTags', massTag: 'massTag', diff --git a/public_html/js/Presenters/TagPresenter.js b/public_html/js/Presenters/TagPresenter.js index c91e9f5f..b7ea4470 100644 --- a/public_html/js/Presenters/TagPresenter.js +++ b/public_html/js/Presenters/TagPresenter.js @@ -83,12 +83,14 @@ App.Presenters.TagPresenter = function( tagCategories: JSON.parse(jQuery('head').attr('data-tag-categories')), })); $el.find('.post-list').hide(); - $el.find('form').submit(editFormSubmitted); + $el.find('form').submit(function(e) { e.preventDefault(); }); + $el.find('form button[name=update]').click(updateButtonClicked); + $el.find('form button[name=delete]').click(deleteButtonClicked); implicationsTagInput = App.Controls.TagInput($el.find('[name=implications]')); suggestionsTagInput = App.Controls.TagInput($el.find('[name=suggestions]')); } - function editFormSubmitted(e) { + function updateButtonClicked(e) { e.preventDefault(); var $form = $el.find('form'); var formData = {}; @@ -121,6 +123,18 @@ App.Presenters.TagPresenter = function( }); } + function deleteButtonClicked(e) { + if (!window.confirm('Are you sure you want to delete this tag?')) { + return; + } + promise.wait(api.delete('/tags/' + tag.name)) + .then(function(response) { + router.navigate('#/tags'); + }).fail(function(response) { + window.alert(response.json && response.json.error || 'An error occured.'); + }); + } + function renderPosts(posts) { var $target = $el.find('.post-list ul'); _.each(posts, function(post) { diff --git a/public_html/templates/tag.tpl b/public_html/templates/tag.tpl index 87e2e2a7..1085f9e7 100644 --- a/public_html/templates/tag.tpl +++ b/public_html/templates/tag.tpl @@ -70,7 +70,8 @@