Bug 26703: reports folder
[koha-ffzg.git] / koha-tmpl / intranet-tmpl / prog / en / modules / reports / guided_reports_start.tt
index 98716fd..a002e40 100644 (file)
 [% INCLUDE 'doc-head-open.inc' %]
 
 <title>
-    Koha &rsaquo; Reports &rsaquo; Guided reports wizard
     [%- IF ( saved1 ) -%]
-        &rsaquo; Saved reports
-    [%- ELSIF ( create ) -%]
-        &rsaquo; Create from SQL
-    [%- ELSIF ( showsql ) -%]
-        &rsaquo; Saved reports &rsaquo; SQL view
-    [%- ELSIF ( execute ) -%]
-        &rsaquo; Saved reports &rsaquo; Report [% name | html %] ([% id | html %])
-    [%- ELSIF ( editsql ) -%]
-        &rsaquo; Saved reports &rsaquo; Edit report [% reportname | html %] ([% id | html %])
-    [%- END -%]
+        Saved reports &rsaquo; [%- ELSIF ( create ) -%]
+        Create from SQL &rsaquo; [%- ELSIF ( showsql ) -%]
+        SQL view &rsaquo; Saved reports &rsaquo; [%- ELSIF ( execute ) -%]
+        Report [% name | html %] ([% id | html %]) &rsaquo; Saved reports &rsaquo; [%- ELSIF ( editsql ) -%]
+        Edit report [% reportname | html %] ([% id | html %]) &rsaquo; Saved reports &rsaquo; [%- END -%]
+
     [%- IF ( build1 ) -%]
-        &rsaquo; Build a report, step 1 of 6: Choose a module
-    [%- ELSIF ( build2 ) -%]
-        &rsaquo; Build a report, step 2 of 6: Pick a report type
-    [%- ELSIF ( build3 ) -%]
-        &rsaquo; Build a report, step 3 of 6: Select columns for display
-    [%- ELSIF ( build4 ) -%]
-        &rsaquo; Build a report, step 4 of 6: Select criteria to limit on
-    [%- ELSIF ( build5 ) -%]
-        &rsaquo; Build a report, step 5 of 6: Pick which columns to total
-    [%- ELSIF ( build6 ) -%]
-        &rsaquo; Build a report, step 6 of 6: Select how you want the report ordered
-    [%- END -%]
+        Build a report, step 1 of 6: Choose a module &rsaquo; [%- ELSIF ( build2 ) -%]
+        Build a report, step 2 of 6: Pick a report type &rsaquo; [%- ELSIF ( build3 ) -%]
+        Build a report, step 3 of 6: Select columns for display &rsaquo; [%- ELSIF ( build4 ) -%]
+        Build a report, step 4 of 6: Select criteria to limit on &rsaquo; [%- ELSIF ( build5 ) -%]
+        Build a report, step 5 of 6: Pick which columns to total &rsaquo; [%- ELSIF ( build6 ) -%]
+        Build a report, step 6 of 6: Select how you want the report ordered &rsaquo; [%- END -%]
+    Guided reports wizard &rsaquo; Reports &rsaquo; Koha
 </title>
 
 [% INCLUDE 'doc-head-close.inc' %]
@@ -53,6 +43,9 @@
     .CodeMirror {
         resize:  vertical;
     }
+    .cm-sqlParams {
+        color: #11917B;
+    }
     #mana_search_errortext { font-family: monospace; font-weight: bold; }
 </style>
 [% Asset.css("css/reports.css") | $raw %]
 [% INCLUDE 'header.inc' %]
 [% INCLUDE 'circ-search.inc' %]
 
