Guest User

Untitled

a guest
Jan 21st, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. String.prototype.capitalize = ->
  2. return @charAt(0).toUpperCase() + @slice(1)
  3.  
  4. window.remove_fields = (link) ->
  5. ($ link).prev("input[type='hidden']").val 1
  6. ($ link).parent.hide
  7.  
  8. window.add_fields = (link, association, content) ->
  9. new_id = new Date().getTime
  10. regexp = new RegExp("new_" + association, "g")
  11. ($ link).parent.after content.replace(regexp, new_id)
  12.  
  13. window.clearForm = (form) ->
  14. ($ ':input', form).each ->
  15. type = @type
  16. tag = @tagName.toLowerCase()
  17. if (type=="hidden" || type == 'text' || type == 'password' || tag == 'textarea')
  18. @value = ""
  19. else if (type == 'checkbox' || type == 'radio')
  20. @checked = false
  21. else if (tag == 'select')
  22. @selectedIndex = -1
  23.  
  24. jQuery ->
  25. $("form")
  26. .bind "ajax:error", (event, xhr, status) ->
  27. errors = JSON.parse xhr.responseText
  28. ($ "#error_explanation").remove
  29. errors_container = ($ "<div>").attr "id","error_explanation"
  30. list = ($ "<ul>")
  31. number_of_errors = 0
  32. $.each errors, (k, v) ->
  33. number_of_errors++
  34. list.append $("<li>").html(k.capitalize() + " " + v)
  35.  
  36. errors_container
  37. .append($("<h2>").html(number_of_errors + " errors prohibited this resource from being saved"))
  38. .append list
  39. ($ @).prepend errors_container
  40.  
  41. if ($ "#map").size()
  42. google.load "maps", "3", {other_params:'sensor=false', callback: -> initialize_map("#map")}
Add Comment
Please, Sign In to add comment