From b206bfa9b2a2c4966b1478c16b4288d182bc0f08 Mon Sep 17 00:00:00 2001 From: Yang Zhao Date: Sun, 1 Jan 2017 12:51:00 +0000 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=94=A8=E6=88=B7=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E5=AE=8C=E6=88=90=EF=BC=9B=E4=BF=AE=E6=94=B9=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE#=E6=B7=BB=E5=8A=A0=E7=94=A8=E6=88=B7=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=EF=BC=88=E5=A2=9E=E5=8A=A0=E9=87=8D=E5=A4=8D=E6=80=A7?= =?UTF-8?q?=E9=AA=8C=E8=AF=81=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/projects_controller.rb | 38 +++++------ public/pages/project_detail.html | 88 +++++++++++++++++--------- 2 files changed, 78 insertions(+), 48 deletions(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 44854cb..5a56ea4 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -52,25 +52,24 @@ class ProjectsController < ApplicationController #=============================================>项目添加用户 def addUsers - #Todo - uid = params[:user_id] - register = session[:user_id] - #username = params[:username] - pid = params[:project_id] - params_pu = {project_id: pid,user_id: uid} - pu = Projects_user.new(params_pu) - pu.save - content = User.find_by(id: register).name + "邀请您进入项目" + Project.find_by(id: pid).name - puts content - params_note = {user_id: uid,content: content,category: 2,project_id: pid} - note = Note.new(params_note) - note.save! - #puts Note.find_by(id: note.id).inspect - # now = Datetime.now - # note.created_at = now - # note.updated_at = now - note.save! - render :json => {:code => 0} + uid = User.find_by(email:params[:email]).id# 需要添加的用户 + register = session[:user_id]# 当前用户 + pid = params[:project_id] + # 检查该项目中是否已经有要添加的用户 + pu_exist=Projects_user.find_by(project_id:pid,user_id:uid) + if pu_exist.nil?# 不存在 + params_pu = {project_id: pid,user_id: uid} + pu = Projects_user.new(params_pu) + pu.save + content = User.find_by(id: register).name + "邀请您进入项目" + Project.find_by(id: pid).name + puts content + params_note = {user_id: uid,content: content,category: 2,project_id: pid} + note = Note.new(params_note) + note.save! + render :json => {:code => 0} + else# 存在 + render json:current_user.errors, status: :unprocessable_entity + end end #=============================================>项目详情 @@ -117,6 +116,7 @@ class ProjectsController < ApplicationController render json:current_user.errors, status: :unprocessable_entity end end + private def project_params params.require(:project).permit(:name,:content,:id) diff --git a/public/pages/project_detail.html b/public/pages/project_detail.html index 15b521f..44b76d3 100644 --- a/public/pages/project_detail.html +++ b/public/pages/project_detail.html @@ -77,7 +77,7 @@ @@ -92,7 +92,6 @@ -
@@ -112,16 +111,15 @@
- +
- +
-
@@ -180,32 +178,64 @@ } }); }); - function cy_addUser(){ - $.ajax({ - type:"post", - dataType:"json", - url:"/projects.json", - data:{ - "user_id":$("#cy_new_user"), - "project_id":parent.LoginUserInfo.selectProject - }, - statusCode: { - 200: function(rpstr) {// 请求成功 - var robj = eval('('+rpstr+')'); - if(robj["code"]==0){ - window.location.reload(); - } - else{ - //todo - } + function addUser(){ + var new_user_email=$("#new_user_email").val(); + if( new_user_email.length>0 ){ + // 邮箱对应的用户是否存在 + var exist; + $.ajax({ + type: "get", + dataType: "json", + url:"/users/emailExist.json", + async:false,// 强制同步 + data: { + "email":new_user_email }, - 401:function(){// 未授权 - + statusCode: { + 200: function(data) {// 请求成功 + //alert(data); + if( data=='1' ) + exist=true; + else + exist=false; + }, + 422:function(){ + alert("输入不符合要求,请重新输入!"); + }, + 401:function(){// 未授权 + alert("用户名或密码错误!"); + } } - } - }); + }); + if( exist ){// 邮箱存在 + $.ajax({ + type:"post", + dataType:"json", + async:false,// 强制同步 + url:"/projects/users.json", + data:{ + "email":new_user_email, + "project_id":parent.LoginUserInfo.selectProject + }, + statusCode: { + 200: function(response) {// 请求成功 + alert("添加成功!"); + window.location.reload(); + }, + 422:function(){ + alert("用户已经在项目中!") + } + } + }); + }else{// 邮箱不存在 + alert("该邮箱对应的用户不存在!") + } + }else{ + alert("请输入完整!"); + } + // 添加用户 } - function cy_deleteUser(id){ + function deleteUser(id){ return; $.ajax({ type:"delete", @@ -232,7 +262,7 @@ } }); } - function cy_submit(){ + function basic_alter(){ var project_content=$("#project_content").val(); var project_name=$("#project_name").val(); if( project_name.length>0 && project_content.length>0 ){