Skip to content

Commit

Permalink
Reference update form improvements
Browse files Browse the repository at this point in the history
 - Delete buttons are now checkboxes.
 - Current value in an editable box.
  • Loading branch information
lomky committed Nov 14, 2018
1 parent b22ffd2 commit 946126d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
27 changes: 19 additions & 8 deletions lib/Tuba/Reference.pm
Original file line number Diff line number Diff line change
Expand Up @@ -124,21 +124,32 @@ sub update {
$c->stash(publication_update_category => delete $json->{publication_update_category});
}
if (my $params = $c->req->params->to_hash ) {
if ( $params->{delete_pub_attr} ) {
$reference->delete_attr( { del_attr => $params->{delete_pub_attr}, audit_user => $c->user, audit_note => "Deleting attributes" });
$c->redirect_without_error('update_form');
}
elsif ( exists $params->{new_attr_key} || /^attribute/ ~~ %$params ) {
my $new_attributes = _collect_attributes($params);
$reference->set_attr( { new_attrs => $new_attributes, audit_user => $c->user, audit_note => "Setting attributes" });
$c->redirect_without_error('update_form');
if ( exists $params->{new_attr_key} || /^attribute/ ~~ %$params || /^delete_pub_attr/ ~~ %$params ) {
if ( exists $params->{new_attr_key} || /^attribute/ ~~ %$params ) {
my $new_attributes = _collect_attributes($params);
$reference->set_attr( { new_attrs => $new_attributes, audit_user => $c->user, audit_note => "Setting attributes" });
}
if ( /^delete_pub_attr/ ~~ %$params ) {
_delete_pub_attrs($c, $reference, $params);
}
$c->redirect_without_error('update_form');
}
else {
$c->SUPER::update(@_);
}
}
}

sub _delete_pub_attrs {
my ($c, $reference, $params ) = @_;
foreach my $key ( keys %$params ) {
if ( $key =~ /^delete_pub_attr(.*)$/ ) {
my $attr_key = $1;
$reference->delete_attr( { del_attr => $attr_key, audit_user => $c->user, audit_note => "Deleting attribute $attr_key" });
}
}
}

sub _collect_attributes {
my ( $params ) = @_;
my $attrs;
Expand Down
14 changes: 9 additions & 5 deletions lib/Tuba/files/templates/reference/update_form.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,21 @@
<tr>
<th>Delete</th>
<th>Key</th>
<th>Current Value</th>
<th>Replace Value</th>
<th>Value</th>
</tr>
% for my $k (sort keys %{ $reference->attrs }) {
<tr>
<td><button type="submit" name='delete_pub_attr' value='<%= $k %>' class="btn btn-danger squeezevert" onclick='{return confirm("Are you sure you want to delete the attribute <%= $k %> (Value: <%= $reference->attrs->{$k} %> )?")}'>Delete</button></td>
%#= <td><button type="submit" name='delete_pub_attr' value='<%= $k %>' class="btn btn-danger squeezevert" onclick='{return confirm("Are you sure you want to delete the attribute <%= $k %> (Value: <%= $reference->attrs->{$k} %> )?")}'>Delete</button></td>
<td> <%= check_box 'delete_pub_attr'.$k %> </td>
<td><%= $k %></td>
<td><%= $reference->attrs->{$k} %></td>
<td><%= text_field 'attribute_'.$k, class => "form-control input-small squeezevert" %></td>
% if ($reference->attrs->{$k} && length($reference->attrs->{$k}) > 40) {
<td><%= text_area 'attribute_'.$k, value => $reference->attrs->{$k}, class => "form-control input-small squeezevert" %></td>
% } else {
<td><%= text_field 'attribute_'.$k, value => $reference->attrs->{$k}, class => "form-control input-small squeezevert" %></td>
% }
</tr>
% }

</table>
<h4>New Attribute</h4>
<div class='form-group row'>
Expand Down

0 comments on commit 946126d

Please sign in to comment.