From 6c3a2b474806d1499780966bdb35c0ddabc609d0 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Tue, 3 Mar 2020 13:26:02 +0000 Subject: [PATCH] Bug 24789: Remove ITS macro format To test: 1 - Apply patches 2 - Confirm you can save, load, and run macros 3 - Confirm you have no choice of format Signed-off-by: Andrew Fuerste-Henry Signed-off-by: Katrin Fischer Signed-off-by: Martin Renvoize --- .../lib/koha/cateditor/macros.js | 6 +- .../lib/koha/cateditor/macros/its.js | 208 ------------------ .../prog/en/includes/cateditor-ui.inc | 15 +- .../prog/en/modules/cataloguing/editor.tt | 1 - 4 files changed, 3 insertions(+), 227 deletions(-) delete mode 100644 koha-tmpl/intranet-tmpl/lib/koha/cateditor/macros/its.js diff --git a/koha-tmpl/intranet-tmpl/lib/koha/cateditor/macros.js b/koha-tmpl/intranet-tmpl/lib/koha/cateditor/macros.js index 4d747f944f..160d5975a1 100644 --- a/koha-tmpl/intranet-tmpl/lib/koha/cateditor/macros.js +++ b/koha-tmpl/intranet-tmpl/lib/koha/cateditor/macros.js @@ -17,13 +17,9 @@ * along with Koha; if not, see . */ -define( [ 'macros/its', 'macros/rancor' ], function( ITSMacro, RancorMacro ) { +define( [ 'macros/rancor' ], function( RancorMacro ) { var Macros = { formats: { - its: { - description: 'TLC® ITS', - Run: ITSMacro.Run, - }, rancor: { description: 'Rancor', Run: RancorMacro.Run, diff --git a/koha-tmpl/intranet-tmpl/lib/koha/cateditor/macros/its.js b/koha-tmpl/intranet-tmpl/lib/koha/cateditor/macros/its.js deleted file mode 100644 index 07bfbeb6d0..0000000000 --- a/koha-tmpl/intranet-tmpl/lib/koha/cateditor/macros/its.js +++ /dev/null @@ -1,208 +0,0 @@ -/** - * Copyright 2015 ByWater Solutions - * - * This file is part of Koha. - * - * Koha is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * Koha is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Koha; if not, see . - */ - -define( function() { - var NAV_FAILED = new Object(); - var NAV_SUCCEEDED = new Object(); - - var _commandGenerators = [ - [ /^copy field data$/i, function() { - return function( editor, state ) { - if ( state.field == null ) return; - - return state.field.getText(); - }; - } ], - [ /^copy subfield data$/i, function() { - return function( editor, state ) { - if ( state.field == null ) return; - - var cur = editor.getCursor(); - var subfields = state.field.getSubfields(); - - for (var i = 0; i < subfields.length; i++) { - if ( cur.ch > subfields[i].end ) continue; - - state.clipboard = subfields[i].text; - return; - } - - return false; - } - } ], - [ /^del(ete)? field$/i, function() { - return function( editor, state ) { - if ( state.field == null ) return; - - state.field.delete(); - return NAV_FAILED; - } - } ], - [ /^goto field end$/i, function() { - return function( editor, state ) { - if ( state.field == null ) return NAV_FAILED; - var cur = editor.cm.getCursor(); - - editor.cm.setCursor( { line: cur.line } ); - return NAV_SUCCEEDED; - } - } ], - [ /^goto field (\w{3})$/i, function(tag) { - return function( editor, state ) { - var field = editor.getFirstField(tag); - if ( field == null ) return NAV_FAILED; - - field.focus(); - return NAV_SUCCEEDED; - } - } ], - [ /^goto subfield end$/i, function() { - return function( editor, state ) { - if ( state.field == null ) return NAV_FAILED; - - var cur = editor.getCursor(); - var subfields = state.field.getSubfields(); - - for (var i = 0; i < subfields.length; i++) { - if ( cur.ch > subfields[i].end ) continue; - - subfield.focusEnd(); - return NAV_SUCCEEDED; - } - - return NAV_FAILED; - } - } ], - [ /^goto subfield (\w)$/i, function( code ) { - return function( editor, state ) { - if ( state.field == null ) return NAV_FAILED; - - var subfield = state.field.getFirstSubfield( code ); - if ( subfield == null ) return NAV_FAILED; - - subfield.focus(); - return NAV_SUCCEEDED; - } - } ], - [ /^insert (new )?field (\w{3}) data=(.*)/i, function(undef, tag, text) { - text = text.replace(/\\([0-9a-z])/g, '$$$1 '); - return function( editor, state ) { - editor.createFieldGrouped(tag).setText(text).focus(); - return NAV_SUCCEEDED; - } - } ], - [ /^insert (new )?subfield (\w) data=(.*)/i, function(undef, code, text) { - return function( editor, state ) { - if ( state.field == null ) return; - - state.field.appendSubfield(code).setText(text); - } - } ], - [ /^paste$/i, function() { - return function( editor, state ) { - var cur = editor.cm.getCursor(); - - editor.cm.replaceRange( state.clipboard, cur, null, 'marcAware' ); - } - } ], - [ /^set indicator([12])=([ _0-9])$/i, function( ind, value ) { - return function( editor, state ) { - if ( state.field == null ) return; - if ( state.field.isControlField ) return false; - - if ( ind == '1' ) { - state.field.setIndicator1(value); - return true; - } else if ( ind == '2' ) { - state.field.setIndicator2(value); - return true; - } else { - return false; - } - } - } ], - [ /^set indicators=([ _0-9])([ _0-9])?$/i, function( ind1, ind2 ) { - return function( editor, state ) { - if ( state.field == null ) return; - if ( state.field.isControlField ) return false; - - state.field.setIndicator1(ind1); - state.field.setIndicator2(ind2 || '_'); - } - } ], - ]; - - var ITSMacro = { - Compile: function( macro ) { - var result = { commands: [], errors: [] }; - - $.each( macro.split(/\r\n|\n/), function( line, contents ) { - var command; - - if ( contents.match(/^\s*$/) ) return; - - $.each( _commandGenerators, function( undef, gen ) { - var match; - - if ( !( match = gen[0].exec( contents ) ) ) return; - - command = gen[1].apply(null, match.slice(1)); - return false; - } ); - - if ( !command ) { - result.errors.push( { line: line, error: 'unrecognized' } ); - } - - result.commands.push( { func: command, orig: contents, line: line } ); - } ); - - return result; - }, - Run: function( editor, macro ) { - var compiled = ITSMacro.Compile(macro); - if ( compiled.errors.length ) return { errors: compiled.errors }; - var state = { - clipboard: '', - field: null, - }; - - var run_result = { errors: [] }; - - editor.cm.operation( function() { - $.each( compiled.commands, function( undef, command ) { - var result = command.func( editor, state ); - - if ( result == NAV_FAILED ) { - state.field = null; - } else if ( result == NAV_SUCCEEDED ) { - state.field = editor.getCurrentField(); - } else if ( result === false ) { - run_result.errors.push( { line: command.line, error: 'failed' } ); - return false; - } - } ); - } ); - - return run_result; - }, - }; - - return ITSMacro; -} ); 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 a37bd5f03f..6b680a31fa 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-ui.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-ui.inc @@ -706,7 +706,6 @@ require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr var macro = Preferences.user.macros[name]; macroEditor.setValue( macro.contents ); macroEditor.setOption( 'readOnly', false ); - $( '#macro-format' ).val( macro.format || 'its' ); if ( macro.history ) macroEditor.setHistory( macro.history ); } @@ -763,7 +762,7 @@ require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr if ( !name || macroEditor.savedGeneration == macroEditor.changeGeneration() ) return; macroEditor.savedGeneration = macroEditor.changeGeneration(); - storeMacro( name, { contents: macroEditor.getValue(), modified: (new Date()).valueOf(), history: macroEditor.getHistory(), format: $('#macro-format').val() } ); +// storeMacro( name, { contents: macroEditor.getValue(), modified: (new Date()).valueOf(), history: macroEditor.getHistory(), format: $('#macro-format').val() } ); $('#macro-save-message').text(_("Saved")); showSavedMacros(); } @@ -862,16 +861,6 @@ require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr $( '#save-dropdown' ).append( '
  • ' + backend[0] + '
  • ' ); } ); - var macro_format_list = $.map( Macros.formats, function( format, name ) { - return $.extend( { name: name }, format ); - } ); - macro_format_list.sort( function( a, b ) { - return a.description.localeCompare(b.description); - } ); - $.each( macro_format_list, function() { - $('#macro-format').append( '' ); - } ); - // Click bindings $( '#save-record, #save-dropdown a' ).click( function() { $( '#save-record' ).find('i').attr( 'class', 'fa fa-spinner fa-spin' ).siblings( 'span' ).text( _("Saving...") ); @@ -978,7 +967,7 @@ require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr } ); $('#run-macro').click( function() { - var result = Macros.Run( editor, $('#macro-format').val(), macroEditor.getValue() ); + var result = Macros.Run( editor, 'rancor', macroEditor.getValue() ); if ( !result.errors.length ) { $('#macro-ui').modal('hide'); 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 253792bdda..a4a2b4d71e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/editor.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/editor.tt @@ -264,7 +264,6 @@
    -
    -- 2.39.5