diff --git a/app/controllers/admin/journal_papers_controller.rb b/app/controllers/admin/journal_papers_controller.rb index c028c38..0c814f4 100644 --- a/app/controllers/admin/journal_papers_controller.rb +++ b/app/controllers/admin/journal_papers_controller.rb @@ -2,7 +2,7 @@ class Admin::JournalPapersController < OrbitMemberController before_action :set_journal_paper, only: [:show, :edit , :update, :destroy] before_action :get_plugins, only: [:index, :writing_journal_setting, :new, :create, :edit, :update] - before_action :set_types, only: [:writing_journal_setting, :new, :edit, :create] + before_action :set_types, only: [:writing_journal_setting, :new, :edit, :create, :update] def index @writing_journals = JournalPaper.all @@ -23,7 +23,7 @@ class Admin::JournalPapersController < OrbitMemberController def new @journal_paper = JournalPaper.new - @members_data = JournalPaper.member_data + @members_data = JournalPaper.member_data rescue nil respond_to do |format| format.html # new.html.erb @@ -33,7 +33,7 @@ class Admin::JournalPapersController < OrbitMemberController def edit @journal_paper = JournalPaper.find(params[:id]) - @members_data = JournalPaper.member_data + @members_data = JournalPaper.member_data rescue nil end def create diff --git a/app/models/journal_paper.rb b/app/models/journal_paper.rb index bb9b245..3226317 100644 --- a/app/models/journal_paper.rb +++ b/app/models/journal_paper.rb @@ -34,6 +34,8 @@ class JournalPaper has_and_belongs_to_many :journal_paper_authors accepts_nested_attributes_for :journal_paper_authors + after_save :save_journal_paper_files, :save_journal_paper_authors + before_validation :add_http validates :paper_title, presence: true @@ -71,6 +73,22 @@ class JournalPaper member_data.to_json end + def save_journal_paper_files + self.journal_paper_files.each do |t| + if t.should_destroy + t.destroy + end + end + end + + def save_journal_paper_authors + self.journal_paper_authors.each do |t| + if t.should_destroy + t.destroy + end + end + end + protected def add_http diff --git a/app/models/journal_paper_author.rb b/app/models/journal_paper_author.rb index 2a3a880..9de194b 100644 --- a/app/models/journal_paper_author.rb +++ b/app/models/journal_paper_author.rb @@ -4,14 +4,12 @@ class JournalPaperAuthor field :name, type: String, localize: true field :email, type: String + field :should_destroy, type: Boolean has_and_belongs_to_many :journal_papers has_and_belongs_to_many :journal_paper_author_types VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/ validates :email, format: { with: VALID_EMAIL_REGEX }, - allow_blank: true, - uniqueness: { case_sensitive: false } - - before_save { |author| author.email = email.downcase if not author.email.nil?} + allow_blank: true end diff --git a/app/models/journal_paper_file.rb b/app/models/journal_paper_file.rb index e6040a1..36af09c 100644 --- a/app/models/journal_paper_file.rb +++ b/app/models/journal_paper_file.rb @@ -5,6 +5,7 @@ class JournalPaperFile field :description, type: String, localize: true field :title, type: String, localize: true + field :should_destroy, type: Boolean mount_uploader :journal_file, AssetUploader belongs_to :journal_paper diff --git a/app/views/admin/journal_papers/_form.html.erb b/app/views/admin/journal_papers/_form.html.erb index 40bbaa9..fc4bd98 100644 --- a/app/views/admin/journal_papers/_form.html.erb +++ b/app/views/admin/journal_papers/_form.html.erb @@ -24,11 +24,8 @@