summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--controller.py17
-rwxr-xr-xindex.py2
-rw-r--r--static/css/style.css4
-rw-r--r--static/images/add.pngbin0 -> 800 bytes
-rw-r--r--static/images/minus.pngbin0 -> 3406 bytes
-rw-r--r--static/images/undo.pngbin0 -> 649 bytes
-rw-r--r--static/js/cats.js39
-rw-r--r--static/js/lib.js6
-rw-r--r--templates/pages/cats.mako22
-rw-r--r--templates/root.mako1
10 files changed, 85 insertions, 6 deletions
diff --git a/controller.py b/controller.py
index 6db7b31..64b7af7 100644
--- a/controller.py
+++ b/controller.py
@@ -210,12 +210,19 @@ class ConstEdit (ConstAdd):
return ConstAdd.POST(self)
class Cat:
- def GET(self, id = '/'):
- if id:
- id = id[1:]
+ def GET(self):
+ categories = Category.query.order_by(Category.name).all()
+
+ return render("cats", cats = categories)
+
+ def POST(self):
+ for id, name in web.input().iteritems():
+ if id.startswith("n-"):
+ Category(name = name)
+ else:
+ Category.get(id).name = name
- if not id: return "Add new cat"
- else: return "Edit cat " + id
+ raise web.seeother("/")
class FourOhFour:
"""
diff --git a/index.py b/index.py
index cb60a95..78d44c9 100755
--- a/index.py
+++ b/index.py
@@ -13,7 +13,7 @@ urls = (
"/const/?", controller.Const,
"/const/add/?", controller.ConstAdd,
"/const/edit/(\d+)", controller.ConstEdit,
- "/cat/?(/\d+)?", controller.Cat,
+ "/categories", controller.Cat,
"/(\d\d\d\d)/(\d\d?)/?", controller.Show,
"/", controller.Show,
"/(.*)", controller.FourOhFour
diff --git a/static/css/style.css b/static/css/style.css
index 2ddf6f2..10f2331 100644
--- a/static/css/style.css
+++ b/static/css/style.css
@@ -88,6 +88,10 @@ div.detail > .mark {
cursor: pointer;
}
+ul.arrow {
+ list-style-image: url(../images/closed.png);
+}
+
/* Header */
diff --git a/static/images/add.png b/static/images/add.png
new file mode 100644
index 0000000..b748150
--- /dev/null
+++ b/static/images/add.png
Binary files differ
diff --git a/static/images/minus.png b/static/images/minus.png
new file mode 100644
index 0000000..99b21ce
--- /dev/null
+++ b/static/images/minus.png
Binary files differ
diff --git a/static/images/undo.png b/static/images/undo.png
new file mode 100644
index 0000000..b39d182
--- /dev/null
+++ b/static/images/undo.png
Binary files differ
diff --git a/static/js/cats.js b/static/js/cats.js
new file mode 100644
index 0000000..e65cc28
--- /dev/null
+++ b/static/js/cats.js
@@ -0,0 +1,39 @@
+var counter = 0;
+
+$(document).ready(function(){
+ $("li > span").click(function(){
+ var span = $(this);
+ var img = $("img#add").copy().attr('src', function() { return this.src.replace("add", "undo"); });
+
+ img.click(function(){
+ var input = $(this).prev();
+
+ $(this).remove();
+ input.fadeOut("slow",
+ function() {
+ span.toggle();
+ });
+
+ input.val(span.text());
+ });
+
+ span.toggle();
+ $(this).next().fadeIn("slow", function() {$(this).after(img); });
+ });
+
+ $("img#add").click(function(){
+ var input = $("input#new").copy();
+ var img = $(this).copy().attr('src', function() { return this.src.replace("add", "minus"); });
+ img.click(function() { $(this).parent().fadeOut("slow", function() { $(this).remove(); }) });
+
+ input.attr('name', function() { return this.name + counter; })
+ .removeAttr('style')
+ .insertBefore($(this).parent())
+ .wrap("<li />");
+
+ input.parent().append(img)
+ .hide().fadeIn("slow", function (){ input.focus(); });
+
+ counter = counter + 1;
+ });
+})
diff --git a/static/js/lib.js b/static/js/lib.js
new file mode 100644
index 0000000..43b0dc8
--- /dev/null
+++ b/static/js/lib.js
@@ -0,0 +1,6 @@
+jQuery.fn.extend({
+ // copies an object and removes 'id' and 'class' values
+ copy: function() {
+ return this.clone().removeAttr("id").removeAttr("class");
+ }
+});
diff --git a/templates/pages/cats.mako b/templates/pages/cats.mako
new file mode 100644
index 0000000..3dbef4c
--- /dev/null
+++ b/templates/pages/cats.mako
@@ -0,0 +1,22 @@
+<%inherit file="/page.mako" />
+
+<form name="categories" method="post">
+ <ul class="arrow">
+ % for c in cats:
+ <li><span>${c.name}</span><input name="${c.id}" type="text" value="${c.name}" style="display:none;"/></li>
+ % endfor
+ <div><img id="add" src=${"/static/images/add.png" | url} /></div>
+ </ul>
+
+ <input type="submit" />
+</form>
+
+<input id="new" name="n-" style="display:none;" />
+<%def name="heading()">
+ Categories
+</%def>
+
+<%def name="js()">
+ ${parent.js()}
+ <script type="text/javascript" src=${"/static/js/cats.js" | url}></script>
+</%def>
diff --git a/templates/root.mako b/templates/root.mako
index e789df5..dce3f81 100644
--- a/templates/root.mako
+++ b/templates/root.mako
@@ -49,6 +49,7 @@
<%def name="js()">
<script type="text/javascript" src=${"/static/js/jquery-1.4.2.js" | url}></script>
+ <script type="text/javascript" src=${"/static/js/lib.js" | url}></script>
</%def>
<%def name="footer()">