Skip to content
This repository
Browse code

Can delete a badge [closes #8]

  • Loading branch information...
commit 23e5f7bd5c9f207f89b27e9f7d7975f2a5bc4bfa 1 parent 8cea644
Brian J Brennan brianloveswords authored
15 app.js
@@ -72,8 +72,17 @@ app.get('/admin/badges', indexMiddleware, admin.badgeIndex);
72 72
73 73 // Creating and editing a badge
74 74 // ----------------------------
  75 +var findBadgeByParamShortname = badge.findByShortName({
  76 + container: 'param',
  77 + field: 'shortname',
  78 + required: true
  79 +});
  80 +
75 81 app.get('/admin/badge', admin.newBadgeForm);
76 82 app.post('/admin/badge', badge.create);
  83 +app.delete('/admin/badge/:shortname', [
  84 + findBadgeByParamShortname
  85 +], badge.destroy);
77 86 app.get('/admin/badge/:shortname', [behavior.findAll], admin.showBadge);
78 87 app.post('/admin/badge/:shortname/behavior', badge.addBehavior);
79 88 app.delete('/admin/badge/:shortname/behavior', badge.removeBehavior);
@@ -92,11 +101,7 @@ app.delete('/admin/behavior/:shortname', [
92 101 // models/badge-instance.js. If you change these routes, change those
93 102 // methods.
94 103 app.get('/badge/image/:shortname.png', [
95   - badge.findByShortName({
96   - container: 'param',
97   - field: 'shortname',
98   - required: true
99   - })
  104 + findBadgeByParamShortname
100 105 ], badge.image);
101 106 app.get('/badge/assertion/:hash', badge.assertion);
102 107
2  public/js/badge-index.js
... ... @@ -1,6 +1,6 @@
1 1 (function ($) {
2 2 console.log('loaded');
3   - var $forms = $('.js-remove-behavior');
  3 + var $forms = $('.js-remove-behavior, .js-remove-badge');
4 4 var $links = $forms.find('.js-show-remove');
5 5
6 6 $links.on('click', function (e) {
2  public/stylesheets/admin.css
@@ -12,6 +12,6 @@
12 12 display: none;
13 13 }
14 14
15   -.remove-behavior input[type="submit"] {
  15 +.remove-form input[type="submit"] {
16 16 display: none;
17 17 }
9 routes/badge.js
@@ -26,6 +26,15 @@ exports.create = function create(req, res) {
26 26 });
27 27 };
28 28
  29 +exports.destroy = function destroy(req, res) {
  30 + var badge = req.badge;
  31 + return badge.remove(function (err) {
  32 + if (err)
  33 + return res.send(500, err);
  34 + return res.redirect('/');
  35 + });
  36 +};
  37 +
29 38 exports.addBehavior = function addBehavior(req, res) {
30 39 var form = req.body;
31 40 var behavior = {
15 views/admin/badge-index.html
@@ -4,21 +4,30 @@
4 4 <ul>
5 5 {% for badge in badges %}
6 6 <li>
7   - <a href="/admin/badge/{{ badge.shortname }}">{{ badge.name }}</a>
8   - (<code>{{ badge.shortname }}</code>)
  7 + <form method="post" action="/admin/badge/{{ badge.shortname }}" class="remove-form js-remove-badge">
  8 + <input type="hidden" name="_method" value="delete">
  9 + <input type="hidden" name="csrf" value="{{ csrf }}">
  10 + <a href="/admin/badge/{{ badge.shortname }}">{{ badge.name }}</a> (<code>{{ badge.shortname }}</code>)
  11 + <br>{{ badge.description | stupidSafe }}
  12 +
  13 + <br><a href="" class="js-show-remove">remove?</a>
  14 + <input type="submit" value="Remove badge" class="btn btn-danger js-remove-button">
  15 + </form>
9 16 </li>
10 17 {% endfor %}
11 18 </ul>
12 19
13 20
14 21 <h1>Behaviors (<a href="/admin/behavior">Create a new behavior</a>)</h1>
  22 +<ul>
15 23 {% for behavior in behaviors %}
16 24 <li>
17   - <form method="post" action="/admin/behavior/{{ behavior.shortname }}" class="remove-behavior js-remove-behavior">
  25 + <form method="post" action="/admin/behavior/{{ behavior.shortname }}" class="remove-form js-remove-behavior">
18 26 <input type="hidden" name="_method" value="delete">
19 27 <input type="hidden" name="csrf" value="{{ csrf }}">
20 28 <strong>{{ behavior.name }}</strong> (<code>{{ behavior.shortname }}</code>)
21 29 <br>{{ behavior.description | stupidSafe }}
  30 +
22 31 <br><a href="" class="js-show-remove">remove?</a>
23 32 <input type="submit" value="Remove behavior" class="btn btn-danger js-remove-button">
24 33 </form>

0 comments on commit 23e5f7b

Please sign in to comment.
Something went wrong with that request. Please try again.