Permalink
Browse files

Consolidate new badge templage and edit badge template.

  • Loading branch information...
brianloveswords committed Nov 6, 2012
1 parent a1aadfe commit f56df96aa6bf9b671d8e334488a529472160d030
Showing with 95 additions and 112 deletions.
  1. +5 −2 routes/admin.js
  2. +8 −0 template.js
  3. +82 −0 views/admin/create-or-edit-badge.html
  4. +0 −56 views/admin/edit-badge.html
  5. +0 −54 views/admin/new-badge.html
View
@@ -1,3 +1,4 @@
+var Badge = require('../models/badge');
var phrases = require('../lib/phrases');
/*
@@ -16,17 +17,19 @@ exports.login = function (req, res) {
}
exports.newBadgeForm = function (req, res) {
- return res.render('admin/new-badge.html', {
+ return res.render('admin/create-or-edit-badge.html', {
page: 'new-badge',
+ badge: new Badge,
issuer: req.issuer,
user: req.session.user,
csrf: req.session._csrf,
});
};
exports.editBadgeForm = function (req, res) {
- return res.render('admin/edit-badge.html', {
+ return res.render('admin/create-or-edit-badge.html', {
page: 'edit-badge',
+ editing: true,
badge: req.badge,
issuer: req.issuer,
user: req.session.user,
View
@@ -1,5 +1,6 @@
var markdown = require('markdown').markdown;
var nunjucks = require('nunjucks');
+var util = require('util');
var env = (new nunjucks.Environment(
new nunjucks.FileSystemLoader('views')
));
@@ -14,6 +15,13 @@ env.addFilter('activize', function (actual, expect) {
env.addFilter('markdown', function (string) {
return markdown.toHTML(string);
});
+env.addFilter('imageForBadge', function (badge) {
+ if (!badge || !badge.relativeUrl)
+ return;
+ return util.format(
+ '<img src="%s" style="float: right">',
+ badge.relativeUrl('image'));
+});
env.addFilter('stupidSafe', function (html) {
return (
@@ -0,0 +1,82 @@
+{% extends "admin/base.html" %}
+
+{% block main %}
+ <form method="post" action="?" enctype="multipart/form-data">
+ <input id="name" type="hidden" name="csrf" value="{{ csrf }}">
+
+ <legend>
+ {% if editing %}
+ Edit Badge: {{ badge.name }}
+ {% else %}
+ New Badge
+ {% endif %}
+ </legend>
+
+ <div>
+ {{ badge | imageForBadge }}
+ <label for="name">Name</label>
+ <input
+ id="name"
+ type="text"
+ name="name"
+ value="{{ badge.name | default('') }}"
+ placeholder="My Very Fancy Badge"
+ required>
+ <span class="help-block">
+ This is the name for your badge, it should be descriptive, but
+ also awesome.
+ </span>
+ </div>
+
+ <div>
+ <label for="description">Description</label>
+ <textarea
+ id="description"
+ rows="5"
+ name="description"
+ maxlength="128"
+ required>{{ badge.description | default('')}}</textarea>
+ <span class="help-block">
+ A description of your badge, this will appear in every assertion
+ created from this badge.
+ </span>
+ </div>
+
+ <div>
+ <label for="criteria">Criteria</label>
+ <textarea
+ id="criteria"
+ rows="5"
+ name="criteria"
+ required>{{ badge.criteria.content | default('')}}</textarea>
+ <span class="help-block">
+ The criteria text for the badge. This can be markdown, but don't
+ go crazy, okay? Keep it simple. That also means you'll have to escape
+ markup by wrapping it in backticks: <code>`&lt;strong&gt;`</code>
+ </span>
+ </div>
+
+ <div>
+ <label for="image">New Image</label>
+ <input
+ type="file"
+ name="image"
+ accept="image/png"
+ {% if not editing%} required {% endif %}>
+ <span class="help-block">
+ The image to use for the badge. It should be the greatest image
+ known to man.
+ {% if editing %} Leave blank to keep old image. {% endif %}
+ </span>
+ </div>
+
+ <div class="form-actions">
+ <button id="update-badge" type="submit" class="btn btn-primary">Update</button>
+ </div>
+ </form>
+{% endblock %}
+
+{% block footer %}
+<script src="/js/admin.js"></script>
+{% endblock %}
+
@@ -1,56 +0,0 @@
-{% extends "admin/base.html" %}
-
-{% block main %}
- <form method="post" action="?" enctype="multipart/form-data">
- <input id="name" type="hidden" name="csrf" value="{{ csrf }}">
-
- <legend>Edit Badge: {{ badge.name }}</legend>
-
- <div>
- <img src="{{ badge.relativeUrl('image') }}" style="float: right">
- <label for="name">Name</label>
- <input id="name" type="text" name="name" value="{{ badge.name }}" placeholder="My Very Fancy Badge">
- <span class="help-block">
- This is the name for your badge, it should be descriptive, but
- also awesome.
- </span>
- </div>
-
- <div>
- <label for="description">Description</label>
- <textarea id="description" rows="5" name="description">{{ badge.description }}</textarea>
- <span class="help-block">
- A description of your badge, this will appear in every assertion
- created from this badge.
- </span>
- </div>
-
- <div>
- <label for="criteria">Criteria</label>
- <textarea id="criteria" rows="5" name="criteria">{{ badge.criteria.content }}</textarea>
- <span class="help-block">
- The criteria text for the badge. This can be markdown, but don't go
- crazy, okay? Keep it simple. That also means you'll have to escape
- markup, by using <code>&amp;lt;</code> and <code>&amp;gt;</code> instead
- of <code>&lt;</code> and <code>&gt;</code>
- </span>
- </div>
-
- <div>
- <label for="image">New Image</label>
- <input type="file" name="image" accept="image/png">
- <span class="help-block">
- Leave blank to keep old image.
- </span>
- </div>
-
- <div class="form-actions">
- <button id="update-badge" type="submit" class="btn btn-primary">Update</button>
- </div>
- </form>
-{% endblock %}
-
-{% block footer %}
-<script src="/js/admin.js"></script>
-{% endblock %}
-
View
@@ -1,54 +0,0 @@
-{% extends "admin/base.html" %}
-
-{% block main %}
- <form method="post" action="?" enctype="multipart/form-data">
- <input id="name" type="hidden" name="csrf" value="{{ csrf }}">
-
- <legend>New Badge</legend>
- <div>
- <label for="name">Badge Name</label>
- <input id="name" type="text" name="name" placeholder="My Very Fancy Badge">
- <span class="help-block">
- This is the name for your badge, it should be descriptive, but
- also awesome.
- </span>
- </div>
-
- <div>
- <label for="description">Description</label>
- <textarea id="description" rows="5" name="description"></textarea>
- <span class="help-block">
- A description of your badge, this will appear in every assertion
- created from this badge.
- </span>
- </div>
-
- <div>
- <label for="criteria">Criteria</label>
- <textarea id="criteria" rows="5" name="criteria"></textarea>
- <span class="help-block">
- The criteria text for the badge. This can be markdown, but don't go
- crazy, okay? Keep it simple. That also means you'll have to escape
- markup, by using <code>&amp;lt;</code> and <code>&amp;gt;</code> instead
- of <code>&lt;</code> and <code>&gt;</code>
- </span>
- </div>
-
- <div>
- <label for="image">Image</label>
- <input type="file" name="image" accept="image/png">
- <span class="help-block">
- The image to use for the badge. It should be the greatest image
- known to man.
- </span>
- </div>
- <div class="form-actions">
- <button id="create-badge" type="submit" class="btn btn-primary">Create</button>
- </div>
- </form>
-{% endblock %}
-
-{% block footer %}
-<script src="/js/admin.js"></script>
-{% endblock %}
-

0 comments on commit f56df96

Please sign in to comment.