User app updates
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
Ember.Handlebars.helper 'time', (time, params..., options = {})->
|
||||
return '' unless time
|
||||
iso = time.toISOString()
|
||||
tag = if options.bare then iso else $("<span data-time=\"#{iso}\"></span>").text(moment(iso).format(options.format || 'dd D MMM HH:MM')).get(0).outerHTML
|
||||
new Handlebars.SafeString tag
|
||||
+7
-5
@@ -58,15 +58,17 @@ function setTranslations(selector){
|
||||
var list = $('#top-navigation-list');
|
||||
list.find('.locale').show();
|
||||
list.find('.locale-'+$locale).hide();
|
||||
moment.lang($locale);
|
||||
if(selector){
|
||||
$(selector).find('[data-t]').each(function(){$(this).html(t($(this).data('t'), $(this).data('tAttributes')))})
|
||||
$(selector).find('*[data-time]').each(function(){
|
||||
$(this).text(moment($(this).data('time')).format($(this).data('timeFormat') || 'dd D MMM HH:MM'))
|
||||
})
|
||||
}else{
|
||||
$('[data-t]').each(function(){$(this).html(t($(this).data('t'),$(this).data('tAttributes')))})
|
||||
$('*[data-time]').each(function(){
|
||||
$(this).text(moment($(this).data('time')).format($(this).data('timeFormat') || 'dd D MMM HH:MM'))
|
||||
})
|
||||
}
|
||||
moment.lang($locale);
|
||||
$('[data-time]').each(function(){
|
||||
$(this).text(moment($(this).data('time')).format($(this).data('timeFormat') || 'dd D MMM HH:MM'))
|
||||
})
|
||||
|
||||
$('.datepicker').datepicker("option", $.datepicker.regional[$locale])
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
|
||||
@$translations =
|
||||
en:
|
||||
models: <%= I18n.t('activemodel.models', locale: :en).to_json %>
|
||||
attributes: <%= I18n.t('activemodel.attributes', locale: :en).to_json %>
|
||||
helpers: <%= I18n.t('helpers', locale: :en).to_json %>
|
||||
pagination: <%= I18n.t('views.pagination', 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 %>
|
||||
@t = (path, vars={}) ->
|
||||
#result = undefined
|
||||
#m = undefined
|
||||
#translatable = undefined
|
||||
#isafety = undefined
|
||||
#replacable = undefined
|
||||
parts = path.split(".")
|
||||
#accessor = "$translations.#{$locale}[\"#{parts.join("\"][\"")}\"]"
|
||||
result = $translations[$locale]
|
||||
try
|
||||
result = result[part] for part in parts
|
||||
catch err
|
||||
result = parts[parts.length - 1].capitalize()
|
||||
return "" if result is ""
|
||||
return parts[parts.length - 1].capitalize() unless result
|
||||
|
||||
|
||||
# allow t('test', {var: 'Benjamin'}) statements
|
||||
# with $translations.nl.test = "Hello %{var}"
|
||||
for variable, value of vars
|
||||
result = result.replace("%{#{variable}}", value)
|
||||
|
||||
isafety = 0
|
||||
while result.indexOf("${") > -1
|
||||
m = result.match(/\${([\w\.]+(\|\w+)?)}/)
|
||||
if m[2]
|
||||
translatable = m[1].replace(m[2], "")
|
||||
operation = $transformation_mappings[m[2].substr(1) or m[2].substr(1)]
|
||||
else
|
||||
translatable = m[1]
|
||||
operation = null
|
||||
replacable = t(translatable)
|
||||
replacable = replacable[operation]() if operation
|
||||
result = result.replace(m[0], replacable)
|
||||
break if isafety > 10 # referencing other translations may cause infinite loops
|
||||
isafety += 1
|
||||
result
|
||||
|
||||
@setLocale = (locale, options={}) ->
|
||||
locale ||= Qstorage.getItem('locale') || options.default || 'en'
|
||||
Qstorage.setItem "locale", locale
|
||||
@$locale = locale
|
||||
setTranslations()
|
||||
|
||||
@setTranslations = (selector) ->
|
||||
list = $("#top-navigation-list")
|
||||
list.find(".locale").show()
|
||||
list.find(".locale-" + $locale).hide()
|
||||
moment.lang $locale
|
||||
if selector
|
||||
$(selector).find("[data-t]").each ->
|
||||
$(this).html t($(this).data("t"), $(this).data("tAttributes"))
|
||||
|
||||
$(selector).find("*[data-time]").each ->
|
||||
$(this).text moment($(this).data("time")).format($(this).data("timeFormat") or "dd D MMM HH:MM")
|
||||
|
||||
else
|
||||
$("[data-t]").each ->
|
||||
$(this).html t($(this).data("t"), $(this).data("tAttributes"))
|
||||
|
||||
$("*[data-time]").each ->
|
||||
$(this).text moment($(this).data("time")).format($(this).data("timeFormat") or "dd D MMM HH:MM")
|
||||
|
||||
$(".datepicker").datepicker "option", $.datepicker.regional[$locale]
|
||||
|
||||
$transformation_mappings =
|
||||
downcase: "toLowerCase"
|
||||
upcase: "toUpperCase"
|
||||
@@ -1,6 +1,7 @@
|
||||
@App = Ember.Application.create
|
||||
LOG_TRANSITIONS: true
|
||||
rootElement: '#ember-app-container'
|
||||
|
||||
Ember.$.ajaxPrefilter (options) ->
|
||||
if options.type.toUpperCase() == 'GET'
|
||||
if auth_token = Qstorage.getItem('auth_token')
|
||||
@@ -13,6 +14,7 @@ Ember.$.ajaxPrefilter (options) ->
|
||||
options.data ||= {}
|
||||
options.data.auth_token = auth_token
|
||||
true
|
||||
|
||||
Ember.$.ajaxSetup
|
||||
error: (jqXHR, textStatus, errorThrown)->
|
||||
console.log "Error: #{textStatus}: #{errorThrown}"
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#= require shared-ember-helpers/all
|
||||
#= require_directory ./modifications
|
||||
#= require ./app
|
||||
#= require_directory ./modules
|
||||
#= require user/quser
|
||||
#= require_tree .
|
||||
@EmberENV = {FEATURES: {'query-params-new': true}}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
App.ActiveListController = Ember.ArrayController.extend
|
||||
orders: (->
|
||||
@get('list.orders')
|
||||
).property('list.orders')
|
||||
App.ActiveListController = Ember.ObjectController.extend
|
||||
#orders: (->
|
||||
#@get('list.orders')
|
||||
#).property('list.orders')
|
||||
|
||||
list: (->
|
||||
@get('controllers.application.list')
|
||||
).property('controllers.application.list')
|
||||
#list: (->
|
||||
#@get('controllers.application.list')
|
||||
#).property('controllers.application.list')
|
||||
|
||||
displayTotal: (-> @get('list.orders.length') and @get('list.orders.length') > 1 ).property('list.orders.length')
|
||||
displayTotal: (-> @get('model.orders.length') and @get('model.orders.length') > 1 ).property('model.orders.length')
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
App.ListController = Ember.ObjectController.extend {}
|
||||
@@ -0,0 +1,4 @@
|
||||
App.ListsIndexController = Ember.ArrayController.extend App.PaginationModule,
|
||||
actions:
|
||||
showList: (list)->
|
||||
@transitionToRoute 'list', list
|
||||
@@ -9,8 +9,12 @@ App.ProductOrdersController = Ember.ArrayController.extend
|
||||
orderProducts: ->
|
||||
order = @store.createRecord('order', list: @get('controllers.application.list'))
|
||||
new_product_orders = @store.all('product_order').filterProperty('order', null)
|
||||
new_product_orders.forEach (po) -> po.setOrder(order)
|
||||
order.save()
|
||||
order.get('product_orders').pushObjects(new_product_orders)
|
||||
order.save().then ->
|
||||
# The new versions will be returned in the json response
|
||||
#new_product_orders.invoke 'rollback'
|
||||
#new_product_orders.invoke 'transitionTo', 'loaded.saved'
|
||||
new_product_orders.invoke 'deleteRecord'
|
||||
@transitionToRoute 'active_list'
|
||||
|
||||
#orders = @store.all('product_order').toArray()
|
||||
|
||||
@@ -3,6 +3,14 @@ App.List = DS.Model.extend
|
||||
orders: DS.hasMany('order')
|
||||
needs_help: attr('boolean')
|
||||
needs_payment: attr('boolean')
|
||||
supplier_name: attr('string')
|
||||
price: attr('number')
|
||||
extended_version: attr('boolean')
|
||||
supplier_orders_in_process_count: attr('number')
|
||||
supplier_orders_placed_count: attr('number')
|
||||
total: (->
|
||||
@get('orders').getEach('total').reduce(((sum, total) -> sum + total), 0)
|
||||
).property('orders.@each.total')
|
||||
|
||||
is_extended_version: ->
|
||||
@get('extended_version')
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
App.PaginationModule = Ember.Mixin.create
|
||||
#modelClass: ->
|
||||
#@modelInfo.class
|
||||
modelNameForStore: ->
|
||||
#@modelInfo.store
|
||||
@get('content.type.typeKey')
|
||||
storeMetadata: (k) ->
|
||||
#res = @store.typeMapFor(@modelClass()).metadata
|
||||
res = @store.metadataFor @get('content.type.typeKey')
|
||||
res = res[k] if k
|
||||
res
|
||||
setStoreMetadata: (k,v) ->
|
||||
#res = @store.typeMapFor(@modelClass()).metadata
|
||||
res = @store.metadataFor @get('content.type.typeKey')
|
||||
res[k] = v
|
||||
|
||||
loadMore: ->
|
||||
page = @storeMetadata('page') + 1
|
||||
@setStoreMetadata('page',page)
|
||||
@store.findQuery(@modelNameForStore(),page: page)
|
||||
page
|
||||
|
||||
hasMoreFunc: ->
|
||||
page = @storeMetadata('page')
|
||||
total = @storeMetadata('total_pages')
|
||||
#unfiltered = @storeMetadata('unfiltered_total_pages')
|
||||
unfiltered = total
|
||||
|
||||
#console.debug "page #{page} total #{total} unfiltered #{unfiltered}"
|
||||
|
||||
!unfiltered || page < unfiltered
|
||||
actions:
|
||||
showMore: ->
|
||||
page = @loadMore()
|
||||
@set 'lastKnownPage', page
|
||||
|
||||
hasMore: (-> @hasMoreFunc()).property('lastKnownPage','firstObject','@each','filtered.@each')
|
||||
@@ -3,8 +3,6 @@
|
||||
App.Router.reopen
|
||||
#location: 'history'
|
||||
rootURL: '/user'
|
||||
activate: (a,b,c)->
|
||||
debugger
|
||||
|
||||
App.Router.map ->
|
||||
@route 'select_qrcode'
|
||||
@@ -12,3 +10,5 @@ App.Router.map ->
|
||||
@route 'active_list'
|
||||
@route 'list_products'
|
||||
@route 'list_products_for_table'
|
||||
@resource 'lists', ->
|
||||
@resource 'list', path: ':list_id'
|
||||
|
||||
@@ -1,3 +1 @@
|
||||
App.ActiveListRoute = Ember.Route.extend
|
||||
model: ->
|
||||
@controllerFor('application').get('list.orders')
|
||||
App.ActiveListRoute = Ember.Route.extend {}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
App.ApplicationRoute = Ember.Route.extend
|
||||
setupController: (controller)->
|
||||
#@controllerFor('product_orders').set 'model', @store.filter('product_order', (po)-> !po.get('order')) # does not work (yet)
|
||||
@controllerFor('product_orders').set 'model', @store.filter('product_order', (po)-> !po.get('placed'))
|
||||
@controllerFor('product_orders').set 'model', @store.filter('product_order', (po)-> !po.get('id'))
|
||||
controller.secured ->
|
||||
faye = new Faye.Client(event_host)
|
||||
user_id = Qstorage.getItem('user_id')
|
||||
@@ -9,7 +9,16 @@ App.ApplicationRoute = Ember.Route.extend
|
||||
console.log e
|
||||
@events[e.event].call(@) if @events[e.event]
|
||||
@store.find('list', 'current').then (list)=>
|
||||
#@store.find('list', 'current').deleteRecord() # gets not replaced, buty stays as dummy
|
||||
|
||||
# A list record with id current and with the content of the returned list is created
|
||||
# at the moment remove the dummy list, this should be resolved by Ember eventually
|
||||
if error_list = @store.all('list').findBy('id', 'current')
|
||||
error_list.rollback()
|
||||
error_list.transitionTo 'loaded.saved'
|
||||
error_list.unloadRecord()
|
||||
@set 'list', list
|
||||
@controllerFor('active_list').set('model', list)
|
||||
|
||||
unauthorized: ->
|
||||
Qstorage.setItem('auth_token', '')
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
App.ListRoute = Ember.Route.extend
|
||||
model: (options)->
|
||||
@store.find 'list', options.list_id
|
||||
afterModel: (model)->
|
||||
model.reload() unless model.is_extended_version()
|
||||
@@ -0,0 +1,5 @@
|
||||
App.ListsRoute = Ember.Route.extend
|
||||
model: ->
|
||||
@store.find 'list'
|
||||
setupController: (controller, model)->
|
||||
controller.set('alreadyLoaded', true)
|
||||
@@ -2,6 +2,32 @@
|
||||
DS.RESTAdapter.reopen
|
||||
namespace: 'user'
|
||||
|
||||
DS.ActiveModelSerializer.reopen
|
||||
serializeBelongsTo: (record, json, relationship) ->
|
||||
console.log "Serialize belongsTo #{record.toString()}"
|
||||
key = relationship.key
|
||||
belongsTo = Ember.get(record, key)
|
||||
key = (if @keyForRelationship then @keyForRelationship(key, "belongsTo") else key)
|
||||
if relationship.options.embedded is "always"
|
||||
json[key] = belongsTo.serialize()
|
||||
else
|
||||
@_super record, json, relationship
|
||||
|
||||
serializeHasMany: (record, json, relationship) ->
|
||||
console.log "Serialize hasMany #{record.toString()}"
|
||||
key = relationship.key
|
||||
hasMany = Ember.get(record, key)
|
||||
relationshipType = DS.RelationshipChange.determineRelationshipType(record.constructor, relationship)
|
||||
if relationship.options.embedded is "always"
|
||||
if hasMany and relationshipType is "manyToNone" or relationshipType is "manyToMany" or relationshipType is "manyToOne"
|
||||
json[key] = []
|
||||
hasMany.forEach (item, index) ->
|
||||
json[key].push item.serialize()
|
||||
else
|
||||
@_super record, json, relationship
|
||||
DS.Model.reopen
|
||||
created_at: DS.attr('date')
|
||||
updated_at: DS.attr('date')
|
||||
App.ApplicationSerializer = DS.ActiveModelSerializer
|
||||
App.CustomAdapter = DS.RESTAdapter.extend
|
||||
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
.row
|
||||
h2=t 'active_list.title'
|
||||
if list.orders
|
||||
if orders
|
||||
ul.active_list-orders
|
||||
each order in list.orders
|
||||
each order in orders
|
||||
li class=order.state
|
||||
= order.display
|
||||
span.currency= currency order.total
|
||||
if displayTotal
|
||||
li.total
|
||||
= t 'total'
|
||||
span.currency= currency list.total
|
||||
span.currency= currency model.total
|
||||
else
|
||||
p
|
||||
span=t 'active_list.no_orders_explanation'
|
||||
|
||||
@@ -31,6 +31,9 @@
|
||||
li
|
||||
=link-to 'active_list'
|
||||
span= t 'active_list.title'
|
||||
li
|
||||
=link-to 'lists'
|
||||
span= t 'models.plural.list'
|
||||
section.main-section
|
||||
if notice
|
||||
#notice.alert-box{action clearNotice} data-alert=true
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
.row
|
||||
h2=t 'models.list'
|
||||
p Hoi
|
||||
= controller
|
||||
if model.extended_version
|
||||
h3 Extended
|
||||
else
|
||||
h3 Not extended
|
||||
link-to 'lists'
|
||||
span Go to lists
|
||||
@@ -0,0 +1 @@
|
||||
= outlet
|
||||
@@ -0,0 +1,11 @@
|
||||
.row
|
||||
h2=t 'models.plural.list'
|
||||
each list in controller
|
||||
.lists-overview-entry{action showList list}
|
||||
span.created_at=time list.created_at
|
||||
span.price.currency= currency list.price
|
||||
span.name= list.supplier_name
|
||||
hr
|
||||
.clearfix
|
||||
if hasMore
|
||||
button{action showMore} Show more
|
||||
@@ -10,12 +10,15 @@
|
||||
#= require js-routes
|
||||
#= require_directory .
|
||||
#= require_self
|
||||
|
||||
(($) ->
|
||||
origAppend = $.fn.append
|
||||
$.fn.append = -> origAppend.apply(@, arguments).trigger("append")
|
||||
)(jQuery)
|
||||
@Qstorage = localStorage
|
||||
|
||||
$.extend($translations.en, <%= I18n.t('user', locale: :en).to_json %>);
|
||||
$.extend($translations.nl, <%= I18n.t('user', locale: :nl).to_json %>);
|
||||
$(document).foundation()
|
||||
setLocale('en')
|
||||
setLocale()
|
||||
$ ->
|
||||
$('.main-section').css 'min-height', ($(window).height() - $('.tab-bar:first').outerHeight())
|
||||
|
||||
Reference in New Issue
Block a user