19 lines
658 B
CoffeeScript
19 lines
658 B
CoffeeScript
|
|
@remove_fields = (link) ->
|
|
$(link).prev("input[type=hidden]").val "1"
|
|
$(link).closest(".field").hide()
|
|
false
|
|
@add_fields = (link, association, content) ->
|
|
new_id = new Date().getTime()
|
|
regexp = new RegExp("new_" + association, "g")
|
|
content_final = content.replace(regexp, new_id).replace(association + "_class", "new_field")
|
|
|
|
if $(link).closest("p").next("." + association + "_form").length > 0
|
|
form_element = $(link).closest("p").next("." + association + "_form")
|
|
else
|
|
form_element = $(link).closest("p").prev("." + association + "_form")
|
|
|
|
form_element.append content_final
|
|
|
|
$(".new_field").removeClass "new_field"
|
|
false |