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

(-)a/cataloguing/addbiblio.pl (-3 / +6 lines)
Lines 170-183 sub build_authorized_values_list { Link Here
170
    # builds list, depending on authorised value...
170
    # builds list, depending on authorised value...
171
171
172
    #---- branch
172
    #---- branch
173
    if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) {
173
    my $category = $tagslib->{$tag}->{$subfield}->{authorised_value};
174
    if ( $category eq "branches" ) {
174
        my $libraries = Koha::Libraries->search_filtered({}, {order_by => ['branchname']});
175
        my $libraries = Koha::Libraries->search_filtered({}, {order_by => ['branchname']});
175
        while ( my $l = $libraries->next ) {
176
        while ( my $l = $libraries->next ) {
176
            push @authorised_values, $l->branchcode;;
177
            push @authorised_values, $l->branchcode;;
177
            $authorised_lib{$l->branchcode} = $l->branchname;
178
            $authorised_lib{$l->branchcode} = $l->branchname;
178
        }
179
        }
179
    }
180
    }
180
    elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes" ) {
181
    elsif ( $category eq "itemtypes" ) {
181
        push @authorised_values, "";
182
        push @authorised_values, "";
182
183
183
        my $itemtype;
184
        my $itemtype;
Lines 188-194 sub build_authorized_values_list { Link Here
188
        }
189
        }
189
        $value = $itemtype unless ($value);
190
        $value = $itemtype unless ($value);
190
    }
191
    }
191
    elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "cn_source" ) {
192
    elsif ( $category eq "cn_source" ) {
192
        push @authorised_values, "";
193
        push @authorised_values, "";
193
194
194
        my $class_sources = GetClassSources();
195
        my $class_sources = GetClassSources();
Lines 219-224 sub build_authorized_values_list { Link Here
219
        }
220
        }
220
    }
221
    }
221
    $authorised_values_sth->finish;
222
    $authorised_values_sth->finish;
223
222
    return {
224
    return {
223
        type     => 'select',
225
        type     => 'select',
224
        id       => "tag_".$tag."_subfield_".$subfield."_".$index_tag."_".$index_subfield,
226
        id       => "tag_".$tag."_subfield_".$subfield."_".$index_tag."_".$index_subfield,
Lines 226-231 sub build_authorized_values_list { Link Here
226
        default  => $value,
228
        default  => $value,
227
        values   => \@authorised_values,
229
        values   => \@authorised_values,
228
        labels   => \%authorised_lib,
230
        labels   => \%authorised_lib,
231
        ( ( grep { $_ eq $category } ( qw(branches itemtypes cn_source) ) ) ? () : ( category => $category ) ),
229
    };
232
    };
230
233
231
}
234
}
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt (-2 / +115 lines)
Lines 483-488 Link Here
483
[% Asset.css("css/addbiblio.css") | $raw %]
483
[% Asset.css("css/addbiblio.css") | $raw %]
484
484
485
[% INCLUDE 'select2.inc' %]
485
[% INCLUDE 'select2.inc' %]
486
<script>
487
  $(document).ready(function() {
488
      [% IF CAN_user_parameters_manage_auth_values %]
489
          var current_select2;
490
          $('.subfield_line select[data-category!=""]').select2({
491
              tags: true,
492
              createTag: function (tag) {
493
                  return {
494
                      id: tag.term,
495
                      text: tag.term,
496
                      newTag: true
497
                  };
498
              },
499
              templateResult: function(state) {
500
                  if (state.newTag) {
501
                      return state.text + " " + "(select to create)";
502
                  }
503
                  return state.text;
504
              }
505
          }).on("select2:select", function(e) {
506
              if(e.params.data.newTag){
507
508
                  var category = $(this).data("category");
509
                  $("#avCreate #new_av_category").html(category);
510
                  $("#avCreate input[name='category']").val(category);
511
                  $("#avCreate input[name='value']").val(e.params.data.text);
512
                  $("#avCreate input[name='description']").val(e.params.data.text);
513
                  $('#avCreate').modal({show:true});
514
515
                  $(current_select2).val($(current_select2).find("option:first").val()).trigger('change');
516
517
                  current_select2 = this;
518
519
              }
520
          }).on("select2:clear", function () {
521
              $(this).on("select2:opening.cancelOpen", function (evt) {
522
                  evt.preventDefault();
523
524
                  $(this).off("select2:opening.cancelOpen");
525
              });
526
          });
527
528
          $("#add_new_av").on("submit", function(){
529
              var data = {
530
                  category: $(this).find('input[name="category"]').val(),
531
                  value: $(this).find('input[name="value"]').val(),
532
                  description: $(this).find('input[name="description"]').val(),
533
                  opac_description: $(this).find('input[name="opac_description"]').val(),
534
              };
535
              $.ajax({
536
                  type: "POST",
537
                  url: "/api/v1/authorised_values",
538
                  data:JSON.stringify(data),
539
                  success: function(response) {
540
                      $('#avCreate').modal('hide');
541
542
                      $(current_select2).append('<option selected value="'+data['value']+'">'+data['description']+'</option>');
543
                  },
544
                  error: function(err) {
545
                      $("#avCreate .error").html(_("Something went wrong, maybe the value already exists?"))
546
                  }
547
              });
548
              return false;
549
          });
550
      [% END %]
551
  });
