From 22d437b74cd511981ca27496263c742cd441f473 Mon Sep 17 00:00:00 2001 From: manson Date: Wed, 2 Jul 2014 17:37:34 +0800 Subject: [PATCH] Finished --- .../.keep | 0 .../.keep | 0 .../.keep | 0 .../admin/honor_types_controller.rb | 41 ++++++ app/controllers/admin/honors_controller.rb | 89 ++++++++++++ app/models/honor.rb | 36 +++++ app/models/honor_intro.rb | 4 + app/models/honor_type.rb | 8 ++ app/views/admin/honor_types/_form.html.erb | 24 ++++ app/views/admin/honor_types/_list.js.erb | 2 + app/views/admin/honor_types/edit.js.erb | 1 + app/views/admin/honor_types/new.js.erb | 1 + app/views/admin/honors/_form.html.erb | 131 ++++++++++++++++++ app/views/admin/honors/_honor.html.erb | 16 +++ .../admin/honors/_list_honor_type.html.erb | 8 ++ app/views/admin/honors/destroy.js.erb | 1 + app/views/admin/honors/edit.html.erb | 5 + .../admin/honors/frontend_setting.html.erb | 93 +++++++++++++ app/views/admin/honors/index.html.erb | 21 +++ app/views/admin/honors/new.html.erb | 5 + app/views/admin/honors/setting.html.erb | 52 +++++++ .../plugin/personal_honor/_profile.html.erb | 86 ++++++++++++ config/routes.rb | 22 +++ lib/personal_honor/engine.rb | 2 +- 24 files changed, 647 insertions(+), 1 deletion(-) rename app/assets/images/{personal_honor => personal_conference}/.keep (100%) rename app/assets/javascripts/{personal_honor => personal_conference}/.keep (100%) rename app/assets/stylesheets/{personal_honor => personal_conference}/.keep (100%) create mode 100644 app/controllers/admin/honor_types_controller.rb create mode 100644 app/controllers/admin/honors_controller.rb create mode 100644 app/models/honor.rb create mode 100644 app/models/honor_intro.rb create mode 100644 app/models/honor_type.rb create mode 100644 app/views/admin/honor_types/_form.html.erb create mode 100644 app/views/admin/honor_types/_list.js.erb create mode 100644 app/views/admin/honor_types/edit.js.erb create mode 100644 app/views/admin/honor_types/new.js.erb create mode 100644 app/views/admin/honors/_form.html.erb create mode 100644 app/views/admin/honors/_honor.html.erb create mode 100644 app/views/admin/honors/_list_honor_type.html.erb create mode 100644 app/views/admin/honors/destroy.js.erb create mode 100644 app/views/admin/honors/edit.html.erb create mode 100644 app/views/admin/honors/frontend_setting.html.erb create mode 100644 app/views/admin/honors/index.html.erb create mode 100644 app/views/admin/honors/new.html.erb create mode 100644 app/views/admin/honors/setting.html.erb create mode 100644 app/views/plugin/personal_honor/_profile.html.erb diff --git a/app/assets/images/personal_honor/.keep b/app/assets/images/personal_conference/.keep similarity index 100% rename from app/assets/images/personal_honor/.keep rename to app/assets/images/personal_conference/.keep diff --git a/app/assets/javascripts/personal_honor/.keep b/app/assets/javascripts/personal_conference/.keep similarity index 100% rename from app/assets/javascripts/personal_honor/.keep rename to app/assets/javascripts/personal_conference/.keep diff --git a/app/assets/stylesheets/personal_honor/.keep b/app/assets/stylesheets/personal_conference/.keep similarity index 100% rename from app/assets/stylesheets/personal_honor/.keep rename to app/assets/stylesheets/personal_conference/.keep diff --git a/app/controllers/admin/honor_types_controller.rb b/app/controllers/admin/honor_types_controller.rb new file mode 100644 index 0000000..0ccb48c --- /dev/null +++ b/app/controllers/admin/honor_types_controller.rb @@ -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 \ No newline at end of file diff --git a/app/controllers/admin/honors_controller.rb b/app/controllers/admin/honors_controller.rb new file mode 100644 index 0000000..8a1fb65 --- /dev/null +++ b/app/controllers/admin/honors_controller.rb @@ -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 \ No newline at end of file diff --git a/app/models/honor.rb b/app/models/honor.rb new file mode 100644 index 0000000..bfa77f9 --- /dev/null +++ b/app/models/honor.rb @@ -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 \ No newline at end of file diff --git a/app/models/honor_intro.rb b/app/models/honor_intro.rb new file mode 100644 index 0000000..0fcfdcc --- /dev/null +++ b/app/models/honor_intro.rb @@ -0,0 +1,4 @@ +class HonorIntro < PersonalPluginIntro + + +end diff --git a/app/models/honor_type.rb b/app/models/honor_type.rb new file mode 100644 index 0000000..543ddad --- /dev/null +++ b/app/models/honor_type.rb @@ -0,0 +1,8 @@ +class HonorType + include Mongoid::Document + include Mongoid::Timestamps + + field :title, localize: true + + has_many :honors +end \ No newline at end of file diff --git a/app/views/admin/honor_types/_form.html.erb b/app/views/admin/honor_types/_form.html.erb new file mode 100644 index 0000000..9c31358 --- /dev/null +++ b/app/views/admin/honor_types/_form.html.erb @@ -0,0 +1,24 @@ +<%= form_for(@honor_type, :html =>{:class=>"form-horizontal", :style=>"margin: 0;"}, :remote => true, :url => @url ) do |f| %> + + + + + +<% end %> \ No newline at end of file diff --git a/app/views/admin/honor_types/_list.js.erb b/app/views/admin/honor_types/_list.js.erb new file mode 100644 index 0000000..1aa6ea2 --- /dev/null +++ b/app/views/admin/honor_types/_list.js.erb @@ -0,0 +1,2 @@ +$('#honor_types tbody').html("<%= j render :partial => '/admin/honors/list_honor_type', :collection => @honor_types %>"); +$('#honor_type_modal').modal('hide'); \ No newline at end of file diff --git a/app/views/admin/honor_types/edit.js.erb b/app/views/admin/honor_types/edit.js.erb new file mode 100644 index 0000000..101bc18 --- /dev/null +++ b/app/views/admin/honor_types/edit.js.erb @@ -0,0 +1 @@ +$('#honor_type_modal').html("<%= j render 'form' %>"); \ No newline at end of file diff --git a/app/views/admin/honor_types/new.js.erb b/app/views/admin/honor_types/new.js.erb new file mode 100644 index 0000000..101bc18 --- /dev/null +++ b/app/views/admin/honor_types/new.js.erb @@ -0,0 +1 @@ +$('#honor_type_modal').html("<%= j render 'form' %>"); \ No newline at end of file diff --git a/app/views/admin/honors/_form.html.erb b/app/views/admin/honors/_form.html.erb new file mode 100644 index 0000000..a1c1af6 --- /dev/null +++ b/app/views/admin/honors/_form.html.erb @@ -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 %> + + +
+ + + + + + +
+ + +
+ +
+ +
+ <%= @member.name rescue ''%> + <%= f.hidden_field :member_profile_id, :value => @member.id %> +
+
+ + +
+ +
+ <%= select_year((@honor.year ? @honor.year.to_i : DateTime.now.year), {:start_year => DateTime.now.year, :end_year => 1930}, {:name => 'honor[year]', :class => "span1"} ) %> +
+
+ + +
+ +
+ <%= f.select :honor_type_id, @honor_types.collect {|t| [ t.title, t.id ]} %> +
+
+ + +
+ +
+ <%= f.text_field :award_name %> +
+
+ + +
+ +
+ <%= f.text_field :awarding_unit %> +
+
+ + +
+ +
+ <%= f.text_field :url , :class => "span6" %> +
+
+ + +
+ +
+ <%= f.text_field :keywords %> +
+
+ + +
+ +
+ +
+
+ + +
+ +
+ <%= f.text_area :note, rows: 2, class: "input-block-level" %> +
+
+ +
+ + +
+
+ +
+ +
+
+
+ +
+ +
+ + +
+ <%= 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" %> +
\ No newline at end of file diff --git a/app/views/admin/honors/_honor.html.erb b/app/views/admin/honors/_honor.html.erb new file mode 100644 index 0000000..43812e2 --- /dev/null +++ b/app/views/admin/honors/_honor.html.erb @@ -0,0 +1,16 @@ +<% @honors.each do |honor| %> + "> + <%= honor.year %> + + <%= link_to honor.award_name, '', target: "blank"%> +
+ +
+ + <%= honor.awarding_unit %> + <%= honor.member_profile.name %> + +<% end %> \ No newline at end of file diff --git a/app/views/admin/honors/_list_honor_type.html.erb b/app/views/admin/honors/_list_honor_type.html.erb new file mode 100644 index 0000000..269de0e --- /dev/null +++ b/app/views/admin/honors/_list_honor_type.html.erb @@ -0,0 +1,8 @@ + + <%= list_honor_type.title %> + + + <%= t(:edit) %> + <%= link_to t(:delete_), admin_honor_type_path(list_honor_type), "data-confirm" => t('sure?'), :method => :delete, :remote => true,:class=>"archive_toggle action" %> + + \ No newline at end of file diff --git a/app/views/admin/honors/destroy.js.erb b/app/views/admin/honors/destroy.js.erb new file mode 100644 index 0000000..6bd7923 --- /dev/null +++ b/app/views/admin/honors/destroy.js.erb @@ -0,0 +1 @@ +$('#honor_<%= @honor.id.to_s%>').remove(); \ No newline at end of file diff --git a/app/views/admin/honors/edit.html.erb b/app/views/admin/honors/edit.html.erb new file mode 100644 index 0000000..8e7c793 --- /dev/null +++ b/app/views/admin/honors/edit.html.erb @@ -0,0 +1,5 @@ +<%= form_for @honor, url:'/admin/honors/'+@honor.id.to_s, html: {class: "form-horizontal main-forms previewable"} do |f| %> +
+ <%= render partial: 'form', locals: {f: f} %> +
+<% end %> \ No newline at end of file diff --git a/app/views/admin/honors/frontend_setting.html.erb b/app/views/admin/honors/frontend_setting.html.erb new file mode 100644 index 0000000..e53ec6a --- /dev/null +++ b/app/views/admin/honors/frontend_setting.html.erb @@ -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| %> +
+ +
+ + + + + + +
+ +
+ <% if !@member.blank? %> +
+ +
+ <%= @member.name rescue ''%> + <%= f.hidden_field :member_profile_id, :value => @member.id %> +
+
+ <% end %> + +
+ +
+ <%= 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") %> +
+
+
+
+ + + + + + +
+ + <% @site_in_use_locales.each_with_index do |locale, i| %> + +
"> + + +
+ +
+
+ <%= 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 %> +
+
+
+ + +
+ + <% end %> + + + +
+ + + +
+ + +
+ <%= 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" %> +
+
+<% end %> \ No newline at end of file diff --git a/app/views/admin/honors/index.html.erb b/app/views/admin/honors/index.html.erb new file mode 100644 index 0000000..ef60eac --- /dev/null +++ b/app/views/admin/honors/index.html.erb @@ -0,0 +1,21 @@ + + + + + + + + + + + <%= render :partial => 'honor', :collection => @honors %> + +
<%= t('personal_honor.year') %><%= t('personal_honor.award_name') %><%= t('personal_honor.awarding_unit') %><%= t('personal_honor.award_winner') %>
+ +
+
+ <%= link_to content_tag(:i, nil, :class => 'icon-cog icon-white') + t('setting'), admin_honor_setting_path, :class => 'btn btn-primary pull-right' %> +
+ +
\ No newline at end of file diff --git a/app/views/admin/honors/new.html.erb b/app/views/admin/honors/new.html.erb new file mode 100644 index 0000000..204d5d5 --- /dev/null +++ b/app/views/admin/honors/new.html.erb @@ -0,0 +1,5 @@ +<%= form_for @honor, url: admin_honors_path, html: {class: "form-horizontal main-forms previewable"} do |f| %> +
+ <%= render partial: 'form', locals: {f: f} %> +
+<% end %> \ No newline at end of file diff --git a/app/views/admin/honors/setting.html.erb b/app/views/admin/honors/setting.html.erb new file mode 100644 index 0000000..768d8c6 --- /dev/null +++ b/app/views/admin/honors/setting.html.erb @@ -0,0 +1,52 @@ + + +
+
+
+