-<div id="breadcrumbs">
-    <a href="/cgi-bin/koha/mainpage.pl">Home</a>
-    &rsaquo; <a href="/cgi-bin/koha/reports/reports-home.pl">Reports</a>
-    &rsaquo; <a href="/cgi-bin/koha/reports/guided_reports.pl">Guided reports wizard</a>
-
-    [% IF ( saved1 ) %]
-        &rsaquo; Saved reports
-    [% ELSIF ( create ) %]
-        &rsaquo; Create from SQL
-    [% ELSIF ( showsql ) %]
-        &rsaquo; <a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved">Saved reports</a> &rsaquo; [% reportname | html %] ([% id | html %])
-    [% ELSIF ( editsql ) %]
-        &rsaquo; <a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved">Saved reports</a> &rsaquo; <a href="/cgi-bin/koha/reports/guided_reports.pl?reports=[% id | uri %]&amp;phase=Show%20SQL">[% reportname | html %] ([% id | html %])</a> &rsaquo; Edit
-    [% ELSIF ( execute ) %]
-        &rsaquo; <a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved">Saved reports</a> &rsaquo; <a href="/cgi-bin/koha/reports/guided_reports.pl?reports=[% id | uri %]&amp;phase=Show%20SQL">[% name | html %] ([% id | html %])</a> &rsaquo; Run
-    [% ELSIF ( build1 || build2 || build3 || build4 || build5 || build6 ) %]
-        &rsaquo; <a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Build%20new">Build a report</a>
-        [% IF ( build1 ) %]
-            &rsaquo; Step 1 of 6: Choose a module
-        [% ELSIF ( build2 ) %]
-            &rsaquo; Step 2 of 6: Pick a report type
-        [% ELSIF ( build3 ) %]
-            &rsaquo; Step 3 of 6: Select columns for display
-        [% ELSIF ( build4 ) %]
-            &rsaquo; Step 4 of 6: Select criteria to limit on
-        [% ELSIF ( build5 ) %]
-            &rsaquo; Step 5 of 6: Pick which columns to total
-        [% ELSIF ( build6 ) %]
-            &rsaquo; Step 6 of 6: Select how you want the report ordered
+<nav id="breadcrumbs" aria-label="Breadcrumb" class="breadcrumb">
+    <ol>
+        <li>
+            <a href="/cgi-bin/koha/mainpage.pl">Home</a>
+        </li>
+        <li>
+            <a href="/cgi-bin/koha/reports/reports-home.pl">Reports</a>
+        </li>
+        <li>
+            <a href="/cgi-bin/koha/reports/guided_reports.pl">Guided reports wizard</a>
+        </li>
+
+        [% IF ( saved1 ) %]
+            <li>
+                <a href="#" aria-current="page">
+                    Saved reports
+                </a>
+            </li>
+        [% ELSIF ( create ) %]
+            <li>
+                <a href="#" aria-current="page">
+                    Create from SQL
+                </a>
+            </li>
+        [% ELSIF ( showsql ) %]
+            <li>
+                <a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved">Saved reports</a>
+            </li>
+            <li>
+                <a href="#" aria-current="page">
+                    [% reportname | html %] ([% id | html %])
+                </a>
+            </li>
+        [% ELSIF ( editsql ) %]
+            <li>
+                <a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved">Saved reports</a>
+            </li>
+            <li>
+                <a href="/cgi-bin/koha/reports/guided_reports.pl?reports=[% id | uri %]&amp;phase=Show%20SQL">[% reportname | html %] ([% id | html %])</a>
+            </li>
+            <li>
+                <a href="#" aria-current="page">
+                    Edit
+                </a>
+            </li>
+        [% ELSIF ( execute ) %]
+            <li>
+                <a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved">Saved reports</a>
+            </li>
+            <li>
+                <a href="/cgi-bin/koha/reports/guided_reports.pl?reports=[% id | uri %]&amp;phase=Show%20SQL">[% name | html %] ([% id | html %])</a>
+            </li>
+            <li>
+                <a href="#" aria-current="page">
+                    Run
+                </a>
+            </li>
+        [% ELSIF ( build1 || build2 || build3 || build4 || build5 || build6 ) %]
+            <li>
+                <a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Build%20new">Build a report</a>
+            </li>
+            <li>
+                <a href="#" aria-current="page">
+                    [% IF ( build1 ) %]
+                        Step 1 of 6: Choose a module
+                    [% ELSIF ( build2 ) %]
+                        Step 2 of 6: Pick a report type
+                    [% ELSIF ( build3 ) %]
+                        Step 3 of 6: Select columns for display
+                    [% ELSIF ( build4 ) %]
+                        Step 4 of 6: Select criteria to limit on
+                    [% ELSIF ( build5 ) %]
+                        Step 5 of 6: Pick which columns to total
+                    [% ELSIF ( build6 ) %]
+                        Step 6 of 6: Select how you want the report ordered
+                    [% END %]
+                </a>
         [% END %]
