Dynamic pages, language switcher and fix schedule drag drop time mismatch bug

This commit is contained in:
2015-02-21 15:05:45 +01:00
parent e60955130a
commit c8109c8ad6
29 changed files with 163 additions and 40 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 427 B

@@ -5,3 +5,29 @@
store: -> @__container__.lookup('controller:application').store
@App.modals = Ember.Namespace.create()
@Modals = @App.modals
Ember.$.ajaxPrefilter (options) ->
locale = $locale
app_version = 0
params =
locale: $locale
app_version: 0
if options.type.toUpperCase() == 'GET'
if options.data
options.data += "&#{$.param(params)}"
else
options.data = $.param(params)
if options.type.toUpperCase() == 'POST'
if options.data
if typeof(options.data) == 'string'
if options.data[0] == '{' || options.data[0] == '[' # json
object = JSON.parse(options.data)
$.extend object, params
options.data = JSON.stringify(object)
else
options.data += "&#{$.param(params)}"
else
options.data = params
else
options.data = $.param(params)
true
@@ -0,0 +1,7 @@
App.LanguageSwitcherComponent = Ember.Component.extend
classNames: ['language-switcher-container']
locales: (-> ['en', 'nl']).property()
actions:
switchTo: (locale)->
setLocale locale
@get('targetObject.store').all("page").invoke 'reload'
@@ -1,8 +1,8 @@
App.ScheduleController = Ember.ArrayController.extend
event_changed: (event)->
@store.find('employee-shift', event.id).then (employee_shift)->
employee_shift.set 'start_from', event.start.toDate()
employee_shift.set 'end_on', event.end.toDate()
employee_shift.set 'start_from', event.start
employee_shift.set 'end_on', event.end
employee_shift.save()
editEvent: (id, callbacks)->
if employee_shift = @store.all('employee-shift').findBy('id', id)
@@ -0,0 +1,2 @@
Ember.Handlebars.helper 'flag', (locale, options)->
"<img src=\"#{$assets_path}supplier/flags/flag-#{locale}.png\">".htmlSafe()
@@ -0,0 +1,4 @@
Ember.Handlebars.registerHelper 'page-body-helper', (resource, params..., options)->
body = @get resource
template = Ember.Handlebars.compile('body')
body.htmlSafe()
@@ -0,0 +1,4 @@
attr = DS.attr
App.Page = DS.Model.extend
title: attr 'string'
body: attr 'string'
@@ -14,6 +14,8 @@ App.Router.map ->
@resource 'list', path: ':list_id'
@resource 'employees', ->
@resource 'employee', path: ':employee_id'
@resource 'pages', ->
@resource 'page', path: ':page_id'
@route 'orders_display' # chromecast etc
@route 'menu'
@route 'settings'
@@ -0,0 +1,2 @@
each locale in locales
a.language-switch-button{ action "switchTo" locale}= flag locale
@@ -0,0 +1,4 @@
.row: .small-12.columns
h2=model.title
/= page-body model.body
view page-body templateBody=model.body
@@ -36,6 +36,7 @@ if editIensProfile
App.NumberField valueBinding="controller.model.iens_profile"
= image_tag 'supplier/settings/iens-example.png'
span=t "settings.reviews.explanation"
.row: .small-12.columns= language-switcher
.form-row.form-actions
if saving
button.button.submit-supplier-settings.disabled
@@ -0,0 +1,11 @@
App.PageBodyView = Ember.View.extend
setTemplate: (->
body = @get('templateBody')
body ||= ""
try
template = Ember.Handlebars.compile(body)
catch
template = Ember.Handlebars.compile(tspan('page.cannot_compile'))
@set 'template', template
@rerender()
).on('init').observes('templateBody')
@@ -25,6 +25,7 @@ String.prototype.capitalize = function() { return this.charAt(0).toUpperCase() +
window.time_zones = <%= ActiveSupport::TimeZone.all.map{|tz| {name: tz.name, formatted: "GMT#{tz.formatted_offset} #{tz.name}"}}.to_json.html_safe %>;
window.countries = <%= IsoCountryCodes.all.map{|cc| {name: cc.name}}.to_json.html_safe %>;
var path_mapping = {
user_root: '/user',
join_occupied_table: '/user/join_occupied_table',
@@ -1,21 +0,0 @@
class List
constructor: (@attributes)->
id: -> @attributes.id || @attributes._id
table_number: -> @attributes.table_number
total_amount: -> @attributes.total_amount
section_title: -> @attributes.section_title
needs_help: -> @attributes.needs_help
needs_payment: -> @attributes.needs_payment
active: -> @attributes.state == 'active'
table_id: -> @attributes.table_id
products: -> @attributes.products || []
has_active_orders: -> @attributes.has_active_orders
supplier_name: -> @attributes.supplier_name
created_at: -> @attributes.created_at
display: ->
txt = @supplier_name()
txt += ' - '
txt += Quser.format_date(@created_at())
txt
@List = List
@@ -1,17 +0,0 @@
class Order
constructor: (@attributes)->
table_number: -> @attributes.table_number
id: -> @attributes.id || @attributes._id
total_amount: -> @attributes.total_amount
section_title: -> @attributes.section_title
list_id: -> @attributes.list_id
state: -> @attributes.state
display: ->
order_txts = []
return '' unless @attributes.products
for product in @attributes.products
order_txts.push(product.name + ' (' + product.number + ')')
order_txts.join(', ')
can_process: -> @attributes.state == 'placed'
@Order = Order
@@ -0,0 +1,5 @@
.language-switcher-container
.language-switch-button
+button($bg: $secondary-color, $padding: $button-tny)
margin: 0
margin-right: 8px
@@ -0,0 +1,19 @@
module Suppliers
class PagesController < Suppliers::ApplicationController
prepend_before_action :find_page, only: [:show]
def index
@pages = Page.all_for_suppliers(locale: params[:locale])
render json: @pages, each_serializer: Suppliers::PageSerializer
end
def show
render json: @page, serializer: Suppliers::PageSerializer
end
private
def find_page
@page = Page.suppliers_page(params[:id], locale: params[:locale])
end
end
end
+18
View File
@@ -1,6 +1,24 @@
class Page
include Cmtool::Includes::Page
include ActiveModel::SerializerSupport
def self.layouts
%w[theme1 theme1-home]
end
def self.suppliers_page(name, locale: :en)
find_by_name_and_locale("suppliers-#{name}", locale) || NullPage.new(name, locale: locale)
end
class NullPage < NullModel
attr_reader :name, :locale, :title, :body
def initialize(name, locale: 'en')
@name = name
@locale = locale
@body = ::I18n.t('page.not_found', locale: locale)
end
def title
@title ||= name.to_s.humanize.gsub(/\W/, ' ')
end
end
end
@@ -0,0 +1,11 @@
class Suppliers::PageSerializer < Qwaiter::Serializer
self.root = :page
attributes :name, :title, :body, :locale, :position
def name
object.name.to_s.sub /^suppliers-/, ''
end
def id
name
end
end
+7
View File
@@ -0,0 +1,7 @@
NullModel = Naught.build do
include ActiveModel::SerializerSupport
def created_at
@created_at ||= Time.current
end
alias_method :updated_at, :created_at
end
@@ -4,6 +4,7 @@
var supplier_object=<%= {id: current_supplier.id}.to_json.html_safe %>;
var employee_object=<%=raw Suppliers::EmployeeSerializer.new(current_employee, root: false).to_json %>;
var data_host = '';
var $asset_path = '/assets/';
var event_host = '<%= Qwaiter.event_host %>';
//var datepicker_options = {dateFormat: 'yy-mm-dd', firstDay: <%= current_supplier.week_starts_on_monday? ? 1 : 0 %>};
</script>