lib/assets/javascripts/transponder/presenter.coffee in transponder-0.9.3 vs lib/assets/javascripts/transponder/presenter.coffee in transponder-0.9.4

- old
+ new

@@ -20,11 +20,11 @@ events.push(Transponder.buildEvent(['ujs', options.module, options.presenterName, action])) doc.on(events.join(' '), @runAction) elify: (event, response) -> if @response.errors - if @response.id then "##{@modelName}_#{@response.id}" else "#new_#{@modelName}" + if @response.id then "##{@response.model_name}_#{@response.id}" else "#new_#{@response.model_name}" else "#{event.target.localName}##{event.target.id}" beforeFilter: (event, response) -> @response = response @@ -32,28 +32,26 @@ @params = Transponder.req.objectifyParams() runAction: (event, response) => @beforeFilter(event, response) if @response.errors - @errorOut() + @errorOut(@response.action) else @[event.type.split(':').pop()]() @afterFilter(event, response) afterFilter: (event, response) -> triggerEmpty: (eventName) -> console.log "#{eventName} triggered! Override this action in your own presenter" - triggerEmptyError: (eventName) -> - console.log "Error #{eventName} triggered! Override this action in your own presenter" - errorOut: -> - for key, value of @response.errors - @error[key](value) + errorOut: (action) -> + @error[action](@response.errors, @element) + index: -> @triggerEmpty('Index') show: -> @triggerEmpty('Show') new: -> @@ -66,19 +64,22 @@ @triggerEmpty('Create') destroy: -> @triggerEmpty('Destroy') error: - index: -> + triggerEmptyError: (eventName) -> + console.log "Error #{eventName} triggered! Override this action in your own presenter" + + index: (errors, element) -> @triggerEmptyError('Index') - show: -> + show: (errors, element) -> @triggerEmptyError('Show') - new: -> + new: (errors, element) -> @triggerEmptyError('New') - edit: -> + edit: (errors, element) -> @triggerEmptyError('Edit') - update: -> + update: (errors, element) -> @triggerEmptyError('Update') - create: -> + create: (errors, element) -> @triggerEmptyError('Create') - destroy: -> + destroy: (errors, element) -> @triggerEmptyError('Destroy') \ No newline at end of file