From b8fb7e90d4c14924ef192ebd8265d5e8a56fbbd5 Mon Sep 17 00:00:00 2001 From: spen Date: Tue, 20 Jan 2015 14:47:46 +0800 Subject: [PATCH] add data can select member --- app/controllers/admin/researchs_controller.rb | 48 ++++++++++++++++--- app/models/research.rb | 2 +- app/views/admin/researchs/_form.html.erb | 15 +++++- app/views/admin/researchs/index.html.erb | 3 ++ 4 files changed, 60 insertions(+), 8 deletions(-) diff --git a/app/controllers/admin/researchs_controller.rb b/app/controllers/admin/researchs_controller.rb index 206105c..e6de65c 100644 --- a/app/controllers/admin/researchs_controller.rb +++ b/app/controllers/admin/researchs_controller.rb @@ -22,14 +22,50 @@ class Admin::ResearchsController < OrbitMemberController end def create - @member = MemberProfile.find(research_params['member_profile_id']) rescue nil - @research = Research.new(research_params) - @research.save - if params[:desktop] == "true" - render json: {"data" => get_paper_list}.to_json - else + + if !research_params['member_profile_id'].blank? + + @member = MemberProfile.find(research_params['member_profile_id']) rescue nil + @research = Research.new(research_params) + @research.save + + if params[:desktop] == "true" + render json: {"data" => get_paper_list}.to_json + else + redirect_to params['referer_url'] + end + + elsif !params[:author_members].blank? + + params[:author_members].each do |author_member| + + research_params['member_profile_id'] = author_member + @research = Research.new(research_params) + @research.save + + if params[:desktop] == "true" + render json: {"data" => get_paper_list}.to_json + end + + end + redirect_to params['referer_url'] + + else + + research_params['member_profile_id'] = User.find(current_user.id).member_profile_id + + @research = Research.new(research_params) + @research.save + + if params[:desktop] == "true" + render json: {"data" => get_paper_list}.to_json + end + + redirect_to params['referer_url'] + end + end def edit diff --git a/app/models/research.rb b/app/models/research.rb index 0d7c738..bc49717 100644 --- a/app/models/research.rb +++ b/app/models/research.rb @@ -58,7 +58,7 @@ class Research pd_data = [] fields_to_show.collect do |t| if t == "research_title" - pd_data << { "data_title" => "#{p.send(t)}" } + pd_data << { "data_title" => "#{p.send(t)}" } else pd_data << { "data_title" => p.send(t) } end diff --git a/app/views/admin/researchs/_form.html.erb b/app/views/admin/researchs/_form.html.erb index a3528c1..682bb99 100644 --- a/app/views/admin/researchs/_form.html.erb +++ b/app/views/admin/researchs/_form.html.erb @@ -115,14 +115,27 @@
+ <% if !@member.nil? %> +
<%= @member.name rescue ''%> - <%= f.hidden_field :member_profile_id, :value => @member.id if !@member.nil? %> + <%= f.hidden_field :member_profile_id, :value => @member.id %> +
+
+ + <% else %> + +
+ +
+ <%= render partial: 'admin/member_selects/email_selection_box', locals: {field: 'author_members[]', email_members:[]} %>
+ <% end %> +
diff --git a/app/views/admin/researchs/index.html.erb b/app/views/admin/researchs/index.html.erb index e3bdce2..db475df 100644 --- a/app/views/admin/researchs/index.html.erb +++ b/app/views/admin/researchs/index.html.erb @@ -13,6 +13,9 @@
+
+ <%= link_to content_tag(:i, nil, :class => 'icon-plus icon-white') + t(:new_), new_admin_research_path, :class => 'btn btn-primary' %> +