View | Details | Raw Unified | Return to bug 10402
Collapse All | Expand All

(-)a/C4/Bookseller.pm (-5 / +7 lines)
Lines 203-212 sub AddBookseller { Link Here
203
    # return the id of this new supplier
203
    # return the id of this new supplier
204
    my $id = $dbh->{'mysql_insertid'};
204
    my $id = $dbh->{'mysql_insertid'};
205
    if ($id && $contacts) {
205
    if ($id && $contacts) {
206
        $contacts->[0] = C4::Bookseller::Contact->new( $contacts->[0] )
206
        foreach my $contact (@$contacts) {
207
          unless ref $contacts->[0] eq 'C4::Bookseller::Contact';
207
            $contact = C4::Bookseller::Contact->new( $contact )
208
        $contacts->[0]->bookseller($id);
208
                unless ref $contacts eq 'C4::Bookseller::Contact';
209
        $contacts->[0]->save();
209
            $contact->bookseller($id);
210
            $contact->save();
211
        }
210
    }
212
    }
211
    return $id;
213
    return $id;
212
}
214
}
Lines 258-264 sub ModBookseller { Link Here
258
    if ($contacts) {
260
    if ($contacts) {
259
        foreach my $contact (@$contacts) {
261
        foreach my $contact (@$contacts) {
260
            $contact = C4::Bookseller::Contact->new( $contact )
262
            $contact = C4::Bookseller::Contact->new( $contact )
261
                unless ref $contacts->[0] eq 'C4::Bookseller::Contact';
263
                unless ref $contacts eq 'C4::Bookseller::Contact';
262
            $contact->bookseller($data->{'id'});
264
            $contact->bookseller($data->{'id'});
263
            $contact->save();
265
            $contact->save();
264
            push @contactparams, $contact->id if $contact->id;
266
            push @contactparams, $contact->id if $contact->id;
(-)a/acqui/updatesupplier.pl (-1 / +3 lines)
Lines 108-117 foreach (qw(id name position phone altphone fax email notes)) { Link Here
108
108
109
for my $cnt (0..scalar(@{$contact_info{'id'}})) {
109
for my $cnt (0..scalar(@{$contact_info{'id'}})) {
110
    my %contact;
110
    my %contact;
111
    my $real_contact;
111
    foreach (qw(id name position phone altphone fax email notes)) {
112
    foreach (qw(id name position phone altphone fax email notes)) {
112
        $contact{$_} = $contact_info{$_}->[$cnt];
113
        $contact{$_} = $contact_info{$_}->[$cnt];
114
        $real_contact = 1 if $contact{$_};
113
    }
115
    }
114
    push @contacts, C4::Bookseller::Contact->new(\%contact);
116
    push @contacts, C4::Bookseller::Contact->new(\%contact) if $real_contact;
115
}
117
}
116
118
117
if($data{'name'}) {
119
if($data{'name'}) {
(-)a/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css (+8 lines)
Lines 2047-2052 div#acqui_order_supplierlist > div.supplier > div.baskets { Link Here
2047
    float: left;
2047
    float: left;
2048
}
2048
}
2049
2049
2050
#add-contact {
2051
    margin: 0 0 8px 8px;
2052
}
2053
2054
#contact-template {
2055
    display: none;
2056
}
2057
2050
/* Override core jQueryUI widgets */
2058
/* Override core jQueryUI widgets */
2051
.ui-widget-content { border: 1px solid #B9D8D9; background: #ffffff none; color: #222222; }
2059
.ui-widget-content { border: 1px solid #B9D8D9; background: #ffffff none; color: #222222; }
2052
.ui-widget-header { border: 1px solid #B9D8D9; background: #E6F0F2 none; color: #222222; font-weight: bold; }
2060
.ui-widget-header { border: 1px solid #B9D8D9; background: #E6F0F2 none; color: #222222; font-weight: bold; }
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/supplier.tt (-17 / +45 lines)
Lines 2-21 Link Here
2
[% BLOCK edit_contact %]
2
[% BLOCK edit_contact %]
3
    <ol id="contact-form">
3
    <ol id="contact-form">
4
        <input type="hidden" name="contact_id" value="[% contact.id %]" />
4
        <input type="hidden" name="contact_id" value="[% contact.id %]" />
5
        <li><label for="contact_name">Contact name: </label>
5
        <li><label for="contact_name[% contact.id %]">Contact name: </label>
6
            <input type="text" size="40" id="contact_name" name="contact_name" value="[% contact.name %]" /></li>
6
            <input type="text" size="40" id="contact_name[% contact.id %]" name="contact_name" value="[% contact.name %]" /></li>
7
        <li><label for="contact_position">Position: </label>
7
        <li><label for="contact_position[% contact.id %]">Position: </label>
8
            <input type="text" size="40" id="contact_position" name="contact_position" value="[% contact.position %]" /></li>
8
            <input type="text" size="40" id="contact_position[% contact.id %]" name="contact_position" value="[% contact.position %]" /></li>
9
        <li><label for="contact_phone">Phone: </label>
9
        <li><label for="contact_phone[% contact.id %]">Phone: </label>
10
                <input type="text" size="20" id="contact_phone" name="contact_phone" value="[% contact.phone %]" /> </li>
10
                <input type="text" size="20" id="contact_phone[% contact.id %]" name="contact_phone" value="[% contact.phone %]" /> </li>
11
        <li><label for="contact_phone_2">Alternative phone: </label>
11
        <li><label for="contact_altphone[% contact.id %]">Alternative phone: </label>
12
            <input type="text" size="20" id="contact_altphone" name="contact_altphone" value="[% contact.altphone %]" /></li>
12
            <input type="text" size="20" id="contact_altphone[% contact.id %]" name="contact_altphone" value="[% contact.altphone %]" /></li>
13
        <li><label for="contact_fax">Fax: </label>
13
        <li><label for="contact_fax[% contact.id %]">Fax: </label>
14
            <input type="text" size="20" id="contact_fax" name="contact_fax" value="[% contact.fax %]" /></li>
14
            <input type="text" size="20" id="contact_fax[% contact.id %]" name="contact_fax" value="[% contact.fax %]" /></li>
15
        <li><label for="contact_email">Email: </label>
15
        <li><label for="contact_email[% contact.id %]">Email: </label>
16
            <input type="text" size="40" id="contact_email" name="contact_email" value="[% contact.email %]" /></li>
16
            <input type="text" size="40" id="contact_email[% contact.id %]" name="contact_email" value="[% contact.email %]" /></li>
17
        <li><label for="contact_notes">Notes: </label>
17
        <li><label for="contact_notes[% contact.id %]">Notes: </label>
18
            <textarea id="contact_notes" name="contact_notes" cols="40" rows="4">[% contnotes %]</textarea></li>
18
            <textarea id="contact_notes[% contact.id %]" name="contact_notes" cols="40" rows="4">[% contnotes %]</textarea></li>
19
        [% IF contact.id %]<li><button class="btn" class="delete-contact"><i class="icon-remove"></i>Delete contact</li>[% END %]
19
    </ol>
20
    </ol>
20
[% END %]
21
[% END %]
21
[% BLOCK show_contact %]
22
[% BLOCK show_contact %]
Lines 55-60 if (f.company.value == "") { Link Here
55
}
56
}
56
57
57
function add_contact() {
58
function add_contact() {
59
    var new_contact = $('#contact-template').clone();
60
    var timestamp = new Date().getTime();
61
    $(new_contact).removeAttr('id');
62
    $('input, textarea', new_contact).each(function () {
63
        $(this).attr('id', $(this).attr('id') + '_' + timestamp);
64
    });
65
    $('label', new_contact).each(function () {
66
        $(this).attr('for', $(this).attr('for') + '_' + timestamp);
67
    });
68
    $(new_contact).insertBefore(this);
69
    $('input[name="contact_name"]', new_contact).focus();
70
    return false;
71
}
72
73
function delete_contact() {
74
    $(this).parents('fieldset').delete();
75
    return false;
58
}
76
}
59
77
60
 $(document).ready(function() {
78
 $(document).ready(function() {
Lines 73-78 function add_contact() { Link Here
73
        'bFilter': false,
91
        'bFilter': false,
74
        'bInfo': false,
92
        'bInfo': false,
75
    } ) );
93
    } ) );
94
    $('.delete-contact').click(delete_contact);
95
    $('#add-contact').click(add_contact);
76
 });
96
 });
77
//]]>
97
//]]>
78
</script>
98
</script>
Lines 117-128 function add_contact() { Link Here
117
            <li><label for="accountnumber">Account number: </label>
137
            <li><label for="accountnumber">Account number: </label>
118
                <input type="text" size="40" id="accountnumber" name="accountnumber" value="[% accountnumber %]" /></li></ol>
138
                <input type="text" size="40" id="accountnumber" name="accountnumber" value="[% accountnumber %]" /></li></ol>
119
        </fieldset>
139
        </fieldset>
120
        [% FOREACH contact IN contacts %]
140
        <fieldset class="rows">
121
            <fieldset class="supplier-contact rows">
141
            <legend>Contacts</legend>
142
            <fieldset id="contact-template" class="supplier-contact">
122
                <legend>Contact details</legend>
143
                <legend>Contact details</legend>
123
                [% INCLUDE edit_contact %]
144
                [% INCLUDE edit_contact %]
124
            </fieldset>
145
            </fieldset>
125
        [% END %]
146
            [% FOREACH contact IN contacts %]
147
                <fieldset class="supplier-contact">
148
                    <legend>Contact details</legend>
149
                    [% INCLUDE edit_contact %]
150
                </fieldset>
151
            [% END %]
152
            <button id="add-contact" class="btn"><i class="icon-plus"></i>Add contact</button>
153
        </fieldset>
126
    </div>
154
    </div>
127
        <div class="yui-g">
155
        <div class="yui-g">
128
        <fieldset class="rows">
156
        <fieldset class="rows">
(-)a/t/db_dependent/Bookseller.t (-4 / +12 lines)
Lines 3-9 Link Here
3
use strict;
3
use strict;
4
use warnings;
4
use warnings;
5
5
6
use Test::More tests => 12;
6
use Test::More tests => 15;
7
7
8
BEGIN {
8
BEGIN {
9
    use_ok('C4::Bookseller');
9
    use_ok('C4::Bookseller');
Lines 16-27 my $booksellerid = C4::Bookseller::AddBookseller( Link Here
16
        phone    => "0123456",
16
        phone    => "0123456",
17
        active   => 1
17
        active   => 1
18
    },
18
    },
19
    [ { name => 'John Smith', phone => '0123456x1' } ]
19
    [
20
        { name => 'John Smith',  phone => '0123456x1' },
21
        { name => 'Leo Tolstoy', phone => '0123456x2' },
22
    ]
20
);
23
);
21
24
22
my @booksellers = C4::Bookseller::GetBookSeller('my vendor');
25
my @booksellers = C4::Bookseller::GetBookSeller('my vendor');
23
ok(
26
ok(
24
    (grep { $_->{'id'} == $booksellerid } @booksellers),
27
    ( grep { $_->{'id'} == $booksellerid } @booksellers ),
25
    'GetBookSeller returns correct record when passed a name'
28
    'GetBookSeller returns correct record when passed a name'
26
);
29
);
27
30
Lines 37-43 is( Link Here
37
);
40
);
38
is( $bookseller->{'contacts'}->[0]->phone,
41
is( $bookseller->{'contacts'}->[0]->phone,
39
    '0123456x1', 'Contact has expected phone number' );
42
    '0123456x1', 'Contact has expected phone number' );
43
is( scalar @{ $bookseller->{'contacts'} }, 2, 'Saved two contacts' );
40
44
45
pop @{ $bookseller->{'contacts'} };
41
$bookseller->{'name'} = 'your vendor';
46
$bookseller->{'name'} = 'your vendor';
42
$bookseller->{'contacts'}->[0]->phone('654321');
47
$bookseller->{'contacts'}->[0]->phone('654321');
43
C4::Bookseller::ModBookseller($bookseller);
48
C4::Bookseller::ModBookseller($bookseller);
Lines 48-53 is( $bookseller->{'name'}, 'your vendor', Link Here
48
is( $bookseller->{'contacts'}->[0]->phone,
53
is( $bookseller->{'contacts'}->[0]->phone,
49
    '654321',
54
    '654321',
50
    'Successfully changed contact phone number by modifying bookseller hash' );
55
    'Successfully changed contact phone number by modifying bookseller hash' );
56
is( scalar @{ $bookseller->{'contacts'} },
57
    1, 'Only one contact after modification' );
51
58
52
C4::Bookseller::ModBookseller( $bookseller,
59
C4::Bookseller::ModBookseller( $bookseller,
53
    [ { name => 'John Jacob Jingleheimer Schmidt' } ] );
60
    [ { name => 'John Jacob Jingleheimer Schmidt' } ] );
Lines 60-65 is( Link Here
60
);
67
);
61
is( $bookseller->{'contacts'}->[0]->phone,
68
is( $bookseller->{'contacts'}->[0]->phone,
62
    undef, 'Removed phone number from contact' );
69
    undef, 'Removed phone number from contact' );
70
is( scalar @{ $bookseller->{'contacts'} },
71
    1, 'Only one contact after modification' );
63
72
64
END {
73
END {
65
    C4::Bookseller::DelBookseller($booksellerid);
74
    C4::Bookseller::DelBookseller($booksellerid);
66
- 

Return to bug 10402