# HG changeset patch # User Matt Johnston # Date 1391528346 -28800 # Node ID 93af94e6bd9d46230cb2def7533ebf33875be93b # Parent 9950ffa9a79bad3fba29854093fd5fd9c153123e param editor roughly working diff -r 9950ffa9a79b -r 93af94e6bd9d web/log.py --- a/web/log.py Tue Feb 04 22:49:16 2014 +0800 +++ b/web/log.py Tue Feb 04 23:39:06 2014 +0800 @@ -260,7 +260,7 @@ 'overshoot_delay': 720, # 12 minutes 'overshoot_factor': 1, # ºC 'disabled': False, - 'nowort': False, + 'nowort': True, 'fridge_range_lower': 3, 'fridge_range_upper': 3, } @@ -274,6 +274,14 @@ kind = 'yesno' else: kind = 'number' + n['amount'] = 0.1; + if k == 'overshoot_delay': + n['unit'] = ' sec' + n['amount'] = 60 + else: + n['unit'] = 'º' n['kind'] = kind + n['title'] = k r.append(n) + return json.dumps(r, sort_keys=True, indent=4) diff -r 9950ffa9a79b -r 93af94e6bd9d web/views/set.tpl --- a/web/views/set.tpl Tue Feb 04 22:49:16 2014 +0800 +++ b/web/views/set.tpl Tue Feb 04 23:39:06 2014 +0800 @@ -1,7 +1,9 @@ - + + + @@ -60,19 +62,22 @@
+
+ +
+ + @@ -80,8 +85,8 @@
{title} {oldvalue}
- - + +
@@ -94,6 +99,7 @@ $.each(self.params, function(idx, param) { param.id = "param_id_" + idx; + param.oldvalue = param.value; }); self.edit = function(param) { @@ -103,9 +109,14 @@ self.adjust = function(param, updown) { // XXX increment + param.value += (param.amount*updown); self.trigger("edit", param); } + self.save = function() { + var j = JSON.stringify(self.params); + self.trigger("saved", j) + } } (function() { 'use strict'; @@ -119,28 +130,45 @@ var button_template = $("[type='html/yesno_button']").html(); setter.on("add", add); + setter.on("edit", function(param) { var el = $("#" + param.id); if (param.kind === "number") { - $(".input", el).text(param.value).value(param.value); + set_text_state(el, param.value); } else if (param.kind === "yesno") { - set_state(el, param.value); + set_button_state(el, param.value); } -}) +}); + +setter.on("saved", function(j) { + $("#jsontest").text(j); +}); + + $.route(function(hash) { // clear list and add new ones root.empty() && $.each(setter.params, function (idx, p) { add(p); + + $("#savebutton").click(function() { + setter.save(); + }) }) }) -function set_state(el, value) +function set_text_state(el, value) +{ + var input = $(".input", el); + input.text(value).val(value) +} + +function set_button_state(el, value) { var button_yes = $(".button_yes", el); var button_no = $(".button_no", el); @@ -162,6 +190,23 @@ { var el = $($.render(number_template, param)).appendTo(root); var input = $(".input", el); + + input.keyup(function(e) { + if (e.which == 13) + { + param.value = Number(this.value); + setter.edit(param); + } + }); + + $(".button_up", el).click(function() { + setter.adjust(param, 1); + }); + $(".button_down", el).click(function() { + setter.adjust(param, -1); + }); + + set_text_state(el, param.value); } else if (param.kind === "yesno") { @@ -179,7 +224,7 @@ setter.edit(param); }) - set_state(el, param.value); + set_button_state(el, param.value); } }