Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String.prototype.capitalize = ->
- return @charAt(0).toUpperCase() + @slice(1)
- window.remove_fields = (link) ->
- ($ link).prev("input[type='hidden']").val 1
- ($ link).parent.hide
- window.add_fields = (link, association, content) ->
- new_id = new Date().getTime
- regexp = new RegExp("new_" + association, "g")
- ($ link).parent.after content.replace(regexp, new_id)
- window.clearForm = (form) ->
- ($ ':input', form).each ->
- type = @type
- tag = @tagName.toLowerCase()
- if (type=="hidden" || type == 'text' || type == 'password' || tag == 'textarea')
- @value = ""
- else if (type == 'checkbox' || type == 'radio')
- @checked = false
- else if (tag == 'select')
- @selectedIndex = -1
- jQuery ->
- $("form")
- .bind "ajax:error", (event, xhr, status) ->
- errors = JSON.parse xhr.responseText
- ($ "#error_explanation").remove
- errors_container = ($ "<div>").attr "id","error_explanation"
- list = ($ "<ul>")
- number_of_errors = 0
- $.each errors, (k, v) ->
- number_of_errors++
- list.append $("<li>").html(k.capitalize() + " " + v)
- errors_container
- .append($("<h2>").html(number_of_errors + " errors prohibited this resource from being saved"))
- .append list
- ($ @).prepend errors_container
- if ($ "#map").size()
- google.load "maps", "3", {other_params:'sensor=false', callback: -> initialize_map("#map")}
Add Comment
Please, Sign In to add comment