forked from saurabh/personal-journal
fixed delete and author
This commit is contained in:
parent
c57a6fa961
commit
be56f7685b
|
@ -2,7 +2,7 @@ class Admin::JournalPapersController < OrbitMemberController
|
||||||
|
|
||||||
before_action :set_journal_paper, only: [:show, :edit , :update, :destroy]
|
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 :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
|
def index
|
||||||
@writing_journals = JournalPaper.all
|
@writing_journals = JournalPaper.all
|
||||||
|
@ -23,7 +23,7 @@ class Admin::JournalPapersController < OrbitMemberController
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@journal_paper = JournalPaper.new
|
@journal_paper = JournalPaper.new
|
||||||
@members_data = JournalPaper.member_data
|
@members_data = JournalPaper.member_data rescue nil
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html # new.html.erb
|
format.html # new.html.erb
|
||||||
|
@ -33,7 +33,7 @@ class Admin::JournalPapersController < OrbitMemberController
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
@journal_paper = JournalPaper.find(params[:id])
|
@journal_paper = JournalPaper.find(params[:id])
|
||||||
@members_data = JournalPaper.member_data
|
@members_data = JournalPaper.member_data rescue nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
|
|
|
@ -34,6 +34,8 @@ class JournalPaper
|
||||||
has_and_belongs_to_many :journal_paper_authors
|
has_and_belongs_to_many :journal_paper_authors
|
||||||
accepts_nested_attributes_for :journal_paper_authors
|
accepts_nested_attributes_for :journal_paper_authors
|
||||||
|
|
||||||
|
after_save :save_journal_paper_files, :save_journal_paper_authors
|
||||||
|
|
||||||
before_validation :add_http
|
before_validation :add_http
|
||||||
validates :paper_title, presence: true
|
validates :paper_title, presence: true
|
||||||
|
|
||||||
|
@ -71,6 +73,22 @@ class JournalPaper
|
||||||
member_data.to_json
|
member_data.to_json
|
||||||
end
|
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
|
protected
|
||||||
|
|
||||||
def add_http
|
def add_http
|
||||||
|
|
|
@ -4,14 +4,12 @@ class JournalPaperAuthor
|
||||||
|
|
||||||
field :name, type: String, localize: true
|
field :name, type: String, localize: true
|
||||||
field :email, type: String
|
field :email, type: String
|
||||||
|
field :should_destroy, type: Boolean
|
||||||
|
|
||||||
has_and_belongs_to_many :journal_papers
|
has_and_belongs_to_many :journal_papers
|
||||||
has_and_belongs_to_many :journal_paper_author_types
|
has_and_belongs_to_many :journal_paper_author_types
|
||||||
|
|
||||||
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/
|
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/
|
||||||
validates :email, format: { with: VALID_EMAIL_REGEX },
|
validates :email, format: { with: VALID_EMAIL_REGEX },
|
||||||
allow_blank: true,
|
allow_blank: true
|
||||||
uniqueness: { case_sensitive: false }
|
|
||||||
|
|
||||||
before_save { |author| author.email = email.downcase if not author.email.nil?}
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,6 +5,7 @@ class JournalPaperFile
|
||||||
|
|
||||||
field :description, type: String, localize: true
|
field :description, type: String, localize: true
|
||||||
field :title, type: String, localize: true
|
field :title, type: String, localize: true
|
||||||
|
field :should_destroy, type: Boolean
|
||||||
|
|
||||||
mount_uploader :journal_file, AssetUploader
|
mount_uploader :journal_file, AssetUploader
|
||||||
belongs_to :journal_paper
|
belongs_to :journal_paper
|
||||||
|
|
|
@ -24,11 +24,8 @@
|
||||||
<li class="active">
|
<li class="active">
|
||||||
<a href="#basic" data-toggle="tab"><%= t(:basic) %></a>
|
<a href="#basic" data-toggle="tab"><%= t(:basic) %></a>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
|
||||||
<a href="#status" data-toggle="tab"><%= t(:status) %></a>
|
|
||||||
</li>
|
|
||||||
<li>
|
<li>
|
||||||
<a href="#tag" data-toggle="tab"><%= t(:tags) %></a>
|
<a href="#status" data-toggle="tab"><%= t(:status) %></a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
<span class="remove_existing_record add-on btn" title="<%= t(:remove) %>">
|
<span class="remove_existing_record add-on btn" title="<%= t(:remove) %>">
|
||||||
<%= f.hidden_field :id %>
|
<%= f.hidden_field :id %>
|
||||||
<a class="icon-remove"></a>
|
<a class="icon-remove"></a>
|
||||||
<%= f.hidden_field :_destroy, :value => nil, :class => 'should_destroy' %>
|
<%= f.hidden_field :should_destroy, :value => nil, :class => 'should_destroy' %>
|
||||||
</span>
|
</span>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
<span class="remove_existing_record add-on btn" title="<%= t(:remove) %>">
|
<span class="remove_existing_record add-on btn" title="<%= t(:remove) %>">
|
||||||
<%= f.hidden_field :id %>
|
<%= f.hidden_field :id %>
|
||||||
<a class="icon-remove"></a>
|
<a class="icon-remove"></a>
|
||||||
<%= f.hidden_field :_destroy, :value => nil, :class => 'should_destroy' %>
|
<%= f.hidden_field :should_destroy, :value => nil, :class => 'should_destroy' %>
|
||||||
</span>
|
</span>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -46,7 +46,7 @@ en:
|
||||||
yes_: "Yes"
|
yes_: "Yes"
|
||||||
no_: "No"
|
no_: "No"
|
||||||
cancel : "Cancel"
|
cancel : "Cancel"
|
||||||
save: "save"
|
save: "Save"
|
||||||
hintText: "Type in a search term"
|
hintText: "Type in a search term"
|
||||||
noResultsText: "No results"
|
noResultsText: "No results"
|
||||||
searchingText: "Searching…"
|
searchingText: "Searching…"
|
Loading…
Reference in New Issue