Update fields and fix bugs

This commit is contained in:
manson 2014-08-11 19:16:52 +08:00
parent b763b047eb
commit 736ba69bc4
9 changed files with 107 additions and 140 deletions

View File

@ -30,11 +30,11 @@ class Admin::JournalPapersController < OrbitMemberController
def new def new
@journal_paper = JournalPaper.new @journal_paper = JournalPaper.new
@members_data = JournalPaper.member_data rescue nil @member = MemberProfile.find_by(:uid=>params['uid']) rescue nil
end end
def edit def edit
@members_data = JournalPaper.member_data rescue nil @member = @journal_paper.member_profile
end end
def create def create
@ -51,8 +51,6 @@ class Admin::JournalPapersController < OrbitMemberController
end end
def update def update
@journal_paper_authors = @journal_paper.journal_paper_authors
respond_to do |format| respond_to do |format|
if @journal_paper.update_attributes(journal_paper_attributes) if @journal_paper.update_attributes(journal_paper_attributes)
format.html { redirect_to params['referer_url'] } format.html { redirect_to params['referer_url'] }

View File

@ -29,6 +29,7 @@ class JournalPapersController < ApplicationController
"journal_title", "journal_title",
"level_type", "level_type",
"paper_type", "paper_type",
"author_name",
"authors", "authors",
"author_type", "author_type",
"year", "year",
@ -41,6 +42,7 @@ class JournalPapersController < ApplicationController
"total_pages", "total_pages",
"isbn", "isbn",
"url", "url",
"associated_project",
"note", "note",
"file" "file"
] ]

View File

@ -9,6 +9,9 @@ class JournalPaper
field :paper_title, as: :slug_title, type: String, localize: true field :paper_title, as: :slug_title, type: String, localize: true
field :journal_title, type: String, localize: true field :journal_title, type: String, localize: true
field :authors, type: String, localize: true
field :associated_project , type: String, localize: true
field :year, type: String field :year, type: String
field :language, type: String field :language, type: String
field :isbn, type: String field :isbn, type: String
@ -22,6 +25,7 @@ class JournalPaper
field :publication_date, type: DateTime field :publication_date, type: DateTime
field :url, type: String field :url, type: String
field :note, type: String field :note, type: String
field :number_of_authors
field :rss2_id field :rss2_id
paginates_per 10 paginates_per 10
@ -34,12 +38,12 @@ class JournalPaper
has_many :journal_paper_files, autosave: true, dependent: :destroy has_many :journal_paper_files, autosave: true, dependent: :destroy
accepts_nested_attributes_for :journal_paper_files accepts_nested_attributes_for :journal_paper_files
has_and_belongs_to_many :journal_paper_authors, dependent: :destroy # has_and_belongs_to_many :journal_paper_authors, dependent: :destroy
accepts_nested_attributes_for :journal_paper_authors # accepts_nested_attributes_for :journal_paper_authors
has_and_belongs_to_many :journal_paper_author_types has_and_belongs_to_many :journal_paper_author_types
after_save :save_journal_paper_files, :save_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
@ -48,7 +52,7 @@ class JournalPaper
title = [] title = []
title << self.member_profile.name if self.member_profile_id.present? title << self.member_profile.name if self.member_profile_id.present?
title << (!self.journal_paper_authors.blank? ? "#{self.journal_paper_authors.collect{|j| j.name}.join(', ')}" : nil) title << (!self.authors.blank? ? self.authors : nil)
if !self.publication_date.nil? if !self.publication_date.nil?
pd = self.publication_date.strftime("%Y-%m-%d").split('-') pd = self.publication_date.strftime("%Y-%m-%d").split('-')
title << pd[0] title << pd[0]
@ -62,41 +66,34 @@ class JournalPaper
title.join(', ').gsub(', ,',',') title.join(', ').gsub(', ,',',')
end end
def authors # def self.member_data
authors = [] # members = MemberProfile.all
authors << self.member_profile.name if self.member_profile_id.present? # member_data = []
authors << self.journal_paper_authors.collect{|j| j.name}.join(', ') unless self.journal_paper_authors.blank? # members.each do |m|
authors.join(', ') # if (m.first_name || m.last_name)
end # member_data << {"memberId" => m.id.to_s, "memberName" => m.name}
# else
# member_data << {"memberId" => m.id.to_s, "memberName" => "No Name"}
# end
# end
# member_data.to_json
# end
def self.member_data # def save_journal_paper_files
members = MemberProfile.all # self.journal_paper_files.each do |t|
member_data = [] # if t.should_destroy
members.each do |m| # t.destroy
if (m.first_name || m.last_name) # end
member_data << {"memberId" => m.id.to_s, "memberName" => m.name} # end
else # end
member_data << {"memberId" => m.id.to_s, "memberName" => "No Name"}
end
end
member_data.to_json
end
def save_journal_paper_files # def save_journal_paper_authors
self.journal_paper_files.each do |t| # self.journal_paper_authors.each do |t|
if t.should_destroy # if t.should_destroy
t.destroy # t.destroy
end # end
end # end
end # end
def save_journal_paper_authors
self.journal_paper_authors.each do |t|
if t.should_destroy
t.destroy
end
end
end
def get_plugin_data(fields_to_show) def get_plugin_data(fields_to_show)
plugin_datas = [] plugin_datas = []
@ -116,6 +113,14 @@ class JournalPaper
value = self.journal_paper_author_types.collect{|type| type.title}.join(',') rescue "" value = self.journal_paper_author_types.collect{|type| type.title}.join(',') rescue ""
when "paper_type" when "paper_type"
value = self.journal_paper_type.title rescue "" value = self.journal_paper_type.title rescue ""
when "author_name"
value = []
([I18n.locale]+(Site.first.in_use_locales-[I18n.locale])).each do |locale|
if self.member_profile.first_name_translations[locale] || self.member_profile.last_name_translations[locale]
value << "#{self.member_profile.first_name_translations[locale]} #{self.member_profile.last_name_translations[locale]}"
end
end
value = value.join(" / ")
when "publication_date" when "publication_date"
value = self.publication_date.to_date.strftime("%Y-%m-%d") rescue "" value = self.publication_date.to_date.strftime("%Y-%m-%d") rescue ""
when "language" when "language"