-    [% END %]
-</div> <!-- /#breadcrumbs -->
+    </ol>
+</nav> <!-- /#breadcrumbs -->
 
 <div id="update_sql" class="modal" tabindex="-1" role="dialog" aria-labelledby="update_sql_label" aria-hidden="true">
     <div class="modal-dialog">
                                                 <th>Subgroup</th>
                                                 <th>Notes</th>
                                                 <th>Author</th>
-                                                <th class="title-string">Creation date</th>
-                                                <th class="title-string">Last edit</th>
-                                                <th class="title-string">Last run</th>
+                                                <th>Creation date</th>
+                                                <th>Last edit</th>
+                                                <th>Last run</th>
                                                 <th class="report_public">Public</th>
                                                 <th class="report_json_url">JSON URL</th>
                                                 [% IF (usecache) %]
                                                 [% ELSE %]
                                                     <th class="hidden">&nbsp;</th>
                                                 [% END %]
-                                                <th class="NoSort">Actions</th>
+                                                <th class="NoSort noExport">Actions</th>
                                             </tr>
                                         </thead>
                                         <tbody>
                                                         [% END %]
                                                         ([% savedreport.borrowernumber | html %])
                                                     </td>
-                                                    <td>
-                                                        <span title="[% savedreport.date_created | html %]">[% savedreport.date_created | $KohaDates %]</span>
+                                                    <td data-order="[% savedreport.date_created | html %]">
+                                                        [% savedreport.date_created | $KohaDates %]
                                                     </td>
-                                                    <td>
-                                                        <span title="[% savedreport.last_modified | html %]">[% savedreport.last_modified | $KohaDates  with_hours => 1 %]</span>
+                                                    <td data-order="[% savedreport.last_modified | html %]">
+                                                        [% savedreport.last_modified | $KohaDates  with_hours => 1 %]
                                                     </td>
-                                                    <td>
-                                                        <span title="[% savedreport.last_run | html %]">[% savedreport.last_run | $KohaDates  with_hours => 1 %]</span>
+                                                    <td data-order="[% savedreport.last_run | html %]">
+                                                        [% savedreport.last_run | $KohaDates  with_hours => 1 %]
                                                     </td>
                                                     <td class="report_public">
                                                         [% IF (savedreport.public) %]
                                                                class="btn btn-default btn-xs dropdown-toggle" id="reportactions[% savedreport.id | html %]" role="button" data-toggle="dropdown"
                                                                href="#"><b class="caret"></b></a>
                                                             <ul class="dropdown-menu pull-right" role="menu" aria-labelledby="reportactions[% savedreport.id | html %]">
-                                                                <li><a href="/cgi-bin/koha/reports/guided_reports.pl?reports=[% savedreport.id | uri %]&amp;phase=Show%20SQL"><i class="fa fa-search"></i> Show</a></li>
+                                                                <li><a href="/cgi-bin/koha/reports/guided_reports.pl?reports=[% savedreport.id | uri %]&amp;phase=Show%20SQL"><i class="fa fa-search"></i> View</a></li>
+                                                                <li>
+                                                                    <a href="/cgi-bin/koha/reports/guided_reports.pl?reports=[% savedreport.id | uri %]&phase=Show%20SQL" class="preview_sql" data-reportid="[% savedreport.id | html %]">
+                                                                        <i class="fa fa-eye"></i> Preview SQL
+                                                                    </a>
+                                                                </li>
                                                                 [% IF ( CAN_user_reports_create_reports ) %]
                                                                     <li><a href="/cgi-bin/koha/reports/guided_reports.pl?reports=[% savedreport.id | uri %]&amp;phase=Edit%20SQL"><i class="fa fa-pencil"></i> Edit</a></li>
                                                                     <li><a title="Duplicate this saved report" href="/cgi-bin/koha/reports/guided_reports.pl?phase=Create report from existing&amp;report_id=[% savedreport.id | uri %]"><i class="fa fa-copy"></i> Duplicate</a></li>
                                                                 [% END %]
                                                             </ul>
                                                         </div>
