From ea0ead04fcea7c6cd86364414812df5569bef2a6 Mon Sep 17 00:00:00 2001 From: JiangRu Date: Fri, 5 Dec 2014 15:03:30 +0800 Subject: [PATCH] desktop lab --- app/assets/images/desktop/personal_lab.svg | 0 app/controllers/admin/labs_controller.rb | 25 +++++- .../desktop/personal_labs_controller.rb | 23 +++++ app/helpers/admin/personal_labs_helper.rb | 27 ++++++ app/views/admin/labs/_form.html.erb | 85 +++++++++---------- lib/personal_lab/engine.rb | 1 + 6 files changed, 114 insertions(+), 47 deletions(-) create mode 100644 app/assets/images/desktop/personal_lab.svg create mode 100644 app/controllers/desktop/personal_labs_controller.rb create mode 100644 app/helpers/admin/personal_labs_helper.rb diff --git a/app/assets/images/desktop/personal_lab.svg b/app/assets/images/desktop/personal_lab.svg new file mode 100644 index 0000000..e69de29 diff --git a/app/controllers/admin/labs_controller.rb b/app/controllers/admin/labs_controller.rb index 7f209bc..878c93c 100644 --- a/app/controllers/admin/labs_controller.rb +++ b/app/controllers/admin/labs_controller.rb @@ -1,4 +1,5 @@ class Admin::LabsController < OrbitMemberController + include Admin::PersonalLabsHelper layout "member_plugin" before_action :set_lab, only: [:show, :edit , :update, :destroy] @@ -15,28 +16,48 @@ class Admin::LabsController < OrbitMemberController def new @member = MemberProfile.find_by(:uid=>params['uid']) rescue nil @lab = Lab.new + if params[:desktop] + render :layout => false + end end def create @member = MemberProfile.find(lab_params['member_profile_id']) rescue nil @lab = Lab.new(lab_params) @lab.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 = @lab.member_profile rescue nil + if params[:desktop] + render :layout => false + end end def update @member = @lab.member_profile rescue nil @lab.update_attributes(lab_params) @lab.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 @lab.destroy + respond_to do |format| + format.html { redirect_to(admin_labs_url) } + # format.xml { head :ok } + format.js + format.json {render json: {"success" => true}} + end end def toggle_hide diff --git a/app/controllers/desktop/personal_labs_controller.rb b/app/controllers/desktop/personal_labs_controller.rb new file mode 100644 index 0000000..f3bbe89 --- /dev/null +++ b/app/controllers/desktop/personal_labs_controller.rb @@ -0,0 +1,23 @@ +class Desktop::PersonalLabsController < DesktopAdminController + include Admin::PersonalLabsHelper + + def menu + user = OrbitHelper.current_user + [ + { + "title" => "List", + "layout" => "list" + }, + { + "title" => "Add/Edit", + "layout" => "form", + "new_path" => "/admin/members/#{user.member_profile.to_param}/labs/new" + } + ] + end + + def list + get_paper_list + end + +end \ No newline at end of file diff --git a/app/helpers/admin/personal_labs_helper.rb b/app/helpers/admin/personal_labs_helper.rb new file mode 100644 index 0000000..a4fd25f --- /dev/null +++ b/app/helpers/admin/personal_labs_helper.rb @@ -0,0 +1,27 @@ +module Admin::PersonalLabsHelper + + def get_paper_list + user = current_user.nil? ? OrbitHelper.current_user : current_user + user_profile = user.member_profile + labs = Lab.where(:member_profile_id => user_profile.id) + labs = labs.collect do |l| + files = l.lab_files.collect do |lf| + { + "title" => lf.title, + "description" => lf.description, + "link" => lf.file.url, + "extension" => (lf.file.url.split(".").last rescue "") + } + end + { + "id" => l.id.to_s, + "edit_url" => "/#{I18n.locale.to_s}/admin/members/#{user_profile.to_param}/labs/#{l.to_param}/edit", + "delete_url" => "/#{I18n.locale.to_s}/admin/labs/#{l.id.to_s}", + "paper_title" => l.lab_title, + "keywords" => l.keywords, + "files" => files + } + end + labs + end +end \ No newline at end of file diff --git a/app/views/admin/labs/_form.html.erb b/app/views/admin/labs/_form.html.erb index 9647526..e05e98f 100644 --- a/app/views/admin/labs/_form.html.erb +++ b/app/views/admin/labs/_form.html.erb @@ -5,7 +5,7 @@ <%= stylesheet_link_tag "lib/main-list" %> <% end %> <% content_for :page_specific_javascript do %> - <%= javascript_include_tag "lib/bootstrap-fileupload" %> + <%= javascript_include_tag "lib/bootstrap-fileupload" %> <%= javascript_include_tag "lib/file-type" %> <%= javascript_include_tag "lib/module-area" %> <% end %> @@ -13,7 +13,7 @@
- +
@@ -61,7 +61,7 @@
<%= f.text_field :research_direction %>
-
+
@@ -69,7 +69,7 @@
<%= f.text_field :facility %>
-
+
@@ -77,7 +77,7 @@
<%= f.text_field :url , :class => "span6" %>
-
+
@@ -85,7 +85,7 @@
<%= f.text_field :keywords %>
-
+
@@ -93,7 +93,7 @@
<%= f.text_area :note, rows: 2, class: "input-block-level" %>
-
+ @@ -125,13 +125,13 @@
<% @site_in_use_locales.each_with_index do |locale, i| %> - +
">
-
+
<%= f.fields_for :lab_title_translations do |f| %> <%= f.text_field locale, class: "input-block-level", placeholder: t("personal_lab.lab_title"), value: (@lab.lab_title_translations[locale] rescue nil) %> <% end %> @@ -141,7 +141,7 @@
-
+
<%= f.fields_for :location_translations do |f| %> <%= f.text_field locale, class: "input-block-level", placeholder: t("personal_lab.location"), value: (@lab.location_translations[locale] rescue nil) %> <% end %> @@ -151,7 +151,7 @@
-
+
<%= f.fields_for :participating_professor_translations do |f| %> <%= f.text_field locale, class: "input-block-level", placeholder: t("personal_lab.participating_professor"), value: (@lab.participating_professor_translations[locale] rescue nil) %> <% end %> @@ -161,7 +161,7 @@
-
+
<%= f.fields_for :participating_student_translations do |f| %> <%= f.text_field locale, class: "input-block-level", placeholder: t("personal_lab.participating_student"), value: (@lab.participating_student_translations[locale] rescue nil) %> <% end %> @@ -184,11 +184,11 @@ <%= f.fields_for :lab_files, lab_file do |f| %> <%= render :partial => 'form_file', :object => lab_file, :locals => {:f => f, :i => i} %> <% end %> - <% end %> + <% end %>
<% end %> - +
@@ -207,34 +207,29 @@ <%= 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" %> + <%= link_to t('cancel'), get_go_back, :class=>"btn" %>
-<% content_for :page_specific_javascript do %> - -<% end %> \ No newline at end of file + $('.add-on').tooltip(); + } else if($(this).hasClass('delete_file')) { + $(this).parents('.input-prepend').remove(); + } else if($(this).hasClass('remove_existing_record')) { + if(confirm("<%= I18n.t(:sure?)%>")){ + $(this).children('.should_destroy').attr('value', 1); + $(this).parents('.start-line').hide(); + } + } + }); + \ No newline at end of file diff --git a/lib/personal_lab/engine.rb b/lib/personal_lab/engine.rb index d3d237b..055b9fc 100644 --- a/lib/personal_lab/engine.rb +++ b/lib/personal_lab/engine.rb @@ -7,6 +7,7 @@ module PersonalLab personal_plugin :enable => true, :sort_number => '30', :app_name=>"Lab", :intro_app_name=>"PersonalLabIntro",:path=>"/plugin/personal_lab/profile",:front_path=>"/profile",:admin_path=>"/admin/labs",:i18n=>'module_name.personal_lab', :module_app_name=>'PersonalLab' version "0.1" + desktop_enabled true organization "Rulingcom" author "RD dep" intro "I am intro"