Permalink
Browse files

Almost have basic options working

  • Loading branch information...
parente committed Dec 11, 2010
1 parent 4bcab21 commit b60cd85c3e3ae530f20d46b335904d3f61be5af4
Showing with 27 additions and 11 deletions.
  1. +4 −2 handlerbag.py
  2. +18 −7 hbag/admin/admin.html
  3. +5 −2 hbag/admin/admin.py
View
@@ -132,16 +132,18 @@ def load_module(self, name):
self.modules[name] = mod
return mod
- def set_handler_status(self, name, enable):
+ def set_handler_status(self, name, enable, opts=None):
# not a known handler
if not self.db.has_key(name): return
info = self.db[name]
# set the state in the db
info = self.db[name]
info['enabled'] = enable
+ if opts is not None:
+ info['options'] = opts
self.db[name] = info
-
+
# unregister existing handlers
try:
mod = self.modules[name]
View
@@ -3,18 +3,28 @@
<head>
<meta charset="utf-8" />
<title>Handler Bag Admin</title>
+ <style type="text/css">
+ textarea { margin-left: 2.25em; width: 90%; height: 50px;}
+ </style>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/dojo/1.5/dojo/dojo.xd.js"></script>
<script type="text/javascript">
var tok;
function save() {
var cbs = dojo.query('[type="checkbox"]');
+ var txts = dojo.query('textarea');
var status = dojo.byId('status');
var data = {};
cbs.forEach(function(item) {
- var key = dojo.attr(item, 'id');
- var val = dojo.attr(item, 'checked');
- data[key] = val;
+ var key = dojo.attr(item, 'name');
+ var enabled = dojo.attr(item, 'checked');
+ data[key] = {enabled : enabled};
});
+ txts.forEach(function(item) {
+ var key = dojo.attr(item, 'name');
+ var options = dojo.attr(item, 'value');
+ data[key].options = options;
+ });
+ console.log(data);
clearTimeout(tok);
status.innerHTML = 'Saving ...'
dojo.xhrPost({
@@ -36,13 +46,14 @@
</script>
</head>
<body>
- <h1>Handler Bag Admin</h1>
+ <h1>handlerbag</h1>
<fieldset>
- <legend>Enabled Handlers</legend>
+ <legend>Available Handlers</legend>
{% for key, info in items %}
<p>
- <input type="checkbox" id="{{ key }}" {{ 'checked' if info['enabled'] else '' }}/>
- <label for="{{ key }}">{{ escape(key) }} - {{ escape(info['description']) or 'no description' }}</label>
+ <input type="checkbox" id="{{ key }}" name="{{ key }}" {{ 'checked' if info['enabled'] else '' }}/>
+ <label for="{{ key }}">{{ escape(key) }} - {{ escape(info['description']) or 'no description' }}</label><br />
+ <textarea id="{{ key }}_options" name="{{ key }}">{{ json_encode(info['options']) }}</textarea>
</p>
{% end %}
</fieldset>
View
@@ -23,5 +23,8 @@ def get(self, *args, **kwargs):
@users.requireRole('admin')
def post(self, *args, **kwargs):
obj = json.loads(self.request.body)
- for name, enabled in obj.iteritems():
- self.application.set_handler_status(name, enabled)
+ for name, info in obj.iteritems():
+ enabled = info['enabled']
+ options = json.loads(info['options'])
+ # @todo: keys can't be unicode, passed around as kwargs everywhere
+ self.application.set_handler_status(name, enabled, options)

0 comments on commit b60cd85

Please sign in to comment.