From af1e0c942afdd3f6c41038ac511c65ca04102e92 Mon Sep 17 00:00:00 2001 From: manson Date: Wed, 2 Jul 2014 11:54:14 +0800 Subject: [PATCH] Finished --- app/controllers/admin/diplomas_controller.rb | 91 +++++++++ app/models/diploma.rb | 43 +++++ app/models/diploma_intro.rb | 2 + app/views/admin/diplomas/_diploma.html.erb | 16 ++ app/views/admin/diplomas/_form.html.erb | 182 ++++++++++++++++++ app/views/admin/diplomas/destroy.js.erb | 1 + app/views/admin/diplomas/edit.html.erb | 5 + .../admin/diplomas/frontend_setting.html.erb | 93 +++++++++ app/views/admin/diplomas/index.html.erb | 21 ++ app/views/admin/diplomas/new.html.erb | 5 + app/views/admin/diplomas/setting.html.erb | 18 ++ .../plugin/personal_diploma/_profile.html.erb | 86 +++++++++ config/locales/en.yml | 3 + config/locales/zh_tw.yml | 5 +- config/routes.rb | 21 ++ lib/personal_diploma/engine.rb | 2 +- 16 files changed, 592 insertions(+), 2 deletions(-) create mode 100644 app/controllers/admin/diplomas_controller.rb create mode 100644 app/models/diploma.rb create mode 100644 app/models/diploma_intro.rb create mode 100644 app/views/admin/diplomas/_diploma.html.erb create mode 100644 app/views/admin/diplomas/_form.html.erb create mode 100644 app/views/admin/diplomas/destroy.js.erb create mode 100644 app/views/admin/diplomas/edit.html.erb create mode 100644 app/views/admin/diplomas/frontend_setting.html.erb create mode 100644 app/views/admin/diplomas/index.html.erb create mode 100644 app/views/admin/diplomas/new.html.erb create mode 100644 app/views/admin/diplomas/setting.html.erb create mode 100644 app/views/plugin/personal_diploma/_profile.html.erb diff --git a/app/controllers/admin/diplomas_controller.rb b/app/controllers/admin/diplomas_controller.rb new file mode 100644 index 0000000..f9e1e23 --- /dev/null +++ b/app/controllers/admin/diplomas_controller.rb @@ -0,0 +1,91 @@ +class Admin::DiplomasController < OrbitMemberController + layout "member_plugin" + + before_action :set_plugin + before_action :get_settings,:only => [:new, :edit, :setting] + + def index + @diplomas = Diploma.all + end + + def new + @member = MemberProfile.find_by(:uid=>params['uid']) rescue nil + @diploma = Diploma.new + end + + def create + @member = MemberProfile.find(diploma_params['member_profile_id']) rescue nil + @diploma = Diploma.new(diploma_params) + @diploma.save + redirect_to '/admin/members/'+@member.to_param+'/Diploma' + end + + def edit + @member = MemberProfile.find_by(:uid=>params['uid']) rescue nil + @diploma = Diploma.find(params[:id]) + end + + def update + @member = MemberProfile.find(diploma_params['member_profile_id']) rescue nil + @diploma = Diploma.find(params[:id]) + @diploma.update_attributes(diploma_params) + @diploma.save + redirect_to '/admin/members/'+@member.to_param+'/Diploma' + end + + def destroy + @diploma = Diploma.find(params[:id]) + @diploma.destroy + end + + def toggle_hide + if params[:ids] + @diplomas = Diploma.any_in(_id: params[:ids]) + + @diplomas.each do |diploma| + diploma.is_hidden = params[:disable] + diploma.save + end + end + + render json: {"success"=>true} + end + + def setting + end + + def frontend_setting + @member = MemberProfile.find_by(:uid=>params['uid']) rescue nil + @intro = DiplomaIntro.find_by(:member_profile_id=>@member.id) rescue nil + @intro = @intro.nil? ? DiplomaIntro.new({:member_profile_id=>@member.id}) : @intro + end + + def update_frontend_setting + @member = MemberProfile.find(intro_params['member_profile_id']) rescue nil + @intro = DiplomaIntro.find_by(:member_profile_id=>@member.id) rescue nil + @intro = @intro.nil? ? DiplomaIntro.new({:member_profile_id=>@member.id}) : @intro + @intro.update_attributes(intro_params) + @intro.save + redirect_to '/admin/members/'+@member.to_param+'/Diploma' + end + + def get_settings + @paper_types = ConferencePaperType.all + @paper_levels = ConferencePaperLevel.all + @author_types = ConferenceAuthorType.all + end + + def set_plugin + @plugin = OrbitApp::Plugin::Registration.all.select{|plugin| plugin.app_name.eql? 'Diploma'}.first + end + + private + + def diploma_params + params.require(:diploma).permit! rescue nil + end + + def intro_params + params.require(:diploma_intro).permit! rescue nil + end +end \ No newline at end of file diff --git a/app/models/diploma.rb b/app/models/diploma.rb new file mode 100644 index 0000000..a5519f6 --- /dev/null +++ b/app/models/diploma.rb @@ -0,0 +1,43 @@ +class Diploma + include Mongoid::Document + include Mongoid::Timestamps + include OrbitModel::Status + include Slug + + field :school_name, localize: true + field :country, localize: true + field :department, localize: true + field :degree, localize: true + + field :language + field :keywords + field :start_date , :type => Date + field :end_date , :type => Date + field :url + field :note + field :create_user_id, :type => BSON::ObjectId + field :update_user_id, :type => BSON::ObjectId + + belongs_to :member_profile + + paginates_per 10 + + before_validation :add_http + + def duration + self.start_date.to_s+' ~ '+self.end_date.to_s + end + + def slug_title + self.school_name+' '+self.department+' '+self.degree + 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/diploma_intro.rb b/app/models/diploma_intro.rb new file mode 100644 index 0000000..696c107 --- /dev/null +++ b/app/models/diploma_intro.rb @@ -0,0 +1,2 @@ +class DiplomaIntro < PersonalPluginIntro +end \ No newline at end of file diff --git a/app/views/admin/diplomas/_diploma.html.erb b/app/views/admin/diplomas/_diploma.html.erb new file mode 100644 index 0000000..74ec7e1 --- /dev/null +++ b/app/views/admin/diplomas/_diploma.html.erb @@ -0,0 +1,16 @@ +<% @diplomas.each do |diploma| %> + "> + <%= diploma.duration %> + + <%= link_to diploma.school_name, '', target: "blank"%> +
+ +
+ + <%= diploma.department %> + <%= diploma.degree %> + +<% end %> \ No newline at end of file diff --git a/app/views/admin/diplomas/_form.html.erb b/app/views/admin/diplomas/_form.html.erb new file mode 100644 index 0000000..83d2e86 --- /dev/null +++ b/app/views/admin/diplomas/_form.html.erb @@ -0,0 +1,182 @@ +<% # 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/bootstrap-datetimepicker" %> + <%= javascript_include_tag "lib/datetimepicker/datetimepicker.js" %> + <%= javascript_include_tag "lib/module-area" %> +<% end %> + + +
+ + + + + + +
+ + +
+ +
+ +
+ <%= @member.name rescue ''%> + <%= f.hidden_field :member_profile_id, :value => @member.id %> +
+
+ + +
+ +
+ <%= f.datetime_picker :start_date, :no_label => true, :format=>"yyyy/MM", :placeholder=>"YYYY/MM" %> +
+
+ + +
+ +
+ <%= f.datetime_picker :end_date, :no_label => true, :format=>"yyyy/MM", :placeholder=>"YYYY/MM" %> +
+
+ + +
+ +
+ +
+
+ + +
+ +
+ <%= f.text_field :url, :class => "span5" %> +
+
+ + +
+ +
+ <%= f.text_field :keywords, :class => "span5" %> +
+
+ + +
+ +
+ <%= f.text_area :note, rows: 2, class: "input-block-level" %> +
+
+ +
+ + +
+ + +
+ +
+ +
+
+ +
+ +
+ + + + + + +
+ + <% @site_in_use_locales.each_with_index do |locale, i| %> + +
"> + + +
+ +
+ <%= f.fields_for :school_name_translations do |f| %> + <%= f.text_field locale, class: "input-block-level", placeholder: t("personal_diploma.school_name"), value: (@diploma.school_name_translations[locale] rescue nil) %> + <% end %> +
+
+ + +
+ +
+ <%= f.fields_for :country_translations do |f| %> + <%= f.text_field locale, class: "input-block-level", placeholder: t("personal_diploma.country"), value: (@diploma.country_translations[locale] rescue nil) %> + <% end %> +
+
+ + +
+ +
+ <%= f.fields_for :department_translations do |f| %> + <%= f.text_field locale, class: "input-block-level", placeholder: t("personal_diploma.department"), value: (@diploma.department_translations[locale] rescue nil) %> + <% end %> +
+
+ + +
+ +
+ <%= f.fields_for :degree_translations do |f| %> + <%= f.text_field locale, class: "input-block-level", placeholder: t("personal_diploma.degree"), value: (@diploma.degree_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" %> +
\ No newline at end of file diff --git a/app/views/admin/diplomas/destroy.js.erb b/app/views/admin/diplomas/destroy.js.erb new file mode 100644 index 0000000..0c278c0 --- /dev/null +++ b/app/views/admin/diplomas/destroy.js.erb @@ -0,0 +1 @@ +$('#diploma_<%= @diploma.id.to_s%>').remove(); \ No newline at end of file diff --git a/app/views/admin/diplomas/edit.html.erb b/app/views/admin/diplomas/edit.html.erb new file mode 100644 index 0000000..39df220 --- /dev/null +++ b/app/views/admin/diplomas/edit.html.erb @@ -0,0 +1,5 @@ +<%= form_for @diploma, url:'/admin/diplomas/'+@diploma.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/diplomas/frontend_setting.html.erb b/app/views/admin/diplomas/frontend_setting.html.erb new file mode 100644 index 0000000..299a027 --- /dev/null +++ b/app/views/admin/diplomas/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(:diploma_intro, :url => update_frontend_setting_admin_diplomas_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/diplomas/index.html.erb b/app/views/admin/diplomas/index.html.erb new file mode 100644 index 0000000..4efdf5d --- /dev/null +++ b/app/views/admin/diplomas/index.html.erb @@ -0,0 +1,21 @@ + + + + + + + + + + + <%= render :partial => 'diploma', :collection => @diplomas %> + +
<%= t('date_') %><%= t('personal_diploma.school_name') %><%= t('personal_diploma.department') %><%= t('personal_diploma.degree') %>
+ + \ No newline at end of file diff --git a/app/views/admin/diplomas/new.html.erb b/app/views/admin/diplomas/new.html.erb new file mode 100644 index 0000000..6510ed3 --- /dev/null +++ b/app/views/admin/diplomas/new.html.erb @@ -0,0 +1,5 @@ +<%= form_for @diploma, url: admin_diplomas_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/diplomas/setting.html.erb b/app/views/admin/diplomas/setting.html.erb new file mode 100644 index 0000000..7a3fa96 --- /dev/null +++ b/app/views/admin/diplomas/setting.html.erb @@ -0,0 +1,18 @@ + \ No newline at end of file diff --git a/app/views/plugin/personal_diploma/_profile.html.erb b/app/views/plugin/personal_diploma/_profile.html.erb new file mode 100644 index 0000000..6803f10 --- /dev/null +++ b/app/views/plugin/personal_diploma/_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 + @diplomas = Diploma.where(member_profile_id: @member.id).desc(:year).page(params[:page]).per(10) + else + @diplomas = Diploma.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_diplomas_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_diplomas_path(member_profile_id: params[:id], disable: 'false') ) %> +
+
+<% end -%> + + + + + <% if is_autorized_user %> + + <% end -%> + + + + + + + + <% @diplomas.each do |diploma| %> + "> + <% if is_autorized_user %> + + <% end %> + + + + + + <% end %> + +
<%= t('date_') %><%= t('personal_diploma.school_name') %><%= t('personal_diploma.department') %><%= t('personal_diploma.degree') %>
+ <%= check_box_tag 'to_change[]', diploma.id.to_s, false, :class => "list-check" %> + <%= diploma.duration %> + <%= link_to diploma.school_name, '', target: "blank"%> +
+ +
+
<%= diploma.department %><%= diploma.degree %>
+ + +
+ <% if is_autorized_user %> +
+ <%= link_to content_tag(:i, nil, :class => 'icon-edit') +' '+ t('setting'),'/admin/members/'+@member.to_param+'/diplomas/frontend_setting', :class => 'btn btn-primary' %> + <%= link_to content_tag(:i, nil, :class => 'icon-plus') +' '+ t('new_'), + '/admin/members/'+@member.to_param+'/diplomas/new', :class => 'btn btn-primary' %> +
+ <% end %> + +
+ + \ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index 84ccb79..4ef01a6 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2,6 +2,9 @@ en: module_name: personal_diploma: Diploma personal_diploma: + school_name : "School Name" + duration: "Duration" + paper_title : "Paper Title" book_title : "Book Title" extracted_chapters : "Extracted Chapters" diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index b91c808..bfd7607 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -2,6 +2,9 @@ zh_tw: module_name: personal_diploma: 學歷 personal_diploma: + school_name : "學校名稱" + duration: "期間" + paper_title : "論文名稱" book_title : "期刊名稱" extracted_chapters : "摘要" @@ -31,7 +34,7 @@ zh_tw: file_name : "檔案名稱" description : "描述" pages : "Pages" - school_name : "學校名稱" + country : "國家" department : "系所" degree : "學位" diff --git a/config/routes.rb b/config/routes.rb index d96d9d4..406579c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2,6 +2,27 @@ 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 'diploma_setting' => "diplomas#setting" + + resources :diplomas do + collection do + get 'toggle_hide' => 'diplomas#toggle_hide' + end + end + + resources :members do + collection do + scope '(:name-:uid)' do + resources :diplomas do + collection do + get 'frontend_setting' => 'diplomas#frontend_setting' + post 'update_frontend_setting' => 'diplomas#update_frontend_setting' + end + end + end + end + end + end end end diff --git a/lib/personal_diploma/engine.rb b/lib/personal_diploma/engine.rb index 43e175c..888239e 100644 --- a/lib/personal_diploma/engine.rb +++ b/lib/personal_diploma/engine.rb @@ -4,7 +4,7 @@ module PersonalDiploma OrbitApp.registration "PersonalDiploma",:type=> 'ModuleApp' do module_label 'module_name.personal_journal' base_url File.expand_path File.dirname(__FILE__) - personal_plugin :enable => true, :sort_number => '40', :app_name=>"Diploma", :intro_app_name=>"PersonalDiplomaIntro",:path=>"/plugin/profile",:front_path=>"/profile",:admin_path=>"/admin/diplomas",:i18n=>'module_name.personal_diploma' + personal_plugin :enable => true, :sort_number => '40', :app_name=>"Diploma", :intro_app_name=>"PersonalDiplomaIntro",:path=>"/plugin/personal_diploma/profile",:front_path=>"/profile",:admin_path=>"/admin/diplomas",:i18n=>'module_name.personal_diploma' version "0.1" organization "Rulingcom"