refactor out old modal structure in favor of the new namespaced one

This commit is contained in:
2015-01-13 12:34:42 +01:00
parent b614eeeaef
commit 6d6b95d9c0
20 changed files with 126 additions and 61 deletions
@@ -1,7 +1,12 @@
@App = Ember.Application.create @App = Ember.Application.create
LOG_TRANSITIONS: true LOG_TRANSITIONS: true
rootElement: '#ember-app-container' rootElement: '#ember-app-container'
App.deferReadiness() App.deferReadiness()
@App.modals = Ember.Namespace.create()
@Modals = @App.modals
Ember.$.ajaxPrefilter (options) -> Ember.$.ajaxPrefilter (options) ->
if options.type.toUpperCase() == 'GET' if options.type.toUpperCase() == 'GET'
if auth_token = Qstorage.getItem('auth_token') if auth_token = Qstorage.getItem('auth_token')
@@ -9,6 +9,10 @@ App.ApplicationController = Ember.Controller.extend
$('#confirm-modal').hide() $('#confirm-modal').hide()
clearNotice: -> clearNotice: ->
@set 'notice', null @set 'notice', null
showSupplierStatusInfo: ->
@modal 'supplier_status_info',
model: @get('list.supplier')
openDebugger: -> openDebugger: ->
debugger debugger
@@ -1,8 +0,0 @@
App.ModalConfirmController = Ember.ObjectController.extend
actions:
close: ->
@get('model.cancel').call(@) if @get('model.cancel')
@send 'closeModal'
confirm: ->
@get('model.ok').call(@)
@send 'closeModal'
@@ -1,4 +0,0 @@
App.ModalController = Ember.ObjectController.extend
actions:
close: ->
@send 'closeModal'
@@ -1,5 +0,0 @@
App.ModalInfoController = Ember.ObjectController.extend
actions:
close: ->
@get('model.cancel').call(@) if @get('model.cancel')
@send 'closeModal'
@@ -1,5 +0,0 @@
App.ModalProductInfoController = Ember.ObjectController.extend
actions:
close: ->
@get('model.cancel').call(@) if @get('model.cancel')
@send 'closeModal'
@@ -0,0 +1,46 @@
@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
translation_params = {}
if model = @get('model')
translation_params = model.serialize() if model.serialize
return new Ember.Handlebars.SafeString(tspan(@title_path, translation_params)) if @title_path
# return translated title_path if directly set by options
return new Ember.Handlebars.SafeString(tspan(@get('modal_options.title_path'), translation_params)) 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()`
# find translated title or humanize the controller name
if convention_translation = ttry("modal.#{underscored}.title", translation_params)
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')
close.apply(@)
@send 'closeModal' unless @preventClose
closeOnOverlay: ->
@send('close') if @get('modal_options.closeOnOverlay')
false
modalClick: ->
@send('close') if @get('modal_options.closeOnModalClick')
false
ok: ->
if ok = @get('modal_options.ok')
ok.apply(@)
@send 'closeModal' unless @preventClose
confirm: -> @send('ok')
save: ->
@get('model').save()
@send 'closeModal' unless @preventClose
destroy: ->
@modal 'confirm',
title_path: @get('modal_options.destroy_text_path') || 'general.destroy.text'
model: @get('model')
ok: ->
@get('model').destroyRecord()
@send 'closeModal' unless @preventClose
@@ -28,4 +28,4 @@ App.TableController = Ember.ObjectController.extend
toggleProductCategory: (product_category)-> toggleProductCategory: (product_category)->
product_category.set 'collapsed', not product_category.get('collapsed') product_category.set 'collapsed', not product_category.get('collapsed')
showProductDescription: (product)-> showProductDescription: (product)->
@send 'openModal', 'modal_product_info', product @modal 'product_info', model: product, title: product.get('name')
@@ -12,6 +12,9 @@ ControllerExtensions = Ember.Mixin.create
unless Qstorage.getItem('auth_token') unless Qstorage.getItem('auth_token')
return @transitionToRoute 'sign_in' return @transitionToRoute 'sign_in'
callback.call(@) if callback callback.call(@) if callback
modal: (name, options={})->
options.model ||= Ember.Object.create()
@send "openModal", name, options
Ember.ArrayController.reopen ControllerExtensions Ember.ArrayController.reopen ControllerExtensions
Ember.Controller.reopen ControllerExtensions Ember.Controller.reopen ControllerExtensions
Ember.ObjectController.reopen ControllerExtensions Ember.ObjectController.reopen ControllerExtensions
@@ -35,19 +35,41 @@ App.ApplicationRoute = Ember.Route.extend
@handleAuthInfo(user_id, auth_token) @handleAuthInfo(user_id, auth_token)
auth_win.close() auth_win.close()
true true
openModal: (modalName, model)-> #openModal: (modalName, model)->
@controllerFor(modalName).set('model', model) # @controllerFor(modalName).set('model', model)
@render modalName, # @render modalName,
# into: 'application'
# outlet: 'modal'
#closeModal: ->
# @disconnectOutlet
# outlet: 'modal'
# parentView: 'application'
openModal: (modalName, options={})->
controller_name = options.controller || modalName
try
controller = @controllerFor("modals/#{modalName}")
catch error
controller = @controllerFor("modals/base")
controller.set 'model', options.model
defaultModalOptions =
closeOnOverlay: true
closeOnModalClick: false
controller.set 'modal_options', $.extend(defaultModalOptions, options)
@render "modals/#{modalName}",
into: 'application' into: 'application'
outlet: 'modal' outlet: 'modal'
view: 'modal'
controller: controller
closeModal: -> closeModal: ->
@disconnectOutlet @disconnectOutlet
outlet: 'modal' outlet: 'modal'
parentView: 'application' parentView: 'application'
confirm: (options = {})-> confirm: (options = {})->
@send 'openModal', 'modal_confirm', Ember.Object.create @send 'openModal', 'confirm',
model: Ember.Object.create(body: options.body)
title: options.title title: options.title
body: options.body
cancel: options.cancel cancel: options.cancel
ok: options.ok ok: options.ok
sendFeedback: (feedback, callback)-> sendFeedback: (feedback, callback)->
@@ -15,7 +15,7 @@
= view "menu-item-scan-qr" = view "menu-item-scan-qr"
= view "menu-item-product-orders" = view "menu-item-product-orders"
if list if list
.extra-info .extra-info{action "showSupplierStatusInfo"}
.supplier-info-row .supplier-info-row
/ .supplier-name= list.supplier.name / .supplier-name= list.supplier.name
.table-number .table-number
@@ -1,4 +0,0 @@
modal-dialog action="close"
h3.flush--top Alert
p= body
button{action "close"} Done
@@ -1,6 +0,0 @@
modal-dialog action="close"
h3.flush--top= title
p=body
hr
button.confirm-cancel{action "close"}= t 'confirm.cancel'
button.confirm-ok.right{action "confirm"}= t 'confirm.confirm'
@@ -1,5 +0,0 @@
modal-dialog action="close"
h3.flush--top= title
p==body
hr
button{action "close"}= t 'modal.info.close'
@@ -1,7 +0,0 @@
modal-dialog action="close"
h3.flush--top= name
if image
.right: img src=image.small alt=""
p==description
hr
button{action "close"}= t 'modal.info.close'
@@ -0,0 +1,4 @@
p=body
hr
button.modal-close{action "close"}= t 'confirm.cancel'
button.modal-confirm.right{action "confirm"}= t 'confirm.confirm'
@@ -0,0 +1,8 @@
.overlay{action "closeOnOverlay"}
.modal{action "modalClick" bubbles=false preventDefault=false}
.modal-header
h3.flush--top= title
hr
.modal-body
.modal-alert== alert_message
= yield
@@ -0,0 +1,5 @@
if image
.right: img src=image.small alt=""
p==description
hr
button{action "close"}= t 'modal.info.close'
@@ -1,10 +1,13 @@
#App.ModalView = Ember.View.extend App.ModalView = Ember.View.extend
#templateName: "modal" layoutName: 'modals/layout'
#title: "" didInsertElement: ->
#classNames: ["reveal-modal"], sortable = $('.sortable')
#didInsertElement: -> controller = @get('controller')
##this.$().foundation('reveal', 'open') if sortable.length
#actions: sortable.sortable
#close: -> update: (e, ui)->
#console.log('close action fired') ids = sortable.find('.sortable-item-container').map((i, el) -> $(el).data('sortableId')).toArray()
#this.destroy() if callback = controller.sortableUpdate
callback.call(controller, ids)
@@ -0,0 +1,9 @@
Feature: A signed in uses sees supplier info in the top right corner
@javascript
Scenario: Clicking on the table number opens the supplier info popup
Given there is a confirmed and open supplier
And there is a facebook user
And the user has an active order
When the user clicks on the table number info in the top right corner
Then the user sees the supplier information popup