diff options
author | Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi> | 2013-05-21 14:46:06 +0300 |
---|---|---|
committer | Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi> | 2013-05-21 16:27:00 +0300 |
commit | b6e2950cd4c9e58764e97ac2085c6fb5be65bef4 (patch) | |
tree | 48a21493552c7fc20c08bbbda4bf1ac9347c034c /web | |
parent | 4d835e9db2be5b912b963e165f97b71822f664fa (diff) | |
download | aconf-b6e2950cd4c9e58764e97ac2085c6fb5be65bef4.tar.bz2 aconf-b6e2950cd4c9e58764e97ac2085c6fb5be65bef4.tar.xz |
web client: fix checkbox highlighting when returning to a modified view
Diffstat (limited to 'web')
-rw-r--r-- | web/client.js | 43 |
1 files changed, 17 insertions, 26 deletions
diff --git a/web/client.js b/web/client.js index 1e425c8..42e5e6f 100644 --- a/web/client.js +++ b/web/client.js @@ -57,12 +57,8 @@ $(function() { return el; }, staticRender: function(value) { return $("<div>").text(value); }, - init: function(value, meta, status) { - this.el = this.render(value, meta); - this.setStatus(status); - }, - render: function(value, meta) { - return $("<input>").attr({type: "text", value: value}); + init: function(value, meta) { + this.el = $("<input>").attr({type: "text", value: value}); }, setStatus: function(status, el) { if (!el) el = this.el; @@ -72,8 +68,9 @@ $(function() { } var ComboBox = Object.create(Field); - ComboBox.render = function(value, meta) { + ComboBox.init = function(value, meta) { var el = $("<select>"); + this.el = el; function opt(value, ui_value, selected) { el.append($("<option>").attr( @@ -90,16 +87,14 @@ $(function() { opt(choice[0], choice[1], value == choice[0]); } ); - - return el; } var CheckBox = Object.create(Field); CheckBox.staticRender = function(value) { return $("<div>").text(value ? "Yes" : "No"); }; - CheckBox.render = function(value, meta) { - return $("<input>").attr({type: "checkbox", checked: value}); + CheckBox.init = function(value, meta) { + this.el = $("<input>").attr({type: "checkbox", checked: value}); }; CheckBox.setStatus = function(status) { Field.setStatus(status, this.el.parent()); @@ -116,12 +111,12 @@ $(function() { } return el; }; - Path.render = function(value, meta) { - return this.staticRender(value); + Path.init = function(value, meta) { + this.el = this.staticRender(value); }; var Reference = Object.create(Path); - Reference.init = function(value, meta, status) { + Reference.init = function(value, meta) { this.cbox = Object.create(ComboBox) this.cbox.init(value, meta); @@ -132,14 +127,10 @@ $(function() { this.cbox.el.change(update); update(); - _.bind(Path.init, this)(value, meta, status); - } - Reference.render = function(value, meta) { - var el = $("<div>"); - el.append(this.cbox.el); - el.append(" "); - el.append(this.link); - return el; + this.el = $("<div>"); + this.el.append(this.cbox.el); + this.el.append(" "); + this.el.append(this.link); }; Reference.setStatus = function(status) { ComboBox.setStatus(status, this.cbox.el); @@ -264,11 +255,9 @@ $(function() { var el; if (editable) { - var widget = Object.create(widget); + widget = Object.create(widget); widget.init( - path in invalid ? invalid[path] : value, - meta, - status[path] + path in invalid ? invalid[path] : value, meta ); el = widget.el; el.change(function() { @@ -340,6 +329,8 @@ $(function() { else el = widget.format(value, status[path]); td.append(el); + + if (editable) widget.setStatus(status[path]); } else td.text(value); |