552
</script>
486
553
487
</head>
554
</head>
488
<body id="cat_addbiblio" class="cat">
555
<body id="cat_addbiblio" class="cat">
Lines 847-853 Link Here
847
                                                [% ELSIF ( mv.type == 'textarea' ) %]
914
                                                [% ELSIF ( mv.type == 'textarea' ) %]
848
                                                    <textarea cols="70" rows="4" id="[%- mv.id | html -%]" name="[%- mv.name | html -%]" class="input_marceditor" tabindex="1">[%- mv.value | html -%]</textarea>
915
                                                    <textarea cols="70" rows="4" id="[%- mv.id | html -%]" name="[%- mv.name | html -%]" class="input_marceditor" tabindex="1">[%- mv.value | html -%]</textarea>
849
                                                [% ELSIF ( mv.type == 'select' ) %]
916
                                                [% ELSIF ( mv.type == 'select' ) %]
850
                                                    <select name="[%- mv.name | html -%]" tabindex="1" size="1" class="input_marceditor select2" id="[%- mv.id | html -%]">
917
                                                    [% IF mv.category AND CAN_user_parameters_manage_auth_values %]
918
                                                        <select name="[%- mv.name | html -%]" tabindex="1" size="1" class="input_marceditor" id="[%- mv.id | html -%]" data-category="[% mv.category | html %]">
919
                                                    [% ELSE %]
920
                                                        <select name="[%- mv.name | html -%]" tabindex="1" size="1" class="input_marceditor select2" id="[%- mv.id | html -%]">
921
                                                    [% END %]
851
                                                    [% FOREACH aval IN mv.values %]
922
                                                    [% FOREACH aval IN mv.values %]
852
                                                        [% IF aval == mv.default %]
923
                                                        [% IF aval == mv.default %]
853
                                                        <option value="[%- aval | html -%]" selected="selected">[%- mv.labels.$aval | html -%]</option>
924
                                                        <option value="[%- aval | html -%]" selected="selected">[%- mv.labels.$aval | html -%]</option>
Lines 892-897 Link Here
892
                <input type="hidden" name="duedatespec" value="[% duedatespec | html %]" />
963
                <input type="hidden" name="duedatespec" value="[% duedatespec | html %]" />
893
                [%# End of fields for fast cataloging %]
964
                [%# End of fields for fast cataloging %]
894
            </form> <!-- /name=f -->
965
            </form> <!-- /name=f -->
966
967
            <div id="avCreate" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="avCreateLabel" aria-hidden="true">
968
                <div class="modal-dialog">
969
                    <div class="modal-content">
970
                        <div class="modal-header">
971
                            <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button>
972
                            <h3 id="avCreateLabel">Create a new authorised value</h3>
973
                        </div>
974
                        <form id="add_new_av" method="post">
975
                            <div class="modal-body">
976
                                <div class="error"></div>
977
                                <fieldset class="rows">
978
                                    <ol>
979
                                        <li>
980
                                            <span class="label">Category:</span>
981
                                            <input type="hidden" name="category" value="" />
982
                                            <span id="new_av_category"></span>
983
                                        </li>
984
                                        <li>
985
                                            <span class="label" for="value">Authorised value:</span>
986
                                            <input type="text" id="value" name="value" />
987
                                        </li>
988
                                        <li>
989
                                            <span class="label" for="description">Description:</span>
990
                                            <input type="text" id="description" name="description" />
991
                                        </li>
992
                                        <li>
993
                                            <span class="label" for="opac_description">Description (OPAC):</span>
994
                                            <input type="text" id="opac_description" name="opac_description" />
995
                                        </li>
996
                                    </ol>
997
                                </fieldset>
998
                            </div>
999
                            <div class="modal-footer">
1000
                                <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">Close</button>
1001
                                <input type="hidden" name="select2" value="" />
1002
                                <input type="submit" class="btn btn-primary" value="Save">
1003
                            </div>
1004
                        </form>
1005
                    </div> <!-- /.modal-content -->
1006
                </div> <!-- /.modal-dialog -->
1007
            </div> <!-- /#avCreate -->
1008
895
        </div> <!-- /.col-md-10.col-md-offset-1 -->
1009
        </div> <!-- /.col-md-10.col-md-offset-1 -->
896
    </div> <!-- /.row -->
1010
    </div> <!-- /.row -->
897
1011
898
- 

Return to bug 25728