diff options
author | jessib <jessib@leap.se> | 2013-06-27 12:31:39 -0700 |
---|---|---|
committer | jessib <jessib@leap.se> | 2013-06-27 12:31:39 -0700 |
commit | a01e7686ea7c046a9cd544b618b30727f2a41b3b (patch) | |
tree | e00261ade269bfe6ddc843a728a4355807228ea9 /users/app/assets | |
parent | ba036558e47da53e86ccb8cb7fb4ee1db725b804 (diff) |
Want to tweak some, but start to displaying base generic message via javascript.
Diffstat (limited to 'users/app/assets')
-rw-r--r-- | users/app/assets/javascripts/users.js.coffee | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/users/app/assets/javascripts/users.js.coffee b/users/app/assets/javascripts/users.js.coffee index 955556c..b0b624c 100644 --- a/users/app/assets/javascripts/users.js.coffee +++ b/users/app/assets/javascripts/users.js.coffee @@ -14,13 +14,27 @@ srp.updated = -> srp.error = (message) -> if $.isPlainObject(message) && message.errors - for field, error of message.errors - element = $('form input[name$="['+field+']"]') - next unless element - element.trigger('element:validate:fail.ClientSideValidations', error).data('valid', false) + display_errors(message.errors) else alert(message) +display_errors = (errors) -> + for field, error of errors + if field == 'base' + display_base_error(error); + else + display_field_error(field, error); + +display_field_error = (field, error) -> + element = $('form input[name$="['+field+']"]') + return unless element + element.trigger('element:validate:fail.ClientSideValidations', error).data('valid', false) + +display_base_error = (message) -> + messages = $('#messages') + messages.append "<div class=\"alert alert-error\"><a class=\"close\" \"data-dismiss\"=\"alert\">×</a><div class=\"flash_error\">" + message + "</div></div>" + + pollUsers = (query, process) -> $.get( "/users.json", query: query).done(process) |