diff options
Diffstat (limited to 'StoneIsland/www/js/vendor')
| -rw-r--r-- | StoneIsland/www/js/vendor/util.js | 4 | ||||
| -rw-r--r-- | StoneIsland/www/js/vendor/view/serializable.js | 15 |
2 files changed, 12 insertions, 7 deletions
diff --git a/StoneIsland/www/js/vendor/util.js b/StoneIsland/www/js/vendor/util.js index 0e48ce5a..fede4761 100644 --- a/StoneIsland/www/js/vendor/util.js +++ b/StoneIsland/www/js/vendor/util.js @@ -24,6 +24,10 @@ function rgba_string (rgb,a) { return "rgba(" + rgb.map(Math.round).join(",") + function hex_string (rgb) { return "#" + rgb.map(Math.round).map(function(n){ var s = n.toString(16); return s.length == 1 ? "0"+s : s }).join("") } function parse_rgba_string (s) { return s.match(/(\d+)/g).slice(0,3) } +function title_case (str) { + return str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();}); +} + var E = Math.E var PI = Math.PI var PHI = (1+Math.sqrt(5))/2 diff --git a/StoneIsland/www/js/vendor/view/serializable.js b/StoneIsland/www/js/vendor/view/serializable.js index db996f23..3c069880 100644 --- a/StoneIsland/www/js/vendor/view/serializable.js +++ b/StoneIsland/www/js/vendor/view/serializable.js @@ -22,15 +22,16 @@ var SerializableView = View.extend({ Object.keys(presence_msgs).forEach(function(k){ if (! data[k]) errors.push( [ k, presence_msgs[k] ] ) }) - this.validate_fields && this.validate_fields(errors) + this.validate_fields && this.validate_fields(data, errors) this.cc && this.cc.validate(errors) this.address && this.address.validate(errors) - return errors.length ? errors : null + return { errors: errors, data: data } }, show_errors: function(errors){ var msgs = [] - errors.forEach(function(e){ + errors.forEach(function(e, i){ + if (i > 0) { return } this.$("[name=" + e[0] + "]").addClass('error_hilite') msgs.push(e[1]) }.bind(this)) @@ -46,9 +47,9 @@ var SerializableView = View.extend({ save: function(e){ e && e.preventDefault() - var errors = this.validate() - if (errors) { - this.show_errors(errors) + var valid = this.validate() + if (valid.errors.length) { + this.show_errors(valid.errors) return } else { @@ -57,7 +58,7 @@ var SerializableView = View.extend({ app.curtain.show("loading") this.action({ - data: data, + data: valid.data, success: function(data){ app.curtain.hide("loading") this.success(data) |
