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