Modal refactor
This commit is contained in:
@@ -2,3 +2,5 @@
|
||||
LOG_TRANSITIONS: true
|
||||
rootElement: '#ember-app-container'
|
||||
store: -> @__container__.lookup('controller:application').store
|
||||
@App.modals = Ember.Namespace.create()
|
||||
@Modals = @App.modals
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#= require_directory ./modifications
|
||||
#= require shared-ember-helpers/all
|
||||
#= require ./app
|
||||
#= require ./controllers/modals/base_controller
|
||||
#= require_tree .
|
||||
@$assets_path = '/assets/';
|
||||
@EmberENV = {FEATURES: {'query-params-new': true}}
|
||||
|
||||
@@ -30,15 +30,6 @@ App.IndexController = Ember.ObjectController.extend
|
||||
order_number_info: (-> " (#{@get('active_orders.length')})").property('active_orders.@each')
|
||||
|
||||
actions:
|
||||
###
|
||||
markListAsHelped: (id)->
|
||||
if list = App.List.findCached(id)
|
||||
list.is_helped()
|
||||
|
||||
closeList: (list)->
|
||||
@send 'openModal', 'modal_close_list', list
|
||||
# list.close()
|
||||
###
|
||||
toggleDashboardLists: -> @set 'show_lists', !@get('show_lists')
|
||||
toggleDashboardOrders: ->@set 'show_orders', !@get('show_orders')
|
||||
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
App.MenuController = Ember.ObjectController.extend
|
||||
needs: ['application']
|
||||
product_categories: ~> @store.all('product_category')
|
||||
@@ -1,7 +0,0 @@
|
||||
App.ModalCloseListController = Ember.ObjectController.extend
|
||||
actions:
|
||||
close: ->
|
||||
@send 'closeModal'
|
||||
confirm: ->
|
||||
@get('model').then (l)->l.close()
|
||||
@send 'closeModal'
|
||||
@@ -1,11 +0,0 @@
|
||||
App.ModalController = Ember.ObjectController.extend
|
||||
modal_options: {}
|
||||
actions:
|
||||
close: ->
|
||||
if close = @get('modal_options.close')
|
||||
close.apply(@)
|
||||
@send 'closeModal' unless @preventClose
|
||||
ok: ->
|
||||
if ok = @get('modal_options.ok')
|
||||
ok.apply(@)
|
||||
@send 'closeModal' unless @preventClose
|
||||
+2
-5
@@ -1,13 +1,10 @@
|
||||
App.ModalAddSectionController = Ember.ObjectController.extend
|
||||
App.modals.AddSectionController = @App.modals.BaseController.extend
|
||||
alert_message: null
|
||||
section_title: ''
|
||||
section_width: 15
|
||||
section_height: 8
|
||||
title_path: 'section.add_section.modal.title'
|
||||
actions:
|
||||
close: ->
|
||||
@set 'alert_message', null
|
||||
@get('model.cancel').call(@) if @get('model.cancel')
|
||||
@send 'closeModal'
|
||||
addSection: ->
|
||||
@set 'alert_message', null
|
||||
title = @get('section_title')
|
||||
@@ -0,0 +1,26 @@
|
||||
@App.modals.BaseController = Ember.ObjectController.extend
|
||||
title: ~>
|
||||
return @get('modal_options.title') if @get('modal_options.title')
|
||||
return t(@title_path) if @title_path
|
||||
return t(@get('modal_options.title_path')) if @get('modal_options.title_path')
|
||||
underscored = `this.constructor.toString().substr(11).replace(/Controller$/, '').underscore()`
|
||||
params = {}
|
||||
if model = @get('model')
|
||||
params = model.serialize() if model.serialize
|
||||
@get('modal_options.title') or ttry("modal.#{underscored}.title", params) or underscored.capitalize().replace(/_/, ' ')
|
||||
actions:
|
||||
close: ->
|
||||
if close = @get('modal_options.close')
|
||||
close.apply(@)
|
||||
@send 'closeModal' unless @preventClose
|
||||
closeOnOverlay: ->
|
||||
@send('close') if @get('modal_options.closeOnOverlay')
|
||||
false
|
||||
modalClick: ->
|
||||
@send('close') if @get('modal_options.closeOnModalClick')
|
||||
false
|
||||
ok: ->
|
||||
if ok = @get('modal_options.ok')
|
||||
ok.apply(@)
|
||||
@send 'closeModal' unless @preventClose
|
||||
confirm: -> @send('ok')
|
||||
@@ -0,0 +1,6 @@
|
||||
App.modals.CloseListController = App.modals.BaseController.extend
|
||||
title_path: 'list.close.modal.title'
|
||||
actions:
|
||||
confirm: ->
|
||||
@get('model').then (l)->l.close()
|
||||
@send 'closeModal'
|
||||
@@ -2,17 +2,11 @@ App.SectionController = Ember.ObjectController.extend
|
||||
needs: ['application', 'sections', 'section'] #wtf? section, otherwise an Ember error
|
||||
editmode: false
|
||||
actions:
|
||||
###
|
||||
markListAsHelped: (list) -> list.is_helped() if list
|
||||
closeList: (list)->
|
||||
@send 'openModal', 'modal_close_list', list
|
||||
###
|
||||
makeEditable: -> @set('editmode', true)
|
||||
finishEditable: ->
|
||||
@set('editmode', false)
|
||||
@get('model').save()
|
||||
addSection: ->
|
||||
@send 'openModal', 'modal_add_section', @get('model')
|
||||
addSection: -> @modal 'add_section', model: @get('model')
|
||||
addTables: ->
|
||||
#$('#add-tables-modal').modal()
|
||||
@send 'openModal', 'modal_section_add_tables', @get('model')
|
||||
@@ -21,13 +15,14 @@ App.SectionController = Ember.ObjectController.extend
|
||||
editTable: (table)->
|
||||
@modal 'edit_table',
|
||||
model: table
|
||||
title_path: 'table.edit.modal.title'
|
||||
ok: ->
|
||||
table.save()
|
||||
close: ->
|
||||
table.rollback()
|
||||
destroySection: ->
|
||||
@send 'openModal', 'modal_confirm',
|
||||
title: t('helpers.links.are_you_sure')
|
||||
@modal 'confirm',
|
||||
title_path: 'helpers.links.are_you_sure'
|
||||
ok: =>
|
||||
@get('model').destroyRecord()
|
||||
@transitionToRoute 'sections'
|
||||
|
||||
@@ -12,7 +12,7 @@ App.SectionsIndexController = Ember.ArrayController.extend
|
||||
showDashboardOrders: (section)->
|
||||
@set 'controllers.application.active_section', section
|
||||
@transitionToRoute('index')
|
||||
addSection: -> @send 'openModal', 'modal_add_section', @get('model')
|
||||
addSection: -> @modal 'add_section', model: @get('model')
|
||||
goToSection: (section)->
|
||||
@set 'controllers.application.active_section', section
|
||||
@transitionToRoute 'section', section.id
|
||||
|
||||
@@ -4,6 +4,7 @@ App.TablesIndexController = Ember.ArrayController.extend
|
||||
editTable: (table)->
|
||||
@modal 'edit_table',
|
||||
model: table
|
||||
title_path: 'table.edit.modal.title'
|
||||
ok: ->
|
||||
table.save()
|
||||
close: ->
|
||||
@@ -11,4 +12,4 @@ App.TablesIndexController = Ember.ArrayController.extend
|
||||
destroyTable: (table)->
|
||||
@send 'confirm',
|
||||
title: t('table.destroy.modal.title', number: table.get('number'))
|
||||
ok: -> table.destroy()
|
||||
ok: -> table.destroyRecord()
|
||||
|
||||
+8
-4
@@ -1,11 +1,15 @@
|
||||
ControllerExtensions = Ember.Mixin.create
|
||||
# conveniance wrapper for open modal. Use like:
|
||||
# @modal "edit_table", model: table
|
||||
# modal: (name, options={})->
|
||||
# @send "openModal", "modals/#{name}", options.model || Ember.Object.create(),
|
||||
# controller: 'modal'
|
||||
# ok: options.ok
|
||||
# close: options.close
|
||||
modal: (name, options={})->
|
||||
@send "openModal", "modals/#{name}", options.model || Ember.Object.create(),
|
||||
controller: 'modal'
|
||||
ok: options.ok
|
||||
close: options.close
|
||||
options.model ||= Ember.Object.create()
|
||||
@send "openModal", name, options
|
||||
|
||||
all_sections: (-> @store.all('section')).property()
|
||||
|
||||
Ember.Controller.reopen ControllerExtensions
|
||||
|
||||
@@ -13,6 +13,7 @@ App.Router.map ->
|
||||
@resource 'lists', ->
|
||||
@resource 'list', path: ':list_id'
|
||||
@route 'orders_display' # chromecast etc
|
||||
@route 'menu'
|
||||
@route 'settings'
|
||||
@route 'empty'
|
||||
#@resource 'lists', queryParams: ['state']
|
||||
|
||||
@@ -16,21 +16,39 @@ App.ApplicationRoute = Ember.Route.extend
|
||||
controller.set 'product_categories', @product_categories
|
||||
|
||||
actions:
|
||||
openModal: (modalName, model, options={})->
|
||||
# openModal: (modalName, model, options={})->
|
||||
# controller_name = options.controller || modalName
|
||||
# controller = @controllerFor(controller_name)
|
||||
# controller.set 'model', model
|
||||
# controller.set 'modal_options', options
|
||||
# @render modalName,
|
||||
# into: 'application'
|
||||
# outlet: 'modal'
|
||||
# controller: controller_name
|
||||
openModal: (modalName, options={})->
|
||||
controller_name = options.controller || modalName
|
||||
controller = @controllerFor(controller_name)
|
||||
controller.set 'model', model
|
||||
controller.set 'modal_options', options
|
||||
@render modalName,
|
||||
try
|
||||
controller = @controllerFor("modals/#{modalName}")
|
||||
catch error
|
||||
controller = @controllerFor("modals/base")
|
||||
controller.set 'model', options.model
|
||||
defaultModalOptions =
|
||||
closeOnOverlay: true
|
||||
closeOnModalClick: false
|
||||
controller.set 'modal_options', $.extend(defaultModalOptions, options)
|
||||
@render "modals/#{modalName}",
|
||||
into: 'application'
|
||||
outlet: 'modal'
|
||||
controller: controller_name
|
||||
view: 'modal'
|
||||
controller: controller
|
||||
|
||||
closeModal: ->
|
||||
@disconnectOutlet
|
||||
outlet: 'modal'
|
||||
parentView: 'application'
|
||||
confirm: (options = {})->
|
||||
@send 'openModal', 'modal_confirm', Ember.Object.create
|
||||
@send 'openModal', 'confirm',
|
||||
model: Ember.Object.create
|
||||
title: options.title
|
||||
body: options.body
|
||||
cancel: options.cancel
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
h2 Menu
|
||||
each product_category in product_categories
|
||||
.row: .small-12.columns
|
||||
h3= product_category.name
|
||||
each product in product_category.products
|
||||
.row
|
||||
.small-4.columns= product.name
|
||||
.small-8.columns= currency product.price
|
||||
@@ -1,24 +0,0 @@
|
||||
modal-dialog action="close"
|
||||
h3.flush--top=t 'section.add_section.modal.title'
|
||||
p==body
|
||||
.modal-body
|
||||
.modal-alert== alert_message
|
||||
.form-row
|
||||
.form-label
|
||||
label=t 'attributes.section.title'
|
||||
.form-field
|
||||
Ember.TextField valueBinding="section_title"
|
||||
.form-row
|
||||
.form-label
|
||||
label=t 'attributes.section.width'
|
||||
.form-field
|
||||
App.NumberField valueBinding="section_width"
|
||||
.form-row
|
||||
.form-label
|
||||
label=t 'attributes.section.height'
|
||||
.form-field
|
||||
App.NumberField valueBinding="section_height"
|
||||
.modal-footer
|
||||
hr
|
||||
button.confirm-cancel{action "close"}=t 'section.add_section.modal.close_button'
|
||||
button.confirm-ok.right{action "addSection"}=t 'section.add_section.modal.add_button'
|
||||
@@ -1,10 +0,0 @@
|
||||
modal-dialog action="close"
|
||||
.modal-header
|
||||
h3.flush--top=t 'list.close.modal.title'
|
||||
hr
|
||||
.modal-body
|
||||
p=t 'list.close.modal.message'
|
||||
.modal-footer
|
||||
hr
|
||||
button.confirm-cancel{action "close"}=t 'list.close.modal.cancel'
|
||||
button.confirm-ok.right{action "confirm"}=t 'list.close.modal.close_list'
|
||||
@@ -1,6 +0,0 @@
|
||||
modal-dialog action="close"
|
||||
h3.flush--top= title
|
||||
p=body
|
||||
hr
|
||||
button.confirm-cancel{action "close"}= t 'confirm.cancel'
|
||||
button.confirm-ok.right{action "confirm"}= t 'confirm.confirm'
|
||||
@@ -0,0 +1,18 @@
|
||||
.form-row
|
||||
.form-label
|
||||
label=t 'attributes.section.title'
|
||||
.form-field
|
||||
Ember.TextField valueBinding="section_title"
|
||||
.form-row
|
||||
.form-label
|
||||
label=t 'attributes.section.width'
|
||||
.form-field
|
||||
App.NumberField valueBinding="section_width"
|
||||
.form-row
|
||||
.form-label
|
||||
label=t 'attributes.section.height'
|
||||
.form-field
|
||||
App.NumberField valueBinding="section_height"
|
||||
hr
|
||||
button.confirm-cancel{action "close"}=t 'section.add_section.modal.close_button'
|
||||
button.confirm-ok.right{action "addSection"}=t 'section.add_section.modal.add_button'
|
||||
@@ -0,0 +1,4 @@
|
||||
p=t 'list.close.modal.message'
|
||||
hr
|
||||
button.confirm-cancel{action "close"}=t 'list.close.modal.cancel'
|
||||
button.confirm-ok.right{action "confirm"}=t 'list.close.modal.close_list'
|
||||
@@ -0,0 +1,4 @@
|
||||
p=body
|
||||
hr
|
||||
button.confirm-cancel{action "close"}= t 'confirm.cancel'
|
||||
button.confirm-ok.right{action "confirm"}= t 'confirm.confirm'
|
||||
@@ -1,17 +1,11 @@
|
||||
modal-dialog action="close"
|
||||
.modal-header
|
||||
h3.flush--top=t 'table.edit.modal.title'
|
||||
hr
|
||||
.modal-body
|
||||
p=t 'table.edit.modal.body_header'
|
||||
.form-row
|
||||
.form-label=t 'attributes.table.number'
|
||||
.form-field: App.NumberField valueBinding="model.number"
|
||||
.form-row
|
||||
.form-label=t 'models.section'
|
||||
.form-field
|
||||
Ember.Select content=all_sections valueBinding="model.section" optionLabelPath="content.title"
|
||||
.modal-footer
|
||||
hr
|
||||
button.confirm-cancel{action "close"}=t 'section.add_tables.modal.close_button'
|
||||
button.confirm-ok.right{action "ok"}=t 'section.add_tables.modal.add_button'
|
||||
p=t 'table.edit.modal.body_header'
|
||||
.form-row
|
||||
.form-label=t 'attributes.table.number'
|
||||
.form-field: App.NumberField valueBinding="model.number"
|
||||
.form-row
|
||||
.form-label=t 'models.section'
|
||||
.form-field
|
||||
Ember.Select content=all_sections valueBinding="model.section" optionLabelPath="content.title"
|
||||
hr
|
||||
button.confirm-cancel{action "close"}=t 'section.add_tables.modal.close_button'
|
||||
button.confirm-ok.right{action "ok"}=t 'section.add_tables.modal.add_button'
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
.overlay{action "closeOnOverlay"}
|
||||
.modal{action "modalClick" bubbles=false preventDefault=false}
|
||||
.modal-header
|
||||
h3.flush--top= title
|
||||
hr
|
||||
.modal-body
|
||||
.modal-alert== alert_message
|
||||
= yield
|
||||
@@ -7,6 +7,7 @@ App.ApplicationView = Ember.View.extend
|
||||
'.top-menu-sections': 'sections'
|
||||
'.top-menu-tables': 'tables'
|
||||
'.top-menu-lists': 'lists'
|
||||
'.top-menu-menu': 'menu'
|
||||
'.supplier-settings-link': 'settings'
|
||||
|
||||
for selector, route of selector_mappings
|
||||
|
||||
@@ -4,4 +4,4 @@ App.CloseListButtonView = Ember.View.extend
|
||||
classNameBindings: ['content.active:show:hide']
|
||||
tagName: 'button'
|
||||
click: (e)->
|
||||
@get('controller').send 'openModal', 'modal_close_list', @get('content')
|
||||
@get('controller').send 'modal', 'close_list', model: @get('content')
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
App.ModalView = Ember.View.extend
|
||||
layoutName: 'modals/layout'
|
||||
|
||||
Reference in New Issue
Block a user