add admin :new and :create

This commit is contained in:
EricTYL 2020-02-06 13:45:12 +08:00
parent f2d9d12d52
commit 43a70af1be
5 changed files with 118 additions and 2 deletions

View File

@ -16,6 +16,23 @@ class Admin::ActivitiesController < OrbitMemberController
end
end
def new
@activity = Activity.new
end
def create
if !activity_params['member_profile_id'].blank?
@member = MemberProfile.find(activity_params['member_profile_id']) rescue nil
elsif !params[:author_members].blank?
activity_params['member_profile_id'] = params[:author_members]
else
activity_params['member_profile_id'] = current_user.member_profile_id
end
@activity = Activity.new(activity_params)
@activity.save
redirect_to params['referer_url']
end
def edit
end
@ -39,6 +56,6 @@ class Admin::ActivitiesController < OrbitMemberController
end
def activity_params
params.require(:activity).permit(:activity_name, :activity_organizer, :activity_area, :year, :activity_start_date, :activity_end_date, :note)
params.require(:activity).permit! rescue nil
end
end

View File

@ -1,5 +1,5 @@
<% @activities.each do |activity| %>
<tr id="<%= %>" class="with_action">
<tr id="<%= dom_id activity %>" class="with_action">
<td class="span1"><%= activity.member_profile.name %></td>
<td class="span1"><%= activity.year %></td>
<td class="span5"><%= activity.activity_name %>

View File

@ -14,6 +14,13 @@
</table>
<div class="bottomnav clearfix">
<!-- buttons -->
<div class="action pull-right">
<%= link_to content_tag(:i, nil, :class => 'icon-plus icon-white') + t(:new_), new_admin_activity_path, :class => 'btn btn-primary' %>
</div>
<!-- pagination -->
<div class="pagination pagination-centered">
<%= content_tag :div, paginate(@activities), class: "pagination pagination-centered" %>
</div>

View File

@ -0,0 +1,5 @@
<%= form_for @activity, url: admin_activities_path, html: { class: "form-horizontal main-forms previewable" } do |f| %>
<fieldset>
<%= render partial: 'form', locals: {f: f} %>
</fieldset>
<% end %>

View File

@ -0,0 +1,87 @@
<% content_for :page_specific_css do %>
<%= stylesheet_link_tag "lib/list-check" %>
<% end %>
<% content_for :page_specific_javascript do %>
<%= javascript_include_tag "lib/list-check" %>
<% end %>
<%
#@activities = Activity.where(member_profile_id: current_user.member_profile.id).desc(:year).page(params[:page]).per(10)
if has_access?
@activities = Activity.where(member_profile_id: @member.id).desc(:year).page(params[:page]).per(10)
else
@activities = Activity.where(is_hidden: false, member_profile_id: @member.id).desc(:year).page(params[:page]).per(10)
end
%>
<table class="table table-condensed table-striped main-list">
<thead>
<tr>
<% if has_access? %>
<th><input type="checkbox" /></th>
<% end %>
<th class="span1"><%= t('personal_activity.year') %></th>
<th><%= t('personal_activity.activity_name') %></th>
<% if not @user%>
<th><%= t('personal_activity.activity_area') %></th>
<% end %>
</tr>
</thead>
<tbody>
<% @activities.each do |activity| %>
<tr id="<%= dom_id activity %>" class="<%= activity.is_hidden ? "checkHide" : "" %>">
<% if has_access? %>
<td>
<%= check_box_tag 'to_change[]', activity.id.to_s, false, :class => "list-check" %>
</td>
<% end %>
<td><%= activity.year %></td>
<td>
<%#= link_to activity.create_link, OrbitHelper.url_to_plugin_show(activity.to_param,'personal_activity'), target: "blank"%>
<% activity.activity_name %>
<% if has_access? %>
<div class="quick-edit">
<ul class="nav nav-pills hide">
<%# if current_user.is_admin? %>
<li><%= link_to t('edit'), edit_admin_activity_path(activity) %></li>
<li><%= link_to t(:delete_), admin_activity_path(id: activity.id), method: :delete, remote: true, data: { confirm: 'Are you sure?' } %></li>
<%# end %>
</ul>
</div>
<% end %>
</td>
<td><%= activity.activity_area %></td>
</tr>
<% end %>
</tbody>
</table>
<div class="bottomnav clearfix">
<% if has_access? %>
<div class="action pull-right">
<%#= link_to content_tag(:i, nil, :class => 'icon-edit') +' '+ t('setting'),'/admin/members/'+@member.to_param+'/books/frontend_setting', :class => 'btn btn-primary' %>
<%#= link_to content_tag(:i, nil, :class => 'icon-plus') +' '+ t('new_'),
'/admin/members/'+@member.to_param+'/books/new', :class => 'btn btn-primary' %>
</div>
<% end %>
<div class="pagination pagination-centered">
<%= paginate @activities, :params => {:direction => params[:direction], :sort => params[:sort] } %>
</div>
</div>
<div id="dialog" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="Delete item" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3><%= t(:sure?) %></h3>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true"><%= t(:close) %></button>
<button class="delete-item btn btn-danger"><%= t(:submit) %></button>
</div>
</div>