+                                                        <input type="hidden" id="previewSql[% savedreport.id | html %]" value="[% savedreport.savedsql | html %]" data-title="[% savedreport.report_name | html %]" />
                                                     </td>
                                                 </tr>
                                             [% END %]
                                                 <label for="sql_params[% loop.count | html %]">[% sql_param.entry | html %]: </label>
                                                 <input id="sql_params[% loop.count | html %]" type="text" name="sql_params" />
                                             </li>
+                                        [% ELSIF ( sql_param.input == 'textarea' ) %]
+                                            <li>
+                                                <label for="sql_params[% loop.count | html %]">[% sql_param.entry | html %]: </label>
+                                                <textarea id="sql_params[% loop.count | html %]" name="sql_params" rows="5"></textarea>
+                                            </li>
                                         [% ELSE %]
                                             <li>
                                                 <label for="sql_params_[% sql_param.labelid | html %]">[% sql_param.entry | html %]:</label>
-                                                <select name="[%- sql_param.input.name | html -%]" tabindex="1"  size="1" id="[%- sql_param.input.id | html -%]">
+                                                <select name="[%- sql_param.input.name | html -%]" tabindex="1"  id="[%- sql_param.input.id | html -%]">
                                                     [% IF (sql_param.include_all) %]
                                                         <option value="%">All</option>
                                                     [% END %]
                                     [%- FOREACH result IN results %]
                                         [%- FOREACH cells IN result.cells %]
                                             [%- place = loop.index %]
-                                            [%- IF header_row.$place.cell == $batch_type || header_types.item(header_row.$place.cell) == $batch_type %]
+                                            [%- IF header_row.$place.cell == batch_type || header_types.item(header_row.$place.cell) == batch_type %]
 [%# We must not add whitespace to the cardnumbers %][% cells.cell | html %]
                                             [%- END %]
                                         [%- END %]
                             [% END %]
                         </table>
                     [% END %]
+                    <div class="pages">[% pagination_bar | $raw %]</div>
 
                     [% INCLUDE 'chart.inc' %]
 
                 [% INCLUDE 'guided-reports-view.inc' %]
             </aside>
         </div> <!-- /.col-sm-2.col-sm-pull-10 -->
-     </div> <!-- /.row -->
+    </div> <!-- /.row -->
 
 [% MACRO jsinclude BLOCK %]
     [% Asset.js("js/charts.js") | $raw %]
         [% INCLUDE 'columns_settings.inc' %]
     [% END %]
     [% Asset.js( "lib/codemirror/codemirror.min.js" ) | $raw %]
+    [% Asset.js( "lib/codemirror/overlay.min.js" ) | $raw %]
     [% Asset.js( "lib/codemirror/sql.min.js" ) | $raw %]
     [% Asset.js( "js/mana.js" ) | $raw %]
     <script>
             }
         }
 
+        /* overlay a syntax-highlighting definition on top of the existing sql one */
+        CodeMirror.defineMode("sqlParams", function(config, parserConfig) {
+            var sqlParamsOverlay = {
+                token: function(stream, state) {
+                var ch;
+                if (stream.match("<<")) {
+                    while ((ch = stream.next()) != null)
+                    if (ch == ">" && stream.next() == ">") {
+                        stream.eat(">");
+                        return "sqlParams";
+                    }
+                }
+                while (stream.next() != null && !stream.match("<<", false)) {}
+                return null;
+                }
+            };
+            return CodeMirror.overlayMode(CodeMirror.getMode(config, parserConfig.backdrop || "text/x-sql"), sqlParamsOverlay);
+        });
+
         var MSG_CONFIRM_DELETE = _("Are you sure you want to delete this report? This cannot be undone.");
         var group_subgroups = {};
         [% FOREACH group IN groups_with_subgroups %]
         [% END %]
 
         [% IF ( create || editsql || save ) %]
