diff --git a/app/controllers/calil/barcodes_controller.rb b/app/controllers/calil/barcodes_controller.rb new file mode 100644 index 0000000000..9e08f83779 --- /dev/null +++ b/app/controllers/calil/barcodes_controller.rb @@ -0,0 +1,11 @@ +class Calil::BarcodesController < ApplicationController + def new + @library = Library.friendly.find(params[:library_id]) + authorize @library + + @calil_barcode = Calil::Barcode.new(name: @library.name) + end + + def create + end +end diff --git a/app/models/calil/barcode.rb b/app/models/calil/barcode.rb new file mode 100644 index 0000000000..c02b81e72c --- /dev/null +++ b/app/models/calil/barcode.rb @@ -0,0 +1,15 @@ +module Calil + class Barcode + include ActiveModel::Model + include ActiveModel::Attributes + attributes :name, :string + attributes :initial_number, :string + attribuets :number_of_sheets, :integer, default: 1 + + with_options presence: true do + validates :name # 図書館名 + validates :initial_number # 開始番号 + end + validates :number_of_sheets, numericality: { greater_than_or_equal_to: 0 } # 枚数 + end +end diff --git a/app/views/calil/barcodes/new.html.erb b/app/views/calil/barcodes/new.html.erb new file mode 100644 index 0000000000..caf34f06ce --- /dev/null +++ b/app/views/calil/barcodes/new.html.erb @@ -0,0 +1,27 @@ +
+

<%= @library.display_name.localize -%>

+
+ <%= render 'page/required_field' %> + <%= form_with(model: @calil_barcode, url: library_barcodes_path, method: :post) do |f| %> + <%= error_messages(@calil_barcode) %> +
+ <%= f.label :name %> + <%= f.text_field :name, class: 'short_name' %> +
+ +
+ <%= f.label :initial_number %> + <%= f.text_field :initial_number, class: 'short_name' %> +
+ +
+ <%= f.label :number_of_sheets %> + <%= f.number_field :number_of_sheets, class: 'short_name' %> +
+ + <% end %> +
+
+ + diff --git a/app/views/libraries/show.html.erb b/app/views/libraries/show.html.erb index 99ac450971..98a713b663 100644 --- a/app/views/libraries/show.html.erb +++ b/app/views/libraries/show.html.erb @@ -133,6 +133,7 @@
  • <%= link_to t('page.new', model: t('activerecord.models.event')), new_event_path(library_id: @library.id) -%>
  • <%- end -%> <%- end -%> +
  • <%= link_to "連番を作成する", new_library_barcode_path(library_id: @library.name) -%>
  • <%= link_to t('page.listing', model: t('activerecord.models.library')), libraries_path -%>
  • diff --git a/config/routes.rb b/config/routes.rb index e6688a4c88..769c369ef4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -52,7 +52,9 @@ resources :carrier_types resources :content_types resources :donates - resources :libraries + resources :libraries do + resources :barcodes, only: [:new, :create], module: 'calil' + end resources :shelves resources :accepts resources :withdraws