App.modals.SectionAddTablesController = App.modals.BaseController.extend
  number_start: 100
  number_end: 100
  title_path: 'section.add_tables.modal.title'
  #number_start: Ember.computed
    #get: ->
      #@_super() || 100
    #set: (key, value)->
      #@set 'number_end', value if value
      #@_super()
  actions:
    addTables: ->
      s = parseInt(@get('number_start'))
      return @set('alert_message', t('section.add_tables.modal.invalid_start_number')) unless isFinite(s)
      e = parseInt(@get('number_end'))
      return @set('alert_message', t('section.add_tables.modal.invalid_end_number')) unless isFinite(e)
      if e < s
        @set 'number_start', e
        @set 'number_end', s
        s = @get('number_start')
        e = @get('number_end')
      number_of_tables = 1 + e - s
      return @set('alert_message', t('section.add_tables.modal.too_many', count: number_of_tables)) if number_of_tables > 10
      for number in [s..e]
        @store.createRecord 'table', number: number, section: @get('model')

      @send 'close'
