From 8e68fee3f6c9bc98050e53e70a7d259842554b51 Mon Sep 17 00:00:00 2001 From: spen Date: Tue, 20 Jan 2015 14:44:04 +0800 Subject: [PATCH] add data can select member --- app/controllers/admin/diplomas_controller.rb | 48 +++++++++++++++++--- app/models/diploma.rb | 2 +- app/views/admin/diplomas/_form.html.erb | 19 ++++++-- app/views/admin/diplomas/index.html.erb | 3 ++ 4 files changed, 62 insertions(+), 10 deletions(-) diff --git a/app/controllers/admin/diplomas_controller.rb b/app/controllers/admin/diplomas_controller.rb index b378d87..45f7f56 100644 --- a/app/controllers/admin/diplomas_controller.rb +++ b/app/controllers/admin/diplomas_controller.rb @@ -23,14 +23,50 @@ class Admin::DiplomasController < OrbitMemberController end def create - @member = MemberProfile.find(diploma_params['member_profile_id']) rescue nil - @diploma = Diploma.new(diploma_params) - @diploma.save - if params[:desktop] == "true" - render json: {"data" => get_paper_list}.to_json - else + + if !diploma_params['member_profile_id'].blank? + + @member = MemberProfile.find(diploma_params['member_profile_id']) rescue nil + @diploma = Diploma.new(diploma_params) + @diploma.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| + + diploma_params['member_profile_id'] = author_member + @diploma = Diploma.new(diploma_params) + @diploma.save + + if params[:desktop] == "true" + render json: {"data" => get_paper_list}.to_json + end + + end + redirect_to params['referer_url'] + + else + + diploma_params['member_profile_id'] = User.find(current_user.id).member_profile_id + + @diploma = Diploma.new(diploma_params) + @diploma.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/diploma.rb b/app/models/diploma.rb index c144327..80409b9 100644 --- a/app/models/diploma.rb +++ b/app/models/diploma.rb @@ -58,7 +58,7 @@ class Diploma pd_data = [] fields_to_show.collect do |t| if t == "school_name" - pd_data << { "data_title" => "#{p.send(t)}" } + pd_data << { "data_title" => "#{p.send(t)}" } elsif t == "duration" if !p.send('start_date').nil? or !p.send('end_date').nil? date = (p.send('start_date').strftime('%Y.%m') rescue "")+' ~ '+(p.send('end_date').strftime('%Y.%m') rescue I18n.t('personal_diploma.up_to_today')) diff --git a/app/views/admin/diplomas/_form.html.erb b/app/views/admin/diplomas/_form.html.erb index d8ffc84..b3944f3 100644 --- a/app/views/admin/diplomas/_form.html.erb +++ b/app/views/admin/diplomas/_form.html.erb @@ -93,14 +93,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/diplomas/index.html.erb b/app/views/admin/diplomas/index.html.erb index 1f3fc04..4375fb4 100644 --- a/app/views/admin/diplomas/index.html.erb +++ b/app/views/admin/diplomas/index.html.erb @@ -14,6 +14,9 @@
+
+ <%= link_to content_tag(:i, nil, :class => 'icon-plus icon-white') + t(:new_), new_admin_diploma_path, :class => 'btn btn-primary' %> +