Skip to content

Commit a4a994c

Browse files
committed
Admin: Remove post, add flash when approved/denied
1 parent f3f26e5 commit a4a994c

File tree

1 file changed

+43
-12
lines changed

1 file changed

+43
-12
lines changed

server/views/admin/index.jade

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ extends /views/layouts/layout
1010

1111
block content
1212

13-
.has-alert
13+
.has-alert.js-alerts
1414
include /views/partials/_flash
1515

1616
section.row.has-sector
@@ -22,7 +22,7 @@ block content
2222

2323
if stories.length > 0
2424
- for story in stories
25-
li.list-item(data-article=story.id)
25+
li.list-item(data-article=story.id id='story-' + story.id)
2626

2727
article.bdrbl.pbl.mbm(role='article')
2828

@@ -44,7 +44,7 @@ block content
4444
p.well.well--l.tsl= story.body
4545

4646
.mbl
47-
a.btn.btn--success.approve(href='#') Approve Story
47+
a.btn.btn--success.js-admin-approve(href='#' data-story-id=story.id) Approve Story
4848

4949
h2 Deny Story
5050
p.tcs.tss
@@ -54,7 +54,7 @@ block content
5454
.g.g--xs
5555
.g-b.g-b--3of4
5656
.select
57-
select.select-input(name="moderate" id="moderate")
57+
select.select-input.js-admin-reason(name="moderate" id="moderate")
5858
option.select-input-option(value=0) Select reason...
5959
option.select-input-option(value=1) Duplicate
6060
option.select-input-option(value=2) Hard to understand
@@ -63,7 +63,7 @@ block content
6363
option.select-input-option(value=5) Disrespectful language
6464
option.select-input-option(value=6) Not within community interests
6565
.g-b.g-b--1of4
66-
a.btn.btn--a.btn--block.deny(href='#') Deny Story
66+
a.btn.btn--a.btn--block.js-admin-deny(href='#' data-story-id=story.id) Deny Story
6767

6868
else
6969
p.tsi There are no unapproved stories right now.
@@ -75,23 +75,50 @@ block inline_javascript
7575
xhr.setRequestHeader('csrf-token', '#{token}');
7676
};
7777

78-
$('a.approve').on('click', function(){
79-
var storyId = $(this).closest('li').attr('data-article');
78+
function notify(type, message) {
79+
var notification = '';
80+
81+
notification +=
82+
'<div class="alert alert--' + type + ' in js-alert">' +
83+
'<a class="alert-msg-close js-alert-close" href="#">&times;</a>' +
84+
'<p class="alert-msg">' + message + '</p>' +
85+
'</div>';
86+
87+
$('.js-alerts').append(notification);
88+
89+
90+
JS.Services.expel({
91+
$toggle : $('.js-alert-close'),
92+
elementNode : '.js-alert'
93+
});
94+
};
95+
96+
$('.js-admin-approve').on('click', function(event) {
97+
event.preventDefault();
98+
99+
var storyId = $(this).data('story-id');
100+
80101
$.ajax({
81102
type: 'POST',
82103
url: '/admin/news/' + storyId + '/approve',
83104
beforeSend: setHeader
84105
})
85-
.done(function(response){
106+
.done(function(response) {
86107
console.log(response);
108+
if (response === true) {
109+
$('#story-' + storyId).remove();
110+
notify('success', 'The story has been approved.');
111+
}
87112
});
88113
});
89114

90-
$('a.deny').on('click', function(){
91-
var storyId = $(this).closest('li').attr('data-article');
115+
$('.js-admin-deny').on('click', function(event) {
116+
event.preventDefault();
117+
118+
var storyId = $(this).data('story-id');
92119
var reason;
93120

94-
switch ($('#moderate').val()) {
121+
switch ($('.js-admin-reason').val()) {
95122
case "1":
96123
reason = 'is a duplicate story.';
97124
case "2":
@@ -112,8 +139,12 @@ block inline_javascript
112139
url: '/admin/news/' + storyId + '/deny',
113140
beforeSend: setHeader
114141
})
115-
.done(function(response){
142+
.done(function(response) {
116143
console.log(response);
144+
if (response === true) {
145+
$('#story-' + storyId).remove();
146+
notify('success', 'The story has been denied.');
147+
}
117148
});
118149
});
119150

0 commit comments

Comments
 (0)