consitency refactor

This commit is contained in:
2014-11-27 19:42:51 +01:00
parent 5453837880
commit 3bc1e5685c
37 changed files with 338 additions and 235 deletions
@@ -1,6 +1,6 @@
App.ApplicationController = Ember.Controller.extend
active_section: null
init: ->
#init: ->
#success = (supplier)=>
## A supplier record with id current and with the content of the returned supplier is created
## at the moment remove the dummy supplier, this should be resolved by Ember eventually
@@ -14,3 +14,12 @@ App.ApplicationController = Ember.Controller.extend
#@set 'supplier', null
#@store.find('supplier', 'current').then success, error
# @set 'supplier', @store.find('supplier', supplier_id)
actions:
signOut: ->
window.location = Routes.destroy_supplier_session_path()
markSupplierClosed: ->
return unless supplier = @get('supplier')
supplier.close()
markSupplierOpen: ->
return unless supplier = @get('supplier')
supplier.open_the_place()
@@ -1,6 +1,6 @@
@App.modals.BaseController = Ember.ObjectController.extend
alert_message: ""
title: ~>
title: (->
# return title if directly set by options
return @get('modal_options.title') if @get('modal_options.title')
# return translated title_path if directly set by controller
@@ -17,6 +17,7 @@
new Ember.Handlebars.SafeString(tspan(@get("modal.#{underscored}.title"), translation_params))
else
underscored.capitalize().replace(/_/, ' ')
).property('model.id')
actions:
close: ->
if close = @get('modal_options.close')
@@ -0,0 +1,13 @@
App.modals.TableEditController = App.modals.BaseController.extend
title_path: 'table.edit.modal.title'
sections: (-> @store.all('section')).property()
#setSelectedSection: (-> @set 'selectedSection', @get('model.section')).on('init')
actions:
confirm: ->
@get('model').then (l)->l.close()
@send 'closeModal'
saveTable: ->
#@set 'model.section', @get('selectedSection')
@set 'model.section', @get('model.section')
#debugger
@send 'save'
@@ -2,14 +2,11 @@ App.TablesIndexController = Ember.ArrayController.extend
tables: (-> @get('model').sortBy('casted_number')).property('model.@each.number')
actions:
editTable: (table)->
@modal 'edit_table',
@modal 'table_edit',
model: table
title_path: 'table.edit.modal.title'
ok: ->
table.save()
close: ->
table.rollback()
destroyTable: (table)->
@send 'confirm',
@modal 'confirm',
title: t('table.destroy.modal.title', number: table.get('number'))
ok: -> table.destroyRecord()
@@ -8,6 +8,7 @@ App.Supplier = DS.Model.extend
house_number_addition: attr 'string'
postal_code: attr 'string'
city: attr 'string'
open: attr 'boolean'
country: attr 'string'
facebook_promotion_url: attr 'string'
iens_profile: attr 'string'
@@ -15,3 +16,11 @@ App.Supplier = DS.Model.extend
lng: attr 'number'
week_starts_on_monday: attr 'boolean'
product_categories: DS.hasMany 'product_category'
close: ->
$.post Routes.supplier_mark_as_closed_path(), =>
@set 'open', false
open_the_place: ->
$.post Routes.supplier_mark_as_open_path(), =>
@set 'open', true
@@ -1,10 +1,11 @@
DS.Model.reopen
created_at: DS.attr('date')
updated_at: DS.attr('date')
#TODO: at the moment deleteRecord might work as expected, check this
eraseRecord: ->
@clearRelationships()
@transitionTo('deleted.saved')
then: (callback) -> callback.call(@, @)
#then: (callback) -> callback.call(@, @) DO NOT USE SINCE THERE IS TYPECHECKING ON .then in ember data https://github.com/emberjs/data/issues/2523
DS.Model.reopenClass
findCached: (id)->
return null unless id
@@ -11,7 +11,7 @@ if list.closed_at
=state 'list' list.state
.display-row
.display-label  
.display-field: App.CloseListButtonView content=list
.display-field= view "close-list-button" content=list
.user-info-container
each user in list.users
=user.facebook_image_tag
@@ -7,7 +7,7 @@ td.status-icons
if view.content.needs_payment
|
span.icon.needs-payment
td.numeric.table_number: App.TableNumberWithInfoView contextBinding="view.content"
td.numeric.table_number= view "table-number-with-info" contextBinding="view.content"
td.section_title: link-to 'section' view.content.table.section.id: span=view.content.table.section.title
td.currency.total_list_amount=currency view.content.total
td.actions
@@ -16,8 +16,8 @@ td.actions
span.fa-stack.fa-2x.fa-stack-sized
i.fa.fa-bell.fa-stack-small
i.fa.fa-ban.revoke
App.MarkListHelpedButtonView content=view.content
/App.RemoveListNeedsPaymentView content=view.content
App.CloseListButtonView content=view.content
= view "mark-list-helped-button" content=view.content
/= view "remove-list-needs-payment" content=view.content
= view "close-list-button" content=view.content
button.show-list.button{action "showList" view.content.id}: span
@@ -5,8 +5,8 @@ td.status-icons
if view.content.active
span.active-order.fa.fa-check.fa-lg
td= view.content.display
td.numeric.table_number: App.TableNumberWithInfoView contextBinding="view.content.list"
td.section_title: link-to 'section' view.content.list.table.section.id: span=view.content.list.table.section.title
td.numeric.table_number= view "table-number-with-info" contextBinding="view.content.list"
td.section_title= link-to 'section' view.content.list.table.section.id: span=view.content.list.table.section.title
td.currency=currency view.content.total
td.time= time view.content.created_at format="HH:mm"
td.actions
@@ -1,2 +1,3 @@
= outlet
= partial "global/top_menu"
.main-section= outlet
= outlet modal
@@ -0,0 +1,36 @@
header.top-menu
.toggle-side-menu
span
.menu-content
section.main-buttons
= link-to 'index' class="top-menu-root"
= image_tag "icons/logo-small.png"
= link-to "menu" class="top-menu-menu"
= t 'supplier.top_menu.menu'
= link-to "sections" class="top-menu-sections"
= t 'models.plural.section'
= link-to "tables" class="top-menu-tables"
= t 'models.plural.table'
= link-to "lists" class="top-menu-lists"
= t 'models.plural.list'
section.extra-info
.supplier-info-row
.supplier-name= supplier.name
.table-number
.supplier-info-row
.counter.supplier-orders-placed-count
span.supplier-orders-placed-count-number= supplier.orders_placed_count
span.supplier-orders-placed-count-icon
.counter.supplier-orders-in-process-count
span.supplier-orders-in-process-count-number= supplier.orders_in_process_count
span.supplier-orders-in-process-count-icon
aside.side-menu
ul
li.title: h3 Menu
if supplier.open
li: a.supplier-close-shop{action "markSupplierClosed"}= t 'supplier.close_for_orders'
else
li: a.supplier-open-shop{action "markSupplierOpen"}= t 'supplier.open_for_orders'
= link-to "settings" class="supplier-settings-link"
= t 'supplier.settings'
li class="supplier-sign-out-link": a{action "signOut"}= t 'supplier.sign_out'
@@ -1,53 +1,56 @@
= sections-header sectionBinding="controller.controllers.application.active_section"
.page-header
div.dashboard-section-selection
/App.HomeSectionSelectorView selectionBinding="controller.controllers.application.active_section" content=controller.sections prompt=controllers.application.supplier.name
/= home-section-selector sectionBinding="controller.controllers.application.active_section"
/= view "home-section-jumper"
if active_lists.length
h3.dashboard-lists-header{action "toggleDashboardLists"}
if show_lists
span.icon
else
span.icon.collapsed
=t 'active_lists.title'
span= list_number_info
else
h3=t 'dashboard.active_lists.no_lists'
if show_lists_table
table.active-lists-table.table
thead
tr
th.user-info.show-for-large-up
th.status-icons
th.numeric=t 'table_number'
th=t 'models.section'
th.currency=t 'active_lists.price'
th.actions
tbody
each list in active_lists: App.ActiveListView contentBinding="list"
.page-header
if active_orders.length
h3.dashboard-orders-header{action "toggleDashboardOrders"}
if show_orders
span.icon
else
span.icon.collapsed
=t 'active_orders.title'
span= order_number_info
else
h3= t 'dashboard.active_orders.no_orders'
if show_orders_table
table.active-orders-table.table
thead
tr
th.user-info.show-for-large-up
th.status-icons
th=t 'models.order'
th.numeric=t 'table_number'
th=t 'models.section'
th.currency=t 'active_orders.price'
th.time
th.actions
tbody
each order in active_orders: App.ActiveOrderView contentBinding="order"
.row: .small-12.columns
= sections-header sectionBinding="controller.controllers.application.active_section"
.page-header
div.dashboard-section-selection
/App.HomeSectionSelectorView selectionBinding="controller.controllers.application.active_section" content=controller.sections prompt=controllers.application.supplier.name
/= home-section-selector sectionBinding="controller.controllers.application.active_section"
/= view "home-section-jumper"
if active_lists.length
h3.dashboard-lists-header{action "toggleDashboardLists"}
if show_lists
span.icon
else
span.icon.collapsed
=t 'active_lists.title'
span= list_number_info
else
h3=t 'dashboard.active_lists.no_lists'
if show_lists_table
table.active-lists-table.table
thead
tr
th.user-info.show-for-large-up
th.status-icons
th.numeric=t 'table_number'
th=t 'models.section'
th.currency=t 'active_lists.price'
th.actions
tbody
each list in active_lists
= view "active-list" contentBinding="list"
.page-header
if active_orders.length
h3.dashboard-orders-header{action "toggleDashboardOrders"}
if show_orders
span.icon
else
span.icon.collapsed
=t 'active_orders.title'
span= order_number_info
else
h3= t 'dashboard.active_orders.no_orders'
if show_orders_table
table.active-orders-table.table
thead
tr
th.user-info.show-for-large-up
th.status-icons
th=t 'models.order'
th.numeric=t 'table_number'
th=t 'models.section'
th.currency=t 'active_orders.price'
th.time
th.actions
tbody
each order in active_orders
= view "active-order" contentBinding="order"
@@ -1,4 +1,5 @@
h2=t 'models.list'
partial "list_content"
link-to 'lists' class="button"
span=t 'list.go_to_lists'
.row: .small-12.columns
h2=t 'models.list'
partial "list_content"
link-to 'lists' class="button"
span=t 'list.go_to_lists'
@@ -1,32 +1,33 @@
h1=t 'models.plural.list'
App.ListDisplayDateSelector valueBinding="date"
if sorted_lists
table.table
thead
tr
th.state=t 'attributes.list.state'
th.boolean=t 'attributes.list.needs_help'
th.boolean=t 'attributes.list.needs_payment'
th.timestamp=t 'attributes.list.closed_at'
th.table_number=t 'models.table'
th.currentcy=t 'attributes.list.price'
th.timestamp=t 'attributes.list.created_at'
tbody
each list in sorted_lists
.row: .small-12.columns
h1=t 'models.plural.list'
= view "list-display-date-selector" valueBinding="date"
if sorted_lists
table.table
thead
tr
td.state
link-to 'list' list.id
= state 'list' list.state
td.boolean.needs_help=boolean list.needs_help
td.boolean.needs_payment=boolean list.needs_payment
td.timestamp=time list.closed_at
td.table_number= list.table.number
td.currency=currency list.price
td.timestamp=time list.created_at
else
.row
.panel
if loading
span.loading
else
=t 'list.none_found'
th.state=t 'attributes.list.state'
th.boolean=t 'attributes.list.needs_help'
th.boolean=t 'attributes.list.needs_payment'
th.timestamp=t 'attributes.list.closed_at'
th.table_number=t 'models.table'
th.currentcy=t 'attributes.list.price'
th.timestamp=t 'attributes.list.created_at'
tbody
each list in sorted_lists
tr
td.state
link-to 'list' list.id
= state 'list' list.state
td.boolean.needs_help=boolean list.needs_help
td.boolean.needs_payment=boolean list.needs_payment
td.timestamp=time list.closed_at
td.table_number= list.table.number
td.currency=currency list.price
td.timestamp=time list.created_at
else
.row: .small-12.columns
.panel
if loading
span.loading
else
=t 'list.none_found'
@@ -1,6 +1,7 @@
.products-menu-filters-container
= input value=product_code_filter type="search" placeholder=product_code_filter_placeholder
h2 Menu
.row: .small-12.columns
.products-menu-filters-container
= input value=product_code_filter type="search" placeholder=product_code_filter_placeholder
h2 Menu
each product_category in sorted_product_categories
.row.product_category-container: .small-12.columns
.product_category-header
@@ -1,11 +0,0 @@
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.modal-close{action "close"}=t 'section.add_tables.modal.close_button'
button.modal-confirm.right{action "ok"}=t 'section.add_tables.modal.add_button'
@@ -0,0 +1,12 @@
p=t 'table.edit.modal.body_header'
.form-row
.form-label=t 'attributes.table.number'
.form-field= input type="number" valueBinding="model.number"
.form-row
.form-label=t 'models.section'
.form-field
= view "select" content=sections selectionBinding="model.section" optionLabelPath="content.title" optionValuePath="content.id"
= model.section.title
hr
button.modal-close{action "close"}=t 'section.add_tables.modal.close_button'
button.modal-confirm.right{action "save"}=t 'section.add_tables.modal.add_button'
@@ -1,7 +1,7 @@
.section-tabs-container
link-to 'sections' class="goto-sections-index-tab-header": span
= link-to 'sections' class="goto-sections-index-tab-header": span
each section in sections
App.SectionTabHeaderView context=section
= view "section-tab-header" context=section
a.add-section{action "addSection"}: span
.section-manage-tables.pull-right
if editmode
@@ -27,11 +27,12 @@
a href="{{route 'qr_codes_suppliers_tables_path' section_id=id}}": span.table-qr-codes=t 'tables.qr_codes.link'
li
a.section-destroy{action "destroySection"}: span.section-remove-icon=t 'helpers.links.destroy'
Ember.TextField valueBinding="title" class="section-edit-title-field"
= input type="text" valueBinding="title" class="section-edit-title-field"
App.NumberField valueBinding="width" class="dimension section-edit-width-field"
span.fa.fa-lg.fa-times
App.NumberField valueBinding="height" class="dimension section-edit-height-field"
a.section-normal-mode-button{ action "finishEditable" }: span
else
a.section-edit-mode-button{ action "makeEditable" }: span
App.SectionTablesView contentBinding="tables"
= view "section-tables" contentBinding="tables"
@@ -7,8 +7,8 @@ if table.active_list
div.table-actions
.title= table.number
.table-action-row
App.MarkListHelpedButtonView contentBinding="table.active_list"
App.CloseListButtonView contentBinding="table.active_list"
= view "mark-list-helped-button" contentBinding="table.active_list"
= view "close-list-button" contentBinding="table.active_list"
.table-action-row=currency table.active_list.total
/.table-action-row
a{action "editTable" table}: span.fa.fa-lg.fa-wrench
@@ -1,2 +1,2 @@
each table in tables
App.SectionTableView content=table
= view "section-table" content=table
@@ -1,40 +1,41 @@
h1=t 'models.plural.section'
if sections
table.table
thead
tr
th=t 'attributes.section.title'
th=t 'models.plural.table'
th.numeric=t 'attributes.section.width'
th.numeric=t 'attributes.section.height'
/th.boolean=t 'attributes.list.needs_help'
/th.boolean=t 'attributes.list.needs_payment'
/th.timestamp=t 'attributes.list.closed_at'
/th.table_number=t 'models.table'
/th.currentcy=t 'attributes.list.price'
/th.timestamp=t 'attributes.list.created_at'
th.actions=t 'helpers.actions.title'
tbody
each section in sections
.row: .small-12.columns
h1=t 'models.plural.section'
if sections
table.table
thead
tr
td
a{ action "goToSection" section}= section.title
td
span.table-count= section.tables.length
td.numeric= section.width
td.numeric= section.height
/td.boolean.needs_help=boolean list.needs_help
/td.boolean.needs_payment=boolean list.needs_payment
/td.timestamp=time list.closed_at
/td.table_number 7
/td.currency=currency list.price
/td.timestamp=time list.created_at
td.actions
a.section-dashboard-orders{action showDashboardOrders section}: span
a.table-qr-codes{path qr_codes_suppliers_tables section_id=section.id}
span
else
.row
.panel=t 'section.none_found'
.form-actions
a.form-action-new{action "addSection"}=t 'helpers.links.new'
th=t 'attributes.section.title'
th=t 'models.plural.table'
th.numeric=t 'attributes.section.width'
th.numeric=t 'attributes.section.height'
/th.boolean=t 'attributes.list.needs_help'
/th.boolean=t 'attributes.list.needs_payment'
/th.timestamp=t 'attributes.list.closed_at'
/th.table_number=t 'models.table'
/th.currentcy=t 'attributes.list.price'
/th.timestamp=t 'attributes.list.created_at'
th.actions=t 'helpers.actions.title'
tbody
each section in sections
tr
td
a{ action "goToSection" section}= section.title
td
span.table-count= section.tables.length
td.numeric= section.width
td.numeric= section.height
/td.boolean.needs_help=boolean list.needs_help
/td.boolean.needs_payment=boolean list.needs_payment
/td.timestamp=time list.closed_at
/td.table_number 7
/td.currency=currency list.price
/td.timestamp=time list.created_at
td.actions
a.section-dashboard-orders{action showDashboardOrders section}: span
a.table-qr-codes{path qr_codes_suppliers_tables section_id=section.id}
span
else
.row: .small-12.columns
.panel=t 'section.none_found'
.form-actions
a.form-action-new{action "addSection"}=t 'helpers.links.new'
@@ -1,11 +1,12 @@
h2=t 'models.table'
.display-row
.display-label= t 'attributes.table.number'
.display-field
span= table.number
if table.section
.row: .small-12.columns
h2=t 'models.table'
.display-row
.display-label=t 'models.section'
.display-label= t 'attributes.table.number'
.display-field
link-to 'section' table.section
span= table.section.title
span= table.number
if table.section
.display-row
.display-label=t 'models.section'
.display-field
link-to 'section' table.section
span= table.section.title
@@ -1,21 +1,22 @@
h1=t 'models.plural.table'
if tables
table.table
thead
tr
th=t 'attributes.table.number'
th.link=t 'models.section'
th.timestamp= t 'attributes.table.created_at'
th.actions=t 'helpers.actions.title'
tbody
each table in tables
.row: .small-12.columns
h1=t 'models.plural.table'
if tables
table.table
thead
tr
td: link-to 'table' table: span= table.number
td.link
if 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
th=t 'attributes.table.number'
th.link=t 'models.section'
th.timestamp= t 'attributes.table.created_at'
th.actions=t 'helpers.actions.title'
tbody
each table in tables
tr
td: link-to 'table' table: span= table.number
td.link
if 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,17 +1,28 @@
App.ApplicationView = Ember.View.extend
classNames: ['application-view']
didInsertElement: ->
Qsupplier.watch_events()
selector_mappings =
'.top-menu-root': '/'
'.top-menu-lists': 'lists'
'.top-menu-sections': 'sections'
'.top-menu-tables': 'tables'
'.top-menu-lists': 'lists'
'.top-menu-menu': 'menu'
'.supplier-settings-link': 'settings'
$('.toggle-side-menu,.side-menu').click ->
menu = $('aside.side-menu')
toggle = $('.toggle-side-menu')
if menu.is(':visible')
menu.animate left: -255, -> $(@).hide()
toggle.animate left: 0, -> $(@).removeClass('open')
else
menu.show().animate left: 0
toggle.animate left: 222 - 30, -> $(@).addClass('open')
for selector, route of selector_mappings
do (selector, route)=>
$(selector).click (e)=>
e.preventDefault()
@get('controller').transitionToRoute route
#selector_mappings =
#'.top-menu-root': '/'
#'.top-menu-lists': 'lists'
#'.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
#do (selector, route)=>
#$(selector).click (e)=>
#e.preventDefault()
#@get('controller').transitionToRoute route
@@ -4,4 +4,4 @@ App.CloseListButtonView = Ember.View.extend
classNameBindings: ['content.active:show:hide']
tagName: 'button'
click: (e)->
@get('controller').send 'modal', 'close_list', model: @get('content')
@get('controller').modal 'close_list', model: @get('content')
@@ -1,4 +1,4 @@
App.ListDisplayDateSelector = Ember.TextField.extend
App.ListDisplayDateSelectorView = Ember.TextField.extend
classNames: 'datepicker'
didInsertElement: ->
setTranslations @$().hide()
@@ -4,4 +4,6 @@ App.MarkListHelpedButtonView = Ember.View.extend
classNameBindings: ['content.needs_help:show:hide']
tagName: 'button'
click: (e)->
@get('content').then (l)->l.is_helped()
# record could be promise or object
record = @get('content')
if record.then then record.then((l)->l.is_helped()) else record.is_helped()