make ControllerModal use @content instead of @el

so that we can use elements and events (spine's own event binding that takes care that we don't create accidental memory leaks)
This commit is contained in:
Felix Niklas 2014-10-29 20:43:35 +01:00
parent 239cfa3e6c
commit 6324e3c2a5
8 changed files with 54 additions and 47 deletions

View file

@ -441,6 +441,17 @@ class App.ControllerContent extends App.Controller
@navShow() @navShow()
class App.ControllerModal extends App.Controller class App.ControllerModal extends App.Controller
elements:
'.modal-body': 'body'
events:
'submit form': 'onSubmit'
'click .js-submit:not(.is-disabled)': 'onSubmit'
'click .js-cancel': 'hide'
'click .js-close': 'hide'
className: 'modal fade zIndex-9'
constructor: (options = {}) -> constructor: (options = {}) ->
defaults = defaults =
backdrop: true backdrop: true
@ -448,23 +459,20 @@ class App.ControllerModal extends App.Controller
close: true close: true
head: '?' head: '?'
buttonClass: 'btn--success' buttonClass: 'btn--success'
centerButtons: []
options = _.extend( defaults, options ) options = _.extend( defaults, options )
# do not use @el, because it's inserted by js
delete options.el
super(options) super(options)
if @shown if @shown
@show() @show()
show: -> show: (content) ->
if @button is true if @button is true
@button = 'Submit' @button = 'Submit'
@modalElement = $( '<div class="modal fade"></div>' ) @html App.view('modal')
@modalElement.append $( App.view('modal')(
head: @head head: @head
message: @message message: @message
detail: @detail detail: @detail
@ -472,41 +480,42 @@ class App.ControllerModal extends App.Controller
cancel: @cancel cancel: @cancel
button: @button button: @button
buttonClass: @buttonClass buttonClass: @buttonClass
) ) centerButtons:@centerButtons
if @el && !@message && !@detail content: content
@modalElement.find('.modal-body').html @el
@modalElement.find('form').on('submit', (e) => @onSubmit(e) ) if @content
@modalElement.find('.js-submit').on('click', (e) => @onSubmit(e) ) @body.html @content
@modalElement.find('.js-cancel').on('click', (e) => @hide(e) )
@modalElement.find('.js-close').on('click', (e) => @hide(e) )
@modalElement.modal( @el.modal
keyboard: @keyboard keyboard: @keyboard
show: true show: true
backdrop: @backdrop backdrop: @backdrop
).on('show.bs.modal', => .on
@onShow() 'show.bs.modal': @onShow
).on('hidden.bs.modal', => 'shown.bs.modal': @onShown
'hidden.bs.modal': =>
@onHide() @onHide()
# remove modal from dom # remove modal from dom
$('.modal').remove() $('.modal').remove()
).find('.js-close').bind('submit', (e) => @hide(e) )
hide: (e) -> hide: (e) =>
if e if e
e.preventDefault() e.preventDefault()
@modalElement.modal('hide') @el.modal('hide')
onShown: ->
console.log('modal shown: do nothing')
# do nothing
onShow: -> onShow: ->
console.log('no nothing') console.log('modal rendered: do nothing')
# do nothing # do nothing
onHide: -> onHide: ->
console.log('no nothing') console.log('modal removed: do nothing')
# do nothing # do nothing
onSubmit: (e) -> onSubmit: (e) =>
e.preventDefault() e.preventDefault()
@log 'error', 'You need to implement your own "onSubmit" method!' @log 'error', 'You need to implement your own "onSubmit" method!'

View file

@ -91,7 +91,7 @@ class App.ChannelEmailFilterEdit extends App.ControllerModal
autofocus: true, autofocus: true,
) )
@el = @form.form @content = @form.form
@show() @show()
onSubmit: (e) => onSubmit: (e) =>
@ -180,7 +180,7 @@ class App.ChannelEmailAddressEdit extends App.ControllerModal
autofocus: true, autofocus: true,
) )
@el = @form.form @content = @form.form
@show() @show()
@ -266,7 +266,7 @@ class App.ChannelEmailSignatureEdit extends App.ControllerModal
autofocus: true autofocus: true
) )
@el = @form.form @content = @form.form
@show() @show()
@ -353,7 +353,7 @@ class App.ChannelEmailInboundEdit extends App.ControllerModal
autofocus: true autofocus: true
) )
@el = @form.form @content = @form.form
@show() @show()

View file

