Make "dependent nullable" work in JS on bug form

hinted-selects
Vitaliy Filippov 2014-06-24 16:13:54 +04:00
parent 8d9b13decd
commit 79711e2cbd
4 changed files with 47 additions and 33 deletions

View File

@ -1343,10 +1343,13 @@ sub json_visibility
nullable => $self->nullable ? 1 : 0,
fields => {},
values => {},
null => {},
};
my $hash = Bugzilla->fieldvaluecontrol_hash->{$self->id};
$data->{fields} = { map { Bugzilla->get_field($_)->name => $hash->{fields}->{$_} } keys %{$hash->{fields}} };
$data->{values} = { map { Bugzilla->get_field($_)->name => $hash->{values}->{$_} } keys %{$hash->{values}} };
for my $key (qw(fields values null))
{
$data->{$key} = { map { Bugzilla->get_field($_)->name => $hash->{$key}->{$_} } keys %{$hash->{$key}} };
}
return $data;
}

View File

@ -60,12 +60,7 @@ addListener(window, 'load', initQueryformFields);
}
elsif ($args->{type} eq 'bug')
{
my $json = {};
for (Bugzilla->get_fields({ is_select => 1, obsolete => 0 }))
{
$json->{$_->name} = $_->json_visibility;
}
$json = bz_encode_json($json);
my $json = bz_encode_json(Bugzilla->full_json_visibility);
print "var show_fields_cached = '$user_tag-".time."';
var show_fields = $json;
addListener(window, 'load', initControlledFields);

View File

@ -114,6 +114,24 @@ function handleControllerField_this(e)
return handleControllerField(e, this);
}
function checkValueVisibility(selected, visible)
{
var vis = true;
if (visible)
{
for (var value in visible)
{
vis = false;
if (selected[value])
{
vis = true;
break;
}
}
}
return vis;
}
// Turn on/off fields and values controlled by 'controller' argument
function handleControllerField(e, controller)
{
@ -122,15 +140,7 @@ function handleControllerField(e, controller)
// Show/hide fields
for (var controlled_id in show_fields[controller.id]['fields'])
{
vis = false;
for (var value in show_fields[controller.id]['fields'][controlled_id])
{
if (opt[value])
{
vis = true;
break;
}
}
vis = checkValueVisibility(opt, show_fields[controller.id]['fields'][controlled_id]);
for (var i in { row: 1, container: 1, label: 1 })
{
field_container = document.getElementById('field_' + i + '_' + controlled_id);
@ -152,27 +162,14 @@ function handleControllerField(e, controller)
controlled = document.getElementById(controlled_id);
copt = getSelectedNames(controlled);
bz_clearOptions(controlled);
if (show_fields[controlled.id]['nullable'] && !controlled.multiple)
if (show_fields[controlled.id].nullable && !controlled.multiple)
{
bz_createOptionInSelect(controlled, '---', '');
}
for (var i in show_fields[controlled.id]['legal'])
{
controlled_value = show_fields[controlled.id]['legal'][i];
vis = true;
item = show_fields[controller.id]['values'][controlled_id][controlled_value[0]];
if (item)
{
for (var value in item)
{
vis = false;
if (opt[value])
{
vis = true;
break;
}
}
}
vis = checkValueVisibility(opt, show_fields[controller.id]['values'][controlled_id][controlled_value[0]]);
if (vis)
{
item = bz_createOptionInSelect(controlled, controlled_value[1], controlled_value[1]);
@ -184,4 +181,23 @@ function handleControllerField(e, controller)
}
}
}
// Enable/disable NULL in single-select fields
for (var controlled_id in show_fields[controller.id]['null'])
{
controlled = document.getElementById(controlled_id);
if (controlled && !controlled.multiple && show_fields[controlled.id] && show_fields[controlled.id].nullable)
{
vis = checkValueVisibility(opt, show_fields[controller.id]['null'][controlled_id]);
item = controlled.options[0].value == '';
if (vis && !item)
{
item = new Option('---', '');
controlled.insertBefore(item, controlled.options[0]);
}
else if (!vis && item)
{
controlled.removeChild(controlled.options[0]);
}
}
}
}

View File

@ -154,7 +154,7 @@
[% dontchange | html %]
</option>
[% END %]
[% IF field.type == constants.FIELD_TYPE_SINGLE_SELECT && field.nullable %]
[% IF field.type == constants.FIELD_TYPE_SINGLE_SELECT && field.check_is_nullable(bug) %]
<option value="">---</option>
[% END %]
[% IF override_legal_values %]