supplier menu progress

This commit is contained in:
2014-11-24 18:20:10 +01:00
parent 148a0a2815
commit 1707f4d19f
37 changed files with 7356 additions and 6046 deletions
@@ -0,0 +1,13 @@
App.MenuController = Ember.ObjectController.extend
needs: ['application']
product_categories: (-> @store.all('product_category')).property()
sorted_product_categories: (-> @get('product_categories').sortBy('position')).property('product_categories.@each', 'product_categories.@each.position')
actions:
editProductCategory: (product_category)->
@modal 'product_category_edit',
model: product_category,
close: -> product_category.rollback()
moveProductCategory: (product_category)->
@modal 'product_category_move',
model: product_category
@@ -1,3 +0,0 @@
App.MenuController = Ember.ObjectController.extend
needs: ['application']
product_categories: ~> @store.all('product_category')
@@ -1,5 +1,4 @@
App.modals.AddSectionController = @App.modals.BaseController.extend
alert_message: null
section_title: ''
section_width: 15
section_height: 8
@@ -1,13 +1,19 @@
@App.modals.BaseController = Ember.ObjectController.extend
alert_message: ""
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
return t(@title_path) if @title_path
# return translated title_path if directly set by options
return t(@get('modal_options.title_path')) if @get('modal_options.title_path')
# infer title path based on controller name App.modals.AddSectionController => add_section
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(/_/, ' ')
# find translated title or humanize the controller name
ttry("modal.#{underscored}.title", params) or underscored.capitalize().replace(/_/, ' ')
actions:
close: ->
if close = @get('modal_options.close')
@@ -24,3 +30,6 @@
ok.apply(@)
@send 'closeModal' unless @preventClose
confirm: -> @send('ok')
save: ->
@get('model').save()
@send 'closeModal' unless @preventClose
@@ -0,0 +1,2 @@
App.modals.ProductCategoryEditController = App.modals.BaseController.extend
title_path: 'product_category.edit.modal.title'
@@ -0,0 +1,29 @@
App.modals.ProductCategoryMoveController = App.modals.BaseController.extend
title_path: 'product_category.move.modal.title'
actions:
moveBelow: (below_product_category)->
position = 0
unless below_product_category
@set 'model.position', position
@get('model').save()
position += 1
for product_category in @get('product_categories')
product_category.set('position', position)
product_category.save()
if below_product_category and product_category.id is below_product_category.id
@set 'model.position', position += 1
@get('model').save()
position += 1
@send 'close'
# moveBelow: (->
# debugger
# ).observes('move_below_selection')
# change: ->
# debugger
product_categories: (->
@store.all('product_category').filter( (pc) => pc.id isnt @get('model.id')).sortBy('position')
).property('model.id')
# setProductCategories: (-> @set 'product_categories', @store.all('product_category')).on('init')
@@ -1,5 +1,4 @@
App.modals.SectionArrangeTablesController = App.modals.BaseController.extend
alert_message: null
arrange_type: 'distributed' # can be distributed, by_row or by_column
row_count: 2
column_count: 2
@@ -0,0 +1,6 @@
Ember.Handlebars.helper 'select-hour', (params..., options)->
debugger
result = "<select class=\"select-hour\">"
result += "<option>#{hour}</option>" for hour in [0..24]
result += "</select>"
new Handlebars.SafeString result
@@ -0,0 +1,5 @@
Ember.Handlebars.helper 'select-minute', (params..., options)->
result = "<select class=\"select-minute\">"
result += "<option>#{minute}</option>" for minute in [0..24]
result += "</select>"
new Handlebars.SafeString result
@@ -2,3 +2,25 @@ attr = DS.attr
App.ProductCategory = DS.Model.extend
name: attr('string')
products: DS.hasMany('product')
supplier: DS.belongsTo 'supplier'
active_on_sunday: attr('boolean')
active_on_monday: attr('boolean')
active_on_tuesday: attr('boolean')
active_on_wednesday: attr('boolean')
active_on_thursday: attr('boolean')
active_on_friday: attr('boolean')
active_on_saturday: attr('boolean')
full_day: attr('boolean')
start_from: attr('number')
end_on: attr('number')
position: attr('number')
availability_text: Ember.computed 'active_on_sunday', 'active_on_monday', 'active_on_tuesday', 'active_on_wednesday', 'active_on_thursday', 'active_on_friday', 'active_on_saturday', 'full_day', 'start_from', 'end_on', ->
days = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday']
active_days = days.filter (day)=>@get("active_on_#{day}")
result = ""
if active_days.length < 7
result += "<span class=\"day-names\">#{active_days.map((day) -> t("date.day_name.#{day}")).join(", ")}</span> "
unless @get('full_day')
result += "<span class=\"time-range\">#{day_minutes_to_time @get('start_from')} - #{day_minutes_to_time @get('end_on')}</span>"
new Ember.Handlebars.SafeString result
@@ -13,3 +13,5 @@ App.Supplier = DS.Model.extend
iens_profile: attr 'string'
lat: attr 'number'
lng: attr 'number'
week_starts_on_monday: attr 'boolean'
product_categories: DS.hasMany 'product_category'
@@ -0,0 +1,2 @@
Ember.Checkbox id=view.switchId checkedBinding="view.value"
label for=view.switchId
@@ -0,0 +1,6 @@
.row.select-minute-of-day
.small-5.columns
view "select" content=view.hours_list value=view.hour
.small-1.columns: span :
.small-5.columns.end
view "select" content=view.minutes_list value=view.minute
@@ -1,7 +1,11 @@
h2 Menu
each product_category in product_categories
each product_category in sorted_product_categories
.row: .small-12.columns
h3= product_category.name
.product_category-header
a.move{action "moveProductCategory" product_category} href="#"
span.title= product_category.name
span.availability= product_category.availability_text
a.edit-product-category-button{action "editProductCategory" product_category} href="#"
each product in product_category.products
.row
.small-4.columns= product.name
@@ -0,0 +1,45 @@
p=t 'product_category.edit.modal.body_header'
.form-row
.form-label.half=t 'attributes.product_category.name'
.form-field.half= input valueBinding="model.name"
.row
.small-6.columns
unless model.supplier.week_starts_on_monday
.form-row
.form-label.half= t 'date.day_name.sunday'
.form-field.half: App.BooleanSwitchView value=model.active_on_sunday
.form-row
.form-label.half= t 'date.day_name.monday'
.form-field.half: App.BooleanSwitchView value=model.active_on_monday
.form-row
.form-label.half= t 'date.day_name.tuesday'
.form-field.half: App.BooleanSwitchView value=model.active_on_tuesday
.form-row
.form-label.half= t 'date.day_name.wednesday'
.form-field.half: App.BooleanSwitchView value=model.active_on_wednesday
.form-row
.form-label.half= t 'date.day_name.thursday'
.form-field.half: App.BooleanSwitchView value=model.active_on_thursday
.form-row
.form-label.half= t 'date.day_name.friday'
.form-field.half: App.BooleanSwitchView value=model.active_on_friday
.form-row
.form-label.half= t 'date.day_name.saturday'
.form-field.half: App.BooleanSwitchView value=model.active_on_saturday
if model.supplier.week_starts_on_monday
.form-row
.form-label.half= t 'date.day_name.sunday'
.form-field.half: App.BooleanSwitchView valueBinding=model.active_on_sunday
.small-6.columns
.row
.small-12.columns.text-center: App.BooleanButtonView value=model.full_day reverse=true text_path="product_category.edit.modal.active_between.top"
unless model.full_day
.row
.small-12.columns= view "select-minute-of-day" value=model.start_from
.row
.small-12.columns.text-center= t 'product_category.edit.modal.active_between.middle'
.row
.small-12.columns= view "select-minute-of-day" value=model.end_on
hr
button.confirm-cancel{action "close"}=t 'section.add_tables.modal.close_button'
button.confirm-ok.right{action "save"}=t 'section.add_tables.modal.add_button'
@@ -0,0 +1,13 @@
p=t 'product_category.move.modal.body_header'
.row
.small-11.small-offset-1.columns
a{action "moveBelow"} href="#" = t 'product_category.move.modal.move_to_top'
h4=t 'product_category.move.modal.move_below_label'
each product_category in product_categories
.row.product_category-move-row
.small-11.small-offset-1.columns
a{action "moveBelow" product_category} href="#"
span.title= product_category.name
span.availability= product_category.availability_text
hr
button.confirm-cancel{action "close"}=t 'section.add_tables.modal.close_button'
@@ -0,0 +1,17 @@
App.BooleanButtonView = Ember.View.extend
tagName: 'a'
href: '#'
classNames: "button"
# templateName: "form_elements/boolean_switch"
template: Ember.Handlebars.compile "<span>{{view.text}}</span>"
classNameBindings: ['rounded:round', 'active:active:disabled']
text: Ember.computed 'text_path', ->
t @text_path
active: Ember.computed 'value', ->
if @reverse then !@get('value') else !!@get('value')
click: ->
@set 'value', !@get('value')
# setUniqueId: (->@set 'switchId', "switch-#{Math.round(Math.random()*1000)}").on('init')
@@ -0,0 +1,8 @@
App.BooleanSwitchView = Ember.View.extend
classNames: "switch"
templateName: "form_elements/boolean_switch"
classNameBindings: ['rounded:round']
click: ->
@set 'value', !@get('value')
setUniqueId: (->@set 'switchId', "switch-#{Math.round(Math.random()*1000)}").on('init')
@@ -0,0 +1,13 @@
App.SelectMinuteOfDayView = Ember.View.extend
templateName: "form_elements/select_minute_of_day"
classNameBindings: ['rounded:round']
hours_list: [0..24]
minutes_list: [0..60]
hour: Ember.computed 'value', (a,b,c)->
if arguments.length > 1
@set 'value', 60*b + (@get('minute') || 0)
Math.floor (@get('value') || 0)/60
minute: Ember.computed 'value', (a,b,c)->
if arguments.length > 1
@set 'value', 60*(@get('hour')||0) + b
Math.floor @get('value')%60
@@ -5,12 +5,19 @@
helpers: <%= I18n.t('helpers', locale: :en).to_json %>
pagination: <%= I18n.t('views.pagination', locale: :en).to_json %>
errors: <%= I18n.t('errors', locale: :en).to_json %>
date: <%= {day_name: Hash[%w[sunday monday tuesday wednesday thursday friday saturday].zip(I18n.t('date.day_names', locale: :en))]}.to_json %>
nl:
models: <%= I18n.t('activemodel.models', locale: :nl).to_json %>
attributes: <%= I18n.t('activemodel.attributes', locale: :nl).to_json %>
helpers: <%= I18n.t('helpers', locale: :nl).to_json %>
pagination: <%= I18n.t('views.pagination', locale: :nl).to_json %>
errors: <%= I18n.t('errors', locale: :nl).to_json %>
date: <%= {day_name: Hash[%w[sunday monday tuesday wednesday thursday friday saturday].zip(I18n.t('date.day_names', locale: :nl))]}.to_json %>
@day_minutes_to_time = (minutes)->
return "" unless minutes
[("0" + Math.floor(minutes/60)).substr(-2,2), ("0" + Math.floor(minutes%60)).substr(-2,2)].join(":")
@ttry = (path, vars={})->
@t(path, $.extend(vars, emptyWhenNotFound: true))
@@ -13,5 +13,4 @@
@import ./qsections
@import ./section_tab_headers
@import ./qlists
@import ./qmodal
@import ./ember_dropdown
@@ -7,6 +7,8 @@
+grid-column($columns:4, $offset:1)
@media #{$large-up}
+grid-column(3)
&.half
+grid-column(6)
.form-field
@media #{$small-only}
+grid-column($columns:10, $center:true, $last-column:true)
@@ -21,6 +23,8 @@
+grid-column($columns:6, $last-column:true)
@media #{$large-up}
+grid-column($columns: 9, $last-column:true)
&.half
+grid-column(6)
&.form-actions
padding-top: 12px
body
@@ -1,6 +1,6 @@
.modal
margin: 10px auto
width: 500px
width: 600px
background-color: #fff
padding: 1em
.modal-alert
@@ -12,7 +12,7 @@
position: fixed
top: 0
left: 0
background-color: rgba(0, 0, 0, 0.2)
background-color: rgba(0, 0, 0, 0.5)
.flush--top
margin-top: 0
@@ -0,0 +1,29 @@
.product_category-header
border-top: 1px solid #ccc
border-bottom: 1px solid #ccc
.move
@extend .fa
// @extend .fa-lg
@extend .fa-arrows
.title
font-weight: bold
font-size: 1.3em
.availability
font-size: 0.8em
padding-left: 1em
padding-right: 1em
.day-names
color: #444
.time-range
color: rgb(39, 6, 121)
.edit-product-category-button
@extend .fa
@extend .fa-lg
@extend .fa-edit
.product_category-move-row
.availability
font-size: 0.8em
.day-names
color: #444
.time-range
color: rgb(39, 6, 121)
@@ -92,7 +92,7 @@ module Suppliers
respond_to do |format|
if @product_category.update_attributes(product_category_params)
format.html { redirect_to [:suppliers, :product_categories], notice: t('action.update.successfull', model: ProductCategory.model_name.human) }
format.json { head :no_content }
format.json { render json: @product_category }
else
format.html { render action: "edit" }
format.json { render json: @product_category.errors, status: :unprocessable_entity }
@@ -124,7 +124,9 @@ module Suppliers
private
def product_category_params
params.require(:product_category).permit(:name, :start_from, :end_on, :full_day, product_ids: [], week_days: [])
params.require(:product_category).permit(:name, :start_from, :end_on, :full_day, :position,
:active_on_sunday, :active_on_monday, :active_on_tuesday, :active_on_wednesday, :active_on_thursday, :active_on_friday, :active_on_saturday,
product_ids: [])
end
end
end
+7
View File
@@ -8,6 +8,13 @@ class ProductCategory
property :full_day, type: :boolean, default: true
property :start_from, type: Fixnum, default: 1320 # 22:00
property :end_on, type: Fixnum, default: 1380 # 23:00
property :active_on_sunday, type: :boolean, default: true
property :active_on_monday, type: :boolean, default: true
property :active_on_tuesday, type: :boolean, default: true
property :active_on_wednesday, type: :boolean, default: true
property :active_on_thursday, type: :boolean, default: true
property :active_on_friday, type: :boolean, default: true
property :active_on_saturday, type: :boolean, default: true
belongs_to :supplier
has_and_belongs_to_many :products, storing_keys: true
+1 -4
View File
@@ -18,6 +18,7 @@ class Supplier
property :city
property :country, default: 'Netherlands'
property :facebook_promotion_url
property :week_starts_on_monday, type: :boolean, default: true
#LOCATION
property :lat, type: Float #, default: 52.08062426379751
@@ -148,10 +149,6 @@ class Supplier
SupplierMailer.creation(self).deliver_now
end
def week_starts_on_monday?
true
end
private
def add_section_on_create
@@ -1,5 +1,7 @@
class ProductCategorySerializer < Qwaiter::Serializer
embed :ids, include: true
attributes :name
attributes :name, :supplier_id, :active_on_sunday, :active_on_monday, :active_on_tuesday, :active_on_wednesday,
:active_on_thursday, :active_on_friday, :active_on_saturday, :full_day, :start_from, :end_on,
:position
has_many :products
end
@@ -1,7 +1,7 @@
class SupplierSupplierSerializer < Qwaiter::Serializer
self.root = :supplier
attributes :extended_version, :open, :name, :lat, :lng, :email, :time_zone, :address, :house_number, :house_number_addition, :postal_code, :city, :country,
:facebook_promotion_url, :iens_profile
:facebook_promotion_url, :iens_profile, :week_starts_on_monday
def extended_version
false
+1 -1
View File
@@ -12,7 +12,7 @@ Qwaiter::Application.configure do
# Show full error reports and disable caching
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
config.action_controller.action_on_unpermitted_parameters = :raise
config.action_controller.action_on_unpermitted_parameters = :log
config.ember.variant = :development
+1 -1
View File
@@ -24,7 +24,7 @@ Qwaiter::Application.configure do
# Show full error reports and disable caching
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
config.action_controller.action_on_unpermitted_parameters = :raise
config.action_controller.action_on_unpermitted_parameters = :log
# Raise exceptions instead of rendering exception templates
config.action_dispatch.show_exceptions = false
+14
View File
@@ -120,6 +120,7 @@ en:
title: Reviews
explanation: Fill in your Iens id. You can find this id in the web location of your page
product_category:
# week days depricated
week_days:
abbreviation:
sunday: S
@@ -129,6 +130,19 @@ en:
thursday: T
friday: F
saturday: S
edit:
modal:
title: Edit ${models.product_category}
body_header: ''
active_between:
top: Active between
middle: and
move:
modal:
title: Move ${models.product_category|downcase}
body_header: ''
move_to_top: Move to top
move_below_label: "Place below ${product_category|downcase}"
product:
new: 'New ${model.product|downcase}'
preview:
+13
View File
@@ -128,6 +128,19 @@ nl:
thursday: D
friday: V
saturday: Z
edit:
modal:
title: Bewerk ${models.product_category}
body_header: ''
active_between:
top: Actief tussen
middle: en
move:
modal:
title: Verplaats ${models.product_category|downcase}
body_header: ''
move_to_top: Plaats bovenaan
move_below_label: "Plaats onder ${product_category|downcase}"
product:
new: 'Nieuw ${model.product|downcase}'
preview:
File diff suppressed because it is too large Load Diff
+5291 -4194
View File
File diff suppressed because it is too large Load Diff
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long