@@ -10,7 +10,7 @@ extends /views/layouts/layout
10
10
11
11
block content
12
12
13
- .has-alert
13
+ .has-alert.js-alerts
14
14
include /views/partials/_flash
15
15
16
16
section.row.has-sector
@@ -22,7 +22,7 @@ block content
22
22
23
23
if stories .length > 0
24
24
- for story in stories
25
- li.list-item ( data-article =story .id )
25
+ li.list-item ( data-article =story .id id = 'story-' + story . id )
26
26
27
27
article.bdrbl.pbl.mbm ( role ='article' )
28
28
@@ -44,7 +44,7 @@ block content
44
44
p.well.well--l.tsl = story .body
45
45
46
46
.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
48
48
49
49
h2 Deny Story
50
50
p.tcs.tss
@@ -54,7 +54,7 @@ block content
54
54
.g.g--xs
55
55
.g-b.g-b--3of4
56
56
.select
57
- select.select-input ( name ="moderate" id ="moderate" )
57
+ select.select-input.js-admin-reason ( name ="moderate" id ="moderate" )
58
58
option.select-input-option ( value =0 ) Select reason...
59
59
option.select-input-option ( value =1 ) Duplicate
60
60
option.select-input-option ( value =2 ) Hard to understand
@@ -63,7 +63,7 @@ block content
63
63
option.select-input-option ( value =5 ) Disrespectful language
64
64
option.select-input-option ( value =6 ) Not within community interests
65
65
.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
67
67
68
68
else
69
69
p.tsi There are no unapproved stories right now.
@@ -75,23 +75,50 @@ block inline_javascript
75
75
xhr .setRequestHeader (' csrf-token' , ' #{token}' );
76
76
};
77
77
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="#">×</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
+
80
101
$ .ajax ({
81
102
type: ' POST' ,
82
103
url: ' /admin/news/' + storyId + ' /approve' ,
83
104
beforeSend: setHeader
84
105
})
85
- .done (function (response ){
106
+ .done (function (response ) {
86
107
console .log (response);
108
+ if (response === true ) {
109
+ $ (' #story-' + storyId).remove ();
110
+ notify (' success' , ' The story has been approved.' );
111
+ }
87
112
});
88
113
});
89
114
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' );
92
119
var reason;
93
120
94
- switch ($ (' #moderate ' ).val ()) {
121
+ switch ($ (' .js-admin-reason ' ).val ()) {
95
122
case " 1" :
96
123
reason = ' is a duplicate story.' ;
97
124
case " 2" :
@@ -112,8 +139,12 @@ block inline_javascript
112
139
url: ' /admin/news/' + storyId + ' /deny' ,
113
140
beforeSend: setHeader
114
141
})
115
- .done (function (response ){
142
+ .done (function (response ) {
116
143
console .log (response);
144
+ if (response === true ) {
145
+ $ (' #story-' + storyId).remove ();
146
+ notify (' success' , ' The story has been denied.' );
147
+ }
117
148
});
118
149
});
119
150
0 commit comments