Fixes #3320 - Problem with Adding new Rows in Tree-Select.
This commit is contained in:
parent
24d15d7bd4
commit
615c4b4c64
2 changed files with 86 additions and 4 deletions
|
@ -362,6 +362,20 @@ class App.UiElement.object_manager_attribute extends App.UiElement.ApplicationUi
|
|||
for subChild in child.children
|
||||
@buildRow(element, subChild, level + 1)
|
||||
|
||||
@findParent: (element, level, mode) ->
|
||||
parent = $(element).closest('tr')
|
||||
parent.nextAll().each(->
|
||||
if parseInt($(@).find('.js-key').attr('level')) > level && mode is 'first'
|
||||
parent = $(@)
|
||||
return true
|
||||
if parseInt($(@).find('.js-key').attr('level')) >= level && mode is 'last'
|
||||
parent = $(@)
|
||||
return true
|
||||
return false
|
||||
)
|
||||
|
||||
return parent
|
||||
|
||||
@tree_select: (item, localParams, params, attribute) ->
|
||||
params.data_option ||= {}
|
||||
params.data_option.options ||= []
|
||||
|
@ -374,16 +388,16 @@ class App.UiElement.object_manager_attribute extends App.UiElement.ApplicationUi
|
|||
item.on('click', '.js-addRow', (e) =>
|
||||
e.stopPropagation()
|
||||
e.preventDefault()
|
||||
addRow = $(e.currentTarget).closest('tr')
|
||||
level = parseInt(addRow.find('.js-key').attr('level'))
|
||||
level = parseInt($(e.currentTarget).closest('tr').find('.js-key').attr('level'))
|
||||
addRow = @findParent(e.currentTarget, level, 'first')
|
||||
@buildRow(item, {}, level, addRow)
|
||||
)
|
||||
|
||||
item.on('click', '.js-addChild', (e) =>
|
||||
e.stopPropagation()
|
||||
e.preventDefault()
|
||||
addRow = $(e.currentTarget).closest('tr')
|
||||
level = parseInt(addRow.find('.js-key').attr('level')) + 1
|
||||
level = parseInt($(e.currentTarget).closest('tr').find('.js-key').attr('level')) + 1
|
||||
addRow = @findParent(e.currentTarget, level, 'last')
|
||||
@buildRow(item, {}, level, addRow)
|
||||
)
|
||||
|
||||
|
|
68
spec/system/system/object_manager_spec.rb
Normal file
68
spec/system/system/object_manager_spec.rb
Normal file
|
@ -0,0 +1,68 @@
|
|||
require 'rails_helper'
|
||||
|
||||
# https://github.com/zammad/zammad/issues/266
|
||||
RSpec.describe 'Admin Panel > Objects', type: :system, authenticated_as: true do
|
||||
before do
|
||||
visit '/#system/object_manager'
|
||||
end
|
||||
|
||||
it 'verifies option creation order of new tree select options' do
|
||||
|
||||
# create new field
|
||||
page.find('.js-new').click
|
||||
|
||||
# set meta information
|
||||
fill_in 'Name', with: 'tree1'
|
||||
fill_in 'Display', with: 'tree1'
|
||||
page.find('select[name=data_type]').select('Tree Select')
|
||||
|
||||
# create 3 childs
|
||||
first_add_child = page.first('div.js-addChild')
|
||||
first_add_child.click
|
||||
first_add_child.click
|
||||
first_add_child.click
|
||||
|
||||
# create 1 top level node sibling
|
||||
page.first('div.js-addRow').click
|
||||
|
||||
# create 3 childs for the new top level node
|
||||
page.all('div.js-addChild').last.click
|
||||
page.all('div.js-addChild').last.click
|
||||
page.all('div.js-addChild').last.click
|
||||
|
||||
# create new top level nodes by first and second top level node
|
||||
add_rows = page.all('div.js-addRow')
|
||||
add_rows[0].click
|
||||
add_rows[4].click
|
||||
|
||||
# add numbers to all inputs to verify order in config later
|
||||
number = 1
|
||||
page.all('input.js-key').each do |input|
|
||||
input.send_keys(number)
|
||||
number += 1
|
||||
end
|
||||
|
||||
page.find('.js-submit').click
|
||||
expected_data_options = { 'options' =>
|
||||
[{ 'name' => '1',
|
||||
'value' => '1',
|
||||
'children' => [{ 'name' => '2', 'value' => '1::2' }, { 'name' => '3', 'value' => '1::3' }, { 'name' => '4', 'value' => '1::4' }] },
|
||||
{ 'name' => '5', 'value' => '5' },
|
||||
{ 'name' => '6',
|
||||
'value' => '6',
|
||||
'children' =>
|
||||
[{ 'name' => '7',
|
||||
'value' => '6::7',
|
||||
'children' => [{ 'name' => '8', 'value' => '6::7::8', 'children' => [{ 'name' => '9', 'value' => '6::7::8::9' }] }] }] },
|
||||
{ 'name' => '10', 'value' => '10' }],
|
||||
'default' => '',
|
||||
'null' => true,
|
||||
'relation' => '',
|
||||
'nulloption' => true,
|
||||
'maxlength' => 255 }
|
||||
|
||||
await_empty_ajax_queue
|
||||
|
||||
expect(ObjectManager::Attribute.last.data_option).to eq(expected_data_options)
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue