Bug 32030: ERM - Periods
[srvgit] / koha-tmpl / intranet-tmpl / prog / en / modules / erm / agreements.tt
1 [% USE raw %]
2 [% USE To %]
3 [% USE Asset %]
4 [% USE KohaDates %]
5 [% USE TablesSettings %]
6 [% USE AuthorisedValues %]
7 [% SET footerjs = 1 %]
8 [% INCLUDE 'doc-head-open.inc' %]
9 <title>
10     [% IF op =='add_form' %]
11         [% IF agreement.agreement_id %]
12             Modify agreement
13         [% ELSE %]
14             New agreement
15         [% END %] &rsaquo; [% ELSE %]
16         [% IF op == 'delete_confirm' %]
17             Confirm deletion of agreement &rsaquo; [% END %]
18     [% END %]
19     Agreements &rsaquo; Electronic resources management &rsaquo; Koha
20 </title>
21 [% INCLUDE 'doc-head-close.inc' %]
22 </head>
23
24 <body id="erm_agreements" class="erm">
25 [% INCLUDE 'header.inc' %]
26 [% INCLUDE 'erm-search.inc' %]
27
28 <nav id="breadcrumbs" aria-label="Breadcrumb" class="breadcrumb">
29     <ol>
30         <li>
31             <a href="/cgi-bin/koha/mainpage.pl">Home</a>
32         </li>
33         <li>
34             <a href="/cgi-bin/koha/erm/erm-home.pl">Electronic resources management</a>
35         </li>
36
37         [% IF op == 'add_form' %]
38             <li>
39                 <a href="/cgi-bin/koha/erm/agreements.pl">Agreements</a>
40             </li>
41             <li>
42                 <a href="#" aria-current="page">
43                     [% IF agreement.agreement_id %]
44                         Modify
45                     [% ELSE %]
46                         New
47                     [% END %] Agreement
48                 </a>
49             </li>
50
51         [% ELSIF op == 'delete_confirm' %]
52             <li>
53                 <a href="/cgi-bin/koha/erm/agreements.pl">Agreements</a>
54             </li>
55             <li>
56                 <a href="#" aria-current="page">
57                     Confirm deletion of agreement
58                 </a>
59             </li>
60
61         [% ELSE %]
62             <li>
63                 <a href="#" aria-current="page">
64                     Agreements
65                 </a>
66             </li>
67         [% END %]
68     </ol>
69 </nav>
70
71 <div class="main container-fluid">
72     <div class="row">
73         <div class="col-sm-10 col-sm-push-2">
74             <main>
75
76 [% FOR m IN messages %]
77     <div class="dialog [% m.type | html %]">
78         [% SWITCH m.code %]
79         [% CASE 'error_on_update' %]
80             An error occurred when updating this agreement. Perhaps it already exists.
81         [% CASE 'error_on_insert' %]
82             An error occurred when adding this agreement. The agreement id might already exist.
83         [% CASE 'error_on_delete' %]
84             An error occurred when deleting this agreement. Check the logs.
85         [% CASE 'success_on_update' %]
86             Agreement updated successfully.
87         [% CASE 'success_on_insert' %]
88             Agreement added successfully.
89         [% CASE 'success_on_delete' %]
90             Agreement deleted successfully.
91         [% CASE 'already_exists' %]
92             This agreement already exists.
93         [% CASE %]
94             [% m.code | html %]
95         [% END %]
96     </div>
97 [% END %]
98
99 [% IF op == 'add_form' %]
100     [% IF agreement %]
101         <h1>Modify a agreement</h1>
102     [% ELSE %]
103         <h1>New agreement</h1>
104     [% END %]
105
106     <form action="/cgi-bin/koha/erm/agreements.pl" name="Aform" method="post" class="validated">
107         <input type="hidden" name="op" value="add_validate" />
108         <input type="hidden" name="agreement_id" value="[% agreement.agreement_id | html %]" />
109
110         <fieldset class="rows">
111             <ol>
112                 [% IF agreement %]
113                     <li><span class="label">Agreement ID: </span>[% agreement.agreement_id | html %]</li>
114                 [% END %]
115
116                 <li>
117                     <label for="vendor_id">Vendor: </label>
118                     <select name="vendor_id">
119                         <option value=""></option>
120                         [% FOR v IN vendors %]
121                             [% IF v.id == agreement.vendor_id %]
122                                 <option value="[% v.id %]" selected="selected">[% v.name %]</option>
123                             [% ELSE %]
124                                 <option value="[% v.id %]">[% v.name %]</option>
125                             [% END %]
126                         [% END %]
127                     </select>
128                 </li>
129                 <li>
130                     <label for="name" class="required">Name: </label>
131                     <input type="text" name="name" id="name" size="80" value="[% agreement.name | html %]" required="required" class="required" /> <span class="required">Required</span>
132                 <li>
133                     <label for="description">Description: </label>
134                     <input type="text" name="description" id="description" size="80" value="[% agreement.description | html %]" />
135                 <li>
136                     <label for="status" class="required">Status: </label>
137                     <select name="status" required="required" required="required">
138                         <option value=""></option>
139                         [% PROCESS options_for_authorised_values authorised_values => AuthorisedValues.GetAuthValueDropbox( 'ERM_AGREEMENT_STATUS' ), selected_av => agreement.status %]
140                     </select>
141                     <span class="required">Required</span>
142                 </li>
143                 <li>
144                     <label for="closure_reason">Closure reason: </label>
145                     <select name="closure_reason">
146                         <option value=""></option>
147                         [% PROCESS options_for_authorised_values authorised_values => AuthorisedValues.GetAuthValueDropbox( 'ERM_AGREEMENT_CLOSURE_REASON' ), selected_av => agreement.closure_reason %]
148                     </select>
149                 </li>
150                 <li>
151                     <label for="is_perpetual">Is perpetual: </label>
152                     <label for="is_perpetual_yes"> Yes
153                         [% IF agreement.is_perpetual %]
154                             <input type="radio" id="is_perpetual_yes" name="is_perpetual" value="1" checked="checked">
155                         [% ELSE %]
156                             <input type="radio" id="is_perpetual_yes" name="is_perpetual" value="1">
157                         [% END %]
158                     </label>
159                     <label for="is_perpetual_no"> No
160                         [% IF agreement.is_perpetual %]
161                             <input type="radio" id="is_perpetual_no" name="is_perpetual" value="0">
162                         [% ELSE %]
163                             <input type="radio" id="is_perpetual_no" name="is_perpetual" value="0" checked="checked">
164                         [% END %]
165                     </label>
166                 </li>
167                 <li>
168                     <label for="renewal_priority">Renewal priority: </label>
169                     <select name="renewal_priority">
170                         <option value=""></option>
171                         [% PROCESS options_for_authorised_values authorised_values => AuthorisedValues.GetAuthValueDropbox( 'ERM_AGREEMENT_RENEWAL_PRIORITY' ), selected_av => agreement.renewal_priority %]
172                     </select>
173                 <li>
174                     <label for="license_info">License info: </label>
175                     <input type="text" name="license_info" id="license_info" size="80" value="[% agreement.license_info | html %]" />
176                 </li>
177             </ol>
178         </fieldset>
179
180 [% BLOCK agreement_period %]
181     <fieldset class="agreement_period">
182     <legend>
183         Agreement period <span class="period_count">[% id | html %]</span>
184         <a href="#" class="remove_period"><i class="fa fa-trash"></i> Remove this period</a>
185     </legend>
186     <input type="hidden" name="period_unique_id" value="[% id | html %]" />
187     <ol>
188         <li>
189             <label for="started_on" class="required">Start date: </label>
190             <input type="text" id="started_on_[% id | html %]" class="started_on" name="started_on_[% id | html %]" value="[% p.started_on | $KohaDates %]" class="flatpickr" data-date_to="ended_on_[% id | html %]" />
191             <span class="required">Required</span>
192             <div class="hint">[% INCLUDE 'date-format.inc' %]</div>
193         </li>
194         <li>
195             <label for="ended_on">End date: </label>
196             <input type="text" id="ended_on_[% id | html %]" class="ended_on" name="ended_on_[% id | html %]" value="[% p.ended_on | $KohaDates %]" class="flatpickr" />
197             <div class="hint">[% INCLUDE 'date-format.inc' %]</div>
198         </li>
199         <li>
200             <label>Cancellation deadline: </label>
201             <input type="text" class="cancellation_deadline" name="cancellation_deadline_[% id | html %]" value="[% p.cancellation_deadline | $KohaDates %]" class="flatpickr" />
202             <div class="hint">[% INCLUDE 'date-format.inc' %]</div>
203         </li>
204         <li>
205             <label>Notes: </label>
206             <input type="text" class="notes" name="notes_[% id | html %]" value="[% p.notes | html %]" />
207         </li>
208     </ol>
209     </fieldset>
210 [% END %]
211
212         <fieldset class="rows" id="agreement_periods">
213             <legend>Periods</legend>
214             [% IF agreement.periods.count %]
215                 [% FOR p IN agreement.periods %]
216                     [% PROCESS agreement_period period => p, id => loop.count %]
217                 [% END %]
218             [% ELSE %]
219                 [% PROCESS agreement_period id => 1 %]
220             [% END %]
221             <button class="add_new_period" type="button" class="btn btn-primary"><i class="fa fa-plus" aria-hidden="true"></i>Add new period</button>
222         </fieldset>
223
224         <fieldset class="action">
225             <input type="submit" value="Submit" />
226             <a class="cancel" href="/cgi-bin/koha/erm/agreements.pl">Cancel</a>
227         </fieldset>
228     </form>
229 [% END %]
230
231 [% IF op == 'delete_confirm' %]
232     <div class="dialog alert">
233         <h3>Delete agreement "[% agreement.agreement_id | html %]?"</h3>
234         <table>
235             <tr><th>Agreement id</th>
236                 <td>[% agreement.agreement_id| html %]</td>
237             </tr>
238             <tr><th>Vendor</th>
239                 <td>[% agreement.vendor_id| html %]</td>
240             </tr>
241             <tr><th>Name</th>
242                 <td>[% agreement.name| html %]</td>
243             </tr>
244             <tr><th>Description</th>
245                 <td>[% agreement.description| html %]</td>
246             </tr>
247             <tr><th>Status</th>
248                 <td>[% agreement.status| html %]</td>
249             </tr>
250             <tr><th>Closure_reason</th>
251                 <td>[% agreement.closure_reason| html %]</td>
252             </tr>
253             <tr><th>Is perpetual</th>
254                 <td>[% agreement.is_perpetual| html %]</td>
255             </tr>
256             <tr><th>Renewal priority</th>
257                 <td>[% agreement.renewal_priority| html %]</td>
258             </tr>
259             <tr><th>License info</th>
260                 <td>[% agreement.license_info| html %]</td>
261             </tr>
262         </table>
263         <form action="/cgi-bin/koha/erm/agreements.pl" method="post">
264             <input type="hidden" name="op" value="delete_confirmed" />
265             <input type="hidden" name="agreement_id" value="[% agreement.agreement_id | html %]" />
266             <button type="submit" class="approve"><i class="fa fa-fw fa-check"></i> Yes, delete</button>
267         </form>
268         <form action="/cgi-bin/koha/erm/agreements.pl" method="get">
269             <button type="submit" class="deny"><i class="fa fa-fw fa-remove"></i> No, do not delete</button>
270         </form>
271     </div>
272 [% END %]
273
274 [% IF op == 'list' %]
275
276     <div id="toolbar" class="btn-toolbar">
277         <a class="btn btn-default" id="newagreement" href="/cgi-bin/koha/erm/agreements.pl?op=add_form"><i class="fa fa-plus"></i> New agreement</a>
278     </div>
279
280     <h2>Agreements</h2>
281     [% IF agreement_name_filter %]
282         Searching: [% agreement_name_filter | html %]
283     [% END %]
284
285     [% IF agreements_count > 0 %]
286         <div class="table_agreements_table_controls"></div>
287         <table id="table_agreements">
288             <thead>
289                 <tr>
290                     <th>ID</th>
291                     <th>Vendor</th>
292                     <th>Name</th>
293                     <th>Description</th>
294                     <th>Status</th>
295                     <th>Closure reason</th>
296                     <th>Is perpetual</th>
297                     <th>Renewal priority</th>
298                     <th data-class-name="actions noExport">Actions</th>
299                 </tr>
300             </thead>
301         </table>
302     [% ELSE %]
303         <div class="dialog message">
304             There are no agreements defined. <a href="/cgi-bin/koha/erm/agreements.pl?op=add_form">Create a new agreement</a>.
305         </div>
306     [% END %]
307 [% END %]
308
309             </main>
310         </div> <!-- /.col-sm-10.col-sm-push-2 -->
311
312         <div class="col-sm-2 col-sm-pull-10">
313             <aside>
314                 [% INCLUDE 'erm-menu.inc' %]
315             </aside>
316         </div> <!-- /.col-sm-2.col-sm-pull-10 -->
317      </div> <!-- /.row -->
318
319 [% MACRO jsinclude BLOCK %]
320     [% Asset.js("js/erm-menu.js") | $raw %]
321     [% INCLUDE 'calendar.inc' %]
322     [% INCLUDE 'datatables.inc' %]
323     [% INCLUDE 'columns_settings.inc' %]
324     <script>
325
326         const agreement_statuses = [% To.json(AuthorisedValues.Get('ERM_AGREEMENT_STATUS')) | $raw %];
327         let agreement_statuses_map = agreement_statuses.reduce((map, e) => {
328             map[e.authorised_value] = e;
329             return map;
330         }, {});
331         const agreement_closure_reasons = [% To.json(AuthorisedValues.Get('ERM_AGREEMENT_CLOSURE_REASON')) | $raw %];
332         let agreement_closure_reasons_map = agreement_closure_reasons.reduce((map, e) => {
333             map[e.authorised_value] = e;
334             return map;
335         }, {});
336         const agreement_renewal_priorities = [% To.json(AuthorisedValues.Get('ERM_AGREEMENT_RENEWAL_PRIORITY')) | $raw %];
337         let agreement_renewal_priorities_map = agreement_renewal_priorities.reduce((map, e) => {
338             map[e.authorised_value] = e;
339             return map;
340         }, {});
341
342
343
344         var columns_settings = [% TablesSettings.GetColumns( 'erm', 'agreements', 'table_agreements', 'json' ) | $raw %];
345         $(document).ready(function() {
346             var agreements_table_url = '/api/v1/erm/agreements?';
347
348         [% IF agreement_name_filter %]
349             var agreement_name_filter = {
350                 'name': {
351                     "like": '%[%- agreement_name_filter | html -%]%'
352                 }
353             };
354             agreements_table_url += 'q='+ encodeURIComponent(JSON.stringify(agreement_name_filter));
355         [% END %]
356
357             var agreements_table = $("#table_agreements").kohaTable({
358                 "ajax": {
359                     "url": agreements_table_url
360                 },
361                 "order": [[ 1, "asc" ]],
362                 "columns": [
363                     {
364                         "data": "agreement_id",
365                         "searchable": true,
366                         "orderable": true
367                     },
368                     {
369                         "data": "vendor_id",
370                         "searchable": true,
371                         "orderable": true
372                     },
373                     {
374                         "data": "name",
375                         "searchable": true,
376                         "orderable": true
377                     },
378                     {
379                         "data": "description",
380                         "searchable": true,
381                         "orderable": true
382                     },
383                     {
384                         "data": "status",
385                         "searchable": true,
386                         "orderable": true,
387                         "render": function( data, type, row, meta ) {
388                             return escape_str(agreement_statuses_map[row.status].lib);
389                         }
390                     },
391                     {
392                         "data": "closure_reason",
393                         "searchable": true,
394                         "orderable": true,
395                         "render": function( data, type, row, meta ) {
396                             return row.closure_reason != undefined && row.closure_reason != "" ? escape_str(agreement_closure_reasons_map[row.closure_reason].lib) : "";
397                         }
398                     },
399                     {
400                         "data": "is_perpetual",
401                         "searchable": true,
402                         "orderable": true,
403                         "render": function( data, type, row, meta ) {
404                             return escape_str(row.is_perpetual ? _("Yes") : _("No"));
405                         }
406                     },
407                     {
408                         "data": "renewal_priority",
409                         "searchable": true,
410                         "orderable": true,
411                         "render": function( data, type, row, meta ) {
412                             return row.renewal_priority != undefined && row.renewal_priority != "" ? escape_str(agreement_renewal_priorities_map[row.renewal_priority].lib) : "";
413                         }
414                     },
415                     {
416                         "data": function( row, type, val, meta ) {
417
418                             var result = '<a class="btn btn-default btn-xs" role="button" href="/cgi-bin/koha/erm/agreements.pl?op=add_form&amp;agreement_id='+ encodeURIComponent(row.agreement_id) +'"><i class="fa fa-pencil" aria-hidden="true"></i> '+_("Edit")+'</a>'+"\n";
419                             result += '<a class="btn btn-default btn-xs" role="button" href="/cgi-bin/koha/erm/agreements.pl?op=delete_confirm&amp;agreement_id='+ encodeURIComponent(row.agreement_id) +'"><i class="fa fa-trash" aria-hidden="true"></i> '+_("Delete")+'</a>';
420                             return result;
421
422                         },
423                         "searchable": false,
424                         "orderable": false
425                     }
426                 ]
427             }, columns_settings, 1);
428
429             $(".add_new_period").on("click", function(e){
430                 e.preventDefault();
431                 let new_period_block = $("fieldset.agreement_period:first").clone(1);
432                 new_period_block.find("input").val("");
433                 $(new_period_block).insertBefore(this);
434                 update_period_count();
435             });
436             $(".remove_period").on("click", function(e){
437                 e.preventDefault();
438                 $(this).parent().parent().remove();
439                 update_period_count();
440             });
441             update_period_count();
442         });
443
444         function update_period_count(){
445             $("fieldset.agreement_period").each(function(i, period){
446                 let id = i + 1;
447                 let remove_period_link = $(this).find(".remove_period");
448                 if ( id == 1 ) {
449                     $(remove_period_link).hide();
450                 } else {
451                     $(remove_period_link).show();
452                 }
453                 $(period).find(".period_count").text(id);
454                 $(period).find("input[name='period_unique_id']").val(id);
455
456                 let ended_on_input = $(period).find("input.ended_on");
457                 $(ended_on_input).attr("id", "ended_on_" + id);
458                 $(ended_on_input).attr("name", "ended_on_" + id);
459                 $(ended_on_input).flatpickr();
460
461                 let started_on_input = $(period).find("input.started_on");
462                 $(started_on_input).attr("name", "started_on_" + id);
463                 $(started_on_input).data("date_to", "ended_on_" + id);
464                 $(started_on_input).flatpickr();
465
466                 let cancellation_deadline_input = $(period).find("input.cancellation_deadline");
467                 $(cancellation_deadline_input).attr("name", "cancellation_deadline_" + id);
468                 $(cancellation_deadline_input).flatpickr();
469
470                 $(period).find(".notes").attr("name", "notes_" + id);
471             });
472         }
473
474     </script>
475 [% END %]
476 [% INCLUDE 'intranet-bottom.inc' %]