Bug 33076: Add context to "Quotes"
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / tools / quotes.tt
1 [% USE raw %]
2 [% USE Asset %]
3 [% PROCESS 'i18n.inc' %]
4 [% SET footerjs = 1 %]
5 [% INCLUDE 'doc-head-open.inc' %]
6 <title>Quote editor &rsaquo; Tools &rsaquo; Koha</title>
7 [% INCLUDE 'doc-head-close.inc' %]
8 [% Asset.css("css/quotes.css") | $raw %]
9 </head>
10
11 <body id="tools_quotes" class="tools">
12 [% WRAPPER 'header.inc' %]
13     [% INCLUDE 'cat-search.inc' %]
14 [% END %]
15
16 [% WRAPPER 'sub-header.inc' %]
17 <nav id="breadcrumbs" aria-label="Breadcrumb" class="breadcrumb">
18     <ol>
19         <li>
20             <a href="/cgi-bin/koha/mainpage.pl">Home</a>
21         </li>
22         <li>
23             <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a>
24         </li>
25         <li>
26             <a href="#" aria-current="page">
27                 Quote editor
28             </a>
29         </li>
30     </ol>
31 </nav>
32 [% END %]
33
34 <div class="main container-fluid">
35     <div class="row">
36         <div class="col-sm-10 col-sm-push-2">
37             <main>
38
39 [% FOREACH m IN messages %]
40     <div class="dialog [% m.type | html %]" id="quote_action_result_dialog">
41         [% SWITCH m.code %]
42         [% CASE 'error_on_update' %]
43             <span>An error occurred when updating this quote. Perhaps it already exists</span>
44         [% CASE 'error_on_insert' %]
45             <span>An error occurred when adding this quote</span>
46         [% CASE 'success_on_update' %]
47             <span>Quote updated successfully</span>
48         [% CASE 'success_on_insert' %]
49             <span>Quote added successfully</span>
50         [% CASE %]
51             <span>[% m.code | html %]</span>
52         [% END %]
53     </div>
54 [% END %]
55
56     <div class="dialog message" id="quote_delete_success" style="display: none;"></div>
57     <div class="dialog alert"   id="quote_delete_error"   style="display: none;"></div>
58
59 [% IF op == 'list' %]
60     <div id="toolbar" class="btn-toolbar">
61         <a class="btn btn-default" id="newquote" href="/cgi-bin/koha/tools/quotes.pl?op=add_form"><i class="fa fa-plus"></i> New quote</a>
62         <a class="btn btn-default" id="import_quotes" href="/cgi-bin/koha/tools/quotes-upload.pl"><i class="fa fa-folder-open"></i> Import quotes</a>
63     </div>
64 [% END %]
65
66 [% IF op == 'add_form' %]
67     <h1>[% IF quote %]Modify quote[% ELSE %]New quote[% END %]</h1>
68     <form action="/cgi-bin/koha/tools/quotes.pl" id="Aform" name="Aform" class="validated" method="post">
69         <fieldset class="rows">
70             <input type="hidden" name="op" value="add_validate" />
71             <ol>
72                 <li>
73                     <label for="text" class="required">Source: </label>
74                     <input type="text" name="source" id="source" value="[% quote.source | html %]" class="required" required="required" />
75                     <span class="required">Required</span>
76                 </li>
77                 <li>
78                     <label for="text" class="required">Text: </label>
79                     <textarea name="text" id="text" class="required" required="required" />[% quote.text | html %]</textarea>
80                     <span class="required">Required</span>
81                 </li>
82             </ol>
83         </fieldset>
84         <fieldset class="action">
85             <input type="hidden" name="id" value="[% quote.id | html %]" />
86             <input type="submit" class="btn btn-primary" value="Submit" />
87             <a class="cancel" href="/cgi-bin/koha/tools/quotes.pl">Cancel</a>
88         </fieldset>
89     </form>
90 [% END %]
91
92 [% IF op == 'delete_confirm' %]
93     <div class="dialog alert">
94         <form action="/cgi-bin/koha/tools/quotes.pl" method="post">
95             <h1>Are you sure you want to delete the following quote?</h1>
96             [% quote.source | html %] - [% quote.text | html %]
97             <input type="hidden" name="op" value="delete_confirmed" />
98             <input type="hidden" name="id" value="[% quote.id | html %]" />
99             <button type="submit" class="approve"><i class="fa fa-fw fa-check"></i> Yes, delete</button>
100         </form>
101         <form action="/cgi-bin/koha/tools/quotes.pl" method="get">
102             <button type="submit" class="deny"><i class="fa fa-fw fa-remove"></i> No, do not delete</button>
103         </form>
104     </div>
105 [% END %]
106
107 [% IF op == 'list' %]
108     <h1>[% tp('citations', 'Quotes') | html %]</h1>
109     [% IF quotes_count > 0 %]
110         <div class="page-section">
111             <table id="quotes">
112                 <thead>
113                     <tr>
114                         <th>ID</th>
115                         <th>Source</th>
116                         <th>Text</th>
117                         <th>Last display</th>
118                         <th data-class-name="actions" class="noExport">Actions</th>
119                     </tr>
120                 </thead>
121             </table>
122         </div> <!-- /.page-section -->
123     [% ELSE %]
124         <div class="dialog message">There are no quotes defined. <a href="/cgi-bin/koha/tools/quotes.pl?op=add_form">Start defining quotes</a>.</div>
125     [% END %]
126
127     <div id="delete_confirm_modal" class="modal" tabindex="-1" role="dialog" aria-labelledby="delete_confirm_modal_label" aria-hidden="true">
128         <div class="modal-dialog">
129             <div class="modal-content">
130                 <div class="modal-header">
131                     <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button>
132                     <h3 id="delete_confirm_modal_label">Delete quote</h3>
133                 </div>
134                 <div class="modal-body">
135                     <div id="delete_confirm_dialog"></div>
136                 </div>
137                 <div class="modal-footer">
138                     <a href="#" class="btn btn-default" id="delete_confirm_modal_button" role="button" data-toggle="modal">Delete</a>
139                     <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">Close</button>
140                 </div>
141             </div> <!-- /.modal-content -->
142         </div> <!-- /.modal-dialog -->
143     </div> <!-- #delete_confirm_modal -->
144 [% END %]
145
146             </main>
147         </div> <!-- /.col-sm-10.col-sm-push-2 -->
148
149         <div class="col-sm-2 col-sm-pull-10">
150             <aside>
151                 [% INCLUDE 'tools-menu.inc' %]
152             </aside>
153         </div> <!-- /.col-sm-2.col-sm-pull-10 -->
154      </div> <!-- /.row -->
155
156 [% MACRO jsinclude BLOCK %]
157     [% Asset.js("js/tools-menu.js") | $raw %]
158     [% INCLUDE 'datatables.inc' %]
159
160     <script>
161         $(document).ready(function() {
162
163             var quotes_url = '/api/v1/quotes';
164             var quotes = $("#quotes").kohaTable({
165                 "ajax": {
166                     "url": quotes_url
167                 },
168                 'emptyTable': '<div class="dialog message">'+_("There are no quotes defined.")+' <a href="/cgi-bin/koha/tools/quotes.pl?op=add_form">'+_("Start defining quotes")+'</a>.</div>',
169                 "columnDefs": [ {
170                     "targets": [0,1,2,3],
171                     "render": function (data, type, row, meta) {
172                         if ( type == 'display' ) {
173                             if ( data != null ) {
174                                 return data.escapeHtml();
175                             }
176                             else {
177                                 return "";
178                             }
179                         }
180                         return data;
181                     }
182                 } ],
183                 "columns": [
184                     {
185                         "data": "quote_id",
186                         "searchable": true,
187                         "orderable": true
188                     },
189                     {
190                         "data": "source",
191                         "searchable": true,
192                         "orderable": true
193                     },
194                     {
195                         "data": "text",
196                         "searchable": true,
197                         "orderable": true
198                     },
199                     {
200                         "data": "displayed_on",
201                         "render": function(data, type, row, meta) {
202                             return $datetime(row.displayed_on);
203                         },
204                         "searchable": true,
205                         "orderable": true
206                     },
207                     {
208                         "data": function( row, type, val, meta ) {
209
210                             var result = '<a class="btn btn-default btn-xs" href="/cgi-bin/koha/tools/quotes.pl?op=add_form&amp;id='+encodeURIComponent(row.quote_id)+'" role="button"><i class="fa fa-pencil" aria-hidden="true"></i> '+_("Edit")+'</a>';
211                             result += '<form action="/cgi-bin/koha/tools/quotes.pl" method="post">';
212                             result += '<input type="hidden" name="id" value="'+row.quote_id.escapeHtml()+'" />'+"\n";
213
214                             result += '<a class="btn btn-default btn-xs delete_quote" role="button" href="#" data-toggle="modal" data-target="#delete_confirm_modal" data-quote-id="'+ encodeURIComponent(row.quote_id) +'"><i class="fa fa-trash" aria-hidden="true"></i> '+_("Delete")+'</a>';
215
216                             return result;
217                         },
218                         "searchable": false,
219                         "orderable": false
220                     },
221                 ]
222             });
223
224             $('#quotes').on( "click", '.delete_quote', function () {
225                 var quote_id   = decodeURIComponent($(this).data('quote-id'));
226
227                 $("#delete_confirm_dialog").html(
228                     _("You are about to delete the quote #%s.").format(quote_id)
229                 );
230
231                 $("#delete_confirm_modal_button").unbind("click").on( "click", function () {
232                     $.ajax({
233                         method: "DELETE",
234                         url: "/api/v1/quotes/"+quote_id
235                     }).success(function() {
236                         $("#delete_confirm_modal").modal('hide');
237                         quotes.api().ajax.reload(function (data) {
238                             $("#quote_action_result_dialog").hide();
239                             $("#quote_delete_success").html(_("Quote #%s deleted successfully.").format(quote_id)).show();
240                         });
241                     }).error(function () {
242                         $("#quote_delete_error").html(_("Error deleting quote #%s. Check the logs.").format(quote_id)).show();
243                     });
244                 });
245             });
246
247         });
248     </script>
249 [% END %]
250
251 [% INCLUDE 'intranet-bottom.inc' %]