Bug 26486: Group edit buttons in reports toolbar

This patch modifies the reports interface to change the reports toolbar
in two ways:

1. The Edit, Duplicate, and Delete buttons are now combined into a
   button menu. My original idea was to have it be a split button, but
   the logic for handling various permissions made the template logic
   too convoluted.
2. The "Show SQL code" button is converted to a "Single toggle" button
   (https://getbootstrap.com/docs/3.3/javascript/#buttons-single-toggle).
   This type of button is specifically designed for this kind of
   interface element.

This patch includes indendation changes, so please diff accordingly.

To test, apply the patch and go to Reports -> Saved reports.

- Logged in as a user with Create and Delete report
  permissions:
  - View an SQL report. In the toolbar you should see an "Edit" button
    menu with three options: Edit, Duplicate, and Delete. Check that all
    work correctly, including a deletion JavaScript confirmation dialog.

- Logged in as a user with Create but not Delete report permissions, you
  should see an "Edit" button menu with two choices: Edit and Duplicate.

- Logged in as a user with Delete but not Create report permission (??)
  you should see only a standalone delete button.

- Logged in as a user with Execute report permission, run an SQL report.
  Test the "Show SQL code" button. The text should change to "Hide SQL
  code" and the button should be styled to look like its "pressed"
  state.

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
(cherry picked from commit 22afd8b4e7)

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Owen Leonard 2022-03-23 14:11:47 +00:00 committed by Lucas Gass
parent 7f64635a66
commit 8a855c86f3
2 changed files with 49 additions and 25 deletions

View file

@ -14,29 +14,49 @@
[% END %]
[% IF ( showsql || execute || editsql || save_successful ) %]
[% IF ( CAN_user_reports_create_reports ) %]
[% UNLESS ( editsql ) # Do not show edit button on edit page %]
<div class="btn-group">
<a id="editreport" class="btn btn-default" href="/cgi-bin/koha/reports/guided_reports.pl?reports=[% id | html %]&amp;phase=Edit%20SQL">
<i class="fa fa-pencil"></i> Edit
</a>
</div>
[% END %]
<div class="btn-group">
<a class="btn btn-default" title="Duplicate this saved report" href="/cgi-bin/koha/reports/guided_reports.pl?phase=Create report from existing&amp;report_id=[% id | uri %]">
<i class="fa fa-copy"></i> Duplicate
</a>
</div>
[% END %]
[% IF ( CAN_user_reports_delete_reports ) %]
[% IF ( CAN_user_reports_delete_reports && !CAN_user_reports_create_reports ) %]
<div class="btn-group">
<a class="delete btn btn-default" href="/cgi-bin/koha/reports/guided_reports.pl?reports=[% id | html %]&phase=Delete%20Saved">
<i class="fa fa-trash"></i> Delete
</a>
</div>
[% END %]
[% ELSE %]
[% IF ( CAN_user_reports_create_reports || CAN_user_reports_delete_reports ) %]
<div class="btn-group">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true"
aria-expanded="false">
<i class="fa fa-pencil"></i> Edit <span class="caret"></span>
</button>
<ul class="dropdown-menu">
[% IF ( CAN_user_reports_create_reports ) %]
[% UNLESS ( editsql ) # Do not show edit button on edit page %]
<li>
<a id="editreport" href="/cgi-bin/koha/reports/guided_reports.pl?reports=[% id | html %]&amp;phase=Edit%20SQL">
Edit
</a>
</li>
[% END %]
<li>
<a title="Duplicate this saved report" href="/cgi-bin/koha/reports/guided_reports.pl?phase=Create report from existing&amp;report_id=[% id | uri %]">
Duplicate
</a>
</li>
[% END %]
[% IF ( CAN_user_reports_delete_reports ) %]
<li>
<a class="delete" href="/cgi-bin/koha/reports/guided_reports.pl?reports=[% id | html %]&phase=Delete%20Saved">
Delete
</a>
</li>
[% END %]
</ul>
</div>
[% END %]
[% END %]
[% END %]
[% IF ( showsql || execute || editsql || save_successful ) %]
[% UNLESS ( errors ) # Unless there are errors saving a report %]
<div class="btn-group">
<a id="runreport" class="btn btn-default" href="/cgi-bin/koha/reports/guided_reports.pl?reports=[% id | html %]&amp;phase=Run%20this%20report">
@ -103,10 +123,9 @@
</ul>
</div>
<div class="btn-group">
<a class="btn btn-default toggle_sql" id="toggle_sql_hid" href="#"><i class="fa fa-eye"></i> Show SQL code</a>
</div>
<div class="btn-group">
<a class="btn btn-default toggle_sql" id="toggle_sql_vis" href="#" style="display:none;"><i class="fa fa-eye-slash"></i> Hide SQL code</a>
<button type="button" id="toggle_sql" class="btn btn-default toggle_sql" data-complete-text="<i class='fa fa-eye-slash'></i> [% t('Hide SQL code') | html %]" data-toggle="button" aria-pressed="false" autocomplete="off">
<i class="fa fa-eye"></i> Show SQL code
</button>
</div>
<div class="btn-group">
[% IF allresults.size %]

View file

@ -5,6 +5,7 @@
[% USE Koha %]
[% USE TablesSettings %]
[% USE JSON.Escape %]
[% PROCESS 'i18n.inc' %]
[% SET footerjs = 1 %]
[%- BLOCK area_name -%]
@ -1930,10 +1931,14 @@
});
[% END %]
$(".toggle_sql").click(function(){
$("#sql_output").toggle();
$("#toggle_sql_hid").toggle();
$("#toggle_sql_vis").toggle();
$("#toggle_sql").click(function(){
var sql_output = $("#sql_output");
sql_output.toggle();
if( sql_output.is(":visible") ){
$(this).button('complete');
} else {
$(this).button('reset');
}
if( !showsql ){
showsql = CodeMirror.fromTextArea(sql, {
lineNumbers: false,