volontariat/voluntary_ranking

View on GitHub
app/assets/javascripts/voluntary_ranking/controllers/thing_controller.js.coffee

Summary

Maintainability
Test Coverage
Volontariat.ThingController = Ember.Controller.extend
  name: ''
  
  actions:
    
    compare: ->
      @transitionToRoute('compare_things', @get('name'), @get('otherThingName'))
    
    addToComparisonList: ->
      list = []
      
      unless Cookies.get('thingComparisonList') == undefined
        list = Cookies.getJSON 'thingComparisonList'
        
        if list.length == 4
          alert Volontariat.t('things.show.limit_of_comparison_list')
          
          return false
          
      list.push @get('thingId')

      Cookies.set 'thingComparisonList', list, expires: 7
      @set 'thingComparisonListCount', list.length
      @set 'onComparisonList', true
      false
        
    removeFromComparisonList: ->
      list = jQuery.grep(Cookies.getJSON('thingComparisonList'), (id) =>
        id != @get('thingId')
      )
      
      Cookies.set 'thingComparisonList', list, expires: 7
      @set 'thingComparisonListCount', list.length
      @set 'onComparisonList', false
      
    goToComparisonList: ->
      @transitionToRoute 'things_comparison_matrix'  
      
    close: ->
      @send "closeModal"