Bug 29019: Unable to delete HTML customization
authorOwen Leonard <oleonard@myacpl.org>
Thu, 23 Sep 2021 21:14:52 +0000 (21:14 +0000)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Tue, 28 Sep 2021 13:12:45 +0000 (15:12 +0200)
This patch makes some corrections to additional contents to allow
content to be deleted. The wrong parameter was being passed to the
script. The script was also not handling multiple deletions correctly.

The patch also adds a "category" parameter to the delete operation so
that the page is redirected correctly.

The patch also changes some strings which referred to "news"
referencing operations which might be performed on news or on HTML
customizations, e.g.:

"Are you sure you want to delete the selected content?" instead of "Are
you sure you want to delete the selected news?"

To test, apply the patch and go to Tools -> News.

- Create multiple news items if necessary.
- Test the "Delete" button corresponding to a single news item:
  - Clicking the button should ask you to confirm.
  - Check that the wording of the message is correct.
  - After confirming the news item should be deleted.
  - Ideally, test on news items which are on the second page of the
    DataTable of news items.
- Test the process of deleting multiple news items at once:
  - Check the checkbox next to multiple items.
  - Click the "Delete selected" button at the bottom of the page.
  - Check that the wording of the confirmation message is correct.
  - After you confirm, the items should be deleted.
- Repeat these tests under Tools -> HTML customizations to confirm that
  redirects work correctly. After deleting an HTML customization you
  should be redirected back to the list of HTML customizations.

Signed-off-by: Caroline Cyr La Rose <caroline.cyr-la-rose@inlibro.com>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
koha-tmpl/intranet-tmpl/prog/en/modules/tools/additional-contents.tt
tools/additional-contents.pl

index c693a68..21dd0ee 100644 (file)
                                 </ul>
                             </div>
                             <div class="btn-group">
-                                <a href="/cgi-bin/koha/tools/additional-contents.pl?op=del&amp;ids=[% c.idnew | uri %]" class="delete_news btn btn-default btn-xs"><i class="fa fa-trash"></i> Delete</a>
+                                <a href="#" class="delete_news btn btn-default btn-xs" data-idnew="[% c.idnew | html %]"><i class="fa fa-trash"></i> Delete</a>
                             </div>
                         </td>
                     </tr>
                     [% END %]
                 </tbody>
             </table>
-            <input type="hidden" name="op" value="del" />
+            <input type="hidden" name="op" value="delete_confirmed" />
+            <input type="hidden" name="category" value="[% category | html %]" />
             <fieldset class="action"><input type="submit" class="button" value="Delete selected" /></fieldset>
         </form>
+        <form action="/cgi-bin/koha/tools/additional-contents.pl" method="post" id="delete_single">
+            <input type="hidden" id="del_op" name="op" value="delete_confirmed" />
+            <input type="hidden" id="del_category" name="category" value="[% category | html %]" />
+            <input type="hidden" id="del_ids" name="ids" />
+        </form>
     [% ELSE %]
         <div class="dialog message">There are no additional contents.</div>
     [% END %]
                     "sPaginationType": "full_numbers"
                 }));
 
-                $(".delete_news").on("click", function(){
-                    return confirmDelete( _("Are you sure you want to delete this news item? This cannot be undone.") );
+                $("#del_form").on("click", ".delete_news", function(e){
+                    e.preventDefault();
+                    if( confirmDelete( _("Are you sure you want to delete this content? This cannot be undone.") ) ){
+                        $("#del_ids").val( $(this).data("idnew") );
+                        $("#delete_single").submit();
+                    }
                 });
 
                 $("#del_form").on("submit",function(){
                     if ( Checkbox() ) {
-                        return confirmDelete( _("Are you sure you want to delete the selected news?") );
+                        return confirmDelete( _("Are you sure you want to delete the selected content?") );
                     } else {
-                        alert(_("Please select a news item to delete."));
+                        alert(_("Please select content to delete."));
                         return false;
                     }
                 });
index e4a409c..288c6e1 100755 (executable)
@@ -174,7 +174,7 @@ elsif ( $op eq 'add_validate' ) {
 elsif ( $op eq 'delete_confirmed' ) {
     my @ids = $cgi->multi_param('ids');
     my $deleted =
-      eval { Koha::AdditionalContents->search( { idnew => @ids } )->delete; };
+        map { Koha::AdditionalContents->find($_)->delete() } @ids;
 
     if ( $@ or not $deleted ) {
         push @messages, { type => 'error', code => 'error_on_delete' };