From d2d3bf1e1b3dd4c767843bbcd1e382a802dbde2f Mon Sep 17 00:00:00 2001 From: Lucas Gass Date: Thu, 13 Jul 2023 17:51:13 +0000 Subject: [PATCH] Bug 34275: Add toggle switch for basic/advanced cataloging editors To test: 1. Apply patch and regenerate CSS. (https://wiki.koha-community.org/wiki/Working_with_SCSS_in_the_OPAC_and_staff_interface) 2. Turn on EnableAdvancedCatalogingEditor. 3. Go to cataloging > 'New record' 4. In the upper left notice a new toggle switch labeled 'Editor:'. 5. Try toggling the switch back and forth to move between editors. Verify it works correecly. 6. Try editing an existing record and make sure the toggle works well when editing records. 7. Try the other method of switch editors, Settings > Switch to basic/advanced editor. Make sure it works the same as always 8. Turn off EnableAdvancedCatalogingEditor, make sure the toggle button is no longer present. Signed-off-by: Brendan Lawlor --- .../prog/css/src/staff-global.scss | 64 +++++++++++++++++++ .../prog/en/includes/cateditor-ui.inc | 31 +++++---- .../prog/en/modules/cataloguing/addbiblio.tt | 51 ++++++++++----- .../prog/en/modules/cataloguing/editor.tt | 12 ++++ 4 files changed, 132 insertions(+), 26 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss b/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss index 2fd3025511..dd3a51f615 100644 --- a/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss +++ b/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss @@ -4102,6 +4102,70 @@ input.renew { } } +#toggle-editor { + display: flex; + align-items: center; + float: right; + + label { + margin-left: 2px; + margin-bottom: 0; + } + + .switch { + position: relative; + display: inline-block; + width: 60px; + height: 24px; + + input { + opacity: 0; + width: 0; + height: 0; + + &:checked { + + .slider { + background-color: #408540; + } + + .slider:before { + -webkit-transform: translateX(26px); + -ms-transform: translateX(26px); + transform: translateX(26px); + } + } + } + + } + + .slider { + position: absolute; + cursor: pointer; + top: 0; + left: 0; + right: 0; + bottom: 0; + background-color: #ccc; + -webkit-transition: .4s; + transition: .4s; + border-radius: 34px; + + &::before { + position: absolute; + content: ""; + height: 16px; + width: 25px; + left: 4px; + bottom: 4px; + background-color: white; + -webkit-transition: .4s; + transition: .4s; + border-radius: 34px; + text-align: center; + font-weight: bold; + } + } +} + /* Permissions */ #permissionstree { diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-ui.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-ui.inc index 4e26c58aac..f54f388cd0 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-ui.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-ui.inc @@ -976,6 +976,20 @@ require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr }); } + function changeEditor() { + if ( !confirm( _("Any changes will not be saved. Continue?") ) ) return; + + Cookies.set( "catalogue_editor_[% logged_in_user.borrowernumber | html %]", "basic", { expires: 365, path: '/', sameSite: 'Lax'} ); + + if ( state.backend == 'catalog' ) { + window.location = '/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=' + state.recordID; + } else if ( state.backend == 'new' ) { + window.location = '/cgi-bin/koha/cataloguing/addbiblio.pl'; + } else { + humanMsg.displayAlert( _("Cannot open this record in the basic editor"), { className: 'humanError' } ); + } + } + $(".macro_shared").change(function(){ if(this.checked){ saveMacro(true); @@ -987,6 +1001,7 @@ require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr // END Macro functions $(document).ready( function() { + // Editor setup editor = new MARCEditor( { onCursorActivity: function() { @@ -1223,18 +1238,12 @@ require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr return false; } ); - $( '#switch-editor' ).click( function() { - if ( !confirm( _("Any changes will not be saved. Continue?") ) ) return; - - Cookies.set( "catalogue_editor_[% logged_in_user.borrowernumber | html %]", "basic", { expires: 365, path: '/', sameSite: 'Lax'} ); + $( '#toggleEditor' ).change( function() { + changeEditor(); + }); - if ( state.backend == 'catalog' ) { - window.location = '/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=' + state.recordID; - } else if ( state.backend == 'new' ) { - window.location = '/cgi-bin/koha/cataloguing/addbiblio.pl'; - } else { - humanMsg.displayAlert( _("Cannot open this record in the basic editor"), { className: 'humanError' } ); - } + $( '#switch-editor' ).click( function() { + changeEditor(); } ); $( '#show-advanced-search' ).click( function() { diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt index 7d7c392ece..79d77fb587 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt @@ -36,6 +36,26 @@ $("#loading").hide(); }); var Sticky; + + function changeEditor() { + + var breedingid = [% breedingid || "null" | html %]; + + if ( !confirm( breedingid ? _("This record cannot be transferred to the advanced editor. Continue?") : _("Any changes will not be saved. Continue?") ) ) return false; + + Cookies.set( 'catalogue_editor_[% logged_in_user.borrowernumber | html %]', 'advanced', { expires: 365, path: '/', sameSite: 'Lax' } ); + + var biblionumber = [% biblionumber || "null" | html %]; + + if ( biblionumber ) { + window.location = '/cgi-bin/koha/cataloguing/editor.pl#catalog/' + biblionumber; + } else { + window.location = '/cgi-bin/koha/cataloguing/editor.pl'; + } + + return false; + } + $(document).ready(function() { [% IF bib_doesnt_exist %] @@ -151,23 +171,14 @@ return false; }); - $( '#switcheditor' ).click( function() { - var breedingid = [% breedingid || "null" | html %]; - - if ( !confirm( breedingid ? _("This record cannot be transferred to the advanced editor. Continue?") : _("Any changes will not be saved. Continue?") ) ) return false; - - Cookies.set( 'catalogue_editor_[% logged_in_user.borrowernumber | html %]', 'advanced', { expires: 365, path: '/', sameSite: 'Lax' } ); - - var biblionumber = [% biblionumber || "null" | html %]; - - if ( biblionumber ) { - window.location = '/cgi-bin/koha/cataloguing/editor.pl#catalog/' + biblionumber; - } else { - window.location = '/cgi-bin/koha/cataloguing/editor.pl'; - } + $( '#toggleEditor' ).change( function() { + changeEditor(); + } ); - return false; + $( '#switcheditor' ).click( function() { + changeEditor(); } ); + $(".change-framework").on("click", function(){ var frameworkcode = $(this).data("frameworkcode"); $("#frameworkcode").val( frameworkcode ); @@ -841,6 +852,16 @@ $(document).ready(function(){
+ [% IF Koha.Preference('EnableAdvancedCatalogingEditor') %] +
+ + +
+ [% END %] +

diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/editor.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/editor.tt index 1824673fc2..3112e10cb4 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/editor.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/editor.tt @@ -1,6 +1,7 @@ [% USE raw %] [% USE Asset %] [% PROCESS 'i18n.inc' %] +[% USE Koha %] [% INCLUDE 'doc-head-open.inc' %] [% FILTER collapse %] [% t("Editor") | html %] › @@ -41,8 +42,19 @@ <div class="col-sm-10 col-sm-push-2"> <main> +[% IF Koha.Preference('EnableAdvancedCatalogingEditor') %] + <div id="toggle-editor"> + <label for="toggle-editor">Advanced editor: </label> + <label class="switch"> + <input id="toggleEditor" type="checkbox" checked="checked"> + <span class="slider"></span> + </label> + </div> +[% END %] + <h1 id="title">Cataloging editor</h1> + <div id="editor"> <input id="import-records-input" type="file" style="display: none"> <div id="toolbar" class="btn-toolbar"> -- 2.30.2