Browse Source

修复超级管理员删除项目失败的BUG

Minho 7 years ago
parent
commit
7db72f2049
4 changed files with 13 additions and 13 deletions
  1. 3 3
      controllers/manager.go
  2. 3 3
      models/book.go
  3. 3 3
      models/book_result.go
  4. 4 4
      views/manager/books.tpl

+ 3 - 3
controllers/manager.go

@@ -358,14 +358,14 @@ func (c *ManagerController) EditBook() {
 func (c *ManagerController) DeleteBook() {
 	c.Prepare()
 
-	book_id, _ := c.GetInt("book_id", 0)
+	bookId, _ := c.GetInt("book_id", 0)
 
-	if book_id <= 0 {
+	if bookId <= 0 {
 		c.JsonResult(6001, "参数错误")
 	}
 	book := models.NewBook()
 
-	err := book.ThoroughDeleteBook(book_id)
+	err := book.ThoroughDeleteBook(bookId)
 
 	if err == orm.ErrNoRows {
 		c.JsonResult(6002, "项目不存在")

+ 3 - 3
models/book.go

@@ -231,15 +231,15 @@ func (m *Book) ThoroughDeleteBook(id int) error {
 	}
 	o := orm.NewOrm()
 
-	m.BookId = id
-	if err := o.Read(m); err != nil {
+	m,err := m.Find(id);
+	if err != nil {
 		return err
 	}
 	o.Begin()
 
 	sql2 := "DELETE FROM " + NewDocument().TableNameWithPrefix() + " WHERE book_id = ?"
 
-	_, err := o.Raw(sql2, m.BookId).Exec()
+	_, err = o.Raw(sql2, m.BookId).Exec()
 
 	if err != nil {
 		o.Rollback()

+ 3 - 3
models/book_result.go

@@ -59,8 +59,8 @@ func NewBookResult() *BookResult {
 }
 
 // 根据项目标识查询项目以及指定用户权限的信息.
-func (m *BookResult) FindByIdentify(identify string, member_id int) (*BookResult, error) {
-	if identify == "" || member_id <= 0 {
+func (m *BookResult) FindByIdentify(identify string, memberId int) (*BookResult, error) {
+	if identify == "" || memberId <= 0 {
 		return m, ErrInvalidParameter
 	}
 	o := orm.NewOrm()
@@ -75,7 +75,7 @@ func (m *BookResult) FindByIdentify(identify string, member_id int) (*BookResult
 
 	relationship := NewRelationship()
 
-	err = o.QueryTable(relationship.TableNameWithPrefix()).Filter("book_id", book.BookId).Filter("member_id", member_id).One(relationship)
+	err = o.QueryTable(relationship.TableNameWithPrefix()).Filter("book_id", book.BookId).Filter("member_id", memberId).One(relationship)
 
 	if err != nil {
 		return m, err

+ 4 - 4
views/manager/books.tpl

@@ -68,7 +68,7 @@
                                             <ul class="dropdown-menu">
                                                 <li><a href="{{urlfor "DocumentController.Index" ":key" $item.Identify}}" target="_blank">阅读</a></li>
                                                 <li><a href="{{urlfor "ManagerController.EditBook" ":key" $item.Identify}}">设置</a></li>
-                                                <li><a href="javascript:deleteBook('{{$item.Identify}}');">删除</a> </li>
+                                                <li><a href="javascript:deleteBook('{{$item.BookId}}');">删除</a> </li>
                                             </ul>
                                         </div>
                                         {{/*<a href="{{urlfor "DocumentController.Index" ":key" $item.Identify}}" title="查看文档" data-toggle="tooltip" target="_blank"><i class="fa fa-eye"></i> 查看文档</a>*/}}
@@ -114,8 +114,8 @@
 <!-- Delete Book Modal -->
 <div class="modal fade" id="deleteBookModal" tabindex="-1" role="dialog" aria-labelledby="deleteBookModalLabel">
     <div class="modal-dialog" role="document">
-        <form method="post" id="deleteBookForm" action="{{urlfor "BookController.Delete"}}">
-            <input type="hidden" name="identify" value="">
+        <form method="post" id="deleteBookForm" action="{{urlfor "ManagerController.DeleteBook"}}">
+            <input type="hidden" name="book_id" value="">
             <div class="modal-content">
                 <div class="modal-header">
                     <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
@@ -145,7 +145,7 @@
          * 删除项目
          */
         function deleteBook($id) {
-            $("#deleteBookModal").find("input[name='identify']").val($id);
+            $("#deleteBookModal").find("input[name='book_id']").val($id);
             $("#deleteBookModal").modal("show");
         }
         $(function () {