From f88bf9bcdb196c4fc5a078467cda6d7637bc1d40 Mon Sep 17 00:00:00 2001 From: huang Date: Fri, 19 May 2017 16:56:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E6=B7=BB=E5=8A=A0=E5=90=88?= =?UTF-8?q?=E4=BD=9C=E8=80=85=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 31 ++++++++++++++++++- app/models/shixun.rb | 4 +++ app/models/user.rb | 13 ++++++++ app/views/layouts/base_shixun.html.erb | 3 +- app/views/shixuns/_add_collaborators.html.erb | 29 +++++++++++++++++ .../shixuns/_collaborators_list.html.erb | 9 ++++++ app/views/shixuns/add_collaborators.js.erb | 6 ++++ app/views/shixuns/collaborators.html.erb | 13 ++++++++ app/views/shixuns/shixun_members_added.js.erb | 1 + config/routes.rb | 4 +++ public/javascripts/edu/shixun.js | 30 ++++++++++++++++++ 11 files changed, 141 insertions(+), 2 deletions(-) create mode 100644 app/views/shixuns/_add_collaborators.html.erb create mode 100644 app/views/shixuns/_collaborators_list.html.erb create mode 100644 app/views/shixuns/add_collaborators.js.erb create mode 100644 app/views/shixuns/collaborators.html.erb create mode 100644 app/views/shixuns/shixun_members_added.js.erb create mode 100644 public/javascripts/edu/shixun.js diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 711ff46e2..88c07a227 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -36,12 +36,41 @@ class ShixunsController < ApplicationController end def propaedeutics - @shixun = Shixun.find_by_identifier(params[:id]) respond_to do |format| format.html end end + def collaborators + @collaborators = @shixun.collaborators + end + + # 已存在的成员不添加 + def add_collaborators + if !params[:search].nil? + # members = searchTeacherAndAssistant @course + member_ids = "(" + @shixun.shixun_members.map(&:user_id).join(',') + ")" + condition = "%#{params[:search].strip}%".gsub(" ","") + @users = User.where("id not in #{member_ids} and status = 1 and LOWER(concat(lastname, firstname)) LIKE '#{condition}'").includes(:user_extensions) + end + respond_to do |format| + format.js + end + end + + def shixun_members_added + unless params[:membership][:user_ids].blank? + memberships = params[:membership][:user_ids] + memberships.each do |member| + ShixunMember.create(:user_id => member, :shixun_id => @shixun.id, :role => 2) + end + @collaborators = @shixun.collaborators + end + respond_to do |format| + format.js + end + end + def search # 确定 sort 1升序 2 降序 if params[:time_reorder] diff --git a/app/models/shixun.rb b/app/models/shixun.rb index 988bdd557..2a2cc1b3f 100644 --- a/app/models/shixun.rb +++ b/app/models/shixun.rb @@ -18,4 +18,8 @@ class Shixun < ActiveRecord::Base rescue ActiveRecord::RecordNotFound render_404 end + + def collaborators + self.shixun_members.select{|member| member.role == 2} unless self.shixun_members.blank? + end end diff --git a/app/models/user.rb b/app/models/user.rb index a3fdc06b2..472622d31 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,3 +1,4 @@ +# encoding: utf-8 # Redmine - project management software # Copyright (C) 2006-2013 Jean-Philippe Lang # @@ -538,6 +539,18 @@ class User < Principal self.read_attribute(:identity_url) end + # 判断用户的身份 + def identity + ue = self.user_extensions + unless ue.blank? + if ue.technical_title.blank? + ue.identity == 0 ? "老师" : (ue.identity == 1 ? "学生" : "专业人士") + else + result = ue.technical_title + end + end + end + VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z]+)*\.[a-z]+\z/i VALID_PHONE_REGEX = /^1\d{10}$/ # VALID_EMAIL_REGEX = /^[0-9a-zA-Z_-]+@[0-9a-zA-Z_-]+(\.[0-9a-zA-Z_-]+)+$/ diff --git a/app/views/layouts/base_shixun.html.erb b/app/views/layouts/base_shixun.html.erb index a5cebb58e..f115e69f3 100644 --- a/app/views/layouts/base_shixun.html.erb +++ b/app/views/layouts/base_shixun.html.erb @@ -39,6 +39,7 @@ <% end %>
  • ">统计
  • <% if User.current.manager_of_shixun?(@shixun) %> +
  • ">合作者
  • ">配置
  • <% end %> @@ -65,6 +66,6 @@ -<%= javascript_include_tag 'application', 'cookie','project',"avatars", 'header','prettify','select_list_move','attachments' %> +<%= javascript_include_tag 'application', 'cookie','project',"avatars", 'header','prettify','select_list_move','attachments','edu/shixun','edu/application' %> diff --git a/app/views/shixuns/_add_collaborators.html.erb b/app/views/shixuns/_add_collaborators.html.erb new file mode 100644 index 000000000..9b153f866 --- /dev/null +++ b/app/views/shixuns/_add_collaborators.html.erb @@ -0,0 +1,29 @@ + +
    +
    +

    添加合作者

    + +
    +
    +
    + <%= form_tag url_for(shixun_members_added_shixun_path(@shixun)), :remote => true, :method => :post, :id => 'add_collaborators_form' do |f| %> +
    +
    + + + +
    +
    +
      + <%#= render :partial => 'courses/settings/search_not_teachers_list' %> +
    +
    +
    + 取消 + 确定 + <% end %> +
    + +
    +
    +
    \ No newline at end of file diff --git a/app/views/shixuns/_collaborators_list.html.erb b/app/views/shixuns/_collaborators_list.html.erb new file mode 100644 index 000000000..bf2097b33 --- /dev/null +++ b/app/views/shixuns/_collaborators_list.html.erb @@ -0,0 +1,9 @@ +<% @collaborators.each do |collaborators| %> +
    + <%= image_tag(url_to_avatar(collaborators.user), :width => 60, :height => 60,:class => 'panel-list-img mr15 mt5') %> + +
    +<% end %> \ No newline at end of file diff --git a/app/views/shixuns/add_collaborators.js.erb b/app/views/shixuns/add_collaborators.js.erb new file mode 100644 index 000000000..36fbc2af7 --- /dev/null +++ b/app/views/shixuns/add_collaborators.js.erb @@ -0,0 +1,6 @@ +<% if params[:is_observe] %> +$("#search_not_teachers_list").html("<%= j(render :partial => 'courses/settings/search_not_teachers_list') %>"); +<% else %> +var htmlvalue = "<%= j(render :partial => 'shixuns/add_collaborators') %>"; +pop_box_new(htmlvalue, 600, 420); +<% end %> \ No newline at end of file diff --git a/app/views/shixuns/collaborators.html.erb b/app/views/shixuns/collaborators.html.erb new file mode 100644 index 000000000..f38bba60d --- /dev/null +++ b/app/views/shixuns/collaborators.html.erb @@ -0,0 +1,13 @@ +
    + +
    + <%= render :partial => "shixuns/collaborators_list" %> +
    +
    \ No newline at end of file diff --git a/app/views/shixuns/shixun_members_added.js.erb b/app/views/shixuns/shixun_members_added.js.erb new file mode 100644 index 000000000..f367b9c1a --- /dev/null +++ b/app/views/shixuns/shixun_members_added.js.erb @@ -0,0 +1 @@ +$("#collaborators_list").html("<%= j(render :partial => 'shixuns/collaborators_list') %>"); \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 8b5a15169..f1d04e33d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -36,9 +36,13 @@ RedmineApp::Application.routes.draw do member do get 'statistics' get 'propaedeutics' + get 'collaborators' + match 'add_collaborators', :via => [:get, :post] + post 'shixun_members_added' get 'shixun_monitor' get 'shixun_exec' post 'add_script' + post 'shixun_members' get 'settings(/:tab)', :action => 'settings', :as => 'settings' get 'shixun_job_create' get 'shixun_job_update' diff --git a/public/javascripts/edu/shixun.js b/public/javascripts/edu/shixun.js new file mode 100644 index 000000000..dddc113c5 --- /dev/null +++ b/public/javascripts/edu/shixun.js @@ -0,0 +1,30 @@ +$(function() { + $("#search_not_collaborators").live('input', function (e) { + throttle(search_not_teacher_f, window, e); + }); +}); + +var lastteSearchCondition = ''; +function search_not_teacher_f(e){ + if($(e.target).val().trim() == "" || ($(e.target).val().trim() == lastteSearchCondition && lastteSearchCondition != '')) + { + return; + } + lastteSearchCondition = $(e.target).val().trim(); + $.ajax({ + url: '/shixuns/' + $("#shixun_collaborators_id").val() + '/add_collaborators', + type:'post', + data: {is_observe:true, search:e.target.value}, + success: function(data){ } + }); +} + +function submit_add_collaborators_form(){ + if($("input[name='membership[user_ids][]']:checked").length >= 1){ + $("#add_teacher_notice").html("").hide(); + $("#add_collaborators_form").submit(); + hideModal(); + }else{ + $("#add_teacher_notice").html("请至少选择一个用户").show(); + } +} \ No newline at end of file