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
modal_options: {}
actions:
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
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')
actions:
openModal: (modalName, model)->
@controllerFor(modalName).set('model', model)
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
closeModal: ->
@disconnectOutlet
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
.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
h2=t 'models.table'
.display-row
.display-label= t 'attributes.table.number'
.display-field
span= table.number
if table.section
.display-row
.display-label=t 'models.section'
.display-field
link-to 'section' table.section
span= table.section.title
@@ -10,9 +10,12 @@ if tables
tbody
each table in tables
tr
td: a= table.number
td: link-to 'table' table: span= table.number
td.link
if table.section
= link-to 'sections:section' table.section
= link-to 'section' table.section
= table.section.title
td.numeric=time table.created_at
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,
templateName: 'table'
templateName: 'section_table'
classNames: ['section-table']
attributeBindings: ['style']
classNameBindings: [
@@ -17,7 +17,6 @@
//= require moment
var Qstorage = localStorage;
$.extend($translations.en, <%= I18n.t('supplier', locale: :en).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
.display-row
.display-label
span data-t='attributes.table.number'
.display-field
span= @table.number
- if @table.section.present?
.display-row
.display-label
span data-t='models.section'
.display-field
span= link_to @table.section.title, [:suppliers, @table.section]
= supplier_form_actions :index, :edit, :destroy, object: @table, for: :tables
- content_for :head do
= javascript_include_tag 'supplier/app/application'
/ .page-header= title :show, @table
/ .display-row
/ .display-label
/ span data-t='attributes.table.number'
/ .display-field
/ span= @table.number
/ - if @table.section.present?
/ .display-row
/ .display-label
/ span data-t='models.section'
/ .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:
link: Print Qr codes sheet
has_no_section: "Not placed"
table:
destroy:
modal:
title: Are you sure you want to delete ${models.table} %{number}
lists:
index:
show_all: Show all ${models.plural.list}
+4
View File
@@ -21,6 +21,10 @@ nl:
qr_codes:
link: Print Qr codes
has_no_section: "Niet geplaatst"
table:
destroy:
modal:
title: Weet je zeker dat je ${models.table} %{number} wilt verwijderen
lists:
index:
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 :)
- Do not destroy tables with active list
- Test list view when table is destroyed