Sha256: 5788ca6edd07e80982e69b540238f5a9ae34551f93238e1929d161b8905feed1

Contents?: true

Size: 1.46 KB

Versions: 1

Compression:

Stored size: 1.46 KB

Contents

Volontariat.CommunityCategoryPersistence = Em.Mixin.create
  actions:
    
    save: ->
      $.ajax(
        type: if @get('categorySlug') then 'PUT' else 'POST'
        url: '/api/v1/community_categories' + if @get('categorySlug') then "/#{@get('categorySlug')}" else '', 
        data: { 
          community_category: { community_slug: @get('communitySlug'), name: $('#community_category_name').val() } 
        }
      ).success((data) =>
        if data.errors
          Volontariat.alert 'danger', "#{Volontariat.t('community_categories.save.failed')}: #{JSON.stringify(data.errors)}"
        else
          @transitionToRoute 'community.category.feedbacks', @get('communitySlug'), data.community_category.slug, 1
          Volontariat.alert 'success', Volontariat.t('community_categories.save.successful')
      ).fail((data) =>
        Volontariat.alert 'danger', "#{Volontariat.t('community_categories.save.failed')}!"
      )
      
    destroy: (slug)  ->
      if confirm(Volontariat.t('community_categories.destroy.confirmation'))
        $.ajax("/api/v1/community_categories/#{slug}?community_slug=#{@get('communitySlug')}", type: 'DELETE').done((data) =>
          @set 'categorySlug', null
          @transitionToRoute 'no_data'
          @transitionToRoute 'community.categories', @get('communitySlug'), 1 
        ).fail((data) ->
          Volontariat.alert 'danger', Volontariat.t('activerecord.errors.models.community_category.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/community_category_persistence.js.coffee