Bug 15451: Rewrite the csv profile tool script
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / tools / csv-profiles.tt
blob5fe6a9152d707ad408958e836995db8725bfc6db
1 [% INCLUDE 'doc-head-open.inc' %]<title>Koha &rsaquo; Tools &rsaquo; CSV export profiles</title>[% INCLUDE 'doc-head-close.inc' %]
2 <script type="text/javascript">
3 //<![CDATA[
4 function reloadPage(p) {
5     var id = p.value;
6     if (id != 0) { document.location = "/cgi-bin/koha/tools/csv-profiles.pl?op=add_form&amp;export_format_id=" + id; }
8      $(document).ready(function() {
9         $("#type").change(function(){
10             if ( $(this).find("option:selected").val() == "marc" ) {
11                 $("li.marc_specific").show();
12                 $("#marc_content").attr("required", "required");
13                 $("li.sql_specific").hide();
14                 $("#sql_content").removeAttr("required");
15             } else {
16                 $("li.marc_specific").hide();
17                 $("#marc_content").removeAttr("required");
18                 $("li.sql_specific").show();
19                 $("#sql_content").attr("required", "required");
20             }
21         });
22         $("#type").change();
23      });
24 //]]>
25 </script>
26 </head>
28 <body id="tools_csv-profiles" class="tools">
29 [% INCLUDE 'header.inc' %]
30 [% INCLUDE 'cat-search.inc' %]
32 <div id="breadcrumbs">
33     <a href="/cgi-bin/koha/mainpage.pl">Home</a>
34     &rsaquo; <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a>
35     &rsaquo; CSV export profiles
36 </div>
38 <div id="doc3" class="yui-t2">
39    <div id="bd">
40     <div id="yui-main">
41     <div class="yui-b">
43 [% FOR m IN messages %]
44     <div class="dialog [% m.type %]">
45         [% SWITCH m.code %]
46         [% CASE 'error_on_update' %]
47             An error occurred when updating this CSV profile. Perhaps it already exists.
48         [% CASE 'error_on_insert' %]
49             An error occurred when adding this CSV profile.
50         [% CASE 'error_on_delete' %]
51             An error occurred when deleting this CSV profile. Check the logs.
52         [% CASE 'success_on_update' %]
53             CSV profile updated successfully.
54         [% CASE 'success_on_insert' %]
55             CSV profile added successfully.
56         [% CASE 'success_on_delete' %]
57             CSV profile deleted successfully.
58         [% CASE 'already_exists' %]
59             This CSV profile already exists.
60         [% CASE %]
61             [% m.code %]
62         [% END %]
63     </div>
64 [% END %]
66 [% BLOCK list_separator_options %]
67     [% IF selected_separator == ',' %]
68         <option value="," selected="selected">Comma (,)</option>
69     [% ELSE %]
70         <option value=",">Comma (,)</option>
71     [% END %]
72     [% IF selected_separator == '|' %]
73         <option value="|" selected="selected">Pipe (|)</option>
74     [% ELSE %]
75         <option value="|">Pipe (|)</option>
76     [% END %]
77     [% IF selected_separator == ';' %]
78         <option value=";" selected="selected">Semi-colon (;)</option>
79     [% ELSE %]
80         <option value=";">Semi-colon (;)</option>
81     [% END %]
82     [% IF selected_separator == '#' %]
83         <option value="#" selected="selected">Sharp (#)</option>
84     [% ELSE %]
85         <option value="#">Sharp (#)</option>
86     [% END %]
87     [% IF selected_separator == ' ' %]
88         <option value=" " selected="selected">Space ( )</option>
89     [% ELSE %]
90         <option value=" ">Space ( )</option>
91     [% END %]
92     [% IF selected_separator == '\t' %]
93         <option value="\t" selected="selected">Tabulation (\t)</option>
94     [% ELSE %]
95         <option value="\t">Tabulation (\t)</option>
96     [% END %]
97     [% IF selected_separator == '\n' %]
98         <option value="\n" selected="selected">New line (\n)</option>
99     [% ELSE %]
100         <option value="\n">New line (\n)</option>
101     [% END %]
102 [% END %]
104 [% IF op == 'add_form' %]
105     [% IF csv_profile %]
106         <h1>Modify a CSV profile</h1>
107     [% ELSE %]
108         <h1>New CSV profile</h1>
109     [% END %]
111     <form action="/cgi-bin/koha/tools/csv-profiles.pl" class="validated" method="post">
112         <input type="hidden" name="op" value="add_validate" />
113         <input type="hidden" name="export_format_id" value="[% csv_profile.export_format_id %]" />
114         <fieldset class="rows">
115             <ol>
116                 [% IF csv_profile %]
117                     <li><span class="label">Profile ID: </span>[% csv_profile.export_format_id %]</li>
118                 [% END %]
119                 <li>
120                     <label for="profile" class="required">Profile name: </label>
121                     <input type="text" name="profile" id="profile" value="[% csv_profile.profile %]" class="required">
122                     <span class="required">Required</span>
123                 </li>
124                 <li>
125                     <label for="type" class="required">Profile type: </label>
126                     <select id="type" name="type">
127                         [% IF csv_profile.type == 'sql' %]
128                             <option value="marc">MARC</option>
129                             <option value="sql" selected="selected">SQL</option>
130                         [% ELSE %]
131                             <option value="marc" selected="selected">MARC</option>
132                             <option value="sql">SQL</option>
133                         [% END %]
134                     </select>
135                     <span class="required">Required</span>
136                 </li>
137                 <li>
138                     <label for="description">Profile description: </label>
139                     <textarea cols="50" rows="2" name="description" id="description">[% csv_profile.description %]</textarea>
140                 </li>
141                 <li>
142                     <label for="csv_separator">CSV separator: </label>
143                     <select name="csv_separator" id="csv_separator">
144                         [% PROCESS list_separator_options selected_separator=csv_profile.csv_separator || ',' %]
145                     </select>
146                 </li>
148                 <li class="marc_specific">
149                     <label for="field_separator">Field separator: </label>
150                     <select name="field_separator" id="field_separator">
151                         [% PROCESS list_separator_options selected_separator=csv_profile.field_separator || '#' %]
152                     </select>
153                 </li>
155                 <li class="marc_specific"><label for="subfield_separator">Subfield separator: </label>
156                     <select name="subfield_separator" id="subfield_separator">
157                         [% PROCESS list_separator_options selected_separator=csv_profile.subfield_separator || '|'%]
158                     </select>
159                 </li>
161                 <li class="marc_specific"><label for="encoding">Encoding: </label>
162                     <select name="encoding" id="encoding">
163                         [% FOREACH encoding IN encodings %]
164                             [% IF csv_profile.encoding == encoding
165                                 OR NOT csv_profile AND encoding == 'utf8' %]
166                                 <option selected="selected">[% encoding %]</option>
167                             [% ELSE %]
168                                 <option>[% encoding %]</option>
169                             [% END %]
170                         [% END %]
171                     </select>
172                 </li>
174                 <li class="marc_specific">
175                     <label for="marc_content" class="required">Profile MARC fields: </label>
176                     <textarea cols="50" rows="2" name="marc_content" id="marc_content">[% csv_profile.content %]</textarea>
177                     <span class="required">Required</span>
178                     <p>You have to define which fields or subfields you want to export, separated by pipes.</p>
179                     <p>You can also use your own headers (instead of the ones from Koha) by prefixing the field number with an header, followed by the equal sign.</p>
180                     <p>Example: Personal name=200|Entry element=210$a|300|009</p>
181                     <p>You can use Template Toolkit tags too. See the help page for more information.</p>
182                 </li>
184                 <li class="sql_specific">
185                   <label for="sql_content" class="required">Profile SQL fields: </label>
186                   <textarea cols="50" rows="2" name="sql_content" id="sql_content">[% csv_profile.content %]</textarea>
187                   <p>You have to define which fields you want to export, separated by pipes.</p>
188                   <p>You can also use your own headers (instead of the ones from Koha) by prefixing the field name with an header, followed by the equal sign.</p>
189                   <p>Example: Name=subscription.name|Title=subscription.title|Issue number=serial.serialseq</p>
190                 </li>
191             </ol>
192         </fieldset>
193         <fieldset class="action">
194             <input type="submit" value="Submit" />
195             <a class="cancel" href="/cgi-bin/koha/tools/csv-profiles.pl">Cancel</a>
196         </fieldset>
197     </form>
198 [% END %]
200 [% IF op == 'delete_confirm' %]
201     <div class="dialog alert">
202         <h3>Delete CSV Profile "[% csv_profile.profile %]?"</h3>
203         <form action="/cgi-bin/koha/tools/csv-profiles.pl" method="post">
204             <input type="hidden" name="op" value="delete_confirmed" />
205             <input type="hidden" name="export_format_id" value="[% csv_profile.export_format_id %]" />
206             <input type="submit" class="approve" value="Yes, delete" />
207         </form>
208         <form action="/cgi-bin/koha/tools/csv-profiles.pl" method="get">
209             <input type="submit" class="deny" value="No, do not Delete" />
210         </form>
211     </div>
212 [% END %]
214 [% IF op == 'list' %]
216     <div id="toolbar" class="btn-toolbar">
217         <a class="btn btn-small" id="newcsvprofile" href="/cgi-bin/koha/tools/csv-profiles.pl?op=add_form"><i class="fa fa-plus"></i> New CSV profile</a>
218     </div>
220     <h2>CSV profiles</h2>
222     [% IF csv_profiles%]
223         <table id="table_csv_profiles">
224             <thead>
225                 <th>CSV profile ID</th>
226                 <th>Name</th>
227                 <th>Description</th>
228                 <th>Content</th>
229                 <th>CSV separator</th>
230                 <th>CSV type</th>
231                 <th>&nbsp;</th>
232                 <th>&nbsp;</th>
233             </thead>
234             <tbody>
235                 [% FOREACH csv_profile IN csv_profiles %]
236                 <tr>
237                     <td>[% csv_profile.export_format_id %]</td>
238                     <td>[% csv_profile.profile %]</td>
239                     <td>[% csv_profile.description %]</td>
240                     <td>[% csv_profile.content %]</td>
241                     <td>[% csv_profile.csv_separator %]</td>
242                     [% IF csv_profile.type == 'sql' %]
243                         <td>SQL</td>
244                     [% ELSE %]
245                         <td>MARC</td>
246                     [% END %]
247                     <td><a href="/cgi-bin/koha/tools/csv-profiles.pl?op=add_form&amp;export_format_id=[% csv_profile.export_format_id %]">Edit</a></td>
248                     <td><a href="/cgi-bin/koha/tools/csv-profiles.pl?op=delete_confirm&amp;export_format_id=[% csv_profile.export_format_id %]">Delete</a></td>
249                 </tr>
250                 [% END %]
251             </tbody>
252         </table>
253     [% ELSE %]
254         There is no CSV profile defined. <a href="/cgi-bin/koha/tools/csv-profiles.pl?op=add_form">Create a new CSV profile</a>.
255     [% END %]
256 [% END %]
258 </div>
259 </div>
260 <div class="yui-b noprint">
261 [% INCLUDE 'tools-menu.inc' %]
262 </div>
263 </div>
264 [% INCLUDE 'intranet-bottom.inc' %]