From bd63df803ca8a7119eaf397bcf38b6eaeccd5264 Mon Sep 17 00:00:00 2001 From: Peter Chiu Date: Mon, 27 Feb 2023 11:54:06 +0800 Subject: [PATCH] add files --- .../admin/journal_types_controller.rb | 43 +++++++++++++++++++ app/models/journal_type.rb | 7 +++ .../_list_journal_type.html.erb | 10 +++++ app/views/admin/journal_types/_form.html.erb | 24 +++++++++++ app/views/admin/journal_types/_list.js.erb | 2 + app/views/admin/journal_types/edit.js.erb | 1 + app/views/admin/journal_types/new.js.erb | 1 + 7 files changed, 88 insertions(+) create mode 100644 app/controllers/admin/journal_types_controller.rb create mode 100644 app/models/journal_type.rb create mode 100644 app/views/admin/journal_papers/_list_journal_type.html.erb create mode 100644 app/views/admin/journal_types/_form.html.erb create mode 100644 app/views/admin/journal_types/_list.js.erb create mode 100644 app/views/admin/journal_types/edit.js.erb create mode 100644 app/views/admin/journal_types/new.js.erb diff --git a/app/controllers/admin/journal_types_controller.rb b/app/controllers/admin/journal_types_controller.rb new file mode 100644 index 0000000..a475bd0 --- /dev/null +++ b/app/controllers/admin/journal_types_controller.rb @@ -0,0 +1,43 @@ +class Admin::JournalTypesController < OrbitMemberController + before_action :allow_admin_only + + def new + @journal_type = JournalType.new + @url = admin_journal_types_path(@journal_type) + render :layout=>false + end + + def create + @journal_type = JournalType.new(journal_type_params) + @journal_type.save + @journal_types = JournalType.all + render :partial=>'list', :layout=>false + end + + def edit + @journal_type = JournalType.find(params[:id]) + @url = admin_journal_paper_journal_type_path(@journal_type) + render :layout=>false + end + + def update + @journal_type = JournalType.find(params[:id]) + @journal_type.update_attributes(journal_type_params) + @journal_type.save + @journal_types = JournalType.all + render :partial=>'list', :layout=>false + end + + def destroy + journal_type = JournalType.find(params[:id]) + journal_type.destroy + @journal_types = JournalType.all + render :partial=>'list', :layout=>false + end + + private + + def journal_type_params + params.require(:journal_type).permit! rescue nil + end +end diff --git a/app/models/journal_type.rb b/app/models/journal_type.rb new file mode 100644 index 0000000..4ae8e4c --- /dev/null +++ b/app/models/journal_type.rb @@ -0,0 +1,7 @@ +class JournalType + include Mongoid::Document + include Mongoid::Timestamps + + field :title, type: String, localize: true + +end diff --git a/app/views/admin/journal_papers/_list_journal_type.html.erb b/app/views/admin/journal_papers/_list_journal_type.html.erb new file mode 100644 index 0000000..0355ade --- /dev/null +++ b/app/views/admin/journal_papers/_list_journal_type.html.erb @@ -0,0 +1,10 @@ +<% # encoding: utf-8 %> + + + <%= list_journal_type.title %> + + + <%= t(:edit) %> + <%= link_to t(:delete_), admin_journal_type_path(list_journal_type), "data-confirm" => t('sure?'), :method => :delete, :remote => true,:class=>"archive_toggle action" %> + + \ No newline at end of file diff --git a/app/views/admin/journal_types/_form.html.erb b/app/views/admin/journal_types/_form.html.erb new file mode 100644 index 0000000..a0c12dc --- /dev/null +++ b/app/views/admin/journal_types/_form.html.erb @@ -0,0 +1,24 @@ +<%= form_for(@journal_type, :html =>{:class=>"form-horizontal", :style=>"margin: 0;"}, :remote => true, :url => @url ) do |f| %> + + + + + +<% end %> \ No newline at end of file diff --git a/app/views/admin/journal_types/_list.js.erb b/app/views/admin/journal_types/_list.js.erb new file mode 100644 index 0000000..a43a135 --- /dev/null +++ b/app/views/admin/journal_types/_list.js.erb @@ -0,0 +1,2 @@ +$('#journal_types tbody').html("<%= j render :partial => '/admin/journal_papers/list_journal_type', :collection => @journal_types %>"); +$('#journal_type_modal').modal('hide'); \ No newline at end of file diff --git a/app/views/admin/journal_types/edit.js.erb b/app/views/admin/journal_types/edit.js.erb new file mode 100644 index 0000000..104a65b --- /dev/null +++ b/app/views/admin/journal_types/edit.js.erb @@ -0,0 +1 @@ +$('#journal_type_modal').html("<%= j render 'form' %>"); \ No newline at end of file diff --git a/app/views/admin/journal_types/new.js.erb b/app/views/admin/journal_types/new.js.erb new file mode 100644 index 0000000..104a65b --- /dev/null +++ b/app/views/admin/journal_types/new.js.erb @@ -0,0 +1 @@ +$('#journal_type_modal').html("<%= j render 'form' %>"); \ No newline at end of file