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

Return to bug 25728