Bug 33104: Add the ability to create vendor interfaces
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / acqui / supplier.tt
1 [% USE raw %]
2 [% USE To %]
3 [% USE Asset %]
4 [% USE KohaDates %]
5 [% USE AuthorisedValues %]
6 [% BLOCK edit_contact %]
7     <ol id="contact-form">
8         <input type="hidden" name="contact_id" value="[% contact.id | html %]" />
9         <li><label for="contact_name[% contact.id | html %]">Contact name: </label>
10             <input type="text" size="40" id="contact_name[% contact.id | html %]" name="contact_name" value="[% contact.name | html %]" /></li>
11         <li><label for="contact_position[% contact.id | html %]">Position: </label>
12             <input type="text" size="40" id="contact_position[% contact.id | html %]" name="contact_position" value="[% contact.position | html %]" /></li>
13         <li><label for="contact_phone[% contact.id | html %]">Phone: </label>
14                 <input type="text" size="20" id="contact_phone[% contact.id | html %]" name="contact_phone" value="[% contact.phone | html %]" /> </li>
15         <li><label for="contact_altphone[% contact.id | html %]">Alternative phone: </label>
16             <input type="text" size="20" id="contact_altphone[% contact.id | html %]" name="contact_altphone" value="[% contact.altphone | html %]" /></li>
17         <li><label for="contact_fax[% contact.id | html %]">Fax: </label>
18             <input type="text" size="20" id="contact_fax[% contact.id | html %]" name="contact_fax" value="[% contact.fax | html %]" /></li>
19         <li><label for="contact_email[% contact.id | html %]">Email: </label>
20             <input type="text" size="40" id="contact_email[% contact.id | html %]" name="contact_email" value="[% contact.email | html %]" class="email" /></li>
21         <li><label for="contact_notes[% contact.id | html %]">Notes: </label>
22             <textarea id="contact_notes[% contact.id | html %]" name="contact_notes" cols="40" rows="4">[% contact.notes | html %]</textarea></li>
23         <li><label for="contact_acqprimary[% contact.id | html %]">Primary acquisitions contact:</label>
24             [% IF contact.acqprimary %]
25                 <input type="checkbox" id="contact_acqprimary[% contact.id | html %]" class="contact_acqprimary" checked="checked"></input>
26             [% ELSE %]
27                 <input type="checkbox" id="contact_acqprimary[% contact.id | html %]" class="contact_acqprimary"></input>
28             [% END %]
29             <input type="hidden" class="contact_acqprimary_hidden" name="contact_acqprimary" value="[% contact.acqprimary | html %]"></input>
30         <li><label for="contact_serialsprimary[% contact.id | html %]">Primary serials contact:</label>
31             [% IF contact.serialsprimary %]
32                 <input type="checkbox" id="contact_serialsprimary[% contact.id | html %]" class="contact_serialsprimary" checked="checked"></input>
33             [% ELSE %]
34                 <input type="checkbox" id="contact_serialsprimary[% contact.id | html %]" class="contact_serialsprimary"></input>
35             [% END %]
36             <input type="hidden" class="contact_serialsprimary_hidden" name="contact_serialsprimary" value="[% contact.serialsprimary | html %]"></input>
37         <li><label for="contact_orderacquisition[% contact.id | html %]">Contact when ordering?</label>
38             [% IF contact.orderacquisition %]
39                 <input type="checkbox" id="contact_orderacquisition[% contact.id | html %]" class="contact_orderacquisition" checked="checked"></input>
40             [% ELSE %]
41                 <input type="checkbox" id="contact_orderacquisition[% contact.id | html %]" class="contact_orderacquisition"></input>
42             [% END %]
43             <input type="hidden" class="contact_orderacquisition_hidden" name="contact_orderacquisition" value="[% contact.orderacquisition | html %]"></input>
44         <li><label for="contact_claimacquisition[% contact.id | html %]">Contact about late orders?</label>
45             [% IF contact.claimacquisition %]
46                 <input type="checkbox" id="contact_claimacquisition[% contact.id | html %]" class="contact_claimacquisition" checked="checked"></input>
47             [% ELSE %]
48                 <input type="checkbox" id="contact_claimacquisition[% contact.id | html %]" class="contact_claimacquisition"></input>
49             [% END %]
50             <input type="hidden" class="contact_claimacquisition_hidden" name="contact_claimacquisition" value="[% contact.claimacquisition | html %]"></input>
51         <li><label for="contact_claimissues[% contact.id | html %]">Contact about late issues?</label>
52             [% IF contact.claimissues %]
53                 <input type="checkbox" id="contact_claimissues[% contact.id | html %]" class="contact_claimissues" checked="checked"></input>
54             [% ELSE %]
55                 <input type="checkbox" id="contact_claimissues[% contact.id | html %]" class="contact_claimissues"></input>
56             [% END %]
57             <input type="hidden" class="contact_claimissues_hidden" name="contact_claimissues" value="[% contact.claimissues | html %]"></input>
58         </li>
59         [% IF contact.id %]<li><button class="btn btn-default delete-contact"><i class="fa fa-trash"></i> Delete contact</li>[% END %]
60     </ol>
61 [% END %]
62
63 [% BLOCK show_contact %]
64     <h3>[% contact.name | html %]</h3>
65     <p><span class="label">Position: </span>[% contact.position | html %]</p>
66     <p><span class="label">Phone: </span>[% contact.phone | html %]</p>
67     <p><span class="label">Alternative phone: </span>[% contact.altphone | html %]</p>
68     <p><span class="label">Fax: </span>[% contact.fax | html %]</p>
69     [% IF ( contact.email ) %]
70         <p><span class="label">Email: </span><a href="mailto:[% contact.email | uri %]">[% contact.email | html %]</a></p>
71     [% END %]
72     [% IF ( contact.notes ) %]
73         <p><span class="label">Notes: </span>[% contact.notes | html %]</p>
74     [% END %]
75     [% IF ( contact.acqprimary ) %]
76         <p><span class="label">Primary acquisitions contact</span></p>
77     [% END %]
78     [% IF ( contact.serialsprimary ) %]
79         <p><span class="label">Primary serials contact</span></p>
80     [% END %]
81     [% IF ( contact.orderacquisition ) %]
82         <p><span class="label">Receives orders</span></p>
83     [% END %]
84     [% IF ( contact.claimacquisition ) %]
85         <p><span class="label">Receives claims for late orders</span></p>
86     [% END %]
87     [% IF ( contact.claimissues ) %]
88         <p><span class="label">Receives claims for late issues</span></p>
89     [% END %]
90 [% END %]
91
92 [% SET footerjs = 1 %]
93 [% INCLUDE 'doc-head-open.inc' %]
94 <title>Vendor [% name | html %] &rsaquo; Koha</title>
95 [% INCLUDE 'doc-head-close.inc' %]
96 </head>
97
98 <body id="acq_supplier" class="acq">
99 [% WRAPPER 'header.inc' %]
100     [% INCLUDE 'acquisitions-search.inc' %]
101 [% END %]
102
103 [% WRAPPER 'sub-header.inc' %]
104     [% WRAPPER breadcrumbs %]
105         [% WRAPPER breadcrumb_item %]
106             <a href="/cgi-bin/koha/acqui/acqui-home.pl">Acquisitions</a>
107         [% END %]
108         [% IF ( enter ) %]
109             [% IF ( booksellerid ) %]
110                 [% WRAPPER breadcrumb_item %]
111                     <a href="/cgi-bin/koha/acqui/supplier.pl?booksellerid=[% booksellerid | uri %]">[% name | html %]</a>
112                 [% END %]
113                 [% WRAPPER breadcrumb_item bc_active= 1 %]
114                     <span>Modify [% name | html %]</span>
115                 [% END %]
116             [% ELSE %]
117                 [% WRAPPER breadcrumb_item bc_active= 1 %]
118                     <span>Add vendor</span>
119                 [% END %]
120             [% END %]
121         [% ELSE %]
122             [% WRAPPER breadcrumb_item bc_active= 1 %]
123                 [% name | html %]
124             [% END %]
125         [% END # /IF (enter) %]
126     [% END #/ WRAPPER breadcrumbs %]
127 [% END #/ WRAPPER sub-header.inc %]
128
129 <div class="main container-fluid">
130     <div class="row">
131         <div class="col-sm-10 col-sm-push-2">
132             <main>
133
134     [% IF ( enter ) %]
135         [% IF ( booksellerid ) %]
136         <h1>Update: [% name | html %]</h1>
137     [% ELSE %]
138         <h1>Add vendor</h1>
139     [% END %]
140     [% END %]
141 [% UNLESS ( enter ) %][% INCLUDE 'acquisitions-toolbar.inc' %][% END %]
142 [% IF ( enter ) %]
143     <form action="updatesupplier.pl" name="updatesupplier" style="display:block" class="validated" method="post">
144         <div id="toolbar" class="btn-toolbar">
145             <button class="btn btn-primary" type="submit"><i class="fa fa-save"></i> Save</button>
146             [% IF ( booksellerid ) %]
147                 <a class="btn btn-default cancel" href="/cgi-bin/koha/acqui/supplier.pl?booksellerid=[% booksellerid | html %]">
148             [% ELSE %]
149                 <a class="btn btn-default cancel" href="/cgi-bin/koha/acqui/acqui-home.pl">
150             [% END %] <i class="fa fa-remove"></i> Cancel</a>
151         </div>
152
153         <input type="hidden" name="booksellerid" value="[% booksellerid | html %]" />
154         <fieldset class="rows">
155             <legend>Company details</legend>
156             <ol><li><label for="company" class="required">Name:</label>
157                 <input type="text" size="40" id="company" name="company" value="[% name | html %]" required="required" class="required focus" /><span class="required">Required</span></li>
158             <li><label for="company_postal">Postal address: </label>
159                     <textarea id="company_postal" name="company_postal" cols="40" rows="3">[% postal | html %]</textarea></li>
160             <li><label for="physical">Physical address: </label>
161                 <textarea id="physical" name="physical" cols="40" rows="3">[% address1 | html %][% address2 | html %][% address3 | html %][% address4 | html %]</textarea></li>
162             <li><label for="company_phone">Phone: </label>
163                 <input type="text" size="20" id="company_phone" name="company_phone" value="[% phone | html %]" /></li>
164             <li><label for="company_fax">Fax: </label>
165                 <input type="text" size="20" id="company_fax" name="company_fax" value="[% fax | html %]" /></li>
166             <li><label for="website">Website: </label>
167                 <input type="text" size="40" id="website" name="website" value="[% url | html %]" class="url" /></li>
168             <li><label for="accountnumber">Account number: </label>
169                 <input type="text" size="40" id="accountnumber" name="accountnumber" value="[% accountnumber | html %]" /></li>
170                 <li>
171                     <label for="vendor_type">Vendor type: </label>
172                     [% PROCESS 'av-build-dropbox.inc' name="vendor_type", category="VENDOR_TYPE", default=type, empty=1, size = 20 %]
173                 </li>
174                 <li>
175                     <label for="aliases">Aliases: </label>
176                     <div id="aliases" style="padding-left: 11rem;"></div>
177                 </li>
178             </ol>
179         </fieldset>
180         <fieldset class="rows">
181             <legend>Contacts</legend>
182             <fieldset id="contact-template" class="supplier-contact">
183                 <legend>Contact details</legend>
184                 [% INCLUDE edit_contact %]
185             </fieldset>
186             [% FOREACH contact IN contacts %]
187                 <fieldset class="supplier-contact">
188                     <legend>Contact details</legend>
189                     [% INCLUDE edit_contact %]
190                 </fieldset>
191             [% END %]
192             <button id="add-contact" class="btn btn-default"><i class="fa fa-plus"></i> Add another contact</button>
193         </fieldset>
194
195         <fieldset class="rows">
196             <legend>Interfaces</legend>
197             <div id="interfaces"></div>
198         </fieldset>
199
200         <fieldset class="rows">
201             <legend>Ordering information</legend>
202             <ol><li><label for="activestatus">Vendor is:</label>
203                     [% IF ( active ) %]
204                         <input type="radio" id="activestatus" name="status" value="1" checked="checked" />
205                         <label class="radio" for="activestatus">Active</label>
206                         <input type="radio" id="inactivestatus" name="status" value="0" />
207                         <label class="radio" for="inactivestatus">Inactive</label>
208                     [% ELSE %]
209                         <input type="radio" id="activestatus" name="status" value="1" />
210                         <label class="radio" for="activestatus">Active</label>
211                         <input type="radio" id="inactivestatus" name="status" value="0" checked="checked" />
212                         <label class="radio" for="inactivestatus">Inactive</label>
213                     [% END %]</li>
214             <li><label for="list_currency">List prices are: </label>
215                 <select name="list_currency" id="list_currency">
216                     [% FOREACH c IN currencies %]
217                         [% IF booksellerid and c.currency == listprice or not booksellerid and c.active %]
218                             <option value="[% c.currency | html %]" selected="selected">[% c.currency | html %]</option>
219                         [% ELSIF not c.archived %]
220                             <option value="[% c.currency | html %]">[% c.currency | html %]</option>
221                         [% END %]
222                     [% END %]
223                 </select>
224             </li>
225             <li><label for="invoice_currency">Invoice prices are: </label>
226                 <select name="invoice_currency" id="invoice_currency">
227                     [% FOREACH c IN currencies %]
228                         [% IF booksellerid and c.currency == invoiceprice or not booksellerid and c.active %]
229                             <option value="[% c.currency | html %]" selected="selected">[% c.currency | html %]</option>
230                         [% ELSIF not c.archived %]
231                             <option value="[% c.currency | html %]">[% c.currency | html %]</option>
232                         [% END %]
233                     [% END %]
234                 </select>
235             </li>
236             <li><label for="gstyes">Tax number registered:</label>
237                 [% IF ( gstreg ) %]
238                     <label class="radio" for="gstyes">Yes</label>
239                     <input type="radio" name="gst" id="gstyes" value="1" checked="checked" />
240                     <label class="radio" for="gstno">No</label>
241                     <input type="radio" name="gst" id="gstno" value="0" />
242                 [% ELSE %]
243                     <label class="radio" for="gstyes">Yes</label>
244                     <input type="radio" name="gst" id="gstyes" value="1" />
245                     <label class="radio" for="gstno">No</label>
246                     <input type="radio" name="gst" id="gstno" value="0" checked="checked" />
247                 [% END %]</li>
248
249             <li><label for="list_gstyes">List prices:</label>
250                 [% IF ( listincgst ) %]
251                     <label class="radio" for="list_gstyes">Include tax</label>
252                     <input type="radio" id="list_gstyes" name="list_gst" value="1" checked="checked" />
253                     <label class="radio" for="list_gstno">Don't include tax</label>
254                     <input type="radio" id="list_gstno" name="list_gst" value="0" />
255                 [% ELSE %]
256                     <label class="radio" for="list_gstyes">Include tax</label>
257                     <input type="radio" id="list_gstyes" name="list_gst" value="1" />
258                     <label class="radio" for="list_gstno">Don't include tax</label>
259                     <input type="radio" id="list_gstno" name="list_gst" value="0" checked="checked" />
260                 [% END %]</li>
261
262             <li><label for="invoice_gstyes">Invoice prices:</label>
263                 [% IF ( invoiceincgst ) %]
264                     <label class="radio" for="invoice_gstyes">Include tax</label>
265                     <input type="radio" id="invoice_gstyes" name="invoice_gst" value="1" checked="checked" />
266                     <label class="radio" for="invoice_gstno">Don't include tax</label>
267                     <input type="radio" id="invoice_gstno" name="invoice_gst" value="0" />
268                     [% ELSE %]
269                     <label class="radio" for="invoice_gstyes">Include tax</label>
270                     <input type="radio" id="invoice_gstyes" name="invoice_gst" value="1" />
271                     <label class="radio" for="invoice_gstno">Don't include tax</label>
272                     <input type="radio" id="invoice_gstno" name="invoice_gst" value="0" checked="checked" />
273                 [% END %]</li>
274
275             [% IF gst_values %]
276                 <li>
277                   <label for="tax_rate">Tax rate: </label>
278                   <select name="tax_rate" id="tax_rate">
279                   [% FOREACH gst IN gst_values %]
280                     [% IF ( tax_rate == gst.option ) %]
281                       <option value="[% gst.option | html %]" selected="selected">[% gst.option * 100 | html %] %</option>
282                     [% ELSE %]
283                       <option value="[% gst.option | html %]">[% gst.option * 100 | html %] %</option>
284                     [% END %]
285                   [% END %]
286                   </select>
287                 </li>
288             [% ELSE %]
289                 <input type="hidden" name="tax_rate" value="0" />
290             [% END %]
291             <li><label for="discount">Discount: </label>
292                 <input type="text" size="6" id="discount" name="discount" value="[% discount | format ('%.1f') %]" />%</li>
293             <li>
294                 <label for="deliverytime">Delivery time: </label>
295                 <input type="text" size="2" id="deliverytime" name="deliverytime" value="[% deliverytime | html %]" /> days
296             </li>
297             <li><label for="notes">Notes: </label>
298                 <textarea cols="40" rows="4" id="notes" name="notes" >[% notes | html %]</textarea></li>
299             </ol>
300         </fieldset>
301
302     </form>
303 [% ELSE %]
304     <h1>[% name | html %]</h1>
305         <div class="row">
306             <div class="col-sm-6">
307                 <div id="supplier-company-details" class="page-section">
308                     <h2>Vendor details</h2>
309                     <p>
310                         <span class="label">Type: </span>
311                         [% IF (type) %][% AuthorisedValues.GetByCode( 'VENDOR_TYPE', type ) | html %][% END %]
312                     </p>
313                     <p><span class="label">Company name: </span>[% name | html %]</p>
314                     <p><span class="label">Postal address: </span>[% postal | html %]</p>
315                     <p><span class="label">Physical address: </span>[% address1 | html %][% address2 | html %][% address3 | html %][% address4 | html %]</p>
316                     <p><span class="label">Phone: </span>[% phone | html %]</p>
317                     <p><span class="label">Fax: </span>[% fax | html %]</p>
318                     [% IF ( url ) %]
319                         <p><span class="label">Website: </span><a href="[% url | url %]">[% url | html %]</a></p>
320                     [% END %]
321                     [% IF ( accountnumber ) %]
322                         <p><span class="label">Account number: </span>[% accountnumber | html %]</p>
323                     [% END %]
324                     [% IF vendor.aliases.count %]
325                         <p>
326                             <span class="label">Aliases: </span>
327                             <ul>
328                             [% FOR alias IN vendor.aliases %]
329                                 <li>[% alias.alias | html %]</li>
330                             [% END %]
331                             </ul>
332                         </p>
333                     [% END %]
334                 </div> <!-- /#supplier-company-details -->
335
336                 <div id="supplier-ordering-information" class="page-section">
337                     <h2>Ordering information</h2>
338                     <p><strong>Vendor is: </strong>[% IF ( active ) %]Active[% ELSE %]Inactive[% END %]</p>
339                     <p><strong>List prices are: </strong>[% listprice | html %]</p>
340                     <p><strong>Invoice prices are: </strong>[% invoiceprice | html %]</p>
341                     [% IF ( tax_rate ) %]
342                         <p><strong>Tax number registered: </strong>[% IF ( gstreg ) %]Yes[% ELSE %]No[% END %]</p>
343                         <p><strong>List item price includes tax: </strong>[% IF ( listincgst ) %]Yes[% ELSE %]No[% END %]</p>
344                         <p><strong>Invoice item price includes tax: </strong>[% IF ( invoiceincgst ) %]Yes[% ELSE %]No[% END %]</p>
345                     [% END %]
346                     <p><strong>Discount: </strong>[% discount | format("%.1f") %] %</p>
347                     <p><strong>Tax rate: </strong>[% ( tax_rate || 0 ) * 100 | html %] %</p>
348                     [% IF deliverytime.defined %]
349                         <p><strong>Delivery time: </strong>[% deliverytime | html %] days</p>
350                     [% END %]
351                     [% IF ( notes ) %]
352                         <p><strong>Notes: </strong>[% notes | html %]</p>
353                     [% END %]
354                 </div> <!-- #supplier-ordering-information -->
355
356                 [% IF vendor.interfaces.count %]
357                 <div id="supplier-interfaces" class="page-section">
358                     <h2>Interfaces</h2>
359
360                     [% FOR interface IN vendor.interfaces %]
361                         <fieldset class="rows">
362                             <legend>[% interface.name | html %]</legend>
363                             <ul>
364                                 <li>
365                                     <li>Type: [% interface.type | html %]</li>
366                                     <li>URI: [% interface.uri | html %]</li>
367                                     <li>Login: [% interface.login | html %]</li>
368                                     <li>Password: [% interface.password | html %]</li>
369                                     <li>Account email: [% interface.account_email | html %]</li>
370                                     <li>Notes : [% interface.notes | html %]</li>
371                                 </li>
372                             </ul>
373                         </fieldset>
374                     [% END %]
375                 </div>
376                 [% END %]
377
378             </div> <!-- /.col-sm-6 -->
379
380             <div class="col-sm-6">
381                 <div id="supplier-contact-details" class="page-section">
382                     <h2>Contact</h2>
383                     [% FOREACH contact IN contacts %]
384                         [% INCLUDE show_contact %]
385                     [% END %]
386                 </div> <!-- /#supplier-contact-details -->
387
388                 <div id="subscription-details" class="page-section">
389                     <h2>Subscription details</h2>
390                     <p><strong>Number of subscriptions: </strong>
391                         [% IF (  CAN_user_serials ) %]
392                             <a href="/cgi-bin/koha/serials/serials-search.pl?bookseller_filter=[% name | uri %]&searched=1">[% subscriptioncount | html %]</a>
393                         [% ELSE %]
394                             [% subscriptioncount | html %]
395                         [% END %]
396                     </p>
397                 </div> <!-- /#subscription-details -->
398             </div> <!-- /.col-sm-6 -->
399
400         </div>
401
402         [% IF ( contracts ) %]
403             <div id="supplier-contracts" class="page-section">
404                 <h2>Contract(s)</h2>
405                 <table id="contractst">
406                   <thead>
407                     <tr>
408                         <th scope="col">Name</th>
409                         <th scope="col">Description</th>
410                         <th scope="col">Start date</th>
411                         <th scope="col">End date</th>
412                         [% IF CAN_user_acquisition_contracts_manage %]
413                             <th scope="col" class="NoSort noExport">Actions</th>
414                         [% END %]
415                     </tr>
416                   </thead>
417                   <tbody>
418                     [% FOREACH contract IN contracts %]
419                         <tr>
420                         <td>
421                             <a href="/cgi-bin/koha/admin/aqcontract.pl?op=add_form&amp;contractnumber=[% contract.contractnumber | uri %]&amp;booksellerid=[% contract.booksellerid | uri %]">[% contract.contractname | html %]</a>
422                         </td>
423                         <td>[% contract.contractdescription | html %]</td>
424                         <td data-order="[% contract.contractstartdate | html %]">[% contract.contractstartdate | $KohaDates %]</td>
425                         <td data-order="[% contract.contractenddate | html %]">[% contract.contractenddate | $KohaDates %]</td>
426                         [% IF CAN_user_acquisition_contracts_manage %]
427                             <td class="actions">
428                                 <a class="btn btn-default btn-xs" href="/cgi-bin/koha/admin/aqcontract.pl?op=add_form&amp;contractnumber=[% contract.contractnumber | html %]&amp;booksellerid=[% contract.booksellerid | html %]"><i class="fa fa-pencil"></i> Edit</a>
429                                 <a class="btn btn-default btn-xs" href="/cgi-bin/koha/admin/aqcontract.pl?op=delete_confirm&amp;contractnumber=[% contract.contractnumber | html %]&amp;booksellerid=[% contract.booksellerid | html %]"><i class="fa fa-trash"></i> Delete</a>
430                             </td>
431                         [% END %]
432                         </tr>
433                     [% END %]
434                   </tbody>
435                 </table>
436             </div> <!-- /#supplier-contracts -->
437         [% END %]
438
439 [% END %]
440
441 </main>
442 </div> <!-- /.col-sm-10.col-sm-push-2 -->
443
444 <div class="col-sm-2 col-sm-pull-10">
445     <aside>
446         [% INCLUDE 'vendor-menu.inc' %]
447     </aside>
448 </div> <!-- /.col-sm-2.col-sm-pull-10 -->
449 </div> <!-- /.row -->
450 [% MACRO jsinclude BLOCK %]
451     [% Asset.js("js/acquisitions-menu.js") | $raw %]
452     [% Asset.js("lib/hc-sticky.js") | $raw %]
453     [% Asset.js("js/acq.js") | $raw %]
454     [% INCLUDE 'datatables.inc' %]
455     <script>
456         function confirm_deletion() {
457             if (confirm(_("Confirm deletion of this vendor ?"))) {
458                 window.location="/cgi-bin/koha/acqui/supplier.pl?booksellerid=[% booksellerid | html %]&op=delete";
459             }
460         }
461
462         function add_contact() {
463             var new_contact = $('#contact-template').clone();
464             var timestamp = new Date().getTime();
465             $(new_contact).removeAttr('id');
466             $('input, textarea', new_contact).each(function () {
467                 $(this).attr('id', $(this).attr('id') + '_' + timestamp);
468             });
469             $('label', new_contact).each(function () {
470                 $(this).attr('for', $(this).attr('for') + '_' + timestamp);
471             });
472             $(new_contact).insertBefore(this);
473             if ($('.supplier-contact').length === 2) { // First contact
474                 $.each(['.contact_acqprimary', '.contact_serialsprimary', '.contact_orderacquisition', '.contact_claimacquisition', '.contact_claimissues'], function (idx, checkbox) {
475                     $(checkbox, new_contact).click();
476                 });
477             }
478             $('input[name="contact_name"]', new_contact).focus();
479             return false;
480         }
481
482         function delete_contact(ev) {
483             $(this).parents('.supplier-contact').remove();
484             ev.preventDefault();
485         }
486
487         [% IF vendor %]
488         let aliases = [% To.json(vendor.aliases.unblessed) | $raw %];
489         [% ELSE %]
490         let aliases = [];
491         [% END %]
492         function remove_alias(i){
493             aliases.splice(i, 1);
494             refresh_aliases();
495         }
496
497         function encodeHTMLEntities(str){
498             return str.replace(/[&<>'"]/g,
499               tag => ({
500                   '&': '&amp;',
501                   '<': '&lt;',
502                   '>': '&gt;',
503                   "'": '&#39;',
504                   '"': '&quot;'
505                 }[tag]));
506         }
507
508         function add_alias(){
509             let alias = $("#new_alias").val();
510             if ( !alias.length > 0 ) { return }
511             aliases.push({alias});
512             refresh_aliases();
513         }
514         function refresh_aliases(){
515             let nodes = $("<div></div>");
516             aliases.forEach((a, i) => {
517                 let alias_str = encodeHTMLEntities(a.alias);
518                 let n = $("<div></div>").append(alias_str);
519                 let input = $('<input type="hidden" name="alias" />');
520                 input.val(a.alias);
521                 n.append(input);
522                 n.append(` <a style="cursor: pointer;" onclick="remove_alias(${i});"><i class="fa fa-trash" aria-hidden="true"></i> ` + _("Remove") + '</a>');
523                 nodes.append(n);
524             });
525             nodes.append("<input id='new_alias' type='text' class='noEnterSubmit' />");
526             nodes.append(' <a style="cursor: pointer;" onclick="add_alias();"><i class="fa fa-plus" aria-hidden="true"></i> ' + _("Add") + '</a>');
527             $("#aliases").html(nodes.html());
528         }
529
530         [% IF vendor %]
531         let interfaces = [% To.json(vendor.interfaces.unblessed) | $raw %];
532         [% ELSE %]
533         let interfaces = [];
534         [% END %]
535         function serialize_interface_form(){
536             interfaces = [];
537             $("#interfaces > fieldset.supplier-interface > ol.interface-form").each( (index, interface_form )=> {
538                 let interface = {};
539                 $(interface_form).find('input,textarea').serializeArray().map(attr => {
540                     let name = attr.name.replace(/interface_([\w_]+)_\d+/, "$1");
541                     interface[name] = attr.value
542                 })
543                 interfaces.push(interface);
544             });
545             return interfaces;
546         }
547         function remove_interface(i){
548             interfaces = serialize_interface_form();
549             interfaces.splice(i, 1);
550             refresh_interfaces();
551         }
552         function add_interface(){
553             interfaces = serialize_interface_form();
554             interfaces.push({
555                 type: "",
556                 name: "",
557                 uri: "",
558                 login: "",
559                 password: "",
560                 account_email: "",
561                 notes: "",
562             });
563             refresh_interfaces();
564         }
565         function refresh_interfaces(){
566             let nodes = $("<div id='interfaces'></div>");
567             interfaces.forEach((interface, i) => {
568                 let n = $("<fieldset class='supplier-interface'></fieldset>");
569                 n.append("<legend>" + _("Interface details") + "</legend>");
570                 n.append(`<input type="hidden" name="interface_counter" value="${i}" />`);
571                 let ol = $('<ol class="interface-form"></ol>');
572                 ol.append(`<li><label for="interface_name_${i}">` + _("Name: ") + `</label><input type="text" size="40" id="interface_name_${i}" name="interface_name_${i}" value="${interface.name}" /></li>`);
573                 ol.append(`<li><label for="interface_type_${i}">` + _("Type: ") + `</label><input type="text" size="40" id="interface_type_${i}" name="interface_type_${i}" value="${interface.type}" /></li>`);
574                 ol.append(`<li><label for="interface_uri_${i}">` + _("URI: ") + `</label><input type="text" size="40" id="interface_uri_${i}" name="interface_uri_${i}" value="${interface.uri}" /></li>`);
575                 ol.append(`<li><label for="interface_login_${i}">` + _("Login: ") + `</label><input type="text" size="40" id="interface_login_${i}" name="interface_login_${i}" value="${interface.login}" /></li>`);
576                 ol.append(`<li><label for="interface_password_${i}">` + _("Password: ") + `</label><input type="text" size="40" id="interface_password_${i}" name="interface_password_${i}" value="${interface.password}" /></li>`);
577                 ol.append(`<li><label for="interface_account_email_${i}">` + _("Account email: ") + `</label><input type="text" size="40" id="interface_account_email_${i}" name="interface_account_email_${i}" value="${interface.account_email}" /></li>`);
578                 ol.append(`<li><label for="interface_notes_${i}">` + _("Notes: ") + `</label><textarea cols="40" rows="3" id="interface_notes_${i}" name="interface_notes_${i}">${interface.notes}</textarea></li>`);
579                 ol.append(`<li><button class="btn btn-default" onclick="remove_interface(${i});"><i class="fa fa-trash"></i> Delete interface</li>`);
580                 n.append(ol);
581                 nodes.append(n);
582             });
583             nodes.append(`<button onclick="add_interface();" class="btn btn-default"><i class="fa fa-plus"></i> ` + _("Add another interface") + '</button>')
584             $("#interfaces").replaceWith(nodes);
585         }
586
587         var Sticky;
588
589          $(document).ready(function() {
590             var contractst = $("#contractst").dataTable($.extend(true, {}, dataTablesDefaults, {
591                 "aoColumnDefs": [
592                     { "bSortable": false, "bSearchable": false, 'aTargets': [ 'NoSort' ] }
593                 ],
594                 'sDom': 't'
595             } ) );
596             $('body').on('click', '.delete-contact', null, delete_contact);
597             $('#add-contact').click(add_contact);
598             $('body').on('click', '.contact_acqprimary', null, function () {
599                 if ($(this).is(':checked')) {
600                     $('.contact_acqprimary').filter(':checked').not(this).prop('checked', false);
601                     $('.contact_acqprimary_hidden').each(function () {
602                         $(this).val('0');
603                     });
604                 }
605                 $(this).next('.contact_acqprimary_hidden').val('1');
606             });
607             $('body').on('click', '.contact_serialsprimary', null, function () {
608                 if ($(this).is(':checked')) {
609                     $('.contact_serialsprimary').filter(':checked').not(this).prop('checked', false);
610                     $('.contact_serialsprimary_hidden').each(function () {
611                         $(this).val('0');
612                     });
613                 }
614                 $(this).next('.contact_serialsprimary_hidden').val($(this).is(':checked') ? '1' : '0');
615             });
616             $('body').on('click', '.contact_orderacquisition', null, function () {
617                 $(this).next('.contact_orderacquisition_hidden').val($(this).is(':checked') ? '1' : '0');
618             });
619             $('body').on('click', '.contact_claimacquisition', null, function () {
620                 $(this).next('.contact_claimacquisition_hidden').val($(this).is(':checked') ? '1' : '0');
621             });
622             $('body').on('click', '.contact_claimissues', null, function () {
623                 $(this).next('.contact_claimissues_hidden').val($(this).is(':checked') ? '1' : '0');
624             });
625
626             refresh_aliases();
627             refresh_interfaces();
628
629             Sticky = $("#toolbar");
630             Sticky.hcSticky({
631                 stickTo: "main",
632                 stickyClass: "floating"
633             });
634         });
635     </script>
636 [% END %]
637
638 [% INCLUDE 'intranet-bottom.inc' %]