Sha256: 8b6a8fafbd027d35ab29254b98f7a755872465f601c481690e3c963951034568

Contents?: true

Size: 1.7 KB

Versions: 1

Compression:

Stored size: 1.7 KB

Contents

Volontariat.FeedbackPersistence = Em.Mixin.create
  categories: []
  
  actions:
    
    save: ->
      categoryIds = jQuery.map($('input[name="category_ids[]"]:checked'), (categoryField) ->
        $(categoryField).val()
      )
        
      $.ajax(
        type: if @get('slug') then 'PUT' else 'POST'
        url: '/api/v1/feedbacks' + if @get('slug') then "/#{@get('slug')}" else '', 
        data: { 
          feedback: { 
            community_slug: @get('communitySlug'), feedback_type: $('#feedback_feedback_type').val()
            name: $('#feedback_name').val(), text: $('#feedback_text').val(),
            mood_type: $('input[name="feedback[mood_type]"]:checked').val(), mood_text: $('#feedback_mood_text').val(),
            category_ids: categoryIds
          } 
        }
      ).success((data) =>
        if data.errors
          Volontariat.alert 'danger', "#{Volontariat.t('feedbacks.save.failed')}: #{JSON.stringify(data.errors)}"
        else
          @transitionToRoute 'community.feedback', @get('communitySlug'), data.feedback.slug, 1
          Volontariat.alert 'success', Volontariat.t('feedbacks.save.successful')
      ).fail((data) =>
        Volontariat.alert 'danger', "#{Volontariat.t('feedbacks.save.failed')}!"
      )
      
    destroy: (slug)  ->
      if confirm(Volontariat.t('feedbacks.destroy.confirmation'))
        $.ajax("/api/v1/feedbacks/#{slug}?community_slug=#{@get('communitySlug')}", type: 'DELETE').done((data) =>
          @transitionToRoute 'no_data'
          @transitionToRoute 'community.feedbacks', @get('communitySlug'), 1 
        ).fail((data) ->
          Volontariat.alert 'danger', Volontariat.t('activerecord.errors.models.feedback.attributes.base.deletion_failed')
        ) 

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
voluntary_feedback-0.1.0 app/assets/javascripts/voluntary_feedback/mixins/feedback_persistence.js.coffee