From b6e2950cd4c9e58764e97ac2085c6fb5be65bef4 Mon Sep 17 00:00:00 2001 From: Kaarle Ritvanen Date: Tue, 21 May 2013 14:46:06 +0300 Subject: web client: fix checkbox highlighting when returning to a modified view --- web/client.js | 43 +++++++++++++++++-------------------------- 1 file changed, 17 insertions(+), 26 deletions(-) (limited to 'web') 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 $("
").text(value); }, - init: function(value, meta, status) { - this.el = this.render(value, meta); - this.setStatus(status); - }, - render: function(value, meta) { - return $("").attr({type: "text", value: value}); + init: function(value, meta) { + this.el = $("").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 = $("").attr({type: "checkbox", checked: value}); + CheckBox.init = function(value, meta) { + this.el = $("").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 = $("
"); - el.append(this.cbox.el); - el.append(" "); - el.append(this.link); - return el; + this.el = $("
"); + 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); -- cgit v1.2.3