refactor out old modal structure in favor of the new namespaced one
This commit is contained in:
@@ -1,7 +1,12 @@
|
||||
@App = Ember.Application.create
|
||||
LOG_TRANSITIONS: true
|
||||
rootElement: '#ember-app-container'
|
||||
|
||||
App.deferReadiness()
|
||||
|
||||
@App.modals = Ember.Namespace.create()
|
||||
@Modals = @App.modals
|
||||
|
||||
Ember.$.ajaxPrefilter (options) ->
|
||||
if options.type.toUpperCase() == 'GET'
|
||||
if auth_token = Qstorage.getItem('auth_token')
|
||||
|
||||
@@ -9,6 +9,10 @@ App.ApplicationController = Ember.Controller.extend
|
||||
$('#confirm-modal').hide()
|
||||
clearNotice: ->
|
||||
@set 'notice', null
|
||||
showSupplierStatusInfo: ->
|
||||
@modal 'supplier_status_info',
|
||||
model: @get('list.supplier')
|
||||
|
||||
openDebugger: ->
|
||||
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)->
|
||||
product_category.set 'collapsed', not product_category.get('collapsed')
|
||||
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')
|
||||
return @transitionToRoute 'sign_in'
|
||||
callback.call(@) if callback
|
||||
modal: (name, options={})->
|
||||
options.model ||= Ember.Object.create()
|
||||
@send "openModal", name, options
|
||||
Ember.ArrayController.reopen ControllerExtensions
|
||||
Ember.Controller.reopen ControllerExtensions
|
||||
Ember.ObjectController.reopen ControllerExtensions
|
||||
|
||||
@@ -35,19 +35,41 @@ App.ApplicationRoute = Ember.Route.extend
|
||||
@handleAuthInfo(user_id, auth_token)
|
||||
auth_win.close()
|
||||
true
|
||||
openModal: (modalName, model)->
|
||||
@controllerFor(modalName).set('model', model)
|
||||
@render modalName,
|
||||
#openModal: (modalName, model)->
|
||||
# @controllerFor(modalName).set('model', model)
|
||||
# @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'
|
||||
outlet: 'modal'
|
||||
view: 'modal'
|
||||
controller: controller
|
||||
|
||||
closeModal: ->
|
||||
@disconnectOutlet
|
||||
outlet: 'modal'
|
||||
parentView: 'application'
|
||||
|
||||
confirm: (options = {})->
|
||||
@send 'openModal', 'modal_confirm', Ember.Object.create
|
||||
@send 'openModal', 'confirm',
|
||||
model: Ember.Object.create(body: options.body)
|
||||
title: options.title
|
||||
body: options.body
|
||||
cancel: options.cancel
|
||||
ok: options.ok
|
||||
sendFeedback: (feedback, callback)->
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
= view "menu-item-scan-qr"
|
||||
= view "menu-item-product-orders"
|
||||
if list
|
||||
.extra-info
|
||||
.extra-info{action "showSupplierStatusInfo"}
|
||||
.supplier-info-row
|
||||
/ .supplier-name= list.supplier.name
|
||||
.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
|
||||
#templateName: "modal"
|
||||
#title: ""
|
||||
#classNames: ["reveal-modal"],
|
||||
#didInsertElement: ->
|
||||
##this.$().foundation('reveal', 'open')
|
||||
#actions:
|
||||
#close: ->
|
||||
#console.log('close action fired')
|
||||
#this.destroy()
|
||||
App.ModalView = Ember.View.extend
|
||||
layoutName: 'modals/layout'
|
||||
didInsertElement: ->
|
||||
sortable = $('.sortable')
|
||||
controller = @get('controller')
|
||||
if sortable.length
|
||||
sortable.sortable
|
||||
update: (e, ui)->
|
||||
ids = sortable.find('.sortable-item-container').map((i, el) -> $(el).data('sortableId')).toArray()
|
||||
if callback = controller.sortableUpdate
|
||||
callback.call(controller, ids)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user