From 2b9ea7b2655bb8723de52f6ab79b0928dc4c070d Mon Sep 17 00:00:00 2001 From: spen Date: Tue, 20 Jan 2015 14:46:24 +0800 Subject: [PATCH] add data can select member --- app/controllers/admin/patents_controller.rb | 48 ++++++++++++++++++--- app/models/patent.rb | 2 +- app/views/admin/patents/_form.html.erb | 15 ++++++- app/views/admin/patents/_patent.html.erb | 2 +- app/views/admin/patents/index.html.erb | 1 + 5 files changed, 59 insertions(+), 9 deletions(-) diff --git a/app/controllers/admin/patents_controller.rb b/app/controllers/admin/patents_controller.rb index 44f0123..6f6bd63 100644 --- a/app/controllers/admin/patents_controller.rb +++ b/app/controllers/admin/patents_controller.rb @@ -23,14 +23,50 @@ class Admin::PatentsController < OrbitMemberController end def create - @member = MemberProfile.find(patent_params['member_profile_id']) rescue nil - @patent = Patent.new(patent_params) - @patent.save - if params[:desktop] == "true" - render json: {"data" => get_paper_list}.to_json - else + + if !patent_params['member_profile_id'].blank? + + @member = MemberProfile.find(patent_params['member_profile_id']) rescue nil + @patent = Patent.new(patent_params) + @patent.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| + + patent_params['member_profile_id'] = author_member + @patent = Patent.new(patent_params) + @patent.save + + if params[:desktop] == "true" + render json: {"data" => get_paper_list}.to_json + end + + end + redirect_to params['referer_url'] + + else + + patent_params['member_profile_id'] = User.find(current_user.id).member_profile_id + + @patent = Patent.new(patent_params) + @patent.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/patent.rb b/app/models/patent.rb index 800c4fc..cec7330 100644 --- a/app/models/patent.rb +++ b/app/models/patent.rb @@ -60,7 +60,7 @@ class Patent pd_data = [] fields_to_show.collect do |t| if t == "patent_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/patents/_form.html.erb b/app/views/admin/patents/_form.html.erb index 23e3812..ccf9ce2 100644 --- a/app/views/admin/patents/_form.html.erb +++ b/app/views/admin/patents/_form.html.erb @@ -114,14 +114,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/patents/_patent.html.erb b/app/views/admin/patents/_patent.html.erb index 1c3d54b..e137c2e 100644 --- a/app/views/admin/patents/_patent.html.erb +++ b/app/views/admin/patents/_patent.html.erb @@ -1,6 +1,6 @@ <% @patents.each do |patent| %> "> - <%= patent.publish_date.strftime("%Y.%m") %> + <%= patent.publish_date.strftime("%Y.%m") rescue "" %> <%= link_to patent.patent_title, OrbitHelper.url_to_plugin_show(patent.to_param,'personal_patent').to_s, target: "blank"%>
diff --git a/app/views/admin/patents/index.html.erb b/app/views/admin/patents/index.html.erb index 3f517e6..aa1890a 100644 --- a/app/views/admin/patents/index.html.erb +++ b/app/views/admin/patents/index.html.erb @@ -15,6 +15,7 @@
+ <%= link_to content_tag(:i, nil, :class => 'icon-plus icon-white') + t(:new_), new_admin_patent_path, :class => 'btn btn-primary' %> <%= link_to content_tag(:i, nil, :class => 'icon-cog icon-white') + t('setting'), admin_patent_setting_path, :class => 'btn btn-primary pull-right' %>