From 448411cdf1255117af70968483cd78712eb661ca Mon Sep 17 00:00:00 2001 From: spen Date: Tue, 20 Jan 2015 14:45:52 +0800 Subject: [PATCH] add data can select member --- app/controllers/admin/labs_controller.rb | 48 +++++++++++++++++++++--- app/models/lab.rb | 2 +- app/views/admin/labs/_form.html.erb | 17 ++++++++- app/views/admin/labs/index.html.erb | 3 ++ 4 files changed, 61 insertions(+), 9 deletions(-) diff --git a/app/controllers/admin/labs_controller.rb b/app/controllers/admin/labs_controller.rb index 878c93c..f7bdd99 100644 --- a/app/controllers/admin/labs_controller.rb +++ b/app/controllers/admin/labs_controller.rb @@ -22,14 +22,50 @@ class Admin::LabsController < OrbitMemberController end def create - @member = MemberProfile.find(lab_params['member_profile_id']) rescue nil - @lab = Lab.new(lab_params) - @lab.save - if params[:desktop] == "true" - render json: {"data" => get_paper_list}.to_json - else + + if !lab_params['member_profile_id'].blank? + + @member = MemberProfile.find(lab_params['member_profile_id']) rescue nil + @lab = Lab.new(lab_params) + @lab.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| + + lab_params['member_profile_id'] = author_member + @lab = Lab.new(lab_params) + @lab.save + + if params[:desktop] == "true" + render json: {"data" => get_paper_list}.to_json + end + + end + redirect_to params['referer_url'] + + else + + lab_params['member_profile_id'] = User.find(current_user.id).member_profile_id + + @lab = Lab.new(lab_params) + @lab.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/lab.rb b/app/models/lab.rb index ee6a969..897bb44 100644 --- a/app/models/lab.rb +++ b/app/models/lab.rb @@ -58,7 +58,7 @@ class Lab pd_data = [] fields_to_show.collect do |t| if t == "lab_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/labs/_form.html.erb b/app/views/admin/labs/_form.html.erb index a12c742..d5ee01f 100644 --- a/app/views/admin/labs/_form.html.erb +++ b/app/views/admin/labs/_form.html.erb @@ -121,14 +121,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/labs/index.html.erb b/app/views/admin/labs/index.html.erb index 8f037a1..38ffe03 100644 --- a/app/views/admin/labs/index.html.erb +++ b/app/views/admin/labs/index.html.erb @@ -13,6 +13,9 @@
+
+ <%= link_to content_tag(:i, nil, :class => 'icon-plus icon-white') + t(:new_), new_admin_lab_path, :class => 'btn btn-primary' %> +