From 97ef6f37064bc2a04576920aaac795ec5793a6bd Mon Sep 17 00:00:00 2001 From: JiangRu Date: Thu, 4 Dec 2014 15:39:43 +0800 Subject: [PATCH] orbit diploma plugin --- .../images/desktop/personal_diploma.svg | 0 app/controllers/admin/diplomas_controller.rb | 25 +++++++++++++++++-- .../desktop/personal_diplomas_controller.rb | 23 +++++++++++++++++ app/helpers/admin/personal_diplomas_helper.rb | 19 ++++++++++++++ lib/personal_diploma/engine.rb | 1 + 5 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 app/assets/images/desktop/personal_diploma.svg create mode 100644 app/controllers/desktop/personal_diplomas_controller.rb create mode 100644 app/helpers/admin/personal_diplomas_helper.rb diff --git a/app/assets/images/desktop/personal_diploma.svg b/app/assets/images/desktop/personal_diploma.svg new file mode 100644 index 0000000..e69de29 diff --git a/app/controllers/admin/diplomas_controller.rb b/app/controllers/admin/diplomas_controller.rb index 9d7378f..b378d87 100644 --- a/app/controllers/admin/diplomas_controller.rb +++ b/app/controllers/admin/diplomas_controller.rb @@ -1,5 +1,6 @@ class Admin::DiplomasController < OrbitMemberController layout "member_plugin" + include Admin::PersonalDiplomasHelper before_action :set_diploma, only: [:show, :edit , :update, :destroy] before_action :set_plugin @@ -15,28 +16,48 @@ class Admin::DiplomasController < OrbitMemberController def new @member = MemberProfile.find_by(:uid=>params['uid']) rescue nil @diploma = Diploma.new + + if params[:desktop] + render :layout => false + end end def create @member = MemberProfile.find(diploma_params['member_profile_id']) rescue nil @diploma = Diploma.new(diploma_params) @diploma.save - redirect_to params['referer_url'] + if params[:desktop] == "true" + render json: {"data" => get_paper_list}.to_json + else + redirect_to params['referer_url'] + end end def edit @member = @diploma.member_profile rescue nil + if params[:desktop] + render :layout =>false + end end def update @member = @diploma.member_profile rescue nil @diploma.update_attributes(diploma_params) @diploma.save - redirect_to params['referer_url'] + if params[:desktop] == "true" + render json: {"data" => get_paper_list}.to_json + else + redirect_to params['referer_url'] + end end def destroy @diploma.destroy + respond_to do |format| + format.html { redirect_to(admin_diplomas_url) } + format.js + format.json {render json: {"success" => true}} + end end def toggle_hide diff --git a/app/controllers/desktop/personal_diplomas_controller.rb b/app/controllers/desktop/personal_diplomas_controller.rb new file mode 100644 index 0000000..48c1a69 --- /dev/null +++ b/app/controllers/desktop/personal_diplomas_controller.rb @@ -0,0 +1,23 @@ +class Desktop::PersonalDiplomasController < DesktopAdminController + include Admin::PersonalDiplomasHelper + + def menu + user = OrbitHelper.current_user + [ + { + "title" => "List", + "layout" => "list" + }, + { + "title" => "Add/Edit", + "layout" => "form", + "new_path" => "/admin/members/#{user.member_profile.to_param}/diplomas/new" + } + ] + end + + def list + get_paper_list + end + +end \ No newline at end of file diff --git a/app/helpers/admin/personal_diplomas_helper.rb b/app/helpers/admin/personal_diplomas_helper.rb new file mode 100644 index 0000000..2a8e611 --- /dev/null +++ b/app/helpers/admin/personal_diplomas_helper.rb @@ -0,0 +1,19 @@ +module Admin::PersonalDiplomasHelper + + def get_paper_list + user = current_user.nil? ? OrbitHelper.current_user : current_user + user_profile = user.member_profile + diplomas = Diploma.where(:member_profile_id => user_profile.id) + + diplomas = diplomas.collect do |d| + { + "id" => d.id.to_s, + "edit_url" => "/#{I18n.locale.to_s}/admin/members/#{user_profile.to_param}/diplomas/#{d.to_param}/edit", + "delete_url" => "/#{I18n.locale.to_s}/admin/diplomas/#{d.id.to_s}", + "paper_title" => d.school_name, + "files" => [] + } + end + diplomas + end +end \ No newline at end of file diff --git a/lib/personal_diploma/engine.rb b/lib/personal_diploma/engine.rb index af68243..ad9325f 100644 --- a/lib/personal_diploma/engine.rb +++ b/lib/personal_diploma/engine.rb @@ -7,6 +7,7 @@ module PersonalDiploma 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', :module_app_name=>'PersonalDiploma' version "0.1" + desktop_enabled true organization "Rulingcom" author "RD dep" intro "I am intro"