View | Details | Raw Unified | Return to bug 25728
Collapse All | Expand All

(-)a/koha-tmpl/intranet-tmpl/prog/js/cataloging.js (-55 / +54 lines)
Lines 521-587 $(document).ready(function() { Link Here
521
        $("input.input_marceditor, input.indicator").addClass('noEnterSubmit');
521
        $("input.input_marceditor, input.indicator").addClass('noEnterSubmit');
522
    });
522
    });
523
523
524
    if ( CAN_user_parameters_manage_auth_values ) {
524
    if ( window.editor === undefined ) { // TODO This does not work with the advanced editor
525
        var current_select2;
525
        if ( CAN_user_parameters_manage_auth_values ) {
526
        $('.subfield_line select[data-category!=""]').select2({
526
            var current_select2;
527
            tags: true,
527
            $('.subfield_line select[data-category!=""]').select2({
528
            createTag: function (tag) {
528
                tags: true,
529
                return {
529
                createTag: function (tag) {
530
                    id: tag.term,
530
                    return {
531
                    text: tag.term,
531
                        id: tag.term,
532
                    newTag: true
532
                        text: tag.term,
533
                };
533
                        newTag: true
534
            },
534
                    };
535
            templateResult: function(state) {
535
                },
536
                if (state.newTag) {
536
                templateResult: function(state) {
537
                    return state.text + " " + __("(select to create)");
537
                    if (state.newTag) {
538
                        return state.text + " " + __("(select to create)");
539
                    }
538
                }
540
                }
539
                return state.text;
541
            }).on("select2:select", function(e) {
540
            }
542
                if(e.params.data.newTag){
541
        }).on("select2:select", function(e) {
542
            if(e.params.data.newTag){
543
543
544
                var category = $(this).data("category");
544
                    var category = $(this).data("category");
545
                $("#avCreate #new_av_category").html(category);
545
                    $("#avCreate #new_av_category").html(category);
546
                $("#avCreate input[name='category']").val(category);
546
                    $("#avCreate input[name='category']").val(category);
547
                $("#avCreate input[name='value']").val(e.params.data.text);
547
                    $("#avCreate input[name='value']").val(e.params.data.text);
548
                $("#avCreate input[name='description']").val(e.params.data.text);
548
                    $("#avCreate input[name='description']").val(e.params.data.text);
549
                $('#avCreate').modal({show:true});
549
                    $('#avCreate').modal({show:true});
550
550
551
                $(current_select2).val($(current_select2).find("option:first").val()).trigger('change');
551
                    $(current_select2).val($(current_select2).find("option:first").val()).trigger('change');
552
552
553
                current_select2 = this;
553
                    current_select2 = this;
554
554
                }
555
            }
555
            }).on("select2:clear", function () {
556
        }).on("select2:clear", function () {
556
                $(this).on("select2:opening.cancelOpen", function (evt) {
557
            $(this).on("select2:opening.cancelOpen", function (evt) {
557
                    evt.preventDefault();
558
                evt.preventDefault();
559
558
560
                $(this).off("select2:opening.cancelOpen");
559
                    $(this).off("select2:opening.cancelOpen");
560
                });
561
            });
561
            });
562
        });
563
562
564
        $("#add_new_av").on("submit", function(){
563
            $("#add_new_av").on("submit", function(){
565
            var data = {
564
                var data = {
566
                category: $(this).find('input[name="category"]').val(),
565
                    category: $(this).find('input[name="category"]').val(),
567
                value: $(this).find('input[name="value"]').val(),
566
                    value: $(this).find('input[name="value"]').val(),
568
                description: $(this).find('input[name="description"]').val(),
567
                    description: $(this).find('input[name="description"]').val(),
569
                opac_description: $(this).find('input[name="opac_description"]').val(),
568
                    opac_description: $(this).find('input[name="opac_description"]').val(),
570
            };
569
                };
571
            $.ajax({
570
                $.ajax({
572
                type: "POST",
571
                    type: "POST",
573
                url: "/api/v1/authorised_values",
572
                    url: "/api/v1/authorised_values",
574
                data:JSON.stringify(data),
573
                    data:JSON.stringify(data),
575
                success: function(response) {
574
                    success: function(response) {
576
                    $('#avCreate').modal('hide');
575
                        $('#avCreate').modal('hide');
577
576
578
                    $(current_select2).append('<option selected value="'+data['value']+'">'+data['description']+'</option>');
577
                        $(current_select2).append('<option selected value="'+data['value']+'">'+data['description']+'</option>');
579
                },
578
                    },
580
                error: function(err) {
579
                    error: function(err) {
581
                    $("#avCreate .error").html(_("Something went wrong, maybe the value already exists?"))
580
                        $("#avCreate .error").html(_("Something went wrong, maybe the value already exists?"))
582
                }
581
                    }
582
                });
583
                return false;
583
            });
584
            });
584
            return false;
585
        }
585
        });
586
    }
586
    }
587
});
587
});
588
- 

Return to bug 25728