diff options
| author | Jules Laplace <jules@okfoc.us> | 2015-11-25 21:55:29 -0500 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2015-11-25 21:55:29 -0500 |
| commit | 704bffcd1d1d49bbb00241b96bacf22e5a750f26 (patch) | |
| tree | f9a4d03c209b9d857abdb85a1b4fdb9008ffb5bd /StoneIsland/www/js/lib/view/Serializable.js | |
| parent | 99c8ec608ee83526ce9e0df2854666920735eda5 (diff) | |
addresses adding properly
Diffstat (limited to 'StoneIsland/www/js/lib/view/Serializable.js')
| -rw-r--r-- | StoneIsland/www/js/lib/view/Serializable.js | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/StoneIsland/www/js/lib/view/Serializable.js b/StoneIsland/www/js/lib/view/Serializable.js index 72978985..b1e095d3 100644 --- a/StoneIsland/www/js/lib/view/Serializable.js +++ b/StoneIsland/www/js/lib/view/Serializable.js @@ -10,7 +10,10 @@ var SerializableView = View.extend({ if (! data && sdk.env == "production") { return } data = data || this.test_data if (! data) { return } + this.load_data(data) + }, + load_data: function(data){ Object.keys(data).forEach(function(key){ var value = data[key] var $el = this.$("[name=" + key + "]") @@ -56,22 +59,21 @@ var SerializableView = View.extend({ update_select: function(e){ var $target = $(e.currentTarget), value = $target.val() - var label = $($("select")[0]).find("option").filter(function(){ return this.value === value }).html() - + var label = $target.find("option").filter(function(){ return this.value === value }).html() $target.parent().addClass("picked") $target.parent().find("span").html(label) }, - validate: function(errors){ - var data = this.serialize() - var errors = [] + validate: function(data, errors){ + var data = data || this.serialize() + var errors = errors || [] var presence_msgs = this.validate_presence || {} Object.keys(presence_msgs).forEach(function(k){ if (! data[k]) errors.push( [ k, presence_msgs[k] ] ) }) this.validate_fields && this.validate_fields(data, errors) - this.cc && this.cc.validate(errors) - this.address && this.address.validate(errors) + this.cc && this.cc.validate(data, errors) + this.address && this.address.validate(data, errors) return { errors: errors, data: data } }, @@ -108,13 +110,16 @@ var SerializableView = View.extend({ } var finalized_data = this.finalize(valid.data) - if (! finalized_data) { + this.submit( finalized_data ) + }, + + submit: function(data){ + if (! data) { return } - app.curtain.show("loading") this.action({ - data: finalized_data, + data: data, success: function(data){ app.curtain.hide("loading") this.success(data) |
