From 79c1701b64d73f51cb1e6ce08f95cb4937a842d0 Mon Sep 17 00:00:00 2001 From: spen Date: Tue, 20 Jan 2015 14:47:03 +0800 Subject: [PATCH] add data can select member --- app/controllers/admin/projects_controller.rb | 48 +++++++++++++++++--- app/models/project.rb | 2 +- app/views/admin/projects/_form.html.erb | 15 +++++- app/views/admin/projects/index.html.erb | 1 + 4 files changed, 58 insertions(+), 8 deletions(-) diff --git a/app/controllers/admin/projects_controller.rb b/app/controllers/admin/projects_controller.rb index 0a35223..a352357 100644 --- a/app/controllers/admin/projects_controller.rb +++ b/app/controllers/admin/projects_controller.rb @@ -22,14 +22,50 @@ class Admin::ProjectsController < OrbitMemberController end def create - @member = MemberProfile.find(project_params['member_profile_id']) rescue nil - @project = Project.new(project_params) - @project.save - if params[:desktop] == "true" - render json: {"data" => get_paper_list}.to_json - else + + if !project_params['member_profile_id'].blank? + + @member = MemberProfile.find(project_params['member_profile_id']) rescue nil + @project = Project.new(project_params) + @project.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| + + project_params['member_profile_id'] = author_member + @project = Project.new(project_params) + @project.save + + if params[:desktop] == "true" + render json: {"data" => get_paper_list}.to_json + end + + end + redirect_to params['referer_url'] + + else + + project_params['member_profile_id'] = User.find(current_user.id).member_profile_id + + @project = Project.new(project_params) + @project.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/project.rb b/app/models/project.rb index 68c05ec..fc7e8e2 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -60,7 +60,7 @@ class Project pd_data = [] fields_to_show.collect do |t| if t == "project_title" - pd_data << { "data_title" => "#{p.send(t)}" } + pd_data << { "data_title" => "#{p.send(t)}" } elsif t == "period" if !p.send('period_start_date').nil? or !p.send('period_end_date').nil? diff --git a/app/views/admin/projects/_form.html.erb b/app/views/admin/projects/_form.html.erb index 56c2982..ce836b8 100644 --- a/app/views/admin/projects/_form.html.erb +++ b/app/views/admin/projects/_form.html.erb @@ -125,14 +125,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/projects/index.html.erb b/app/views/admin/projects/index.html.erb index 2f4fc96..04e23ca 100644 --- a/app/views/admin/projects/index.html.erb +++ b/app/views/admin/projects/index.html.erb @@ -16,6 +16,7 @@
+ <%= link_to content_tag(:i, nil, :class => 'icon-plus icon-white') + t(:new_), new_admin_project_path, :class => 'btn btn-primary' %> <%= link_to content_tag(:i, nil, :class => 'icon-cog icon-white') + t('setting'), admin_project_setting_path, :class => 'btn btn-primary pull-right' %>