项目选择和列表功能完成;项目详情和修改功能完成;增加项目修改接口
This commit is contained in:
parent
774c7a5fa8
commit
921bbc3f95
|
@ -1,7 +1,7 @@
|
||||||
class ProjectsController < ApplicationController
|
class ProjectsController < ApplicationController
|
||||||
|
|
||||||
before_action :authenticate
|
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中.
|
#=============================================>获取我的项目列表,user_id保存在session中.
|
||||||
def index
|
def index
|
||||||
|
@ -107,8 +107,18 @@ class ProjectsController < ApplicationController
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end
|
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
|
private
|
||||||
def project_params
|
def project_params
|
||||||
params.require(:project).permit(:name,:content)
|
params.require(:project).permit(:name,:content,:id)
|
||||||
end
|
end
|
||||||
end
|
end
|
|
@ -1,12 +1,7 @@
|
||||||
class Project < ActiveRecord::Base
|
class Project < ActiveRecord::Base
|
||||||
has_and_belongs_to_many :users
|
has_and_belongs_to_many :users
|
||||||
|
|
||||||
<<<<<<< HEAD
|
|
||||||
validate :require_at_least_on_user,on: :update # 项目中最少要有一个用户
|
|
||||||
|
|
||||||
=======
|
|
||||||
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
|
validates :name, presence: true, length: { minimum: 1, maximum: 50 }, uniqueness: true
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -68,6 +68,7 @@ Rails.application.routes.draw do
|
||||||
|
|
||||||
get 'projects' => 'projects#index'
|
get 'projects' => 'projects#index'
|
||||||
post 'projects' => 'projects#create'
|
post 'projects' => 'projects#create'
|
||||||
|
patch 'projects' => 'projects#update'
|
||||||
post 'projects/users' => 'projects#addUsers'
|
post 'projects/users' => 'projects#addUsers'
|
||||||
get 'projects/detail' => 'projects#detail'
|
get 'projects/detail' => 'projects#detail'
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@
|
||||||
//3:通知
|
//3:通知
|
||||||
//4:修改个人信息
|
//4:修改个人信息
|
||||||
//5:项目详情 edited by cy
|
//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";
|
var src="pages/"+src_array[seq]+".html";
|
||||||
if(seq == 5){
|
if(seq == 5){
|
||||||
$("#cy_close").click();
|
$("#cy_close").click();
|
||||||
|
|
|
@ -62,14 +62,14 @@
|
||||||
<div class="form-group row has-feedback">
|
<div class="form-group row has-feedback">
|
||||||
<label for="inputEmail3" class="col-sm-2 col-md-push-2 control-label">项目名称</label>
|
<label for="inputEmail3" class="col-sm-2 col-md-push-2 control-label">项目名称</label>
|
||||||
<div class="col-sm-6 col-md-push-2">
|
<div class="col-sm-6 col-md-push-2">
|
||||||
<input type="text" class="form-control" value="11" id="name" name="name" placeholder="姓名">
|
<input type="text" class="form-control" value="" id="project_name" placeholder="请输入项目名称">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!-- ./form-group -->
|
<!-- ./form-group -->
|
||||||
<div class="form-group row has-feedback">
|
<div class="form-group row has-feedback">
|
||||||
<label for="inputPassword3" class="col-sm-2 col-md-push-2 control-label">项目简介</label>
|
<label for="inputPassword3" class="col-sm-2 col-md-push-2 control-label">项目简介</label>
|
||||||
<div class="col-sm-6 col-md-push-2">
|
<div class="col-sm-6 col-md-push-2">
|
||||||
<input type="text" class="form-control" value="11" id="address" name="address" placeholder="地址">
|
<textarea class="form-control" value="" id="project_content" placeholder="请输入项目简介"></textarea>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!-- ./form-group -->
|
<!-- ./form-group -->
|
||||||
|
@ -104,14 +104,6 @@
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
|
||||||
<td>杨诏</td>
|
|
||||||
<td><button class="btn btn-primary btn-danger">删除</button></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>杨诏</td>
|
|
||||||
<td><button class="btn btn-primary btn-danger">删除</button></td>
|
|
||||||
</tr>
|
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
@ -158,32 +150,32 @@
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type:"get",
|
type:"get",
|
||||||
dataType:"json",
|
dataType:"json",
|
||||||
url:"/projects.json",
|
url:"/projects/detail.json",
|
||||||
data:{
|
data:{
|
||||||
"id":parent.LoginUserInfo.selectProject
|
"id":parent.LoginUserInfo.selectProject
|
||||||
},
|
},
|
||||||
statusCode: {
|
statusCode: {
|
||||||
200: function(rpstr) {// 请求成功
|
200: function(rpstr) {// 请求成功
|
||||||
var robj = eval('('+rpstr+')');
|
var data=rpstr.data;
|
||||||
if(robj["code"]=="0"){
|
if(rpstr.code=="0"){
|
||||||
$("#name").val(robj["name"]);
|
$("#project_name").val(data.name);
|
||||||
$("#address").val(robj["content"]);
|
$("#project_content").val(data.content);
|
||||||
var users = robj["users"];
|
var users = data.users;
|
||||||
for(var i = 0; i < users.length; ++i){
|
for(var i = 0; i < users.length; ++i){
|
||||||
var tduser = $("<td></td>").text(users[i]["nickname"]);
|
var tduser = $("<td></td>").text(users[i].nickname);
|
||||||
var btn = $("<button></button>").text("删除");
|
var btn = $("<button></button>").text("删除");
|
||||||
btn.attr("class","btn btn-primary btn-danger");
|
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 = $("<td></td>").append(btn);
|
var tdbtn = $("<td></td>").append(btn);
|
||||||
$("#cy_user_lists").children("tbody").append($("<tr></tr>").append(tduser,tdbtn));
|
$("#cy_user_lists").children("tbody").append($("<tr></tr>").append(tduser,tdbtn));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
//todo
|
alert("服务器内部出错啦!");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
401:function(){// 未授权
|
401:function(){// 未授权
|
||||||
|
// TODO
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -241,31 +233,34 @@
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function cy_submit(){
|
function cy_submit(){
|
||||||
$.ajax({
|
var project_content=$("#project_content").val();
|
||||||
type:"patch",
|
var project_name=$("#project_name").val();
|
||||||
dataType:"json",
|
if( project_name.length>0 && project_content.length>0 ){
|
||||||
url:"/projects.json",
|
$.ajax({
|
||||||
data:{
|
type:"patch",
|
||||||
"project_id":parent.LoginUserInfo.selectProject,
|
dataType:"json",
|
||||||
"name":$("#name").val(),
|
url:"/projects.json",
|
||||||
"content":$("#address").val()
|
data:{
|
||||||
//todo (write todo for find, need to be edited)
|
"project[id]":parent.LoginUserInfo.selectProject,
|
||||||
},
|
"project[name]":project_name,
|
||||||
statusCode: {
|
"project[content]":project_content
|
||||||
200: function(rpstr) {// 请求成功
|
},
|
||||||
var robj = eval('('+rpstr+')');
|
statusCode: {
|
||||||
if(robj["code"]==0){
|
200: function(rpstr) {// 请求成功
|
||||||
window.location.reload();
|
var robj = rpstr;
|
||||||
|
if(robj["code"]==0){
|
||||||
|
alert("修改成功!");
|
||||||
|
window.location.reload();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
422:function(){
|
||||||
|
alert("输入不符合要求,请重新输入!");
|
||||||
}
|
}
|
||||||
else{
|
}
|
||||||
//todo
|
});
|
||||||
}
|
}else{
|
||||||
},
|
alert("请输入完整!");
|
||||||
401:function(){// 未授权
|
}
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
|
@ -183,11 +183,12 @@
|
||||||
statusCode: {
|
statusCode: {
|
||||||
200: function(data) {// 请求成功
|
200: function(data) {// 请求成功
|
||||||
alert("更新成功!");
|
alert("更新成功!");
|
||||||
window.location.reload();
|
|
||||||
// alter
|
// alter
|
||||||
LoginUserInfo.name=name;
|
parent.LoginUserInfo.name=name;
|
||||||
LoginUserInfo.email=email;
|
parent.LoginUserInfo.email=email;
|
||||||
LoginUserInfo.phone=phone;
|
parent.LoginUserInfo.phone=phone;
|
||||||
|
window.location.reload();
|
||||||
|
|
||||||
},
|
},
|
||||||
401:function(){// 未授权
|
401:function(){// 未授权
|
||||||
alert("未登录!");
|
alert("未登录!");
|
Loading…
Reference in New Issue