项目选择和列表功能完成;项目详情和修改功能完成;增加项目修改接口

This commit is contained in:
Yang Zhao 2017-01-01 12:24:38 +00:00
parent 774c7a5fa8
commit 921bbc3f95
6 changed files with 58 additions and 56 deletions

View File

@ -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

View File

@ -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

View File

@ -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'

View File

@ -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();

View File

@ -62,14 +62,14 @@
<div class="form-group row has-feedback">
<label for="inputEmail3" class="col-sm-2 col-md-push-2 control-label">项目名称</label>
<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>
<!-- ./form-group -->
<div class="form-group row has-feedback">
<label for="inputPassword3" class="col-sm-2 col-md-push-2 control-label">项目简介</label>
<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>
<!-- ./form-group -->
@ -104,14 +104,6 @@
</tr>
</thead>
<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>
</table>
</div>
@ -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 = $("<td></td>").text(users[i]["nickname"]);
var tduser = $("<td></td>").text(users[i].nickname);
var btn = $("<button></button>").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 = $("<td></td>").append(btn);
$("#cy_user_lists").children("tbody").append($("<tr></tr>").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("请输入完整!");
}
}
</script>
</body>

View File

@ -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("未登录!");