engine/app/assets/javascripts/locomotive/views/pages/new_view.js.coffee

33 lines
774 B
CoffeeScript
Raw Normal View History

2011-11-14 09:13:58 +00:00
Locomotive.Views.Pages ||= {}
class Locomotive.Views.Pages.NewView extends Locomotive.Views.Pages.FormView
save: (event) ->
event.stopPropagation() & event.preventDefault()
@clear_errors()
console.log('saving')
@model.save {},
success: (model, response, xhr) =>
console.log('success')
model._normalize()
$.growl('success', xhr.getResponseHeader('X-Message'))
if model.get('template_changed') == true
@reset_editable_elements()
else
@refresh_editable_elements()
error: (model, xhr) =>
console.log('error')
window.xhr = xhr
errors = JSON.parse(xhr.responseText)
@show_errors errors
$.growl('error', xhr.getResponseHeader('X-Message'))