+
             var editor = CodeMirror.fromTextArea(sql, {
                 lineNumbers: true,
-                mode: "text/x-sql",
+                mode: "sqlParams", /* text/x-sql plus custom sqlParams configuration */
                 lineWrapping: true,
                 smartIndent: false
             });
         [% IF ( showsql ) %]
             var editor = CodeMirror.fromTextArea(sql, {
                 lineNumbers: false,
-                mode: "text/x-sql",
+                mode: "sqlParams", /* text/x-sql plus custom sqlParams configuration */
                 lineWrapping: true,
                 readOnly: true
             });
                     'sPaginationType': 'full',
                     'aaSorting': [[ 1, "asc" ]],
                     'aoColumnDefs': [
-                        { 'bSearchable': false, 'aTargets': [3] },
-                        { "aTargets": [ 1, 2 ], "sType": "natural"  },
                         { "visible": false, "aTargets" : [ "hidden" ] }
                     ],
                     'oLanguage': {
                 e.preventDefault();
                 addToList();
             });
+
+            $("body").on("click", ".preview_sql", function(e){
+                e.preventDefault();
+                var reportid = $(this).data("reportid");
+                previewSql( reportid );
+            });
         });
 
         function tabsInit( ui, rtable ){
                             ],
                             "aoColumnDefs": [
                                 { 'bSortable': false, "bSearchable": false, 'aTargets': [ 'NoSort' ] },
-                                { "sType": "title-string", "aTargets" : [ "title-string" ] },
                                 { 'sType': "anti-the", 'aTargets' : [ 'anti-the'] }
                             ]
                         }));
             window.open(url, 'Add_to_virtualshelf', 'width=500, height=400, toolbar=false, scrollbars=yes');
             return false;
         }
+
+        // Adapted from https://gist.github.com/jnormore/7418776
+        function previewSql(reportid) {
+            var yes_label = "";
+            var no_label = "";
+            var message = $("#previewSql" + reportid ).val();
+            var title = $("#previewSql" + reportid ).data("title");
+            if( $("#preview-sql-modal").length > 0) {
+                $("#preview-sql-modal").remove();
+            }
+            $("body").append('<div id="preview-sql-modal" tabindex="-1" role="dialog" aria-hidden="true" class="modal">\
+                <div class="modal-dialog">\
+                    <div class="modal-content">\
+                        <div class="modal-header" style="min-height:40px;">\
+                            <button type="button" class="closebtn" data-dismiss="modal" aria-label="Close">\
+                                <span aria-hidden="true">×</span>\
+                            </button>\
+                            <h4 class="modal-title">' + title + '</h4>\
+                        </div>\
+                        <div class="modal-body"><textarea id="code' + reportid + '">' + message + '</textarea>\
+                        <div class="modal-footer">\
+                            <a id="preview-modal-editreport" class="btn btn-default" href="/cgi-bin/koha/reports/guided_reports.pl?reports=' + reportid + '&amp;phase=Edit%20SQL"><i class="fa fa-pencil"></i> Edit</a>\
+                            <a id="preview-modal-duplicate" class="btn btn-default" href="/cgi-bin/koha/reports/guided_reports.pl?phase=Create report from existing&amp;report_id=' + reportid + '"><i class="fa fa-copy"></i> Duplicate</a>\
+                            <a id="preview-modal-duplicate" class="btn btn-default" href="/cgi-bin/koha/tools/scheduler.pl?id=' + reportid + '"><i class="fa fa-clock-o"></i> Schedule</a>\
+                            <a id="preview-modal-delete" class="delete btn btn-default" href="/cgi-bin/koha/reports/guided_reports.pl?reports=' + reportid + '&amp;phase=Delete%20Saved"><i class="fa fa-trash"></i> Delete</a>\
+                            <a id="preview-modal-runreport" class="btn btn-default" href="/cgi-bin/koha/reports/guided_reports.pl?reports=' + reportid + '&amp;phase=Run%20this%20report"><i class="fa fa-play"></i> Run report</a>\
+                            <a href="#" id="preview-sql-modal-cancel" data-dismiss="modal" class="btn btn-default"><i class="fa fa-remove" aria-hidden="true"></i> Close</a>\
+                        </div>\
+                    </div>\
+                </div>\
+            </div>');
+
+            $("#preview-sql-modal").modal('show');
+            CodeMirror.fromTextArea( document.getElementById("code" + reportid ), {
+                lineNumbers: false,
+                mode: "text/x-sql",
+                lineWrapping: true,
+                readOnly: true
+            });
+        }
     </script>
 [% END %]