From cc01a4e133565c2dfce6576ad11e2314c1bcc574 Mon Sep 17 00:00:00 2001 From: Benjamin ter Kuile Date: Wed, 12 Aug 2015 17:37:47 +0200 Subject: [PATCH] Better global list for user --- .../application_controller.js.coffee | 41 ++++++++++--------- .../routes/application_route.js.coffee.erb | 6 +-- .../app/templates/global/_side_menu.emblem | 6 +-- app/mailers/notifier.rb | 2 +- 4 files changed, 28 insertions(+), 27 deletions(-) diff --git a/app/assets/javascripts/user/app/controllers/application_controller.js.coffee b/app/assets/javascripts/user/app/controllers/application_controller.js.coffee index 7fa0c9d4..7d72da8b 100644 --- a/app/assets/javascripts/user/app/controllers/application_controller.js.coffee +++ b/app/assets/javascripts/user/app/controllers/application_controller.js.coffee @@ -1,5 +1,6 @@ App.ApplicationController = Ember.Controller.extend needs: ['product_orders'] + #list: Ember.computed.alias 'globals.list' #notice: '' actions: confirmCancel: -> @@ -10,7 +11,7 @@ App.ApplicationController = Ember.Controller.extend @set 'globals.notice', '' showSupplierStatusInfo: -> @modal 'supplier_status_info', - model: @get('list.supplier') + model: @get('globals.list.supplier') title_path: 'supplier_status_info.title' openDebugger: -> @@ -21,14 +22,14 @@ App.ApplicationController = Ember.Controller.extend ).observes('currentPath') events: notify: (notification) -> @set 'globals.notice', notification.message - list_helped: -> @set 'list.needs_help', false - list_needs_help: -> @set 'list.needs_help', true # incoming from other users - list_is_paid: -> @set 'list.needs_payment', false - list_needs_payment: -> @set 'list.needs_payment', true # incoming from other users + list_helped: -> @set 'globals.list.needs_help', false + list_needs_help: -> @set 'globals.list.needs_help', true # incoming from other users + list_is_paid: -> @set 'globals.list.needs_payment', false + list_needs_payment: -> @set 'globals.list.needs_payment', true # incoming from other users list_closed: (data)-> @transitionToRoute('list', data.id).then => - @set 'list.state', 'closed' - @set 'list', null + @set 'globals.list.state', 'closed' + @set 'globals.list', null join_request_approved: (data)-> @setCurrentList -> @transitionToRoute('active_list') order_being_processed: (data)-> @@ -38,22 +39,22 @@ App.ApplicationController = Ember.Controller.extend order = @store.all('order').findBy 'id', data.id order.set('state', 'delivered') if order user_join_request: (data)-> - list = @store.all('list').findBy 'id', data.join_request.list_id + list = @store.peekRecord('list', data.join_request.list_id) user_data = data.users[0] - user = @store.all('user').findBy 'id', user_data.id + user = @store.peekRecord('user', user_data.id) user = @store.createRecord 'user', user_data unless user data.join_request.list = list data.join_request.user = user join_request = @store.createRecord 'join_request', data.join_request @transitionToRoute 'join_requests' order_cancelled: (data)-> - if order = @store.all('order').findBy('id', data.id) + if order = @store.peekRecord('order', data.id) order.markCancelled() @events.orders_placed_count.call(@, count: data.supplier_orders_placed_count) if data.supplier_orders_placed_count == 0 or data.supplier_orders_placed_count @events.orders_in_process_count.call(@, count: data.supplier_orders_in_process_count) if data.supplier_orders_in_process_count == 0 or data.supplier_orders_in_process_count join_request_rejected: (data)-> # Remove join request from connected users - join_request = @store.all('join_request').findBy 'id', data.id + join_request = @store.peekRecord('join_request', data.id) join_request.eraseRecord() if join_request # Notify requestor in a proper manner @@ -64,7 +65,7 @@ App.ApplicationController = Ember.Controller.extend @set 'globals.join_request_sent', false join_request_approved: -> - return if @get('list.id') + return if @get('globals.list.id') # Not interested when there is an active list @setCurrentList -> @transitionToRoute('active_list').then => @set 'globals.notice', t('join_request.requestor.join_request_approved') @@ -73,9 +74,9 @@ App.ApplicationController = Ember.Controller.extend list_changed_table: -> @setCurrentList() orders_in_process_count: (data)-> - @set 'list.supplier.orders_in_process_count', data.count + @set 'globals.list.supplier.orders_in_process_count', data.count orders_placed_count: (data)-> - @set 'list.supplier.orders_placed_count', data.count + @set 'globals.list.supplier.orders_placed_count', data.count new_order: (data)-> # return if @store.all('order').findProperty('id', data.order.id) @store.pushPayload data @@ -86,7 +87,7 @@ App.ApplicationController = Ember.Controller.extend remove_list_needs_payment: (data)-> - if list = @store.all('list').findBy 'id', data.id + if list = @store.peekRecord('list', data.id) list.set 'needs_payment', false setCurrentList: (callback)-> success = (list)=> @@ -94,10 +95,10 @@ App.ApplicationController = Ember.Controller.extend # 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') + if error_list = @store.peekRecord('list', 'current') error_list.eraseRecord() #TODO: depricate list on application controller - @set 'list', list + #@set 'list', list @set 'globals.list', list if list.get('join_requests.length') @transitionToRoute 'join_requests' @@ -108,11 +109,11 @@ App.ApplicationController = Ember.Controller.extend # if jqXHR.status == 404 officially, now assume close list on error #@redirect_to 'index', message: 'the_list_has_been_closed' #console.log "Error: #{emberError.message}" if emberError.message - if error_list = @store.all('list').findBy('id', 'current') + if error_list = @store.peekRecord('list', 'current') error_list.eraseRecord() - @set 'list', null + @set 'globals.list', null switch @currentRouteName when 'table' then # nothing else @redirect_to 'user_root' - @store.find('list', 'current').then(success, error) + @store.findRecord('list', 'current').then(success, error) diff --git a/app/assets/javascripts/user/app/routes/application_route.js.coffee.erb b/app/assets/javascripts/user/app/routes/application_route.js.coffee.erb index 7ef70a39..df9b85b9 100644 --- a/app/assets/javascripts/user/app/routes/application_route.js.coffee.erb +++ b/app/assets/javascripts/user/app/routes/application_route.js.coffee.erb @@ -13,7 +13,7 @@ App.ApplicationRoute = Ember.Route.extend unauthorized: -> Qstorage.removeItem('auth_token') Qstorage.removeItem('user_id') - @controllerFor('application').set 'list', null + @set 'globals.list', null #@send 'obtain_token' @controllerFor('application').redirect_to 'sign_in', message: 'unauthorized' @@ -76,13 +76,13 @@ App.ApplicationRoute = Ember.Route.extend listNeedsPayment: -> @get('controller').secured -> - @set 'list.needs_payment', true + @set 'globals.list.needs_payment', true Ember.$.post "#{$data_host}/user/list_needs_payment.json" #Ember.$.post("#{$data_host}/user/list_needs_payment.json").then (res) => #@set('list.needs_payment', true) # also done by faye listNeedsHelp: -> @get('controller').secured -> - @set 'list.needs_help', true + @set 'globals.list.needs_help', true Ember.$.post "#{$data_host}/user/needs_help.json" #Ember.$.post("#{$data_host}/user/needs_help.json").then (res) => #@set('list.needs_help', true) # also done by faye diff --git a/app/assets/javascripts/user/app/templates/global/_side_menu.emblem b/app/assets/javascripts/user/app/templates/global/_side_menu.emblem index 971da8bb..380234f6 100644 --- a/app/assets/javascripts/user/app/templates/global/_side_menu.emblem +++ b/app/assets/javascripts/user/app/templates/global/_side_menu.emblem @@ -9,9 +9,9 @@ a{action "scanQr" bubbles=false} span.scan-qr-icon span Scan QR - if list.id + if globals.list.id li - =link-to 'table' list.table.id class="side-menu-list-products" + =link-to 'table' globals.list.table.id class="side-menu-list-products" span.fa.fa-cutlery span.fa.fa-glass = t 'list_products.title' @@ -19,7 +19,7 @@ =link-to 'active_list' class="side-menu-active-list" span.active-list-icon span= t 'active_list.title' - if list.join_requests + if globals.list.join_requests li =link-to 'join_requests' span= t 'models.plural.join_request' diff --git a/app/mailers/notifier.rb b/app/mailers/notifier.rb index 8b85f573..ce15c9b5 100644 --- a/app/mailers/notifier.rb +++ b/app/mailers/notifier.rb @@ -5,6 +5,6 @@ class Notifier < ActionMailer::Base def contact_form(contact_form_id) @contact_form = Cmtool::ContactForm.find(contact_form_id) I18n.locale = :en - mail to: "contact-form@mozo.bar", subject: "[CONTACTFORM] new entry" + mail to: "bterkuile+mozo-contact-form@gmail.com", subject: "[CONTACTFORM] new entry" end end