From c878990c35e96d9c98e095338527496968e8fdc2 Mon Sep 17 00:00:00 2001 From: Jared Camins-Esakov Date: Thu, 13 Jun 2013 11:31:21 -0400 Subject: [PATCH] Bug 10402: Add ability to enter multiple contacts Some vendors may have more than one contact. For example, a technical contact and a billing contact, or a contact for journals and a contact for monographs. Rather than require that each contact be either made into a separate vendor or recorded somewhere outside of Koha, it would be really useful of Koha had the ability to add multiple additional contacts to vendors in the Acquisitions module. To test: 1) Apply patch. 2) Edit a bookseller, making sure to add a contact. 3) View the bookseller's information, making sure the contact information is there. 4) Run the unit test: > prove t/db_dependent/Bookseller.t 5) Add multiple contacts to a vendor, see that they show up. 6) Delete one contact from a vendor with multiple contacts, see that the result is correct. 7) Sign off. Note: This test plan can supersede that on the previous two patches, as all functionality of the previous two patches is required by this one. Signed-off-by: Owen Leonard Signed-off-by: Jared Camins-Esakov --- C4/Bookseller.pm | 12 ++-- acqui/updatesupplier.pl | 4 +- .../intranet-tmpl/prog/en/css/staff-global.css | 8 +++ .../prog/en/modules/acqui/supplier.tt | 62 ++++++++++++++------ t/db_dependent/Bookseller.t | 15 ++++- 5 files changed, 75 insertions(+), 26 deletions(-) diff --git a/C4/Bookseller.pm b/C4/Bookseller.pm index 6ceb606..4386bb4 100644 --- a/C4/Bookseller.pm +++ b/C4/Bookseller.pm @@ -209,10 +209,12 @@ sub AddBookseller { # return the id of this new supplier my $id = $dbh->{'mysql_insertid'}; if ($id && $contacts) { - $contacts->[0] = C4::Bookseller::Contact->new( $contacts->[0] ) - unless ref $contacts->[0] eq 'C4::Bookseller::Contact'; - $contacts->[0]->bookseller($id); - $contacts->[0]->save(); + foreach my $contact (@$contacts) { + $contact = C4::Bookseller::Contact->new( $contact ) + unless ref $contacts eq 'C4::Bookseller::Contact'; + $contact->bookseller($id); + $contact->save(); + } } return $id; } @@ -265,7 +267,7 @@ sub ModBookseller { if ($contacts) { foreach my $contact (@$contacts) { $contact = C4::Bookseller::Contact->new( $contact ) - unless ref $contacts->[0] eq 'C4::Bookseller::Contact'; + unless ref $contacts eq 'C4::Bookseller::Contact'; $contact->bookseller($data->{'id'}); $contact->save(); push @contactparams, $contact->id if $contact->id; diff --git a/acqui/updatesupplier.pl b/acqui/updatesupplier.pl index 77fa276..7ce5633 100755 --- a/acqui/updatesupplier.pl +++ b/acqui/updatesupplier.pl @@ -108,10 +108,12 @@ foreach (qw(id name position phone altphone fax email notes)) { for my $cnt (0..scalar(@{$contact_info{'id'}})) { my %contact; + my $real_contact; foreach (qw(id name position phone altphone fax email notes)) { $contact{$_} = $contact_info{$_}->[$cnt]; + $real_contact = 1 if $contact{$_}; } - push @contacts, C4::Bookseller::Contact->new(\%contact); + push @contacts, C4::Bookseller::Contact->new(\%contact) if $real_contact; } if($data{'name'}) { diff --git a/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css b/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css index 1a78033..b529142 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css +++ b/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css @@ -2060,6 +2060,14 @@ div#acqui_order_supplierlist > div.supplier > div.baskets { float: left; } +#add-contact { + margin: 0 0 8px 8px; +} + +#contact-template { + display: none; +} + /* Override core jQueryUI widgets */ .ui-widget-content { border: 1px solid #B9D8D9; background: #ffffff none; color: #222222; } .ui-widget-header { border: 1px solid #B9D8D9; background: #E6F0F2 none; color: #222222; font-weight: bold; } diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/supplier.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/supplier.tt index 03ea71c..44418e8 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/supplier.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/supplier.tt @@ -2,20 +2,21 @@ [% BLOCK edit_contact %]
    -
  1. -
  2. -
  3. -
  4. -
  5. -
  6. -
  7. -
  8. -
  9. -
  10. -
  11. -
  12. -
  13. -
  14. +
  15. +
  16. +
  17. +
  18. +
  19. +
  20. +
  21. +
  22. +
  23. +
  24. +
  25. +
  26. +
  27. +
  28. + [% IF contact.id %]
  29. [% END %]
