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 (-3 / +108 lines)
Lines 485-491 Link Here
485
[% INCLUDE 'select2.inc' %]
485
[% INCLUDE 'select2.inc' %]
486
<script>
486
<script>
487
  $(document).ready(function() {
487
  $(document).ready(function() {
488
    $('.subfield_line select').select2();
488
      $('.subfield_line select[data-category=""]').select2(); // branches, itemtypes and cn_source
489
490
      [% UNLESS CAN_user_parameters_manage_auth_values %]
491
          $('.subfield_line select[data-category!=""]').select2();
492
      [% ELSE %]
493
          var current_select2;
494
          $('.subfield_line select[data-category!=""]').select2({
495
              tags: true,
496
              createTag: function (tag) {
497
                  return {
498
                      id: tag.term,
499
                      text: tag.term,
500
                      newTag: true
501
                  };
502
              },
503
              templateResult: function(state) {
504
                  if (state.newTag) {
505
                      return state.text + " " + "(select to create)";
506
                  }
507
                  return state.text;
508
              }
509
          }).on("select2:select", function(e) {
510
              if(e.params.data.newTag){
511
512
                  var category = $(this).data("category");
513
                  $("#avCreate #new_av_category").html(category);
514
                  $("#avCreate input[name='category']").val(category);
515
                  $("#avCreate input[name='value']").val(e.params.data.text);
516
                  $("#avCreate input[name='description']").val(e.params.data.text);
517
                  $('#avCreate').modal({show:true});
518
519
                  $(current_select2).val($(current_select2).find("option:first").val()).trigger('change');
520
521
                  current_select2 = this;
522
523
              }
524
          });
525
526
          $("#avCreate").on('hide.bs.modal', function(e){
527
          });
528
529
          $("#add_new_av").on("submit", function(){
530
              var data = {
531
                  category: $(this).find('input[name="category"]').val(),
532
                  value: $(this).find('input[name="value"]').val(),
533
                  description: $(this).find('input[name="description"]').val(),
534
                  opac_description: $(this).find('input[name="opac_description"]').val(),
535
              };
536
              $.ajax({
537
                  type: "POST",
538
                  url: "/api/v1/authorised_values",
539
                  data:JSON.stringify(data),
540
                  success: function(response) {
541
                      $('#avCreate').modal('hide');
542
543
                      $(current_select2).append('<option selected value="'+data['value']+'">'+data['description']+'</option>');
544
                  },
545
                  error: function(err) {
546
                      $("#avCreate .error").html(_("Something went wrong, maybe the value already exists?"))
547
                  }
548
              });
549
              return false;
550
          });
551
      [% END %]
489
  });
552
  });
490
</script>
553
</script>
491
554
Lines 852-858 Link Here
852
                                                [% ELSIF ( mv.type == 'textarea' ) %]
915
                                                [% ELSIF ( mv.type == 'textarea' ) %]
853
                                                    <textarea cols="70" rows="4" id="[%- mv.id | html -%]" name="[%- mv.name | html -%]" class="input_marceditor" tabindex="1">[%- mv.value | html -%]</textarea>
916
                                                    <textarea cols="70" rows="4" id="[%- mv.id | html -%]" name="[%- mv.name | html -%]" class="input_marceditor" tabindex="1">[%- mv.value | html -%]</textarea>
854
                                                [% ELSIF ( mv.type == 'select' ) %]
917
                                                [% ELSIF ( mv.type == 'select' ) %]
855
                                                    <select name="[%- mv.name | html -%]" tabindex="1" size="1" class="input_marceditor" id="[%- mv.id | html -%]">
918
                                                    <select name="[%- mv.name | html -%]" tabindex="1" size="1" class="input_marceditor" id="[%- mv.id | html -%]" data-category="[% mv.category | html %]">
856
                                                    [% FOREACH aval IN mv.values %]
919
                                                    [% FOREACH aval IN mv.values %]
857
                                                        [% IF aval == mv.default %]
920
                                                        [% IF aval == mv.default %]
858
                                                        <option value="[%- aval | html -%]" selected="selected">[%- mv.labels.$aval | html -%]</option>
921
                                                        <option value="[%- aval | html -%]" selected="selected">[%- mv.labels.$aval | html -%]</option>
Lines 897-902 Link Here
897
                <input type="hidden" name="duedatespec" value="[% duedatespec | html %]" />
960
                <input type="hidden" name="duedatespec" value="[% duedatespec | html %]" />
898
                [%# End of fields for fast cataloging %]
961
                [%# End of fields for fast cataloging %]
899
            </form> <!-- /name=f -->
962
            </form> <!-- /name=f -->
963
964
            <div id="avCreate" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="avCreateLabel" aria-hidden="true">
965
                <div class="modal-dialog">
966
                    <div class="modal-content">
967
                        <div class="modal-header">
968
                            <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button>
969
                            <h3 id="avCreateLabel">Create a new authorised value</h3>
970
                        </div>
971
                        <form id="add_new_av" method="post">
972
                            <div class="modal-body">
973
                                <div class="error"></div>
974
                                <fieldset class="rows">
975
                                    <ol>
976
                                        <li>
977
                                            <span class="label">Category:</span>
978
                                            <input type="hidden" name="category" value="" />
979
                                            <span id="new_av_category"></span>
980
                                        </li>
981
                                        <li>
982
                                            <span class="label" for="value">Authorised value:</span>
983
                                            <input type="text" id="value" name="value" />
984
                                        </li>
985
                                        <li>
986
                                            <span class="label" for="description">Description:</span>
987
                                            <input type="text" id="description" name="description" />
988
                                        </li>
989
                                        <li>
990
                                            <span class="label" for="opac_description">Description (OPAC):</span>
991
                                            <input type="text" id="opac_description" name="opac_description" />
992
                                        </li>
993
                                    </ol>
994
                                </fieldset>
995
                            </div>
996
                            <div class="modal-footer">
997
                                <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">Close</button>
998
                                <input type="hidden" name="select2" value="" />
999
                                <input type="submit" class="btn btn-primary" value="Save">
1000
                            </div>
1001
                        </form>
1002
                    </div> <!-- /.modal-content -->
1003
                </div> <!-- /.modal-dialog -->
1004
            </div> <!-- /#avCreate -->
1005
900
        </div> <!-- /.col-md-10.col-md-offset-1 -->
1006
        </div> <!-- /.col-md-10.col-md-offset-1 -->
901
    </div> <!-- /.row -->
1007
    </div> <!-- /.row -->
902
1008
903
- 

Return to bug 25728