Fixed tests.

This commit is contained in:
Martin Edenhofer 2014-10-14 23:24:33 +02:00
parent 2690a885f7
commit a153681ea1
2 changed files with 31 additions and 27 deletions

View file

@ -320,18 +320,19 @@ class App.ControllerForm extends App.Controller
# remove on click # remove on click
itemInput.find('.remove').bind('click', (e) -> itemInput.find('.remove').bind('click', (e) ->
e.preventDefault() e.preventDefault()
key = $(e.target).parent().find('select, input').attr('name') key = $(e.target).closest('.form-group').find('select, input').attr('name')
return if !key return if !key
$(e.target).parent().parent().parent().find('.addSelection select option[value="' + key + '"]').show() $(e.target).closest('.controls').find('.addSelection select option[value="' + key + '"]').show()
$(e.target).parent().parent().parent().find('.addSelection select option[value="' + key + '"]').prop('disabled', false) $(e.target).closest('.controls').find('.addSelection select option[value="' + key + '"]').prop('disabled', false)
$(e.target).parent().parent().parent().find('.list [name="' + key + '"]').parent().parent().remove() $(e.target).closest('.form-group').remove()
) )
# add new item # add new item
el.parent().parent().parent().find('.list').append(itemInput) control = el.closest('.postmaster_match')
el.parent().parent().parent().find('.addSelection select').val('') control.find('.list').append(itemInput)
el.parent().parent().parent().find('.addSelection select option[value="' + key + '"]').prop('disabled', true) control.find('.addSelection select').val('')
el.parent().parent().parent().find('.addSelection select option[value="' + key + '"]').hide() control.find('.addSelection select option[value="' + key + '"]').prop('disabled', true)
control.find('.addSelection select option[value="' + key + '"]').hide()
# scaffold of match elements # scaffold of match elements
item = $(' item = $('
@ -470,8 +471,8 @@ class App.ControllerForm extends App.Controller
# bind add click # bind add click
item.find('.add').bind('click', (e) -> item.find('.add').bind('click', (e) ->
e.preventDefault() e.preventDefault()
name = $(@).parent().parent().find('.addSelection').find('select').val() name = $(@).closest('.controls').find('.addSelection').find('select').val()
displayName = $(@).parent().parent().find('.addSelection').find('select option:selected').html() displayName = $(@).closest('.controls').find('.addSelection').find('select option:selected').html()
return if !name return if !name
addItem( name, displayName, $(@) ) addItem( name, displayName, $(@) )
) )
@ -503,18 +504,19 @@ class App.ControllerForm extends App.Controller
# remove on click # remove on click
itemInput.find('.remove').bind('click', (e) -> itemInput.find('.remove').bind('click', (e) ->
e.preventDefault() e.preventDefault()
key = $(e.target).parent().find('select, input').attr('name') key = $(e.target).closest('.form-group').find('select, input').attr('name')
return if !key return if !key
$(e.target).parent().parent().parent().find('.addSelection select option[value="' + key + '"]').show() $(e.target).closest('.controls').find('.addSelection select option[value="' + key + '"]').show()
$(e.target).parent().parent().parent().find('.addSelection select option[value="' + key + '"]').prop('disabled', false) $(e.target).closest('.controls').find('.addSelection select option[value="' + key + '"]').prop('disabled', false)
$(e.target).parent().parent().parent().find('.list [name="' + key + '"]').parent().parent().remove() $(e.target).closest('.form-group').remove()
) )
# add new item # add new item
el.parent().parent().parent().find('.list').append(itemInput) control = el.closest('.perform_set')
el.parent().parent().parent().find('.addSelection select').val('') control.find('.list').append(itemInput)
el.parent().parent().parent().find('.addSelection select option[value="' + key + '"]').prop('disabled', true) control.find('.addSelection select').val('')
el.parent().parent().parent().find('.addSelection select option[value="' + key + '"]').hide() control.find('.addSelection select option[value="' + key + '"]').prop('disabled', true)
control.find('.addSelection select option[value="' + key + '"]').hide()
# scaffold of perform elements # scaffold of perform elements
item = $(' item = $('
@ -592,8 +594,8 @@ class App.ControllerForm extends App.Controller
item.find('.add').bind('click', (e) -> item.find('.add').bind('click', (e) ->
e.preventDefault() e.preventDefault()
name = $(@).parent().parent().find('.addSelection').find('select').val() name = $(@).closest('.controls').find('.addSelection').find('select').val()
displayName = $(@).parent().parent().find('.addSelection').find('select option:selected').html() displayName = $(@).closest('.controls').find('.addSelection').find('select option:selected').html()
return if !name return if !name
addItem( name, displayName, $(@) ) addItem( name, displayName, $(@) )
) )
@ -1400,6 +1402,8 @@ class App.ControllerForm extends App.Controller
do (action, attribute) -> do (action, attribute) ->
item.bind('change', -> item.bind('change', ->
value = $(@).val() value = $(@).val()
if !value
value = $(@).find('select, input').val()
# lookup relation if needed # lookup relation if needed
if action.bind.relation if action.bind.relation
@ -1440,14 +1444,14 @@ class App.ControllerForm extends App.Controller
if !_.isArray(name) if !_.isArray(name)
name = [name] name = [name]
for key in name for key in name
el.find('[name="' + key + '"]').parents('.form-group').removeClass('hide') el.find('[name="' + key + '"]').closest('.form-group').removeClass('hide')
el.find('[name="' + key + '"]').removeClass('is-hidden') el.find('[name="' + key + '"]').removeClass('is-hidden')
_hide: (name, el = @el) -> _hide: (name, el = @el) ->
if !_.isArray(name) if !_.isArray(name)
name = [name] name = [name]
for key in name for key in name
el.find('[name="' + key + '"]').parents('.form-group').addClass('hide') el.find('[name="' + key + '"]').closest('.form-group').addClass('hide')
el.find('[name="' + key + '"]').addClass('is-hidden') el.find('[name="' + key + '"]').addClass('is-hidden')
_mandantory: (name, el = @el) -> _mandantory: (name, el = @el) ->
@ -1797,9 +1801,9 @@ class App.ControllerForm extends App.Controller
else if form.find('form').is('form') is true else if form.find('form').is('form') is true
#console.log('child from') #console.log('child from')
return form.find('form') return form.find('form')
else if $(form).parents('form').is('form') is true else if $(form).closest('form').is('form') is true
#console.log('parent from') #console.log('closest from')
return form.parents('form') return form.closest('form')
# use current content as form if form isn't already finished # use current content as form if form isn't already finished
else if !@finishForm else if !@finishForm
#console.log('finishForm') #console.log('finishForm')

View file

@ -440,8 +440,8 @@ test( "form postmaster filter", function() {
}, },
}; };
deepEqual( params, test_params, 'form param check' ); deepEqual( params, test_params, 'form param check' );
el.find('[name="set::x-zammad-ticket-priority_id"]').parent().next().click() el.find('[name="set::x-zammad-ticket-priority_id"]').closest('.form-group').find('.remove').click()
el.find('[name="set::x-zammad-ticket-customer"]').parent().next().click() el.find('[name="set::x-zammad-ticket-customer"]').closest('.form-group').find('.remove').click()
App.Delay.set( function() { App.Delay.set( function() {
test( "form param check after remove click", function() { test( "form param check after remove click", function() {
params = App.ControllerForm.params( el ) params = App.ControllerForm.params( el )