View File

@ -20,8 +20,7 @@
<div class="input-area"> <div class="input-area">
<!-- Module Tabs --> <!-- Module Tabs -->
<div class="nav-name"><strong><%= t(:module) %></strong></div> <ul class="nav nav-pills module-nav">
<ul class="nav nav-pills module-nav">
<li></li> <li></li>
<li class="active"> <li class="active">
<a href="#basic" data-toggle="tab"><%= t(:basic) %></a> <a href="#basic" data-toggle="tab"><%= t(:basic) %></a>
@ -37,17 +36,14 @@
<!-- Basic Module --> <!-- Basic Module -->
<div class="tab-pane fade in active" id="basic"> <div class="tab-pane fade in active" id="basic">
<% if !params[:user_id].blank? %>
<div class="control-group"> <div class="control-group">
<label class="control-label muted"><%= t("personal_plugins.author") %></label> <label class="control-label muted"><%= t("personal_plugins.author") %></label>
<div class="controls"> <div class="controls">
<%= User.from_id(params[:user_id]).name rescue ''%> <%= @member.name rescue ''%>
<%= f.hidden_field :member_profile_id, :value => @member.id %>
</div> </div>
</div> </div>
<% end %>
<!-- year --> <!-- year -->
<div class="control-group"> <div class="control-group">
<label class="control-label muted"><%= t("personal_journal.year") %></label> <label class="control-label muted"><%= t("personal_journal.year") %></label>
@ -60,7 +56,11 @@
<div class="control-group"> <div class="control-group">
<label class="control-label muted"><%= t("personal_journal.language") %></label> <label class="control-label muted"><%= t("personal_journal.language") %></label>
<div class="controls"> <div class="controls">
<%= f.select :language, @site_valid_locales, :prompt => 'Select', :class => "span3" %> <select id="journal_paper_language" name="journal_paper[language]">
<% @site_in_use_locales.each do |locale| %>
<option value="<%= locale %>" <%= @journal_paper.language.eql?(locale.to_s) ? "selected" : ""%>><%= t(locale) %></option>
<% end %>
</select>
</div> </div>
</div> </div>
@ -86,16 +86,6 @@
</div> </div>
</div> </div>
<!-- authors-->
<div class="control-group input-title">
<label class="control-label muted"><%= t("personal_journal.author") %></label>
<div class="controls">
<%= f.text_field :member_profile_id, id: "member_autocomplete", autocomplete: "off", data: { provide: "typeahead"}, class: "input-block-level", value: (@journal_paper.member_profile.name rescue nil), placeholder: t("personal_journal.author")%>
<%= f.hidden_field :member_profile_id, value: (@journal_paper.member_profile_id ? @journal_paper.member_profile_id : ""), id: "member_value" %>
</div>
</div>
<!-- author_type --> <!-- author_type -->
<div class="control-group"> <div class="control-group">
<label class="control-label muted"><%= t("personal_journal.author_type") %></label> <label class="control-label muted"><%= t("personal_journal.author_type") %></label>
@ -109,6 +99,22 @@
</div> </div>
</div> </div>
<!-- number_of_authors -->
<div class="control-group">
<label class="control-label muted"><%= t("personal_journal.number_of_authors") %></label>
<div class="controls">
<%= f.text_field :number_of_authors, :class=>'span1' %>
</div>
</div>
<!-- associated_project -->
<div class="control-group">
<label class="control-label muted"><%= t("personal_journal.associated_project") %></label>
<div class="controls">
<%= f.text_field :associated_project %>
</div>
</div>
<!-- vol_no --> <!-- vol_no -->
<div class="control-group"> <div class="control-group">
<label class="control-label muted"><%= t("personal_journal.vol_no") %></label> <label class="control-label muted"><%= t("personal_journal.vol_no") %></label>
@ -161,7 +167,7 @@
<div class="control-group"> <div class="control-group">
<label class="control-label muted"><%= t("personal_journal.publication_date") %></label> <label class="control-label muted"><%= t("personal_journal.publication_date") %></label>
<div class="controls"> <div class="controls">
<%= f.datetime_picker :publication_date, :no_label => true %> <%= f.datetime_picker :publication_date, :no_label => true, :format=>"yyyy/MM/dd", :placeholder=>"YYYY/MM/DD" %>
</div> </div>
</div> </div>
@ -245,32 +251,19 @@
</div> </div>
</div> </div>
<!-- authors-->
<div class="control-group input-title">
<label class="control-label muted"><%= t("personal_journal.authors") %></label>
<div class="controls">
<%= f.fields_for :authors_translations do |f| %>
<%= f.text_area locale, class: "input-block-level", placeholder: t("personal_journal.authors"), value: (@journal_paper.authors_translations[locale] rescue nil) %>
<% end %>
</div>
</div>
</div> </div>
<% end %> <% end %>
<div class="control-group">
<label class="control-label muted"><%= t("personal_journal.co-authors") %></label>
<div class="controls">
<% if @journal_paper && !@journal_paper.journal_paper_authors.blank? %>
<div class="exist">
<% @journal_paper.journal_paper_authors.each_with_index do |author, i| %>
<%= f.fields_for :journal_paper_authors, author do |f| %>
<%= render :partial => 'form_author', :object => author, :locals => {:f => f, :i => i} %>
<% end %>
<% end %>
<hr>
</div>
<% end %>
<!-- Add -->
<div class="add-target-box">
</div>
<p class="add-btn-box">
<a id="add_author" class="trigger btn btn-small btn-primary"><i class="icons-plus"></i> <%= t(:add) %></a>
</p>
</div>
</div>
<!-- File --> <!-- File -->
<div class="control-group"> <div class="control-group">
@ -299,12 +292,8 @@
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<!-- Form Actions --> <!-- Form Actions -->
@ -313,7 +302,6 @@
<%= f.submit t('submit'), class: 'btn btn-primary' %> <%= f.submit t('submit'), class: 'btn btn-primary' %>
<%= link_to t('cancel'), get_go_back, :class=>"btn" %> <%= link_to t('cancel'), get_go_back, :class=>"btn" %>
</div> </div>
<%= render 'author_autocomplete'%>
<script> <script>
$(document).ready(function() { $(document).ready(function() {
$('.main-forms .add-on').tooltip(); $('.main-forms .add-on').tooltip();
@ -340,29 +328,3 @@
}); });
}); });
</script> </script>
<script>
$(document).ready(function() {
$('.main-forms .add-on').tooltip();
$(document).on('click', '#add_author', function(){
var new_id = $(this).prev().attr('value');
var old_id = new RegExp("new_authors", "g");
var on = $('.language-nav li.active').index();
var le = $(this).parent('.add-btn-box').prev('.add-target-box').children('.start-line').length;
$(this).prev().attr('value', parseInt(new_id) + 1);
$(this).parent().siblings('.add-target-box').append(("<%= escape_javascript(add_attribute 'form_author', f, :journal_paper_authors) %>").replace(old_id, new_id));
$(this).parent('.add-btn-box').prev('.add-target-box').children('.start-line').eq(le).children('.input-append').find('.tab-content').each(function() {
$(this).children('.tab-pane').eq(on).addClass('in active').siblings().removeClass('in active');
});
formTip();
});
$(document).on('click', '.delete_file', function(){
$(this).parents('.input-prepend').remove();
});
$(document).on('click', '.remove_existing_record', function(){
if(confirm("<%= I18n.t(:sure?)%>")){
$(this).children('.should_destroy').attr('value', 1);
$(this).parents('.start-line').hide();
}
});
});
</script>

