From f5d16219a569964fd486a4b1ae41d5e0815a2934 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 9 Jun 2020 17:34:30 +0200 Subject: [PATCH] Bug 25728: Don't explode in the advanced editor Sponsored-by: Orex Digital --- koha-tmpl/intranet-tmpl/prog/js/cataloging.js | 108 +++++++++--------- 1 file changed, 55 insertions(+), 53 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/js/cataloging.js b/koha-tmpl/intranet-tmpl/prog/js/cataloging.js index 792059eacb..4d775bc8a2 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/cataloging.js +++ b/koha-tmpl/intranet-tmpl/prog/js/cataloging.js @@ -521,65 +521,67 @@ $(document).ready(function() { $("input.input_marceditor, input.indicator").addClass('noEnterSubmit'); }); - $('.subfield_line select[data-category=""]').select2(); // branches, itemtypes and cn_source - - if ( ! CAN_user_parameters_manage_auth_values ) { - $('.subfield_line select[data-category!=""]').select2(); - } else { - var current_select2; - $('.subfield_line select[data-category!=""]').select2({ - tags: true, - createTag: function (tag) { - return { - id: tag.term, - text: tag.term, - newTag: true - }; - }, - templateResult: function(state) { - if (state.newTag) { - return state.text + " " + "(select to create)"; + if ( window.editor === undefined ) { // TODO This does not work with the advanced editor + $('.subfield_line select[data-category=""]').select2(); // branches, itemtypes and cn_source + + if ( ! CAN_user_parameters_manage_auth_values ) { + $('.subfield_line select[data-category!=""]').select2(); + } else { + var current_select2; + $('.subfield_line select[data-category!=""]').select2({ + tags: true, + createTag: function (tag) { + return { + id: tag.term, + text: tag.term, + newTag: true + }; + }, + templateResult: function(state) { + if (state.newTag) { + return state.text + " " + "(select to create)"; + } + return state.text; } - return state.text; - } - }).on("select2:select", function(e) { - if(e.params.data.newTag){ + }).on("select2:select", function(e) { + if(e.params.data.newTag){ - var category = $(this).data("category"); - $("#avCreate #new_av_category").html(category); - $("#avCreate input[name='category']").val(category); - $("#avCreate input[name='value']").val(e.params.data.text); - $("#avCreate input[name='description']").val(e.params.data.text); - $('#avCreate').modal({show:true}); + var category = $(this).data("category"); + $("#avCreate #new_av_category").html(category); + $("#avCreate input[name='category']").val(category); + $("#avCreate input[name='value']").val(e.params.data.text); + $("#avCreate input[name='description']").val(e.params.data.text); + $('#avCreate').modal({show:true}); - $(current_select2).val($(current_select2).find("option:first").val()).trigger('change'); + $(current_select2).val($(current_select2).find("option:first").val()).trigger('change'); - current_select2 = this; - - } - }); + current_select2 = this; - $("#add_new_av").on("submit", function(){ - var data = { - category: $(this).find('input[name="category"]').val(), - value: $(this).find('input[name="value"]').val(), - description: $(this).find('input[name="description"]').val(), - opac_description: $(this).find('input[name="opac_description"]').val(), - }; - $.ajax({ - type: "POST", - url: "/api/v1/authorised_values", - data:JSON.stringify(data), - success: function(response) { - $('#avCreate').modal('hide'); - - $(current_select2).append(''); - }, - error: function(err) { - $("#avCreate .error").html(_("Something went wrong, maybe the value already exists?")) } }); - return false; - }); + + $("#add_new_av").on("submit", function(){ + var data = { + category: $(this).find('input[name="category"]').val(), + value: $(this).find('input[name="value"]').val(), + description: $(this).find('input[name="description"]').val(), + opac_description: $(this).find('input[name="opac_description"]').val(), + }; + $.ajax({ + type: "POST", + url: "/api/v1/authorised_values", + data:JSON.stringify(data), + success: function(response) { + $('#avCreate').modal('hide'); + + $(current_select2).append(''); + }, + error: function(err) { + $("#avCreate .error").html(_("Something went wrong, maybe the value already exists?")) + } + }); + return false; + }); + } } }); -- 2.20.1