60 lines
2.3 KiB
CoffeeScript
60 lines
2.3 KiB
CoffeeScript
App.SectionController = Ember.Controller.extend
|
|
needs: ['application', 'sections', 'section'] #wtf? section, otherwise an Ember error
|
|
editmode: false
|
|
actions:
|
|
makeEditable: -> @set('editmode', true)
|
|
finishEditable: ->
|
|
@set('editmode', false)
|
|
@get('model').save()
|
|
@get('model.tables').filterProperty('hasDirtyAttributes').invoke 'save'
|
|
@get('model.section_elements').filterProperty('hasDirtyAttributes').invoke 'save'
|
|
@get('model.section_areas').filterProperty('hasDirtyAttributes').invoke 'save'
|
|
rollbackEditable: ->
|
|
@get('model').rollback()
|
|
@get('model.tables').forEach (table) ->
|
|
if table.get('isNew')
|
|
table.deleteRecord()
|
|
else
|
|
table.rollback()
|
|
@get('model.section_elements').forEach (section_element) ->
|
|
if section_element.get('isNew')
|
|
section_element.deleteRecord()
|
|
else
|
|
section_element.rollback()
|
|
@get('model.section_areas').forEach (section_area) ->
|
|
if section_area.get('isNew')
|
|
section_area.deleteRecord()
|
|
else
|
|
section_area.rollback()
|
|
@set('editmode', false)
|
|
addSection: -> @modal 'add_section', model: @get('model')
|
|
addTables: -> @modal 'section_add_tables', model: @get('model')
|
|
arrangeTables: -> @modal 'section_arrange_tables', model: @get('model')
|
|
destroySection: ->
|
|
@modal 'confirm',
|
|
title_path: 'helpers.links.are_you_sure'
|
|
ok: =>
|
|
@get('model').destroyRecord()
|
|
@transitionToRoute 'sections'
|
|
addSectionElement: ->
|
|
@modal 'add_section_element',
|
|
model: @get('model')
|
|
ok: => @send 'makeEditable'
|
|
addSectionArea: ->
|
|
section_area = @store.createRecord('section-area')
|
|
section_area.set 'section', @get('model')
|
|
@set 'editmode', true
|
|
@modal 'section_area',
|
|
title_path: 'section_area.add_button'
|
|
model: section_area
|
|
ok: => @send 'makeEditable'
|
|
close: =>
|
|
if section_area.get('isNew')
|
|
section_area.deleteRecord()
|
|
else
|
|
section_area.rollback()
|
|
removeSectionElement: (section_element)-> section_element.destroyRecord()
|
|
textures: ['wood1', 'wood2']
|
|
|
|
sections: (-> @get('controllers.sections.model')).property('controllers.sections.model')
|