From 3ec3ccc13ff120f1c7d7ab4d94e115fc6626b9e9 Mon Sep 17 00:00:00 2001 From: spen Date: Tue, 20 Jan 2015 14:44:40 +0800 Subject: [PATCH] add data can select member --- app/controllers/admin/honors_controller.rb | 48 +++++++++++++++++++--- app/models/honor.rb | 2 +- app/views/admin/honors/_form.html.erb | 17 +++++++- app/views/admin/honors/index.html.erb | 1 + 4 files changed, 59 insertions(+), 9 deletions(-) diff --git a/app/controllers/admin/honors_controller.rb b/app/controllers/admin/honors_controller.rb index 0dd8d92..ed2df5f 100644 --- a/app/controllers/admin/honors_controller.rb +++ b/app/controllers/admin/honors_controller.rb @@ -23,14 +23,50 @@ class Admin::HonorsController < OrbitMemberController end def create - @member = MemberProfile.find(honor_params['member_profile_id']) rescue nil - @honor = Honor.new(honor_params) - @honor.save - if params[:desktop] == "true" - render json: {"data" => get_paper_list}.to_json - else + + if !honor_params['member_profile_id'].blank? + + @member = MemberProfile.find(honor_params['member_profile_id']) rescue nil + @honor = Honor.new(honor_params) + @honor.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| + + honor_params['member_profile_id'] = author_member + @honor = Honor.new(honor_params) + @honor.save + + if params[:desktop] == "true" + render json: {"data" => get_paper_list}.to_json + end + + end + redirect_to params['referer_url'] + + else + + honor_params['member_profile_id'] = User.find(current_user.id).member_profile_id + + @honor = Honor.new(honor_params) + @honor.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/honor.rb b/app/models/honor.rb index 96df36a..139522f 100644 --- a/app/models/honor.rb +++ b/app/models/honor.rb @@ -55,7 +55,7 @@ class Honor pd_data = [] fields_to_show.collect do |t| if t == "award_name" - 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/honors/_form.html.erb b/app/views/admin/honors/_form.html.erb index f2a3c11..943055c 100644 --- a/app/views/admin/honors/_form.html.erb +++ b/app/views/admin/honors/_form.html.erb @@ -72,13 +72,26 @@
+ <% 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/honors/index.html.erb b/app/views/admin/honors/index.html.erb index 4ba2370..97c6f50 100644 --- a/app/views/admin/honors/index.html.erb +++ b/app/views/admin/honors/index.html.erb @@ -14,6 +14,7 @@
+ <%= link_to content_tag(:i, nil, :class => 'icon-plus icon-white') + t(:new_), new_admin_honor_path, :class => 'btn btn-primary' %> <%= link_to content_tag(:i, nil, :class => 'icon-cog icon-white') + t('setting'), admin_honor_setting_path, :class => 'btn btn-primary pull-right' %>