Sha256: e3a185b8527e820a98b4fea1281ba36b5d5c2a105b348090f4c37568e1bd56ff

Contents?: true

Size: 1.54 KB

Versions: 1

Compression:

Stored size: 1.54 KB

Contents

Volontariat.ReplyCellComponent = Ember.Component.extend
  editMode: (-> @get('selectedId') == @get('id')).property('selectedId', 'id')
  your: (-> Volontariat.User.current() != undefined && Volontariat.User.current().id == @get('userId')).property('userId')
  
  actions:
    
    edit: ->
      @sendAction 'editAction', @get('id')
    
    cancel: ->
      if @get 'id'
        @sendAction 'leaveEditReplyModeAction'
      else
        @sendAction 'leaveNewReplyModeAction'
        
    save: ->
      $.ajax(
        type: if @get('id') then 'PUT' else 'POST'
        url: '/api/v1/replies' + if @get('id') then "/#{@get('id')}" else '', 
        data: { 
          reply: { feedback_id: @get('feedbackId'), reply_id: @get('replyId'), text: $('#reply_text').val() } 
        }
      ).success((data) =>
        if data.errors
          alert "#{Volontariat.t('replies.save.failed')}: #{JSON.stringify(data.errors)}"
        else
          if @get('id')
            @sendAction 'leaveEditReplyModeAction'
          else
            @sendAction 'leaveNewReplyModeAction'
            @set 'text', ''
          
          @sendAction 'reloadAction'
      ).fail((data) =>
        alert "#{Volontariat.t('replies.save.failed')}!"
      )
      
    destroy: ->
      if confirm(Volontariat.t('replies.destroy.confirmation'))
        $.ajax("/api/v1/replies/#{@get('id')}", type: 'DELETE').done((data) =>
          @sendAction 'reloadAction'
        ).fail((data) ->
          alert Volontariat.t('activerecord.errors.models.reply.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/components/reply_cell_component.js.coffee