fixed delete and author

This commit is contained in:
Saurabh Bhatia 2014-06-18 12:09:19 +08:00
parent c57a6fa961
commit be56f7685b
8 changed files with 28 additions and 14 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -27,9 +27,6 @@
<li>
<a href="#status" data-toggle="tab"><%= t(:status) %></a>
</li>
<li>
<a href="#tag" data-toggle="tab"><%= t(:tags) %></a>
</li>
</ul>
<!-- Module -->

View File

@ -32,7 +32,7 @@
<span class="remove_existing_record add-on btn" title="<%= t(:remove) %>">
<%= f.hidden_field :id %>
<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>
<% end %>
</div>

View File

@ -38,7 +38,7 @@
<span class="remove_existing_record add-on btn" title="<%= t(:remove) %>">
<%= f.hidden_field :id %>
<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>
<% end %>
</div>

View File

@ -46,7 +46,7 @@ en:
yes_: "Yes"
no_: "No"
cancel : "Cancel"
save: "save"
save: "Save"
hintText: "Type in a search term"
noResultsText: "No results"
searchingText: "Searching…"