This commit is contained in:
manson 2014-07-02 17:37:34 +08:00
parent e5260c59dd
commit 22d437b74c
24 changed files with 647 additions and 1 deletions

View File

@ -0,0 +1,41 @@
class Admin::HonorTypesController < OrbitAdminController
def new
@honor_type = HonorType.new
@url = admin_honor_types_path(@honor_type)
render :layout=>false
end
def create
@honor_type = HonorType.new(honor_type_params)
@honor_type.save
@honor_types = HonorType.all
render :partial=>'list', :layout=>false
end
def edit
@honor_type = HonorType.find(params[:id])
@url = admin_honor_type_path(@honor_type)
render :layout=>false
end
def update
@honor_type = HonorType.find(params[:id])
@honor_type.update_attributes(honor_type_params)
@honor_type.save
@honor_types = HonorType.all
render :partial=>'list', :layout=>false
end
def destroy
honor_type = HonorType.find(params[:id])
honor_type.destroy
@honor_types = HonorType.all
render :partial=>'list', :layout=>false
end
private
def honor_type_params
params.require(:honor_type).permit! rescue nil
end
end

View File

@ -0,0 +1,89 @@
class Admin::HonorsController < OrbitMemberController
layout "member_plugin"
before_action :set_plugin
before_action :get_settings,:only => [:new, :edit, :setting]
def index
@honors = Honor.all
end
def new
@member = MemberProfile.find_by(:uid=>params['uid']) rescue nil
@honor = Honor.new
end
def create
@member = MemberProfile.find(honor_params['member_profile_id']) rescue nil
@honor = Honor.new(honor_params)
@honor.save
redirect_to '/admin/members/'+@member.to_param+'/Honor'
end
def edit
@member = MemberProfile.find_by(:uid=>params['uid']) rescue nil
@honor = Honor.find(params[:id])
end
def update
@member = MemberProfile.find(honor_params['member_profile_id']) rescue nil
@honor = Honor.find(params[:id])
@honor.update_attributes(honor_params)
@honor.save
redirect_to '/admin/members/'+@member.to_param+'/Honor'
end
def destroy
@honor = Honor.find(params[:id])
@honor.destroy
end
def toggle_hide
if params[:ids]
@honors = Honor.any_in(_id: params[:ids])
@honors.each do |honor|
honor.is_hidden = params[:disable]
honor.save
end
end
render json: {"success"=>true}
end
def setting
end
def frontend_setting
@member = MemberProfile.find_by(:uid=>params['uid']) rescue nil
@intro = HonorIntro.find_by(:member_profile_id=>@member.id) rescue nil
@intro = @intro.nil? ? HonorIntro.new({:member_profile_id=>@member.id}) : @intro
end
def update_frontend_setting
@member = MemberProfile.find(intro_params['member_profile_id']) rescue nil
@intro = HonorIntro.find_by(:member_profile_id=>@member.id) rescue nil
@intro = @intro.nil? ? HonorIntro.new({:member_profile_id=>@member.id}) : @intro
@intro.update_attributes(intro_params)
@intro.save
redirect_to '/admin/members/'+@member.to_param+'/Honor'
end
def get_settings
@honor_types = HonorType.all
end
def set_plugin
@plugin = OrbitApp::Plugin::Registration.all.select{|plugin| plugin.app_name.eql? 'Honor'}.first
end
private
def honor_params
params.require(:honor).permit! rescue nil
end
def intro_params
params.require(:honor_intro).permit! rescue nil
end
end

36
app/models/honor.rb Normal file
View File

