Tables to ember with modal extension cq refactor

This commit is contained in:
2014-07-30 10:22:58 +02:00
parent 640dbc37b8
commit 1b83157de2
15 changed files with 120 additions and 40 deletions
@@ -1,4 +1,11 @@
Qsupplier.App.ModalController = Ember.ObjectController.extend Qsupplier.App.ModalController = Ember.ObjectController.extend
modal_options: {}
actions: actions:
close: -> close: ->
@send 'closeModal' 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
@@ -0,0 +1,2 @@
Qsupplier.App.TableController = Ember.ObjectController.extend
table: (-> @get('model')).property('model')
@@ -1,2 +1,14 @@
Qsupplier.App.TablesIndexController = Ember.ArrayController.extend Qsupplier.App.TablesIndexController = Ember.ArrayController.extend
tables: (-> @get('model')).property('model') tables: (-> @get('model').sortBy('number')).property('model.@each.number')
actions:
editTable: (table)->
@modal 'edit_table',
model: table
ok: ->
table.save()
close: ->
table.rollback()
destroyTable: (table)->
@send 'confirm',
title: t('table.destroy.modal.title', number: table.get('number'))
ok: -> table.destroy()
@@ -0,0 +1,13 @@
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
all_sections: (-> @store.all('section')).property()
Ember.Controller.reopen ControllerExtensions
Ember.ArrayController.reopen ControllerExtensions
Ember.ObjectController.reopen ControllerExtensions
@@ -13,11 +13,15 @@ Qsupplier.App.ApplicationRoute = Ember.Route.extend
controller.set 'product_categories', @store.all('product_category') controller.set 'product_categories', @store.all('product_category')
actions: actions:
openModal: (modalName, model)-> openModal: (modalName, model, options={})->
@controllerFor(modalName).set('model', model) controller_name = options.controller || modalName
controller = @controllerFor(controller_name)
controller.set 'model', model
controller.set 'modal_options', options
@render modalName, @render modalName,
into: 'application' into: 'application'
outlet: 'modal' outlet: 'modal'
controller: controller_name
closeModal: -> closeModal: ->
@disconnectOutlet @disconnectOutlet
outlet: 'modal' outlet: 'modal'
@@ -0,0 +1,17 @@
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: Qsupplier.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'
@@ -0,0 +1,19 @@
.table-number= table.number
.status-icons
span.needs_payment
span.needs_help
span.active_order
if table.active_list
div class="table-actions table-actions-#{unbound table.id}"
.title= table.number
.table-action-row
Qsupplier.App.MarkListHelpedButtonView content=table.active_list
Qsupplier.App.CloseListButtonView content=table.active_list
.table-action-row=currency table.active_list.total
each user in table.active_list.users
img src=user.facebook_image
if editmodedisabled
.table-settings
select
option Round
option rectangular
@@ -1,19 +1,11 @@
.table-number= table.number h2=t 'models.table'
.status-icons .display-row
span.needs_payment .display-label= t 'attributes.table.number'
span.needs_help .display-field
span.active_order span= table.number
if table.active_list if table.section
div class="table-actions table-actions-#{unbound table.id}" .display-row
.title= table.number .display-label=t 'models.section'
.table-action-row .display-field
Qsupplier.App.MarkListHelpedButtonView content=table.active_list link-to 'section' table.section
Qsupplier.App.CloseListButtonView content=table.active_list span= table.section.title
.table-action-row=currency table.active_list.total
each user in table.active_list.users
img src=user.facebook_image
if editmodedisabled
.table-settings
select
option Round
option rectangular
@@ -10,9 +10,12 @@ if tables
tbody tbody
each table in tables each table in tables
tr tr
td: a= table.number td: link-to 'table' table: span= table.number
td.link td.link
if table.section if table.section
= link-to 'sections:section' table.section = link-to 'section' table.section
= table.section.title
td.numeric=time table.created_at td.numeric=time table.created_at
td.actions td.actions
a.table-edit{ action 'editTable' table }: span
a.table-destroy{ action 'destroyTable' table }: span
@@ -1,5 +1,5 @@
Qsupplier.App.SectionTableView = Ember.View.extend DragNDrop.Draggable, Qsupplier.App.SectionTableView = Ember.View.extend DragNDrop.Draggable,
templateName: 'table' templateName: 'section_table'
classNames: ['section-table'] classNames: ['section-table']
attributeBindings: ['style'] attributeBindings: ['style']
classNameBindings: [ classNameBindings: [
@@ -17,7 +17,6 @@
//= require moment //= require moment
var Qstorage = localStorage; var Qstorage = localStorage;
$.extend($translations.en, <%= I18n.t('supplier', locale: :en).to_json %>); $.extend($translations.en, <%= I18n.t('supplier', locale: :en).to_json %>);
$.extend($translations.nl, <%= I18n.t('supplier', locale: :nl).to_json %>); $.extend($translations.nl, <%= I18n.t('supplier', locale: :nl).to_json %>);
+15 -13
View File
@@ -1,13 +1,15 @@
.page-header= title :show, @table - content_for :head do
.display-row = javascript_include_tag 'supplier/app/application'
.display-label / .page-header= title :show, @table
span data-t='attributes.table.number' / .display-row
.display-field / .display-label
span= @table.number / span data-t='attributes.table.number'
- if @table.section.present? / .display-field
.display-row / span= @table.number
.display-label / - if @table.section.present?
span data-t='models.section' / .display-row
.display-field / .display-label
span= link_to @table.section.title, [:suppliers, @table.section] / span data-t='models.section'
= supplier_form_actions :index, :edit, :destroy, object: @table, for: :tables / .display-field
/ span= link_to @table.section.title, [:suppliers, @table.section]
/ = supplier_form_actions :index, :edit, :destroy, object: @table, for: :tables
+4
View File
@@ -21,6 +21,10 @@ en:
qr_codes: qr_codes:
link: Print Qr codes sheet link: Print Qr codes sheet
has_no_section: "Not placed" has_no_section: "Not placed"
table:
destroy:
modal:
title: Are you sure you want to delete ${models.table} %{number}
lists: lists:
index: index:
show_all: Show all ${models.plural.list} show_all: Show all ${models.plural.list}
+4
View File
@@ -21,6 +21,10 @@ nl:
qr_codes: qr_codes:
link: Print Qr codes link: Print Qr codes
has_no_section: "Niet geplaatst" has_no_section: "Niet geplaatst"
table:
destroy:
modal:
title: Weet je zeker dat je ${models.table} %{number} wilt verwijderen
lists: lists:
index: index:
show_all: Toon alle ${models.plural.list} show_all: Toon alle ${models.plural.list}
+2
View File
@@ -59,3 +59,5 @@ Post release
============ ============
- Chromecast app Waiter app Users can disable their own help request (maak ongedaan?) Users can disable their own bill request (maak ongedaan?) Think about extra confirmation box for these requests Supplier section 100% on ember :) - Chromecast app Waiter app Users can disable their own help request (maak ongedaan?) Users can disable their own bill request (maak ongedaan?) Think about extra confirmation box for these requests Supplier section 100% on ember :)
- Do not destroy tables with active list
- Test list view when table is destroyed