[% END %] [% BLOCK show_contact %] @@ -53,6 +54,23 @@ if (f.company.value == "") { } function add_contact() { + var new_contact = $('#contact-template').clone(); + var timestamp = new Date().getTime(); + $(new_contact).removeAttr('id'); + $('input, textarea', new_contact).each(function () { + $(this).attr('id', $(this).attr('id') + '_' + timestamp); + }); + $('label', new_contact).each(function () { + $(this).attr('for', $(this).attr('for') + '_' + timestamp); + }); + $(new_contact).insertBefore(this); + $('input[name="contact_name"]', new_contact).focus(); + return false; +} + +function delete_contact() { + $(this).parents('fieldset').delete(); + return false; } $(document).ready(function() { @@ -71,6 +89,8 @@ function add_contact() { 'bFilter': false, 'bInfo': false, } ) ); + $('.delete-contact').click(delete_contact); + $('#add-contact').click(add_contact); }); //]]> @@ -115,12 +135,20 @@ function add_contact() {
  • - [% FOREACH contact IN contacts %] -
    +
    + Contacts +
    Contact details [% INCLUDE edit_contact %]
    - [% END %] + [% FOREACH contact IN contacts %] +
    + Contact details + [% INCLUDE edit_contact %] +
    + [% END %] + +
    diff --git a/t/db_dependent/Bookseller.t b/t/db_dependent/Bookseller.t index 80368d0..d1a0f1d 100644 --- a/t/db_dependent/Bookseller.t +++ b/t/db_dependent/Bookseller.t @@ -2,7 +2,7 @@ use Modern::Perl; -use Test::More tests => 69; +use Test::More tests => 72; use C4::Context; use Koha::DateUtils; use DateTime::Duration; @@ -671,12 +671,15 @@ my $booksellerid = C4::Bookseller::AddBookseller( phone => "0123456", active => 1 }, - [ { name => 'John Smith', phone => '0123456x1' } ] + [ + { name => 'John Smith', phone => '0123456x1' }, + { name => 'Leo Tolstoy', phone => '0123456x2' }, + ] ); my @booksellers = C4::Bookseller::GetBookSeller('my vendor'); ok( - (grep { $_->{'id'} == $booksellerid } @booksellers), + ( grep { $_->{'id'} == $booksellerid } @booksellers ), 'GetBookSeller returns correct record when passed a name' ); @@ -692,7 +695,9 @@ is( ); is( $bookseller->{'contacts'}->[0]->phone, '0123456x1', 'Contact has expected phone number' ); +is( scalar @{ $bookseller->{'contacts'} }, 2, 'Saved two contacts' ); +pop @{ $bookseller->{'contacts'} }; $bookseller->{'name'} = 'your vendor'; $bookseller->{'contacts'}->[0]->phone('654321'); C4::Bookseller::ModBookseller($bookseller); @@ -703,6 +708,8 @@ is( $bookseller->{'name'}, 'your vendor', is( $bookseller->{'contacts'}->[0]->phone, '654321', 'Successfully changed contact phone number by modifying bookseller hash' ); +is( scalar @{ $bookseller->{'contacts'} }, + 1, 'Only one contact after modification' ); C4::Bookseller::ModBookseller( $bookseller, [ { name => 'John Jacob Jingleheimer Schmidt' } ] ); @@ -715,6 +722,8 @@ is( ); is( $bookseller->{'contacts'}->[0]->phone, undef, 'Removed phone number from contact' ); +is( scalar @{ $bookseller->{'contacts'} }, + 1, 'Only one contact after modification' ); #End transaction $dbh->rollback; -- 1.7.9.5