+ <%= t('add')%> + <%= t("personal_honor.honor_category") %> +

+
+
+
+
+
+
+
+
+
+
+ + + <%= render :partial => 'list_honor_type', :collection => @honor_types %> + +
+
+
+
+
+
+
+ +
+ +
\ No newline at end of file diff --git a/app/views/plugin/personal_honor/_profile.html.erb b/app/views/plugin/personal_honor/_profile.html.erb new file mode 100644 index 0000000..5a88f96 --- /dev/null +++ b/app/views/plugin/personal_honor/_profile.html.erb @@ -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 %> +
+
+ <%= 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') ) %> +
+
+<% end -%> + + + + + <% if is_autorized_user %> + + <% end -%> + + + + + + + + <% @honors.each do |honor| %> + "> + <% if is_autorized_user %> + + <% end %> + + + + + + <% end %> + +
<%= t('personal_honor.year') %><%= t('personal_honor.award_name') %><%= t('personal_honor.awarding_unit') %><%= t('personal_honor.award_winner') %>
+ <%= check_box_tag 'to_change[]', honor.id.to_s, false, :class => "list-check" %> + <%= honor.year %> + <%= link_to honor.award_name, '', target: "blank"%> +
+ +
+
<%= honor.awarding_unit %><%= honor.member_profile.name %>
+ + +
+ <% if is_autorized_user %> +
+ <%= 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' %> +
+ <% end %> + +
+ + \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index d96d9d4..0286f99 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/lib/personal_honor/engine.rb b/lib/personal_honor/engine.rb index a6579e8..44b0ad5 100644 --- a/lib/personal_honor/engine.rb +++ b/lib/personal_honor/engine.rb @@ -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"