Fixed issue #1952 - New ticket attributes is also show for customers (which should not).

This commit is contained in:
Martin Edenhofer 2018-04-14 09:49:44 +02:00
parent 221c8a0538
commit 6b2e43baef
5 changed files with 207 additions and 5 deletions

View file

@ -443,6 +443,8 @@ class App.ControllerForm extends App.Controller
if item.type is 'boolean'
if value is ''
value = undefined
else if value is undefined
value = false
else if value is 'true'
value = true
else if value is 'false'
@ -463,21 +465,31 @@ class App.ControllerForm extends App.Controller
# verify if we have not checked checkboxes
uncheckParam = {}
lookupForm.find('input[type=checkbox]').each( (index) ->
type = $(@).data('field-type')
checked = $(@).attr('checked')
name = $(@).attr('name')
if name && !checked && (!(name of param) || param[name] is '')
if !(name of uncheckParam)
uncheckParam[name] = undefined
if type is 'boolean'
uncheckParam[name] = false
else
uncheckParam[name] = undefined
else
uncheckParam[name] = []
true
)
# verify if we have not checked radios
lookupForm.find('input[type=radio]').each( (index) ->
type = $(@).data('field-type')
checked = $(@).attr('checked')
name = $(@).attr('name')
if name && !checked && !(name of param)
uncheckParam[name] = undefined
if type is 'boolean'
uncheckParam[name] = false
else
uncheckParam[name] = undefined
true
)
# apply empty checkboxes & radio values to params

View file

