Permalink
Browse files

Can delete a badge [closes #8]

  • Loading branch information...
brianloveswords committed Nov 3, 2012
1 parent 8cea644 commit 23e5f7bd5c9f207f89b27e9f7d7975f2a5bc4bfa
Showing with 33 additions and 10 deletions.
  1. +10 −5 app.js
  2. +1 −1 public/js/badge-index.js
  3. +1 −1 public/stylesheets/admin.css
  4. +9 −0 routes/badge.js
  5. +12 −3 views/admin/badge-index.html
View
15 app.js
@@ -72,8 +72,17 @@ app.get('/admin/badges', indexMiddleware, admin.badgeIndex);
// Creating and editing a badge
// ----------------------------
+var findBadgeByParamShortname = badge.findByShortName({
+ container: 'param',
+ field: 'shortname',
+ required: true
+});
+
app.get('/admin/badge', admin.newBadgeForm);
app.post('/admin/badge', badge.create);
+app.delete('/admin/badge/:shortname', [
+ findBadgeByParamShortname
+], badge.destroy);
app.get('/admin/badge/:shortname', [behavior.findAll], admin.showBadge);
app.post('/admin/badge/:shortname/behavior', badge.addBehavior);
app.delete('/admin/badge/:shortname/behavior', badge.removeBehavior);
@@ -92,11 +101,7 @@ app.delete('/admin/behavior/:shortname', [
// models/badge-instance.js. If you change these routes, change those
// methods.
app.get('/badge/image/:shortname.png', [
- badge.findByShortName({
- container: 'param',
- field: 'shortname',
- required: true
- })
+ findBadgeByParamShortname
], badge.image);
app.get('/badge/assertion/:hash', badge.assertion);
View
@@ -1,6 +1,6 @@
(function ($) {
console.log('loaded');
- var $forms = $('.js-remove-behavior');
+ var $forms = $('.js-remove-behavior, .js-remove-badge');
var $links = $forms.find('.js-show-remove');
$links.on('click', function (e) {
@@ -12,6 +12,6 @@
display: none;
}
-.remove-behavior input[type="submit"] {
+.remove-form input[type="submit"] {
display: none;
}
View
@@ -26,6 +26,15 @@ exports.create = function create(req, res) {
});
};
+exports.destroy = function destroy(req, res) {
+ var badge = req.badge;
+ return badge.remove(function (err) {
+ if (err)
+ return res.send(500, err);
+ return res.redirect('/');
+ });
+};
+
exports.addBehavior = function addBehavior(req, res) {
var form = req.body;
var behavior = {
@@ -4,21 +4,30 @@ <h1>Badges (<a href="/admin/badge">Create a new badge</a>)</h1>
<ul>
{% for badge in badges %}
<li>
- <a href="/admin/badge/{{ badge.shortname }}">{{ badge.name }}</a>
- (<code>{{ badge.shortname }}</code>)
+ <form method="post" action="/admin/badge/{{ badge.shortname }}" class="remove-form js-remove-badge">
+ <input type="hidden" name="_method" value="delete">
+ <input type="hidden" name="csrf" value="{{ csrf }}">
+ <a href="/admin/badge/{{ badge.shortname }}">{{ badge.name }}</a> (<code>{{ badge.shortname }}</code>)
+ <br>{{ badge.description | stupidSafe }}
+
+ <br><a href="" class="js-show-remove">remove?</a>
+ <input type="submit" value="Remove badge" class="btn btn-danger js-remove-button">
+ </form>
</li>
{% endfor %}
</ul>
<h1>Behaviors (<a href="/admin/behavior">Create a new behavior</a>)</h1>
+<ul>
{% for behavior in behaviors %}
<li>
- <form method="post" action="/admin/behavior/{{ behavior.shortname }}" class="remove-behavior js-remove-behavior">
+ <form method="post" action="/admin/behavior/{{ behavior.shortname }}" class="remove-form js-remove-behavior">
<input type="hidden" name="_method" value="delete">
<input type="hidden" name="csrf" value="{{ csrf }}">
<strong>{{ behavior.name }}</strong> (<code>{{ behavior.shortname }}</code>)
<br>{{ behavior.description | stupidSafe }}
+
<br><a href="" class="js-show-remove">remove?</a>
<input type="submit" value="Remove behavior" class="btn btn-danger js-remove-button">
</form>

0 comments on commit 23e5f7b

Please sign in to comment.