Bug 91153 - add interface for setting default values for custom fields
git-svn-id: svn://svn.office.custis.ru/3rdparty/bugzilla.org/trunk@1710 6955db30-a419-402b-8a0d-67ecbb4d7f56custis
parent
9fb33a2897
commit
e6b20d0ed1
|
@ -844,7 +844,8 @@ sub fieldvaluecontrol
|
|||
->{values}
|
||||
->{$_->{field_id}}
|
||||
->{$_->{value_id}}
|
||||
->{$_->{visibility_value_id}} = 1;
|
||||
->{$_->{visibility_value_id}}
|
||||
->{is_default} = $_->{is_default};
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -2134,7 +2134,7 @@ sub _check_select_field
|
|||
{
|
||||
$tmp->{$field->name} = $object;
|
||||
}
|
||||
return $value;
|
||||
return $object->name;
|
||||
}
|
||||
my $object = Bugzilla::Field::Choice->type($field)->check($value);
|
||||
return $object->name;
|
||||
|
|
|
@ -1227,7 +1227,7 @@ sub update_visibility_values
|
|||
|
||||
sub update_controlled_values
|
||||
{
|
||||
my ($controlled_field, $controlled_value_ids, $visibility_value_id) = @_;
|
||||
my ($controlled_field, $controlled_value_ids, $visibility_value_id, $default_value_ids) = @_;
|
||||
$controlled_value_ids ||= [];
|
||||
my $vis_field = $controlled_value_ids
|
||||
? $controlled_field->value_field
|
||||
|
@ -1250,9 +1250,14 @@ sub update_controlled_values
|
|||
{
|
||||
my $type = Bugzilla::Field::Choice->type($controlled_field);
|
||||
$controlled_value_ids = [ map { $_->id } @{ $type->new_from_list($controlled_value_ids) } ];
|
||||
if ($default_value_ids)
|
||||
{
|
||||
my $type = Bugzilla::Field::Choice->type($controlled_field);
|
||||
$default_value_ids = { map { $_->id => 1 } @{ $type->new_from_list($default_value_ids) } };
|
||||
}
|
||||
my $f = $controlled_field->id;
|
||||
my $sql = "INSERT INTO fieldvaluecontrol (field_id, visibility_value_id, value_id) VALUES ".
|
||||
join(",", map { "($f, $visibility_value_id, $_)" } @$controlled_value_ids);
|
||||
my $sql = "INSERT INTO fieldvaluecontrol (field_id, visibility_value_id, value_id, is_default) VALUES ".
|
||||
join(",", map { "($f, $visibility_value_id, $_, " . ($default_value_ids->{$_} ? '1' : '0') . ')' } @$controlled_value_ids);
|
||||
Bugzilla->dbh->do($sql);
|
||||
}
|
||||
# Touch the field
|
||||
|
|
|
@ -486,6 +486,14 @@ sub has_visibility_value
|
|||
return $hash->{$value};
|
||||
}
|
||||
|
||||
sub is_default_controlled_value
|
||||
{
|
||||
my $self = shift;
|
||||
my $result = $self->has_visibility_value(@_);
|
||||
return $result unless ref $result;
|
||||
return $result->{is_default};
|
||||
}
|
||||
|
||||
# Check visibility of field value for a bug
|
||||
sub check_visibility
|
||||
{
|
||||
|
|
|
@ -135,6 +135,7 @@ if ($action eq 'control_list') {
|
|||
my $step = $cgi->param('step') || 0;
|
||||
my $visibility_value_id = $cgi->param('visibility_value_id');
|
||||
my $values = [ $cgi->param('values') ];
|
||||
my $default_value_ids = [ $cgi->param('default_value_ids') ];
|
||||
my $need_token = 0;
|
||||
|
||||
$vars->{'visibility_value_id'} = -1;
|
||||
|
@ -146,8 +147,9 @@ if ($action eq 'control_list') {
|
|||
$need_token = 1;
|
||||
if ($token) {
|
||||
check_token_data($token, "edit_control_list");
|
||||
$field->update_controlled_values($values, $visibility_value_id);
|
||||
$field->update_controlled_values($values, $visibility_value_id, $default_value_ids);
|
||||
$step++;
|
||||
$need_token = 0;
|
||||
delete_token($token);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -76,6 +76,8 @@ sub db_schema_abstract_schema
|
|||
field_id => {TYPE => 'INT3', NOTNULL => 1},
|
||||
value_id => {TYPE => 'INT2', NOTNULL => 1},
|
||||
visibility_value_id => {TYPE => 'INT2', NOTNULL => 1},
|
||||
# Bug 91153 - Default'ные значения Custom полей
|
||||
is_default => {TYPE => 'BOOLEAN', NOTNULL => 1, DEFAULT => 0},
|
||||
],
|
||||
INDEXES => [
|
||||
fieldvaluecontrol_primary_idx =>
|
||||
|
@ -380,6 +382,9 @@ sub install_update_db
|
|||
}
|
||||
}
|
||||
|
||||
# Bug 91153 - Default'ные значения Custom полей
|
||||
$dbh->bz_add_column('fieldvaluecontrol', is_default => {TYPE => 'BOOLEAN', NOTNULL => 1, DEFAULT => 0});
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,49 @@ function initControlledField(i)
|
|||
{
|
||||
var f = document.getElementById(i);
|
||||
if (f)
|
||||
{
|
||||
if (document.forms['Create'])
|
||||
{
|
||||
var control_id = null;
|
||||
var controlled,copt;
|
||||
|
||||
for (var controlled_id in show_fields[f.id]['values'])
|
||||
{
|
||||
controlled = document.getElementById(controlled_id);
|
||||
if (!controlled)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (!control_id)
|
||||
{
|
||||
for (var i in show_fields[f.id]['legal'])
|
||||
{
|
||||
if (f.value == show_fields[f.id]['legal'][i][1])
|
||||
{
|
||||
control_id = show_fields[f.id]['legal'][i][0];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var vals = show_fields[f.id]['values'][controlled_id];
|
||||
for (var value_id in vals)
|
||||
{
|
||||
if (!vals[value_id][control_id])
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (vals[value_id][control_id].is_default == 1)
|
||||
{
|
||||
document.getElementById('v' + value_id + '_' + controlled_id).selected = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
addListener(f, 'change', handleControllerField_this);
|
||||
}
|
||||
}
|
||||
|
||||
function getSelectedIds(sel)
|
||||
|
|
|
@ -15,7 +15,8 @@
|
|||
<h3>Выбор активных [% field.description FILTER html %] для различных значений поля [% field.value_field.description FILTER html %]</h3>
|
||||
|
||||
<form action="editvalues.cgi?action=control_list&field=[% field.name FILTER html %][% '&visibility_value_id=' _ visibility_value_id IF visibility_value_id %]"
|
||||
method="[% IF step > 0 %]POST[% ELSE %]GET[% END %]">
|
||||
method="[% IF step > 0 %]POST[% ELSE %]GET[% END %]"
|
||||
name="setValuesForm">
|
||||
[% IF token %]<input type="hidden" name="token" value="[% token %]"/>[% END %]
|
||||
[% IF step == 0 %]
|
||||
<input type="hidden" name="action" value="control_list"/>
|
||||
|
@ -36,15 +37,32 @@
|
|||
<input type="hidden" name="step" value="[% step FILTER html %]"/>
|
||||
<input type="hidden" name="visibility_value_id" value="[% visibility_value_id FILTER html %]"/>
|
||||
<p>Значения <strong>[% field.description FILTER html %]</strong> для <strong>[% field_value.name FILTER html %]</strong>:</p>
|
||||
<div style="margin-left: 1em">
|
||||
[% FOREACH value = field.legal_values %]
|
||||
[% NEXT IF value.is_static %]
|
||||
<input type="checkbox" id="val_[% value.id %]" value="[% value.id %]" name="values"[% ' checked="checked"' IF value.has_visibility_value(field_value.id, 0) %]/>
|
||||
<label for="val_[% value.id %]">[% value.name FILTER html %]</label>
|
||||
<a title="Править значение..." href="editvalues.cgi?action=edit&field=[% field.name %]&value=[% value.name | uri %]">→</a>
|
||||
<br />
|
||||
[% END %]
|
||||
</div>
|
||||
<table id="admin_table" cellpadding="4">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th align="left">Значение</th>
|
||||
<th align="left">Активно</th>
|
||||
<th align="left">По умолчанию</th>
|
||||
</tr>
|
||||
[% count = 0 %]
|
||||
[% FOREACH value = field.legal_values %]
|
||||
[% NEXT IF value.is_static %]
|
||||
<tr class="[%+ count % 2 == 1 ? 'odd' : 'even' +%]_row">
|
||||
<td>
|
||||
<label for="val_[% value.id %]">[% value.name FILTER html %]</label>
|
||||
<a title="Править значение..." href="editvalues.cgi?action=edit&field=[% field.name %]&value=[% value.name | uri %]">→</a>
|
||||
</td>
|
||||
<td align="center">
|
||||
<input type="checkbox" id="val_[% value.id %]" value="[% value.id %]" name="values" onchange="changeDefaultEnabling(this);"[% ' checked="checked"' IF value.has_visibility_value(field_value.id, 0) %]/>
|
||||
</td>
|
||||
<td align="center">
|
||||
<input type="[% (field.type == constants.FIELD_TYPE_MULTI_SELECT ? 'checkbox' : 'radio') %]" id="def_val_[% value.id %]" value="[% value.id %]" name="default_value_ids"[% ' checked="checked"' IF value.is_default_controlled_value(field_value.id, 0) %]/>
|
||||
</td>
|
||||
</tr>
|
||||
[% count = count + 1 %]
|
||||
[% END %]
|
||||
</tbody>
|
||||
</table>
|
||||
<br/>
|
||||
<input type="submit" id="update" name="update" value="Сохранить"/>
|
||||
<a href="editvalues.cgi?action=control_list&field=[% field.name FILTER html %]">К выбору <strong>[% field.value_field.description FILTER html %]</strong></a>
|
||||
|
@ -61,5 +79,37 @@
|
|||
<a href="editvalues.cgi?field=
|
||||
[%- field.name FILTER url_quote %]">К списку значений <strong>[% field.description FILTER html %]</strong></a>
|
||||
</form>
|
||||
<script type="text/javascript">
|
||||
function clearDefault()
|
||||
{
|
||||
var elems = document.forms['setValuesForm'].elements['default_value_id'];
|
||||
for (var i in elems)
|
||||
{
|
||||
elems[i].checked = false;
|
||||
}
|
||||
}
|
||||
function changeDefaultEnabling(self)
|
||||
{
|
||||
var id = self.id.substr('val_'.length);
|
||||
var elem = document.getElementById('def_val_' + id);
|
||||
if (elem)
|
||||
{
|
||||
if ((elem.disabled = !self.checked) && elem.checked)
|
||||
{
|
||||
elem.checked = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var checkboxes = document.forms['setValuesForm'].elements['values'];
|
||||
for (var i in checkboxes)
|
||||
{
|
||||
if (!checkboxes[i].tagName) continue;
|
||||
if (checkboxes[i].tagName.toLowerCase() != 'input') continue;
|
||||
changeDefaultEnabling(checkboxes[i]);
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
[% PROCESS global/footer.html.tmpl %]
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
|
||||
[% IF field.custom && field.value_field %]
|
||||
<h4>
|
||||
Чтобы отредактировать наборы активных [% field.description FILTER html %]
|
||||
Чтобы отредактировать наборы активных [% field.description FILTER html %] и значения по умолчанию
|
||||
для разных значений поля [% field.value_field.description FILTER html %],
|
||||
<a href="editvalues.cgi?action=control_list&field=[%- field.name FILTER url_quote %]">нажмите сюда</a>.
|
||||
</h4>
|
||||
|
|
|
@ -288,7 +288,7 @@ function checkWorktime(inp)
|
|||
<form name="Create" id="Create" method="post" action="post_bug.cgi"
|
||||
enctype="multipart/form-data" onkeypress="return ctrlEnter(event||window.event,this)"
|
||||
onsubmit="return validateEntryForm(this)">
|
||||
<input type="hidden" name="product" value="[% product.name FILTER html %]">
|
||||
<input type="hidden" name="product" value="[% product.name FILTER html %]" id="product">
|
||||
<input type="hidden" name="token" value="[% token FILTER html %]">
|
||||
<input type="hidden" name="cloned_bug_id" value="[% cloned_bug_id FILTER html %]">
|
||||
<input type="hidden" name="cloned_comment" value="[% cloned_comment FILTER html %]">
|
||||
|
|
Loading…
Reference in New Issue