From 98e83d8ffc9cc31986fb2672140aed005480cddb Mon Sep 17 00:00:00 2001 From: René 'Necoro' Neumann Date: Tue, 27 Jul 2010 01:16:48 +0200 Subject: Add category manipulation support --- controller.py | 17 ++++++++++++----- index.py | 2 +- static/css/style.css | 4 ++++ static/images/add.png | Bin 0 -> 800 bytes static/images/minus.png | Bin 0 -> 3406 bytes static/images/undo.png | Bin 0 -> 649 bytes static/js/cats.js | 39 +++++++++++++++++++++++++++++++++++++++ static/js/lib.js | 6 ++++++ templates/pages/cats.mako | 22 ++++++++++++++++++++++ templates/root.mako | 1 + 10 files changed, 85 insertions(+), 6 deletions(-) create mode 100644 static/images/add.png create mode 100644 static/images/minus.png create mode 100644 static/images/undo.png create mode 100644 static/js/cats.js create mode 100644 static/js/lib.js create mode 100644 templates/pages/cats.mako 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 Binary files /dev/null and b/static/images/add.png differ diff --git a/static/images/minus.png b/static/images/minus.png new file mode 100644 index 0000000..99b21ce Binary files /dev/null and b/static/images/minus.png differ diff --git a/static/images/undo.png b/static/images/undo.png new file mode 100644 index 0000000..b39d182 Binary files /dev/null and b/static/images/undo.png 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("
  • "); + + 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" /> + +
    +
      + % for c in cats: +
    • ${c.name}
    • + % endfor +
      +
    + + +
    + + +<%def name="heading()"> + Categories + + +<%def name="js()"> + ${parent.js()} + + 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()"> + <%def name="footer()"> -- cgit v1.2.3-70-g09d2