diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index b324444..44854cb 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -1,7 +1,7 @@ class ProjectsController < ApplicationController before_action :authenticate - skip_before_action :verify_authenticity_token, :only => [:index,:create,:addUsers,:detail] + skip_before_action :verify_authenticity_token, :only => [:index,:create,:addUsers,:detail,:update] #=============================================>获取我的项目列表,user_id保存在session中. def index @@ -107,8 +107,18 @@ class ProjectsController < ApplicationController } } end + + #=============================================>项目修改 + def update + project = Project.find_by(:id => params[:project][:id]) + if project.update(project_params) + render :json => {:code => 0} + else + render json:current_user.errors, status: :unprocessable_entity + end + end private def project_params - params.require(:project).permit(:name,:content) + params.require(:project).permit(:name,:content,:id) end end \ No newline at end of file diff --git a/app/models/project.rb b/app/models/project.rb index 74f7f30..24e0dc1 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1,12 +1,7 @@ class Project < ActiveRecord::Base has_and_belongs_to_many :users -<<<<<<< HEAD - validate :require_at_least_on_user,on: :update # 项目中最少要有一个用户 - -======= validate :require_at_least_on_user,on: :update # 项目中最少要有一个用户 ->>>>>>> 27ebee595014926419b6ccba922ad39450b73f6b validates :name, presence: true, length: { minimum: 1, maximum: 50 }, uniqueness: true private diff --git a/config/routes.rb b/config/routes.rb index 0c11c60..740ee37 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -68,6 +68,7 @@ Rails.application.routes.draw do get 'projects' => 'projects#index' post 'projects' => 'projects#create' + patch 'projects' => 'projects#update' post 'projects/users' => 'projects#addUsers' get 'projects/detail' => 'projects#detail' diff --git a/public/index.html b/public/index.html index 070f9bd..a1e7f1a 100644 --- a/public/index.html +++ b/public/index.html @@ -37,7 +37,7 @@ //3:通知 //4:修改个人信息 //5:项目详情 edited by cy - var src_array=["project_select","task","share","inform","alter_info","project_detail"]; + var src_array=["project_select","task","share","inform","user_detail","project_detail"]; var src="pages/"+src_array[seq]+".html"; if(seq == 5){ $("#cy_close").click(); diff --git a/public/pages/project_detail.html b/public/pages/project_detail.html index 09d598b..15b521f 100644 --- a/public/pages/project_detail.html +++ b/public/pages/project_detail.html @@ -62,14 +62,14 @@
- +
- +
@@ -104,14 +104,6 @@ - - 杨诏 - - - - 杨诏 - - @@ -158,32 +150,32 @@ $.ajax({ type:"get", dataType:"json", - url:"/projects.json", + url:"/projects/detail.json", data:{ "id":parent.LoginUserInfo.selectProject }, statusCode: { 200: function(rpstr) {// 请求成功 - var robj = eval('('+rpstr+')'); - if(robj["code"]=="0"){ - $("#name").val(robj["name"]); - $("#address").val(robj["content"]); - var users = robj["users"]; + var data=rpstr.data; + if(rpstr.code=="0"){ + $("#project_name").val(data.name); + $("#project_content").val(data.content); + var users = data.users; for(var i = 0; i < users.length; ++i){ - var tduser = $("").text(users[i]["nickname"]); + var tduser = $("").text(users[i].nickname); var btn = $("").text("删除"); btn.attr("class","btn btn-primary btn-danger"); - btn.attr("onclick","cy_deleteUser("+users[i]['id']+")"); + btn.attr("onclick","cy_deleteUser("+users[i].id+")"); var tdbtn = $("").append(btn); $("#cy_user_lists").children("tbody").append($("").append(tduser,tdbtn)); } } else{ - //todo + alert("服务器内部出错啦!"); } }, 401:function(){// 未授权 - + // TODO } } }); @@ -241,31 +233,34 @@ }); } function cy_submit(){ - $.ajax({ - type:"patch", - dataType:"json", - url:"/projects.json", - data:{ - "project_id":parent.LoginUserInfo.selectProject, - "name":$("#name").val(), - "content":$("#address").val() - //todo (write todo for find, need to be edited) - }, - statusCode: { - 200: function(rpstr) {// 请求成功 - var robj = eval('('+rpstr+')'); - if(robj["code"]==0){ - window.location.reload(); + var project_content=$("#project_content").val(); + var project_name=$("#project_name").val(); + if( project_name.length>0 && project_content.length>0 ){ + $.ajax({ + type:"patch", + dataType:"json", + url:"/projects.json", + data:{ + "project[id]":parent.LoginUserInfo.selectProject, + "project[name]":project_name, + "project[content]":project_content + }, + statusCode: { + 200: function(rpstr) {// 请求成功 + var robj = rpstr; + if(robj["code"]==0){ + alert("修改成功!"); + window.location.reload(); + } + }, + 422:function(){ + alert("输入不符合要求,请重新输入!"); } - else{ - //todo - } - }, - 401:function(){// 未授权 - - } - } - }); + } + }); + }else{ + alert("请输入完整!"); + } } diff --git a/public/pages/alter_info.html b/public/pages/user_detail.html similarity index 96% rename from public/pages/alter_info.html rename to public/pages/user_detail.html index 5fb57d9..253c5ed 100644 --- a/public/pages/alter_info.html +++ b/public/pages/user_detail.html @@ -183,11 +183,12 @@ statusCode: { 200: function(data) {// 请求成功 alert("更新成功!"); - window.location.reload(); // alter - LoginUserInfo.name=name; - LoginUserInfo.email=email; - LoginUserInfo.phone=phone; + parent.LoginUserInfo.name=name; + parent.LoginUserInfo.email=email; + parent.LoginUserInfo.phone=phone; + window.location.reload(); + }, 401:function(){// 未授权 alert("未登录!");