View File

@ -5,7 +5,7 @@
<% if form_file.journal_file.blank? %> <% if form_file.journal_file.blank? %>
<%= t(:no_file) %> <%= t(:no_file) %>
<% else %> <% else %>
<%= link_to content_tag(:i) + form_file.title, form_file.journal_file.url, {:class => 'file-link file-type', :target => '_blank', :title => form_file.title} %> <%= link_to content_tag(:i) + form_file.journal_file_identifier, form_file.journal_file.url, {:class => 'file-link file-type', :target => '_blank', :title => form_file.journal_file_identifier} %>
<% end %> <% end %>
<% end %> <% end %>
<div class="input-prepend input-append"> <div class="input-prepend input-append">

View File

@ -6,29 +6,11 @@
<% end %> <% end %>
<% <%
@filter = params[:filter]
new_filter = params[:new_filter]
if @filter && params[:clear]
@filter.delete(params[:type])
elsif @filter && new_filter
if @filter.has_key?(new_filter[:type]) && @filter[new_filter[:type]].include?(new_filter[:id].to_s)
@filter[new_filter[:type]].delete(new_filter[:id].to_s)
elsif @filter.has_key?(new_filter[:type])
@filter[new_filter[:type]] << new_filter[:id].to_s
else
@filter.merge!({new_filter[:type] => [new_filter[:id].to_s]})
end
elsif new_filter
@filter = {new_filter[:type] => [new_filter[:id].to_s]}
end
if has_access? if has_access?
@writing_journals = JournalPaper.where(member_profile_id: @member.id).desc(:year).page(params[:page]).per(10) @writing_journals = JournalPaper.where(member_profile_id: @member.id).desc(:year).page(params[:page]).per(10)
else else
@writing_journals = JournalPaper.where(is_hidden: false, member_profile_id: @member.id).desc(:year).page(params[:page]).per(10) @writing_journals = JournalPaper.where(is_hidden: false, member_profile_id: @member.id).desc(:year).page(params[:page]).per(10)
end end
%> %>
<% if has_access? %> <% if has_access? %>
@ -69,7 +51,7 @@
<div class="quick-edit"> <div class="quick-edit">
<ul class="nav nav-pills hide"> <ul class="nav nav-pills hide">
<% if has_access? %> <% if has_access? %>
<li><%= link_to t('edit'), edit_admin_journal_paper_path(writing_journal, member_profile_id: @member.id) %></li> <li><%= link_to t('edit'), edit_admin_journal_paper_path(writing_journal) %></li>
<li><%= link_to t(:delete_), admin_journal_paper_path(id: writing_journal.id, member_profile_id: @member.id), method: :delete, remote: true, data: { confirm: t('sure?') } %></li> <li><%= link_to t(:delete_), admin_journal_paper_path(id: writing_journal.id, member_profile_id: @member.id), method: :delete, remote: true, data: { confirm: t('sure?') } %></li>
<% end %> <% end %>
</ul> </ul>
@ -90,10 +72,10 @@
<div class="action pull-right"> <div class="action pull-right">
<%= link_to content_tag(:i, nil, :class => 'icon-edit') +' '+ t('setting'),admin_journal_paper_intros_path(member_profile_id: @member.id), :class => 'btn btn-primary' %> <%= link_to content_tag(:i, nil, :class => 'icon-edit') +' '+ t('setting'),admin_journal_paper_intros_path(member_profile_id: @member.id), :class => 'btn btn-primary' %>
<%= link_to content_tag(:i, nil, :class => 'icon-plus') + t('new_'), new_admin_journal_paper_path(member_profile_id: @member.id), :class => 'btn btn-primary' %> <%= link_to content_tag(:i, nil, :class => 'icon-plus') + t('new_'), '/admin/members/'+@member.to_param+'/journal_papers/new', :class => 'btn btn-primary' %>
</div> </div>
<div class="pagination pagination-centered"> <div class="pagination pagination-centered">
<%= paginate @writing_journals, :params => {:direction => params[:direction], :sort => params[:sort], :filter => @filter, :new_filter => nil} %> <%= paginate @writing_journals, :params => {:direction => params[:direction], :sort => params[:sort]} %>
</div> </div>
</div> </div>
<% end %> <% end %>

