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