From 4f2ade31ad0071511911b8a2575ee63235d9bce1 Mon Sep 17 00:00:00 2001 From: Kaarle Ritvanen Date: Fri, 27 Sep 2013 11:03:40 +0300 Subject: resolve reference choices on client side --- web/client.js | 113 +++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 72 insertions(+), 41 deletions(-) (limited to 'web') diff --git a/web/client.js b/web/client.js index 1c1bc89..a0449c9 100644 --- a/web/client.js +++ b/web/client.js @@ -383,7 +383,13 @@ $(function() { return el; } - this.el = this.render(value, meta); + this.makeEl(); + + var self = this; + this.requestData(value, meta).done(function(value, meta) { + self.render(value, meta); + self.setStatus(status); + }); var el = this.wrap(); @@ -399,8 +405,6 @@ $(function() { el.append(link); } - this.setStatus(status); - return el; }, @@ -408,6 +412,12 @@ $(function() { el.prop("class", status); }, + makeEl: function() { this.el = this.createEl(); }, + + requestData: function(value, meta) { + return $.Deferred().resolve(value, meta); + }, + wrap: function() { return this.el; }, setStatus: function(status) { @@ -426,8 +436,6 @@ $(function() { ); if (editable) { - if (!this.field) this.field = this.el; - var self = this; function change() { @@ -473,8 +481,15 @@ $(function() { return $("
").text(value); }; + Field.makeEl = function() { + _.bind(Widget.makeEl, this)(); + if (!this.field) this.field = this.el; + }; + + Field.createEl = function() { return $(""); }; + Field.render = function(value, meta) { - return $("").attr({type: "text", value: value}); + this.field.attr({type: "text", value: value}); }; Field.wrap = function() { @@ -490,8 +505,10 @@ $(function() { var ComboBox = Object.create(Field); + ComboBox.createEl = function() { return $(""); + var el = this.field; function opt(value, ui_value, selected) { el.append($("