View File

@ -6,6 +6,7 @@ en:
journal_title : "Journal Title" journal_title : "Journal Title"
authors : "Authors" authors : "Authors"
author: "Author" author: "Author"
author_name: "Author Name"
co-authors: "Co-Authors" co-authors: "Co-Authors"
tags : "Tags" tags : "Tags"
year : "Year" year : "Year"

View File

@ -2,10 +2,13 @@ zh_tw:
module_name: module_name:
journal_paper: 期刊論文 journal_paper: 期刊論文
personal_journal: personal_journal:
associated_project: "所屬計畫案"
number_of_authors: "著作人數"
paper_title : "論文名稱" paper_title : "論文名稱"
journal_title : "期刊名稱" journal_title : "期刊名稱"
authors : "作者" authors : "全部作者"
author: "作者" author: "作者"
author_name: "作者姓名"
tags : "領域" tags : "領域"
year : "年度" year : "年度"
language : "語言" language : "語言"

View File

@ -16,6 +16,20 @@ Rails.application.routes.draw do
match "add_paper_type" => "journal_papers#add_paper_type" ,as: :add_paper_type, via: [:get, :post] match "add_paper_type" => "journal_papers#add_paper_type" ,as: :add_paper_type, via: [:get, :post]
match "edit_paper_type" => "journal_papers#edit_paper_type" ,as: :edit_paper_type, via: [:get, :post] match "edit_paper_type" => "journal_papers#edit_paper_type" ,as: :edit_paper_type, via: [:get, :post]
end end
resources :members do
collection do
scope '(:name-:uid)' do
resources :journal_papers do
collection do
get 'frontend_setting' => 'journal_papers#frontend_setting'
post 'update_frontend_setting' => 'journal_papers#update_frontend_setting'
end
end
end
end
end
resources :journal_levels resources :journal_levels
resources :journal_paper_author_types resources :journal_paper_author_types
resources :journal_paper_types resources :journal_paper_types