@ -0,0 +1,36 @@
class Honor
include Mongoid::Document
include Mongoid::Timestamps
include OrbitModel::Status
include Slug
belongs_to :honor_type
belongs_to :member_profile
field :year
field :award_name
field :awarding_unit
field :language
field :keywords
field :url
field :note
field :create_user_id, :type => BSON::ObjectId
field :update_user_id, :type => BSON::ObjectId
paginates_per 10
before_validation :add_http
def slug_title
self.award_name+' '+self.awarding_unit
end
protected
def add_http
unless self.url.blank? || self.url[/^http:\/\//] || self.url[/^https:\/\//]
self.url = 'http://' + self.url
end
end
end

View File

@ -0,0 +1,4 @@
class HonorIntro < PersonalPluginIntro
end

8
app/models/honor_type.rb Normal file
View File

@ -0,0 +1,8 @@
class HonorType
include Mongoid::Document
include Mongoid::Timestamps
field :title, localize: true
has_many :honors
end

View File

@ -0,0 +1,24 @@
<%= form_for(@honor_type, :html =>{:class=>"form-horizontal", :style=>"margin: 0;"}, :remote => true, :url => @url ) do |f| %>
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel"><%= t("personal_honor.honor_category") %></h3>
</div>
<div class="modal-body">
<%= f.fields_for :title_translations do |f| %>
<% @site_in_use_locales.each do |locale| %>
<div class="control-group">
<%= label_tag t(locale), t(locale), :class => 'control-label' %>
<div class="controls">
<%= f.text_field locale, :value => (@honor_type.title_translations[locale] rescue nil) %>
</div>
</div>
<% end %>
<% end %>
</div>
<div class="modal-footer">
<%= f.submit t('submit'), :class=>'btn btn-primary' %>
<a class="btn" data-dismiss="modal"><%= t('cancel')%></a>
</div>
<% end %>

View File

@ -0,0 +1,2 @@
$('#honor_types tbody').html("<%= j render :partial => '/admin/honors/list_honor_type', :collection => @honor_types %>");
$('#honor_type_modal').modal('hide');

View File

@ -0,0 +1 @@
$('#honor_type_modal').html("<%= j render 'form' %>");

View File

@ -0,0 +1 @@
$('#honor_type_modal').html("<%= j render 'form' %>");

View File

@ -0,0 +1,131 @@
<% # encoding: utf-8 %>
<% content_for :page_specific_css do %>
<%= stylesheet_link_tag "lib/main-forms" %>
<%= stylesheet_link_tag "lib/main-list" %>
<% end %>
<% content_for :page_specific_javascript do %>
<%= javascript_include_tag "lib/file-type" %>
<%= javascript_include_tag "lib/module-area" %>
<% end %>
<!-- Input Area -->
<div class="input-area">
<!-- Module Tabs -->
<div class="nav-name"><strong><%= t(:module) %></strong></div>
<ul class="nav nav-pills module-nav">
<li></li>
<li class="active">
<a href="#basic" data-toggle="tab"><%= t(:basic) %></a>
</li>
<li>
<a href="#status" data-toggle="tab"><%= t(:status) %></a>
</li>
</ul>
<!-- Module -->
<div class="tab-content module-area">
<!-- Basic Module -->
<div class="tab-pane fade in active" id="basic">
<div class="control-group">
<label class="control-label muted"><%= t("personal_plugins.author") %></label>
<div class="controls">
<%= @member.name rescue ''%>
<%= f.hidden_field :member_profile_id, :value => @member.id %>
</div>
</div>
<!-- personal_honor -->
<div class="control-group">
<label class="control-label muted"><%= t("personal_honor.year") %></label>
<div class="controls">
<%= select_year((@honor.year ? @honor.year.to_i : DateTime.now.year), {:start_year => DateTime.now.year, :end_year => 1930}, {:name => 'honor[year]', :class => "span1"} ) %>
</div>
</div>
<!-- honor_type -->
<div class="control-group">
<label class="control-label muted"><%= t("personal_honor.honor_category") %></label>
<div class="controls">
<%= f.select :honor_type_id, @honor_types.collect {|t| [ t.title, t.id ]} %>
</div>
</div>
<!-- award_name -->
<div class="control-group">
<label class="control-label muted"><%= t("personal_honor.award_name") %></label>
<div class="controls">
<%= f.text_field :award_name %>
</div>
</div>
<!-- awarding_unit -->
<div class="control-group">
<label class="control-label muted"><%= t("personal_honor.awarding_unit") %></label>
<div class="controls">
<%= f.text_field :awarding_unit %>
</div>
</div>
<!-- url -->
<div class="control-group">
<label class="control-label muted"><%= t("personal_honor.url") %></label>
<div class="controls">
<%= f.text_field :url , :class => "span6" %>
</div>
</div>
<!-- keywords -->
<div class="control-group">
<label class="control-label muted"><%= t("personal_honor.keywords") %></label>
<div class="controls">
<%= f.text_field :keywords %>
</div>
</div>
<!-- language -->
<div class="control-group">
<label class="control-label muted"><%= t("personal_honor.language") %></label>
<div class="controls">
<select id="honor_language" name="honor[language]">
<% @site_in_use_locales.each do |locale| %>
<option value="<%= locale %>" <%= @honor.language.eql?(locale.to_s) ? "selected" : ""%>><%= t(locale) %></option>
<% end %>
</select>
</div>
</div>
<!-- note -->
<div class="control-group">
<label class="control-label muted"><%= t("personal_honor.note") %></label>
<div class="controls">
<%= f.text_area :note, rows: 2, class: "input-block-level" %>
</div>
</div>
</div>
<!-- Status Module -->
<div class="tab-pane fade" id="status">
<div class="control-group">
<label class="control-label muted"><%= t(:status) %></label>
<div class="controls" data-toggle="buttons-checkbox">
<label class="checkbox inline btn <%= 'active' if @honor.is_hidden? %>">
<%= f.check_box :is_hidden %> <%= t(:hide) %>
</label>
</div>
</div>
</div>
</div>
</div>
<!-- Form Actions -->
<div class="form-actions">
<%= f.hidden_field :user_id, :value => params[:user_id] if !params[:user_id].blank? %>
<%= f.submit t('submit'), class: 'btn btn-primary' %>
<%= link_to t('cancel'), get_go_back, :class=>"btn" %>
</div>

View File

@ -0,0 +1,16 @@
<% @honors.each do |honor| %>
<tr id="<%= dom_id honor %>" class="<%= honor.is_hidden ? "checkHide" : "" %>">
<td><%= honor.year %></td>
<td>
<%= link_to honor.award_name, '', target: "blank"%>
<div class="quick-edit">
<ul class="nav nav-pills hide">
<li><%= link_to t('edit'), '/admin/members/'+honor.member_profile.to_param+'/honors/'+honor.id+'/edit' %></li>
<li><%= link_to t(:delete_), admin_honor_path(id: honor.id, member_profile_id: honor.member_profile.id), method: :delete, remote: true, data: { confirm: t('sure?') } %></li>
</ul>
</div>
</td>
<td><%= honor.awarding_unit %></td>
<td><%= honor.member_profile.name %></td>
</tr>
<% end %>

View File

@ -0,0 +1,8 @@
<tr id="<%= dom_id list_honor_type %>">
<td><%= list_honor_type.title %></td>
<td class="span2">
<a href="<%= edit_admin_honor_type_path(list_honor_type) %>#honor_type_modal" data-toggle="modal" data-remote="true" class="action"><%= t(:edit) %></a>
<%= link_to t(:delete_), admin_honor_type_path(list_honor_type), "data-confirm" => t('sure?'), :method => :delete, :remote => true,:class=>"archive_toggle action" %>
</td>
</tr>

View File

@ -0,0 +1 @@
$('#honor_<%= @honor.id.to_s%>').remove();

View File

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

View File

@ -0,0 +1,93 @@
<% content_for :page_specific_css do %>
<%= stylesheet_link_tag "lib/main-forms" %>
<%= stylesheet_link_tag "lib/main-list" %>
<% end %>
<%= form_for(:honor_intro, :url => update_frontend_setting_admin_honors_path, :method => "post", html: {class: "form-horizontal main-forms previewable"} ) do |f| %>
<fieldset>
<!-- Input Area -->
<div class="input-area">
<!-- Module Tabs -->
<div class="nav-name"><strong><%= t("module_name.personal_honor") %></strong></div>
<ul class="nav nav-pills module-nav">
<li></li>
<li class="active">
<a href="#basic" data-toggle="tab"><%= t(:basic) %></a>
</li>
</ul>
<!-- Module -->
<div class="tab-content module-area">
<!-- Basic Module -->
<div class="tab-pane fade in active" id="basic">
<% if !@member.blank? %>
<div class="control-group">
<label class="control-label muted"><%= t("personal_plugins.author") %></label>
<div class="controls">
<%= @member.name rescue ''%>
<%= f.hidden_field :member_profile_id, :value => @member.id %>
</div>
</div>
<% end %>
<!-- frontend_page -->
<div class="control-group">
<label class="control-label muted"><%= t("personal_plugins.frontend_page") %></label>
<div class="controls">
<%= f.check_box :brief_intro, :checked => @intro.brief_intro %> <%= t("personal_plugins.brief_intro") %>
<%= f.check_box :complete_list, :checked => @intro.complete_list %> <%= t("personal_plugins.complete_list") %>
</div>
</div>
</div>
</div>
<!-- Language Tabs -->
<div class="nav-name"><strong><%= t(:language) %></strong></div>
<ul class="nav nav-pills language-nav">
<% @site_in_use_locales.each_with_index do |locale, i| %>
<li class="<%= 'active' if i == 0 %>">
<a data-toggle="tab" href=".<%= locale %>"><%= t(locale) %></a>
</li>
<% end %>
</ul>
<!-- Language -->
<div class="tab-content language-area">
<% @site_in_use_locales.each_with_index do |locale, i| %>
<div class="<%= locale %> tab-pane fade <%= ( i == 0 ) ? "in active" : '' %>">
<!-- Content -->
<div class="control-group input-content">
<label class="control-label muted"><%= t(:content) %></label>
<div class="controls">
<div class="textarea">
<%= f.fields_for :text_translations do |f| %>
<%= f.cktext_area locale, rows: 5, class: "input-block-level", :value => (@intro.text_translations[locale] rescue nil) %>
<% end %>
</div>
</div>
</div>
</div>
<% end %>
</div>
</div>
<!-- Form Actions -->
<div class="form-actions">
<%= f.hidden_field :user_id, :value => params[:user_id] if !params[:user_id].blank? %>
<%= f.submit t('submit'), class: 'btn btn-primary' %>
<%= link_to t('cancel'), get_go_back, :class=>"btn" %>
</div>
</fieldset>
<% end %>

View File

@ -0,0 +1,21 @@
<table class="table main-list">
<thead>
<tr>
<th class="span3"><%= t('personal_honor.year') %></th>
<th class="span3"><%= t('personal_honor.award_name') %></th>
<th class="span3"><%= t('personal_honor.awarding_unit') %></th>
<th class="span3"><%= t('personal_honor.award_winner') %></th>
</tr>
</thead>
<tbody id="tbody_experiences" class="sort-holder">
<%= render :partial => 'honor', :collection => @honors %>
</tbody>
</table>
<div class="bottomnav clearfix">
<div class="action pull-right">
<%= link_to content_tag(:i, nil, :class => 'icon-cog icon-white') + t('setting'), admin_honor_setting_path, :class => 'btn btn-primary pull-right' %>
</div>
<div class="pagination pagination-centered">
</div>
</div>

View File

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

View File

@ -0,0 +1,52 @@
<style type="text/css">
.element{
background: #FFF;
margin-bottom: 10px;
border-radius: 5px;
border: 1px solid #DDD;
}
.detail{
padding: 10px;
min-height: 250px;
}
.totle{
margin-bottom: 25px;
}
.totle span{
font-size: 18px;
}
</style>
<div class="row">
<div class="element span4">
<div class="detail w-a h-a">
<p class="totle">
<a class="btn btn-small btn-primary pull-right" href="<%= new_admin_honor_type_path %>#honor_type_modal" data-toggle="modal" data-remote="true"><i class="icon-plus"></i> <%= t('add')%></a>
<span><%= t("personal_honor.honor_category") %></span>
</p>
<div class="detal-list my_scroll">
<div class="scrollbar">
<div class="track">
<div class="thumb">
<div class="end"></div>
</div>
</div>
</div>
<div class="viewport">
<div class="overview">
<table id="honor_types" class="table table-striped">
<tbody>
<%= render :partial => 'list_honor_type', :collection => @honor_types %>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
<div id="honor_type_qe">
<div style="display:none;" class="modal" id="honor_type_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
</div>
</div>

View File

@ -0,0 +1,86 @@
<% 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 %>
<%
is_autorized_user = (current_user==@member.user || current_user.is_admin?)
if is_autorized_user
@honors = Honor.where(member_profile_id: @member.id).desc(:year).page(params[:page]).per(10)
else
@honors = Honor.where(is_hidden: false, member_profile_id: @member.id).desc(:year).page(params[:page]).per(10)
end
%>
<% if is_autorized_user %>
<div class="list-active">
<div class="btn-group">
<%= link_to('Hide', '#', :class => "btn btn-mini list-active-btn disabled", "data-check-action" => "list-be-hide", :rel => toggle_hide_admin_honors_path(member_profile_id: params[:id], disable: 'true') ) %>
<%= link_to('Show', '#', :class => "btn btn-mini list-active-btn disabled", "data-check-action" => "list-be-show", :rel => toggle_hide_admin_honors_path(member_profile_id: params[:id], disable: 'false') ) %>
</div>
</div>
<% end -%>
<table class="table table-condensed table-striped main-list">
<thead>
<tr>
<% if is_autorized_user %>
<th><input type="checkbox" /></th>
<% end -%>
<th class="span3"><%= t('personal_honor.year') %></th>
<th class="span3"><%= t('personal_honor.award_name') %></th>
<th class="span3"><%= t('personal_honor.awarding_unit') %></th>
<th class="span3"><%= t('personal_honor.award_winner') %></th>
</tr>
</thead>
<tbody>
<% @honors.each do |honor| %>
<tr id="<%= dom_id honor %>" class="<%= honor.is_hidden ? "checkHide" : "" %>">
<% if is_autorized_user %>
<td>
<%= check_box_tag 'to_change[]', honor.id.to_s, false, :class => "list-check" %>
</td>
<% end %>
<td><%= honor.year %></td>
<td>
<%= link_to honor.award_name, '', target: "blank"%>
<div class="quick-edit">
<ul class="nav nav-pills hide">
<li><%= link_to t('edit'), '/admin/members/'+@member.to_param+'/honors/'+honor.id+'/edit' %></li>
<li><%= link_to t(:delete_), admin_honor_path(id: honor.id, member_profile_id: @member.id), method: :delete, remote: true, data: { confirm: t('sure?') } %></li>
</ul>
</div>
</td>
<td><%= honor.awarding_unit %></td>
<td><%= honor.member_profile.name %></td>
</tr>
<% end %>
</tbody>
</table>
<div class="bottomnav clearfix">
<% if is_autorized_user %>
<div class="action pull-right">
<%= link_to content_tag(:i, nil, :class => 'icon-edit') +' '+ t('setting'),'/admin/members/'+@member.to_param+'/honors/frontend_setting', :class => 'btn btn-primary' %>
<%= link_to content_tag(:i, nil, :class => 'icon-plus') +' '+ t('new_'),
'/admin/members/'+@member.to_param+'/honors/new', :class => 'btn btn-primary' %>
</div>
<% end %>
<div class="pagination pagination-centered">
<%= paginate @honors, :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>

View File

@ -2,6 +2,28 @@ Rails.application.routes.draw do
locales = Site.find_by(site_active: true).in_use_locales rescue I18n.available_locales
scope "(:locale)", locale: Regexp.new(locales.join("|")) do
namespace :admin do
get 'honor_setting' => "honors#setting"
resources :honors do
collection do
get 'toggle_hide' => 'honors#toggle_hide'
end
end
resources :members do
collection do
scope '(:name-:uid)' do
resources :honors do
collection do
get 'frontend_setting' => 'honors#frontend_setting'
post 'update_frontend_setting' => 'honors#update_frontend_setting'
end
end
end
end
end
resources :honor_types
end
end
end

View File

@ -4,7 +4,7 @@ module PersonalHonor
OrbitApp.registration "PersonalHonor",:type=> 'ModuleApp' do
module_label 'module_name.personal_honor'
base_url File.expand_path File.dirname(__FILE__)
personal_plugin :enable => true, :sort_number => '50', :app_name=>"Honor", :intro_app_name=>"PersonalHonorIntro",:path=>"/plugin/profile",:front_path=>"/profile",:admin_path=>"/admin/honors",:i18n=>'module_name.personal_honor'
personal_plugin :enable => true, :sort_number => '50', :app_name=>"Honor", :intro_app_name=>"PersonalHonorIntro",:path=>"/plugin/personal_honor/profile",:front_path=>"/profile",:admin_path=>"/admin/honors",:i18n=>'module_name.personal_honor'
version "0.1"
organization "Rulingcom"