编辑文档.
()
| 523 | |
| 524 | // 编辑文档. |
| 525 | func (this *DocumentController) Edit() { |
| 526 | docId := 0 // 文档id |
| 527 | |
| 528 | identify := this.Ctx.Input.Param(":key") |
| 529 | if identify == "" { |
| 530 | this.Abort("404") |
| 531 | } |
| 532 | |
| 533 | bookResult := models.NewBookResult() |
| 534 | |
| 535 | var err error |
| 536 | //如果是超级管理者,则不判断权限 |
| 537 | if this.Member.IsAdministrator() { |
| 538 | book, err := models.NewBook().FindByFieldFirst("identify", identify) |
| 539 | if err != nil { |
| 540 | this.JsonResult(6002, "书籍不存在或权限不足") |
| 541 | } |
| 542 | bookResult = book.ToBookResult() |
| 543 | } else { |
| 544 | bookResult, err = models.NewBookResult().FindByIdentify(identify, this.Member.MemberId) |
| 545 | if err != nil { |
| 546 | beego.Error("DocumentController.Edit => ", err) |
| 547 | this.Abort("404") |
| 548 | } |
| 549 | |
| 550 | if bookResult.RoleId == conf.BookObserver { |
| 551 | this.JsonResult(6002, "书籍不存在或权限不足") |
| 552 | } |
| 553 | } |
| 554 | |
| 555 | //根据不同编辑器类型加载编辑器【注:现在只支持markdown】 |
| 556 | this.TplName = "document/markdown_edit_template.html" |
| 557 | |
| 558 | this.Data["Model"] = bookResult |
| 559 | r, _ := json.Marshal(bookResult) |
| 560 | |
| 561 | this.Data["ModelResult"] = template.JS(string(r)) |
| 562 | |
| 563 | this.Data["Result"] = template.JS("[]") |
| 564 | |
| 565 | // 编辑的文档 |
| 566 | if id := this.GetString(":id"); id != "" { |
| 567 | if num, _ := strconv.Atoi(id); num > 0 { |
| 568 | docId = num |
| 569 | } else { //字符串 |
| 570 | var doc = models.NewDocument() |
| 571 | orm.NewOrm().QueryTable(doc).Filter("identify", id).Filter("book_id", bookResult.BookId).One(doc, "document_id") |
| 572 | docId = doc.DocumentId |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | trees, err := models.NewDocument().FindDocumentTree(bookResult.BookId, docId, true) |
| 577 | if err != nil { |
| 578 | beego.Error("FindDocumentTree => ", err) |
| 579 | } else { |
| 580 | if len(trees) > 0 { |
| 581 | if jsTree, err := json.Marshal(trees); err == nil { |
| 582 | this.Data["Result"] = template.JS(string(jsTree)) |
nothing calls this directly
no test coverage detected