@ -134,6 +134,17 @@ class App.UiElement.object_manager_attribute extends App.UiElement.ApplicationUi
init = false
if params && !params.id
init = true
data = objects[object]
if init
for role, screenOptions of data
for screen, options of screenOptions
for key, defaultValue of options
params.screens ||= {}
params.screens[screen] ||= {}
params.screens[screen][role] ||= {}
params.screens[screen][role][key] = defaultValue
item = $(App.view('object_manager/screens')(
attribute: attribute
data: objects[object]

View file

@ -237,8 +237,8 @@ set new attributes of model (remove already available attributes)
attributesNew = {}
if screen
for attribute in attributes
if attribute && attribute.screen && attribute.screen[ screen ] && !_.isEmpty(attribute.screen[ screen ])
for item, value of attribute.screen[ screen ]
if attribute && attribute.screen && attribute.screen[screen] && (!_.isEmpty(attribute.screen[screen]) && (attribute.screen[screen].shown is true || attribute.screen[screen].shown is undefined))
for item, value of attribute.screen[screen]
attribute[item] = value
attributesNew[ attribute.name ] = attribute

View file

@ -20,7 +20,7 @@
<%= screen %>
<td class="settings-list-row-control">
<% for key, defaultValue of options: %>
<%- @T(key) %>: <input class="js-boolean" name="screens::<%= screen %>::<%= role %>::<%= key %>" type="checkbox" <% if (@init && defaultValue is true) || (@params && @params.screens && @params.screens[screen] && @params.screens[screen][role] && @params.screens[screen][role][key] is true) : %>checked<% end %> value="true">
<%- @T(key) %>: <input class="js-boolean" name="screens::<%= screen %>::<%= role %>::<%= key %>" type="checkbox" <% if @params && @params.screens && @params.screens[screen] && @params.screens[screen][role] && @params.screens[screen][role][key] is true: %>checked<% end %> value="true">
<% end %>
<% end %>
<% end %>

View file

@ -26,6 +26,8 @@ test("form elements check", function() {
datetime1: Date.parse('2015-01-11T12:40:00Z'),
checkbox1: [],
checkbox2: '1',
boolean1: true,
boolean2: false,
}
new App.ControllerForm({
el: el,
@ -49,6 +51,9 @@ test("form elements check", function() {
{ name: 'datetime2', display: 'Datetime2', tag: 'datetime', null: false, default: defaults['datetime2'] },
{ name: 'checkbox1', display: 'Checkbox1', tag: 'checkbox', null: false, default: defaults['checkbox1'], options: { a: 'AA', b: 'BB' } },
{ name: 'checkbox2', display: 'Checkbox2', tag: 'checkbox', null: false, default: defaults['checkbox2'], options: { 1: '11' } },
{ name: 'boolean1', display: 'Boolean1', tag: 'boolean', null: false, default: defaults['boolean1'] },
{ name: 'boolean2', display: 'Boolean2', tag: 'boolean', null: false, default: defaults['boolean2'] },
{ name: 'boolean3', display: 'Boolean3', tag: 'boolean', null: false, default: defaults['boolean3'] },
]
},
autofocus: true
@ -108,6 +113,9 @@ test("form elements check", function() {
equal(el.find('[name="checkbox1"]').last().is(":checked"), false)
equal(el.find('[name="checkbox2"]').is(":checked"), true)
equal(el.find('[name="boolean1"]').val(), 'true')
equal(el.find('[name="boolean1"]').val(), 'true')
equal(el.find('[name="boolean2"]').val(), 'false')
});
test("form params check", function() {
@ -147,6 +155,8 @@ test("form params check", function() {
checkbox3: 'd',
radiobox1: undefined,
radiobox2: 'a',
boolean1: true,
boolean2: false,
}
new App.ControllerForm({
el: el,
@ -192,6 +202,9 @@ test("form params check", function() {
{ name: 'checkbox4', display: 'Checkbox4', tag: 'checkbox', null: false, default: defaults['checkbox4'], options: { aa: 'AA', bb: 'BB' } },
{ name: 'radiobox1', display: 'Radiobox1', tag: 'radio', null: false, default: defaults['radiobox1'], options: { a: 'AA', b: 'BB' } },
{ name: 'radiobox2', display: 'Radiobox2', tag: 'radio', null: false, default: defaults['radiobox2'], options: { a: '11' } },
{ name: 'boolean1', display: 'Boolean1', tag: 'boolean', null: false, default: defaults['boolean1'] },
{ name: 'boolean2', display: 'Boolean2', tag: 'boolean', null: false, default: defaults['boolean2'] },
{ name: 'boolean3', display: 'Boolean3', tag: 'boolean', null: false, default: defaults['boolean3'] },
],
},
params: defaults,
@ -296,6 +309,9 @@ test("form params check", function() {
checkbox4: [],
radiobox1: undefined,
radiobox2: 'a',
boolean1: true,
boolean2: false,
boolean3: true,
}
deepEqual(params, test_params, 'form param check')
@ -995,5 +1011,168 @@ test("form params check direct", function() {
//console.log('params', params)
//console.log('test_params', test_params)
deepEqual(params, test_params, 'form param check')
});
test("object manager form 1", function() {
$('#forms').append('<hr><h1>object manager 1</h1><form id="form11"></form>')
var el = $('#form11')
var defaults = {}
new App.ControllerForm({
el: el,
model: {
configure_attributes: [
{ name: 'data_type', display: 'Format', tag: 'object_manager_attribute', null: false },
],
},
params: $.extend(defaults, { object: 'Ticket' }),
autofocus: true
});
var params = App.ControllerForm.params(el)
var test_params = {
data_option: {
default: "",
maxlength: 120,
type: "text"
},
data_type: "input",
screens: {
create_middle: {
"ticket.agent": {
shown: true,
required: false,
},
"ticket.customer": {
shown: true,
required: false,
}
},
edit: {
"ticket.agent": {
shown: true,
required: false,
},
"ticket.customer": {
shown: true,
required: false,
}
}
}
}
deepEqual(params, test_params, 'form param check')
el.find('[name=data_type]').val('datetime').trigger('change')
params = App.ControllerForm.params(el)
var test_params = {
data_option: {
diff: 24,
future: true,
past: true
},
data_type: "datetime",
screens: {
create_middle: {
"ticket.agent": {
shown: true,
required: false,
},
"ticket.customer": {
shown: true,
required: false,
}
},
edit: {
"ticket.agent": {
shown: true,
required: false,
},
"ticket.customer": {
shown: true,
required: false,
}
}
}
}
deepEqual(params, test_params, 'form param check')
});
test("object manager form 2", function() {
$('#forms').append('<hr><h1>object manager 2</h1><form id="form12"></form>')
var el = $('#form12')
var defaults = {
id: 123,
data_option: {
default: "",
maxlength: 120,
type: "text"
},
data_type: "input",
screens: {
create_middle: {
"ticket.agent": {
shown: true,
required: false,
},
},
edit: {
"ticket.agent": {
shown: true,
required: false,
},
}
}
}
new App.ControllerForm({
el: el,
model: {
configure_attributes: [
{ name: 'data_type', display: 'Format', tag: 'object_manager_attribute', null: false },
],
},
params: $.extend(defaults, { object: 'Ticket' }),
autofocus: true
});
var params = App.ControllerForm.params(el)
var test_params = {
data_option: {
default: "",
maxlength: 120,
type: "text"
},
data_type: "input",
screens: {
create_middle: {
"ticket.agent": {
shown: true,
required: false,
},
"ticket.customer": {
shown: false,
required: false,
}
},
edit: {
"ticket.agent": {
shown: true,
required: false,
},
"ticket.customer": {
shown: false,
required: false,
}
}
}
}
deepEqual(params, test_params, 'form param check')
});