@ -26,7 +26,7 @@ class App.TicketMerge extends App.ControllerModal
render: -> render: ->
@html App.view('agent_ticket_merge')() @content = $ App.view('agent_ticket_merge')()
list = [] list = []
for ticket_id in @ticket_ids_by_customer for ticket_id in @ticket_ids_by_customer
@ -34,7 +34,7 @@ class App.TicketMerge extends App.ControllerModal
ticketItem = App.Ticket.fullLocal( ticket_id ) ticketItem = App.Ticket.fullLocal( ticket_id )
list.push ticketItem list.push ticketItem
new App.ControllerTable( new App.ControllerTable(
el: @el.find('#ticket-merge-customer-tickets'), el: @content.find('#ticket-merge-customer-tickets'),
overview: [ 'number', 'title', 'state', 'group', 'created_at' ] overview: [ 'number', 'title', 'state', 'group', 'created_at' ]
model: App.Ticket, model: App.Ticket,
objects: list, objects: list,
@ -47,18 +47,18 @@ class App.TicketMerge extends App.ControllerModal
ticketItem = App.Ticket.fullLocal( ticket_id ) ticketItem = App.Ticket.fullLocal( ticket_id )
list.push ticketItem list.push ticketItem
new App.ControllerTable( new App.ControllerTable(
el: @el.find('#ticket-merge-recent-tickets'), el: @content.find('#ticket-merge-recent-tickets'),
overview: [ 'number', 'title', 'state', 'group', 'created_at' ] overview: [ 'number', 'title', 'state', 'group', 'created_at' ]
model: App.Ticket, model: App.Ticket,
objects: list, objects: list,
radio: true, radio: true,
) )
@el.delegate('[name="master_ticket_number"]', 'focus', (e) -> @content.delegate('[name="master_ticket_number"]', 'focus', (e) ->
$(e.target).parents().find('[name="radio"]').prop( 'checked', false ) $(e.target).parents().find('[name="radio"]').prop( 'checked', false )
) )
@el.delegate('[name="radio"]', 'click', (e) -> @content.delegate('[name="radio"]', 'click', (e) ->
if $(e.target).prop('checked') if $(e.target).prop('checked')
ticket_id = $(e.target).val() ticket_id = $(e.target).val()
ticket = App.Ticket.fullLocal( ticket_id ) ticket = App.Ticket.fullLocal( ticket_id )

View file

@ -398,7 +398,7 @@ class ModalForm extends App.ControllerModal
model: App.User model: App.User
autofocus: true autofocus: true
) )
@el = controller.form @content = controller.form
@show() @show()
@ -421,9 +421,7 @@ class ModalText extends App.ControllerModal
@render() @render()
render: -> render: ->
@html App.view('layout_ref/content')() @show( App.view('layout_ref/content')() )
@show()
onHide: => onHide: =>
window.history.back() window.history.back()

View file

@ -17,7 +17,7 @@ class App.TicketCustomer extends App.ControllerModal
autofocus: true autofocus: true
) )
@el = controller.form @content = controller.form
@show() @show()

View file

@ -639,7 +639,7 @@ class App.OverviewSettings extends App.ControllerModal
model: { configure_attributes: @configure_attributes_article } model: { configure_attributes: @configure_attributes_article }
autofocus: false autofocus: false
) )
@el = controller.form @content = controller.form
@show() @show()
onSubmit: (e) => onSubmit: (e) =>

View file

@ -116,7 +116,7 @@ class App.LinkAdd extends App.ControllerModal
render: -> render: ->
@html App.view('link/add')( @content = $ App.view('link/add')(
link_object: @link_object, link_object: @link_object,
link_object_id: @link_object_id, link_object_id: @link_object_id,
object: @object, object: @object,
@ -128,7 +128,7 @@ class App.LinkAdd extends App.ControllerModal
ticketItem = App.Ticket.fullLocal( ticket_id ) ticketItem = App.Ticket.fullLocal( ticket_id )
list.push ticketItem list.push ticketItem
new App.ControllerTable( new App.ControllerTable(
el: @el.find('#ticket-merge-customer-tickets'), el: @content.find('#ticket-merge-customer-tickets'),
overview: [ 'number', 'title', 'state', 'group', 'created_at' ] overview: [ 'number', 'title', 'state', 'group', 'created_at' ]
model: App.Ticket, model: App.Ticket,
objects: list, objects: list,
@ -141,18 +141,18 @@ class App.LinkAdd extends App.ControllerModal
ticketItem = App.Ticket.fullLocal( ticket_id ) ticketItem = App.Ticket.fullLocal( ticket_id )
list.push ticketItem list.push ticketItem
new App.ControllerTable( new App.ControllerTable(
el: @el.find('#ticket-merge-recent-tickets'), el: @content.find('#ticket-merge-recent-tickets'),
overview: [ 'number', 'title', 'state', 'group', 'created_at' ] overview: [ 'number', 'title', 'state', 'group', 'created_at' ]
model: App.Ticket, model: App.Ticket,
objects: list, objects: list,
radio: true, radio: true,
) )
@el.delegate('[name="ticket_number"]', 'focus', (e) -> @content.delegate('[name="ticket_number"]', 'focus', (e) ->
$(e.target).parents().find('[name="radio"]').prop( 'checked', false ) $(e.target).parents().find('[name="radio"]').prop( 'checked', false )
) )
@el.delegate('[name="radio"]', 'click', (e) -> @content.delegate('[name="radio"]', 'click', (e) ->
if $(e.target).prop('checked') if $(e.target).prop('checked')
ticket_id = $(e.target).val() ticket_id = $(e.target).val()
ticket = App.Ticket.fullLocal( ticket_id ) ticket = App.Ticket.fullLocal( ticket_id )

View file

@ -282,7 +282,7 @@ class UserNew extends App.ControllerModal
autofocus: true autofocus: true
) )
@el = controller.form @content = controller.form
@show() @show()