From 7adae4930bcd2ff27bc28186ab5fa1e866829e99 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 29 Jul 2020 12:12:59 +0200 Subject: [PATCH] Bug 26080: Some refactoring A new include file is created per background job to avoid background_jobs.tt to grow too much Signed-off-by: Fridolin Somers Signed-off-by: Tomas Cohen Arazi Signed-off-by: Jonathan Druart --- .../batch_authority_record_modification.inc | 39 +++++ .../batch_biblio_record_deletion.inc | 49 ++++++ .../batch_biblio_record_modification.inc | 64 ++++++++ .../prog/en/modules/admin/background_jobs.tt | 148 +----------------- 4 files changed, 159 insertions(+), 141 deletions(-) create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/background_jobs/batch_authority_record_modification.inc create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/background_jobs/batch_biblio_record_deletion.inc create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/background_jobs/batch_biblio_record_modification.inc diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/background_jobs/batch_authority_record_modification.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/background_jobs/batch_authority_record_modification.inc new file mode 100644 index 0000000000..47bfc08a0a --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/background_jobs/batch_authority_record_modification.inc @@ -0,0 +1,39 @@ +[% BLOCK report %] + [% SET report = job.report %] + [% IF report %] + [% IF report.total_records == report.total_success %] +
+ All records have successfully been modified! New batch record modification +
+ [% ELSE %] +
+ [% report.total_success | html %] / [% report.total_records | html %] records have successfully been modified. Some errors occurred. + [% IF job.status == 'cancelled' %]The job has been cancelled before it finished.[% END %] + New batch record modification +
+ [% END %] + [% END %] +[% END %] + +[% BLOCK detail %] + [% FOR m IN job.messages %] +
+ [% IF m.type == 'success' %] + + [% ELSIF m.type == 'warning' %] + + [% ELSIF m.type == 'error' %] + + [% END %] + [% SWITCH m.code %] + [% CASE 'authority_not_modified' %] + Authority record [% m.authid | html %] has not been modified. An error occurred on modifying it[% IF m.error %] ([% m.error %])[% END %]. + [% CASE 'authority_modified' %] + Authority record [% m.authid | html %] has successfully been modified.. + [% END %] +
+ [% END %] +[% END %] + +[% BLOCK js %] +[% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/background_jobs/batch_biblio_record_deletion.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/background_jobs/batch_biblio_record_deletion.inc new file mode 100644 index 0000000000..83f81cb538 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/background_jobs/batch_biblio_record_deletion.inc @@ -0,0 +1,49 @@ +[% BLOCK report %] + [% SET report = job.report %] + [% IF report %] + [% IF report.total_records == report.total_success %] +
+ All records have been deleted successfully! +
+ [% ELSIF report.total_success == 0 %] +
+ No record has been deleted. An error occurred. +
+ [% ELSE %] +
+ [% report.total_success | html %] / [% report.total_records | html %] records have been deleted successfully but some errors occurred. +
+ [% END %] + [% END %] +[% END %] + +[% BLOCK detail %] + [% FOR m IN job.messages %] +
+ [% IF m.type == 'success' %] + + [% ELSIF m.type == 'warning' %] + + [% ELSIF m.type == 'error' %] + + [% END %] + [% SWITCH m.code %] + [% CASE 'biblio_not_exists' %] + The biblionumber [% m.biblionumber | html %] does not exist in the database. + [% CASE 'item_issued' %] + At least one item is checked out on bibliographic record [% m.biblionumber | html %]. + [% CASE 'reserve_not_cancelled' %] + Bibliographic record [% m.biblionumber | html %] was not deleted. A hold could not be canceled (reserve_id [% m.reserve_id | html %]). + [% CASE 'item_not_deleted' %] + The bibliographic record [% m.biblionumber | html %] was not deleted. An error was encountered when deleting an item (itemnumber [% m.itemnumber | html %]). + [% CASE 'biblio_not_deleted' %] + Bibliographic record [% m.biblionumber | html %] was not deleted. An error occurred. + [% CASE 'biblio_deleted' %] + Bibliographic record [% m.biblionumber | html %] has been deleted successfully. + [% END %] +
+ [% END %] +[% END %] + +[% BLOCK js %] +[% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/background_jobs/batch_biblio_record_modification.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/background_jobs/batch_biblio_record_modification.inc new file mode 100644 index 0000000000..51a447e3b2 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/background_jobs/batch_biblio_record_modification.inc @@ -0,0 +1,64 @@ +[% BLOCK report %] + [% SET report = job.report %] + [% IF report %] + [% IF report.total_records == report.total_success %] +
+ All records have successfully been modified! New batch record modification + [% IF lists.count %] +
+ Add modified records to the following list: + + [% END %] +
+ [% ELSE %] +
+ [% report.total_success | html %] / [% report.total_records | html %] records have successfully been modified. Some errors occurred. + [% IF job.status == 'cancelled' %]The job has been cancelled before it finished.[% END %] + New batch record modification +
+ [% END %] + [% END %] +[% END %] + +[% BLOCK detail %] + [% FOR m IN job.messages %] +
+ [% IF m.type == 'success' %] + + [% ELSIF m.type == 'warning' %] + + [% ELSIF m.type == 'error' %] + + [% END %] + [% SWITCH m.code %] + [% CASE 'biblio_not_modified' %] + Bibliographic record [% m.biblionumber | html %] has not been modified. An error occurred on modifying it.[% IF m.error %] ([% m.error | html %])[% END %]. + [% CASE 'biblio_modified' %] + Bibliographic record [% m.biblionumber | html %] has successfully been modified. + [% END %] +
+ [% END %] +[% END %] + +[% BLOCK js %] + $("#add_bibs_to_list").change(function(){ + var selected = $("#add_bibs_to_list").find("option:selected"); + if ( selected.attr("class") == "shelf" ){ + var shelfnumber = selected.attr("value"); + var bibs = new Array(); + [% FOREACH message IN job.messages %] + [% IF message.code == 'biblio_modified' %] + bibs.push("biblionumber="+[% message.biblionumber | html %]); + [% END %] + [% END %] + var bibstring = bibs.join("&"); + window.open('/cgi-bin/koha/virtualshelves/addbybiblionumber.pl?shelfnumber='+shelfnumber+'&confirm=1&'+bibstring, 'popup', 'width=500,height=500,toolbar=false,scrollbars=yes,resizeable=yes'); + return false; + } + }); +[% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/background_jobs.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/background_jobs.tt index ab49bbec96..f7c724f478 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/background_jobs.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/background_jobs.tt @@ -93,6 +93,8 @@ [% IF op == 'view' %]

Details of job #[% job.id | html %]

+ [% PROCESS "background_jobs/${job.type}.inc" %] +
  1. Job ID: [% job.id | html %]
  2. @@ -118,134 +120,10 @@ [% job.ended_on | $KohaDates with_hours = 1 %]
  3. - [% SWITCH job.type %] - [% CASE 'batch_biblio_record_modification' %] - [% SET report = job.report %] - [% IF report %] - [% IF report.total_records == report.total_success %] -
    - All records have successfully been modified! New batch record modification - [% IF lists.count %] -
    - Add modified records to the following list: - - [% END %] -
    - [% ELSE %] -
    - [% report.total_success | html %] / [% report.total_records | html %] records have successfully been modified. Some errors occurred. - [% IF job.status == 'cancelled' %]The job has been cancelled before it finished.[% END %] - New batch record modification -
    - [% END %] - [% END %] - [% CASE 'batch_authority_record_modification' %] - [% SET report = job.report %] - [% IF report %] - [% IF report.total_records == report.total_success %] -
    - All records have successfully been modified! New batch record modification -
    - [% ELSE %] -
    - [% report.total_success | html %] / [% report.total_records | html %] records have successfully been modified. Some errors occurred. - [% IF job.status == 'cancelled' %]The job has been cancelled before it finished.[% END %] - New batch record modification -
    - [% END %] - [% END %] - [% CASE 'batch_biblio_record_deletion' %] - [% SET report = job.report %] - [% IF report %] - [% IF report.total_records == report.total_success %] -
    - All records have been deleted successfully! -
    - [% ELSIF report.total_success == 0 %] -
    - No record has been deleted. An error occurred. -
    - [% ELSE %] -
    - [% report.total_success | html %] / [% report.total_records | html %] records have been deleted successfully but some errors occurred. -
    - [% END %] - [% END %] - [% CASE %]Job type "[% job.type | html %]" not handled in the template - [% END %] + [% PROCESS 'report' %]
  4. - [% SWITCH job.type %] - [% CASE 'batch_biblio_record_modification' %] - [% FOR m IN job.messages %] -
    - [% IF m.type == 'success' %] - - [% ELSIF m.type == 'warning' %] - - [% ELSIF m.type == 'error' %] - - [% END %] - [% SWITCH m.code %] - [% CASE 'biblio_not_modified' %] - Bibliographic record [% m.biblionumber | html %] has not been modified. An error occurred on modifying it.[% IF m.error %] ([% m.error | html %])[% END %]. - [% CASE 'biblio_modified' %] - Bibliographic record [% m.biblionumber | html %] has successfully been modified. - [% END %] -
    - [% END %] - [% CASE 'batch_authority_record_modification' %] - [% FOR m IN job.messages %] -
    - [% IF m.type == 'success' %] - - [% ELSIF m.type == 'warning' %] - - [% ELSIF m.type == 'error' %] - - [% END %] - [% SWITCH m.code %] - [% CASE 'authority_not_modified' %] - Authority record [% m.authid | html %] has not been modified. An error occurred on modifying it[% IF m.error %] ([% m.error | html %])[% END %]. - [% CASE 'authority_modified' %] - Authority record [% m.authid | html %] has successfully been modified. - [% END %] -
    - [% END %] - [% CASE 'batch_biblio_record_deletion' %] - [% FOR m IN job.messages %] -
    - [% IF m.type == 'success' %] - - [% ELSIF m.type == 'warning' %] - - [% ELSIF m.type == 'error' %] - - [% END %] - [% SWITCH m.code %] - [% CASE 'biblio_not_exists' %] - The biblionumber [% m.biblionumber | html %] does not exist in the database. - [% CASE 'item_issued' %] - At least one item is checked out on bibliographic record [% m.biblionumber | html %]. - [% CASE 'reserve_not_cancelled' %] - Bibliographic record [% m.biblionumber | html %] was not deleted. A hold could not be canceled (reserve_id [% m.reserve_id | html %]). - [% CASE 'item_not_deleted' %] - The bibliographic record [% m.biblionumber | html %] was not deleted. An error was encountered when deleting an item (itemnumber [% m.itemnumber | html %]). - [% CASE 'biblio_not_deleted' %] - Bibliographic record [% m.biblionumber | html %] was not deleted. An error occurred. - [% CASE 'biblio_deleted' %] - Bibliographic record [% m.biblionumber | html %] has been deleted successfully. - [% END %] -
    - [% END %] - - [% CASE %]Job type "[% job.type | html %]" not handled in the template - [% END %] + [% PROCESS 'detail' %]
@@ -335,21 +213,9 @@ "sPaginationType": "full_numbers" })); - $("#add_bibs_to_list").change(function(){ - var selected = $("#add_bibs_to_list").find("option:selected"); - if ( selected.attr("class") == "shelf" ){ - var shelfnumber = selected.attr("value"); - var bibs = new Array(); - [% FOREACH message IN job.messages %] - [% IF message.code == 'biblio_modified' %] - bibs.push("biblionumber="+[% message.biblionumber | html %]); - [% END %] - [% END %] - var bibstring = bibs.join("&"); - window.open('/cgi-bin/koha/virtualshelves/addbybiblionumber.pl?shelfnumber='+shelfnumber+'&confirm=1&'+bibstring, 'popup', 'width=500,height=500,toolbar=false,scrollbars=yes,resizable=yes'); - return false; - } - }); + [% IF op == 'view' %] + [% PROCESS 'js' %] + [% END %] }); [% END %] -- 2.39.5