mirror of
https://github.com/mindoc-org/mindoc.git
synced 2025-12-17 18:31:21 +08:00
实现文档保存
This commit is contained in:
@@ -81,6 +81,7 @@ func (c *DocumentController) Create() {
|
|||||||
doc_identify := c.GetString("doc_identify")
|
doc_identify := c.GetString("doc_identify")
|
||||||
doc_name := c.GetString("doc_name")
|
doc_name := c.GetString("doc_name")
|
||||||
parent_id,_ := c.GetInt("parent_id",0)
|
parent_id,_ := c.GetInt("parent_id",0)
|
||||||
|
doc_id,_ := c.GetInt("doc_id",0)
|
||||||
|
|
||||||
if identify == "" {
|
if identify == "" {
|
||||||
c.JsonResult(6001,"参数错误")
|
c.JsonResult(6001,"参数错误")
|
||||||
@@ -94,7 +95,7 @@ func (c *DocumentController) Create() {
|
|||||||
c.JsonResult(6003, "文档标识只能包含小写字母、数字,以及“-”和“_”符号,并且只能小写字母开头")
|
c.JsonResult(6003, "文档标识只能包含小写字母、数字,以及“-”和“_”符号,并且只能小写字母开头")
|
||||||
}
|
}
|
||||||
d,_ := models.NewDocument().FindByFieldFirst("identify",doc_identify);
|
d,_ := models.NewDocument().FindByFieldFirst("identify",doc_identify);
|
||||||
if d.DocumentId > 0{
|
if d.DocumentId > 0 && d.DocumentId != doc_id{
|
||||||
c.JsonResult(6006,"文档标识已被使用")
|
c.JsonResult(6006,"文档标识已被使用")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -112,16 +113,17 @@ func (c *DocumentController) Create() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
document := models.NewDocument()
|
document,_ := models.NewDocument().Find(doc_id)
|
||||||
|
|
||||||
document.MemberId = c.Member.MemberId
|
document.MemberId = c.Member.MemberId
|
||||||
document.BookId = bookResult.BookId
|
document.BookId = bookResult.BookId
|
||||||
if doc_identify != ""{
|
if doc_identify != ""{
|
||||||
document.Identify = doc_identify
|
document.Identify = doc_identify
|
||||||
}
|
}
|
||||||
document.Version = time.Now().UnixNano()
|
document.Version = time.Now().Unix()
|
||||||
document.DocumentName = doc_name
|
document.DocumentName = doc_name
|
||||||
document.ParentId = parent_id
|
document.ParentId = parent_id
|
||||||
logs.Info("%+v",document)
|
|
||||||
if err := document.InsertOrUpdate();err != nil {
|
if err := document.InsertOrUpdate();err != nil {
|
||||||
logs.Error("InsertOrUpdate => ",err)
|
logs.Error("InsertOrUpdate => ",err)
|
||||||
c.JsonResult(6005,"保存失败")
|
c.JsonResult(6005,"保存失败")
|
||||||
@@ -279,3 +281,116 @@ func (c *DocumentController) DownloadAttachment() {
|
|||||||
|
|
||||||
c.StopRun()
|
c.StopRun()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *DocumentController) Delete() {
|
||||||
|
c.Prepare()
|
||||||
|
|
||||||
|
identify := c.GetString("identify")
|
||||||
|
doc_id,err := c.GetInt("doc_id",0)
|
||||||
|
|
||||||
|
bookResult,err := models.NewBookResult().FindByIdentify(identify,c.Member.MemberId)
|
||||||
|
|
||||||
|
if err != nil || bookResult.RoleId == conf.BookObserver {
|
||||||
|
logs.Error("FindByIdentify => ",err)
|
||||||
|
c.JsonResult(6002,"项目不存在或权限不足")
|
||||||
|
}
|
||||||
|
|
||||||
|
if doc_id <= 0 {
|
||||||
|
c.JsonResult(6001,"参数错误")
|
||||||
|
}
|
||||||
|
|
||||||
|
doc,err := models.NewDocument().Find(doc_id)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
logs.Error("Delete => ",err)
|
||||||
|
c.JsonResult(6003,"删除失败")
|
||||||
|
}
|
||||||
|
if doc.BookId != bookResult.BookId {
|
||||||
|
c.JsonResult(6004,"参数错误")
|
||||||
|
}
|
||||||
|
err = doc.RecursiveDocument(doc.DocumentId)
|
||||||
|
if err != nil {
|
||||||
|
c.JsonResult(6005,"删除失败")
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JsonResult(0,"ok")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *DocumentController) Content() {
|
||||||
|
c.Prepare()
|
||||||
|
|
||||||
|
identify := c.Ctx.Input.Param(":key")
|
||||||
|
doc_id,err := c.GetInt("doc_id")
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
doc_id,_ = strconv.Atoi(c.Ctx.Input.Param(":id"))
|
||||||
|
}
|
||||||
|
|
||||||
|
bookResult,err := models.NewBookResult().FindByIdentify(identify,c.Member.MemberId)
|
||||||
|
|
||||||
|
if err != nil || bookResult.RoleId == conf.BookObserver {
|
||||||
|
logs.Error("FindByIdentify => ",err)
|
||||||
|
c.JsonResult(6002,"项目不存在或权限不足")
|
||||||
|
}
|
||||||
|
|
||||||
|
if doc_id <= 0 {
|
||||||
|
c.JsonResult(6001,"参数错误")
|
||||||
|
}
|
||||||
|
|
||||||
|
if c.Ctx.Input.IsPost() {
|
||||||
|
markdown := strings.TrimSpace(c.GetString("markdown",""))
|
||||||
|
content := c.GetString("html")
|
||||||
|
version,_ := c.GetInt64("version",0)
|
||||||
|
is_cover := c.GetString("cover")
|
||||||
|
|
||||||
|
doc ,err := models.NewDocument().Find(doc_id);
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
c.JsonResult(6003,"读取文档错误")
|
||||||
|
}
|
||||||
|
if doc.BookId != bookResult.BookId {
|
||||||
|
c.JsonResult(6004,"保存的文档不属于指定项目")
|
||||||
|
}
|
||||||
|
if doc.Version != version && !strings.EqualFold(is_cover,"yes"){
|
||||||
|
logs.Info("%d|",version,doc.Version)
|
||||||
|
c.JsonResult(6005,"文档已被修改确定要覆盖吗?")
|
||||||
|
}
|
||||||
|
if markdown == "" && content != ""{
|
||||||
|
doc.Markdown = content
|
||||||
|
}else{
|
||||||
|
doc.Markdown = markdown
|
||||||
|
}
|
||||||
|
doc.Version = time.Now().Unix()
|
||||||
|
doc.Content = content
|
||||||
|
if err := doc.InsertOrUpdate();err != nil {
|
||||||
|
logs.Error("InsertOrUpdate => ",err)
|
||||||
|
c.JsonResult(6006,"保存失败")
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JsonResult(0,"ok",doc)
|
||||||
|
}
|
||||||
|
doc,err := models.NewDocument().Find(doc_id)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
c.JsonResult(6003,"文档不存在")
|
||||||
|
}
|
||||||
|
c.JsonResult(0,"ok",doc)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -41,6 +41,9 @@ func NewBookResult() *BookResult {
|
|||||||
|
|
||||||
// 根据项目标识查询项目以及指定用户权限的信息.
|
// 根据项目标识查询项目以及指定用户权限的信息.
|
||||||
func (m *BookResult) FindByIdentify(identify string,member_id int) (*BookResult,error) {
|
func (m *BookResult) FindByIdentify(identify string,member_id int) (*BookResult,error) {
|
||||||
|
if identify == "" || member_id <= 0 {
|
||||||
|
return m,ErrInvalidParameter
|
||||||
|
}
|
||||||
o := orm.NewOrm()
|
o := orm.NewOrm()
|
||||||
|
|
||||||
book := NewBook()
|
book := NewBook()
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
|
|
||||||
"github.com/lifei6671/godoc/conf"
|
"github.com/lifei6671/godoc/conf"
|
||||||
"github.com/astaxie/beego/orm"
|
"github.com/astaxie/beego/orm"
|
||||||
|
"github.com/astaxie/beego/logs"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Document struct.
|
// Document struct.
|
||||||
@@ -12,7 +13,7 @@ type Document struct {
|
|||||||
DocumentId int `orm:"pk;auto;unique;column(document_id)" json:"doc_id"`
|
DocumentId int `orm:"pk;auto;unique;column(document_id)" json:"doc_id"`
|
||||||
DocumentName string `orm:"column(document_name);size(500)" json:"doc_name"`
|
DocumentName string `orm:"column(document_name);size(500)" json:"doc_name"`
|
||||||
// Identify 文档唯一标识
|
// Identify 文档唯一标识
|
||||||
Identify string `orm:"column(identify);size(100);unique;null;default(null)" json:"identify"`
|
Identify string `orm:"column(identify);size(100);index;null;default(null)" json:"identify"`
|
||||||
BookId int `orm:"column(book_id);type(int);index" json:"book_id"`
|
BookId int `orm:"column(book_id);type(int);index" json:"book_id"`
|
||||||
ParentId int `orm:"column(parent_id);type(int);index" json:"parent_id"`
|
ParentId int `orm:"column(parent_id);type(int);index" json:"parent_id"`
|
||||||
OrderSort int `orm:"column(order_sort);default(0);type(int);index" json:"order_sort"`
|
OrderSort int `orm:"column(order_sort);default(0);type(int);index" json:"order_sort"`
|
||||||
@@ -26,19 +27,10 @@ type Document struct {
|
|||||||
MemberId int `orm:"column(member_id);type(int)" json:"member_id"`
|
MemberId int `orm:"column(member_id);type(int)" json:"member_id"`
|
||||||
ModifyTime time.Time `orm:"column(modify_time);type(datetime);auto_now" json:"modify_time"`
|
ModifyTime time.Time `orm:"column(modify_time);type(datetime);auto_now" json:"modify_time"`
|
||||||
ModifyAt int `orm:"column(modify_at);type(int)" json:"-"`
|
ModifyAt int `orm:"column(modify_at);type(int)" json:"-"`
|
||||||
Version int64 `orm:"type(bigint);column(version)" json:"-"`
|
Version int64 `orm:"type(bigint);column(version)" json:"version"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type DocumentTree struct {
|
|
||||||
DocumentId int `json:"id,string"`
|
|
||||||
DocumentName string `json:"text"`
|
|
||||||
ParentId int `json:"parent_id,string"`
|
|
||||||
State *DocumentSelected `json:"state,omitempty"`
|
|
||||||
}
|
|
||||||
type DocumentSelected struct {
|
|
||||||
Selected bool `json:"selected"`
|
|
||||||
Opened bool `json:"opened"`
|
|
||||||
}
|
|
||||||
// TableName 获取对应数据库表名.
|
// TableName 获取对应数据库表名.
|
||||||
func (m *Document) TableName() string {
|
func (m *Document) TableName() string {
|
||||||
return "documents"
|
return "documents"
|
||||||
@@ -63,7 +55,7 @@ func (m *Document) Find(id int) (*Document,error) {
|
|||||||
o := orm.NewOrm()
|
o := orm.NewOrm()
|
||||||
|
|
||||||
|
|
||||||
err := o.Read(m)
|
err := o.QueryTable(m.TableNameWithPrefix()).Filter("document_id",id).One(m)
|
||||||
|
|
||||||
if err == orm.ErrNoRows{
|
if err == orm.ErrNoRows{
|
||||||
return m,ErrDataNotExist
|
return m,ErrDataNotExist
|
||||||
@@ -71,37 +63,6 @@ func (m *Document) Find(id int) (*Document,error) {
|
|||||||
return m,nil
|
return m,nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (m *Document) FindDocumentTree(book_id int) ([]*DocumentTree,error){
|
|
||||||
o := orm.NewOrm()
|
|
||||||
|
|
||||||
trees := make([]*DocumentTree,0)
|
|
||||||
|
|
||||||
var docs []*Document
|
|
||||||
|
|
||||||
count ,err := o.QueryTable(m).Filter("book_id",book_id).OrderBy("-order_sort","document_id").All(&docs,"document_id","document_name","parent_id")
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return trees,err
|
|
||||||
}
|
|
||||||
|
|
||||||
trees = make([]*DocumentTree,count)
|
|
||||||
|
|
||||||
for index,item := range docs {
|
|
||||||
tree := &DocumentTree{}
|
|
||||||
if index == 0{
|
|
||||||
tree.State = &DocumentSelected{ Selected: true, Opened: true }
|
|
||||||
}
|
|
||||||
tree.DocumentId = item.DocumentId
|
|
||||||
tree.ParentId = item.ParentId
|
|
||||||
tree.DocumentName = item.DocumentName
|
|
||||||
|
|
||||||
trees[index] = tree
|
|
||||||
}
|
|
||||||
|
|
||||||
return trees,nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *Document) InsertOrUpdate(cols... string) error {
|
func (m *Document) InsertOrUpdate(cols... string) error {
|
||||||
o := orm.NewOrm()
|
o := orm.NewOrm()
|
||||||
|
|
||||||
@@ -122,6 +83,30 @@ func (m *Document) FindByFieldFirst(field string,v interface{}) (*Document,error
|
|||||||
return m,err
|
return m,err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//递归删除一个文档.
|
||||||
|
func (m *Document) RecursiveDocument(doc_id int) error {
|
||||||
|
|
||||||
|
o := orm.NewOrm()
|
||||||
|
|
||||||
|
var docs []*Document
|
||||||
|
|
||||||
|
_,err := o.QueryTable(m.TableNameWithPrefix()).Filter("parent_id",doc_id).All(&docs)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
logs.Error("",err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _,item := range docs {
|
||||||
|
doc_id := item.DocumentId
|
||||||
|
o.QueryTable(m.TableNameWithPrefix()).Filter("document_id",doc_id).Delete()
|
||||||
|
m.RecursiveDocument(doc_id)
|
||||||
|
}
|
||||||
|
if doc,err := m.Find(doc_id); err != nil {
|
||||||
|
o.Delete(doc)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
56
models/document_tree.go
Normal file
56
models/document_tree.go
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/astaxie/beego/orm"
|
||||||
|
)
|
||||||
|
|
||||||
|
type DocumentTree struct {
|
||||||
|
DocumentId int `json:"id"`
|
||||||
|
DocumentName string `json:"text"`
|
||||||
|
ParentId interface{} `json:"parent"`
|
||||||
|
Identify string `json:"identify"`
|
||||||
|
Version int64 `json:"version"`
|
||||||
|
State *DocumentSelected `json:"state,omitempty"`
|
||||||
|
}
|
||||||
|
type DocumentSelected struct {
|
||||||
|
Selected bool `json:"selected"`
|
||||||
|
Opened bool `json:"opened"`
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func (m *Document) FindDocumentTree(book_id int) ([]*DocumentTree,error){
|
||||||
|
o := orm.NewOrm()
|
||||||
|
|
||||||
|
trees := make([]*DocumentTree,0)
|
||||||
|
|
||||||
|
var docs []*Document
|
||||||
|
|
||||||
|
count ,err := o.QueryTable(m).Filter("book_id",book_id).OrderBy("-order_sort","document_id").All(&docs,"document_id","version","document_name","parent_id","identify")
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return trees,err
|
||||||
|
}
|
||||||
|
|
||||||
|
trees = make([]*DocumentTree,count)
|
||||||
|
|
||||||
|
for index,item := range docs {
|
||||||
|
tree := &DocumentTree{}
|
||||||
|
if index == 0{
|
||||||
|
tree.State = &DocumentSelected{ Selected: true, Opened: true }
|
||||||
|
}
|
||||||
|
tree.DocumentId = item.DocumentId
|
||||||
|
tree.Identify = item.Identify
|
||||||
|
tree.Version = item.Version
|
||||||
|
if item.ParentId > 0 {
|
||||||
|
tree.ParentId = item.ParentId
|
||||||
|
}else{
|
||||||
|
tree.ParentId = "#"
|
||||||
|
}
|
||||||
|
|
||||||
|
tree.DocumentName = item.DocumentName
|
||||||
|
|
||||||
|
trees[index] = tree
|
||||||
|
}
|
||||||
|
|
||||||
|
return trees,nil
|
||||||
|
}
|
||||||
@@ -48,6 +48,8 @@ func init() {
|
|||||||
beego.Router("/docs/:key/edit/?:id", &controllers.DocumentController{},"*:Edit")
|
beego.Router("/docs/:key/edit/?:id", &controllers.DocumentController{},"*:Edit")
|
||||||
beego.Router("/docs/upload",&controllers.DocumentController{},"post:Upload")
|
beego.Router("/docs/upload",&controllers.DocumentController{},"post:Upload")
|
||||||
beego.Router("/docs/:key/create",&controllers.DocumentController{},"post:Create")
|
beego.Router("/docs/:key/create",&controllers.DocumentController{},"post:Create")
|
||||||
|
beego.Router("/docs/:key/delete", &controllers.DocumentController{},"post:Delete")
|
||||||
|
beego.Router("/docs/:key/content/?:id",&controllers.DocumentController{},"*:Content")
|
||||||
|
|
||||||
|
|
||||||
beego.Router("/docs/:key", &controllers.DocumentController{},"*:Index")
|
beego.Router("/docs/:key", &controllers.DocumentController{},"*:Index")
|
||||||
|
|||||||
@@ -169,6 +169,10 @@
|
|||||||
.jstree .jstree-node .m-tree-operate.operate-hover .operate-hide {
|
.jstree .jstree-node .m-tree-operate.operate-hover .operate-hide {
|
||||||
width: 108px
|
width: 108px
|
||||||
}
|
}
|
||||||
|
.jstree-default .jstree-wholerow-hovered {
|
||||||
|
background: #08c;
|
||||||
|
color: white !important;
|
||||||
|
}
|
||||||
.jstree-default .jstree-wholerow-clicked {
|
.jstree-default .jstree-wholerow-clicked {
|
||||||
background: #10af88;
|
background: #10af88;
|
||||||
background: -webkit-linear-gradient(top, #beebff 0%, #a8e4ff 100%);
|
background: -webkit-linear-gradient(top, #beebff 0%, #a8e4ff 100%);
|
||||||
|
|||||||
@@ -71,7 +71,17 @@ body{
|
|||||||
}
|
}
|
||||||
.manual-editor-container .manual-editormd{
|
.manual-editor-container .manual-editormd{
|
||||||
position: absolute;
|
position: absolute;
|
||||||
bottom: 15px;
|
bottom: 30px;
|
||||||
|
top: -1px;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
}
|
||||||
|
.manual-editor-container .manual-editormd .manual-editormd-active{
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
bottom: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
}
|
}
|
||||||
.editormd-group{
|
.editormd-group{
|
||||||
float: left;
|
float: left;
|
||||||
@@ -81,6 +91,20 @@ body{
|
|||||||
.editormd-group a{
|
.editormd-group a{
|
||||||
float: left;
|
float: left;
|
||||||
}
|
}
|
||||||
|
.editormd-group a.change{
|
||||||
|
|
||||||
|
}
|
||||||
|
.editormd-group .change i{
|
||||||
|
color: #ffffff;
|
||||||
|
background-color: #44B036 !important;
|
||||||
|
border: 1px #44B036 solid !important;
|
||||||
|
}
|
||||||
|
.editormd-group .change i:hover{
|
||||||
|
background-color: #58CB48 !important;
|
||||||
|
}
|
||||||
|
.editormd-group .disabled i:hover{
|
||||||
|
background: #ffffff !important;
|
||||||
|
}
|
||||||
.editormd-group a.disabled{
|
.editormd-group a.disabled{
|
||||||
border-color: #c9c9c9;
|
border-color: #c9c9c9;
|
||||||
opacity: .6;
|
opacity: .6;
|
||||||
@@ -134,4 +158,5 @@ body{
|
|||||||
border-left: 1px solid #DDDDDD;
|
border-left: 1px solid #DDDDDD;
|
||||||
color: #555;
|
color: #555;
|
||||||
background-color: #FAFAFA;
|
background-color: #FAFAFA;
|
||||||
|
z-index: 1000;
|
||||||
}
|
}
|
||||||
@@ -15,6 +15,7 @@ function showSuccess($msg,$id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$(function () {
|
$(function () {
|
||||||
|
window.addDocumentModalFormHtml = $(this).find("form").html();
|
||||||
window.editor = editormd("docEditor", {
|
window.editor = editormd("docEditor", {
|
||||||
width : "100%",
|
width : "100%",
|
||||||
height : "100%",
|
height : "100%",
|
||||||
@@ -37,10 +38,25 @@ $(function () {
|
|||||||
saveHTMLToTextarea : true,
|
saveHTMLToTextarea : true,
|
||||||
onload : function() {
|
onload : function() {
|
||||||
this.hideToolbar();
|
this.hideToolbar();
|
||||||
|
var $select_node_id = window.treeCatalog.get_selected();
|
||||||
|
if($select_node_id) {
|
||||||
|
var $select_node = window.treeCatalog.get_node($select_node_id[0])
|
||||||
|
if ($select_node) {
|
||||||
|
$select_node.node = {
|
||||||
|
id: $select_node.id
|
||||||
|
};
|
||||||
|
|
||||||
|
loadDocument($select_node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onchange : function () {
|
||||||
|
resetEditorChanged(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
editormd.loadPlugin("/static/editor.md/plugins/file-dialog/file-dialog");
|
editormd.loadPlugin("/static/editor.md/plugins/file-dialog/file-dialog");
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 实现标题栏操作
|
* 实现标题栏操作
|
||||||
*/
|
*/
|
||||||
@@ -50,6 +66,10 @@ $(function () {
|
|||||||
window.editor.fileDialog();
|
window.editor.fileDialog();
|
||||||
}else if(name === "history"){
|
}else if(name === "history"){
|
||||||
|
|
||||||
|
}else if(name === "save"){
|
||||||
|
|
||||||
|
saveDocument(false);
|
||||||
|
|
||||||
}else if(name === "sidebar"){
|
}else if(name === "sidebar"){
|
||||||
$("#manualCategory").toggle(0,"swing",function () {
|
$("#manualCategory").toggle(0,"swing",function () {
|
||||||
|
|
||||||
@@ -115,26 +135,32 @@ $(function () {
|
|||||||
$("#btnAddDocument").on("click",function () {
|
$("#btnAddDocument").on("click",function () {
|
||||||
$("#addDocumentModal").modal("show");
|
$("#addDocumentModal").modal("show");
|
||||||
});
|
});
|
||||||
$("#addDocumentModal").on("show.bs.modal",function () {
|
$("#addDocumentModal").on("hidden.bs.modal",function () {
|
||||||
window.addDocumentModalFormHtml = $(this).find("form").html();
|
|
||||||
}).on("hidden.bs.modal",function () {
|
|
||||||
$(this).find("form").html(window.addDocumentModalFormHtml);
|
$(this).find("form").html(window.addDocumentModalFormHtml);
|
||||||
|
}).on("shown.bs.modal",function () {
|
||||||
|
$(this).find("input[name='doc_name']").focus();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/***
|
||||||
|
* 加载指定的文档到编辑器中
|
||||||
|
* @param $node
|
||||||
|
*/
|
||||||
function loadDocument($node) {
|
function loadDocument($node) {
|
||||||
var index = layer.load(1, {
|
var index = layer.load(1, {
|
||||||
shade: [0.1,'#fff'] //0.1透明度的白色背景
|
shade: [0.1,'#fff'] //0.1透明度的白色背景
|
||||||
});
|
});
|
||||||
|
|
||||||
$.get("/docs/"+ window.book.identify +"/" + $node.node.id ).done(function (data) {
|
$.get(window.editURL + $node.node.id ).done(function (res) {
|
||||||
win.isEditorChange = true;
|
|
||||||
layer.close(index);
|
layer.close(index);
|
||||||
$("#documentId").val(selected.node.id);
|
|
||||||
window.editor.clear();
|
resetEditor();
|
||||||
if(data.errcode === 0 && data.data.doc.content){
|
if(res.errcode === 0){
|
||||||
window.editor.insertValue(data.data.doc.content);
|
window.editor.insertValue(res.data.markdown);
|
||||||
window.editor.setCursor({line:0, ch:0});
|
window.editor.setCursor({line:0, ch:0});
|
||||||
}else if(data.errcode !== 0){
|
var node = { "id" : res.data.doc_id,'parent' : res.data.parent_id === 0 ? '#' : res.data.parent_id ,"text" : res.data.doc_name,"identify" : res.data.identify,"version" : res.data.version};
|
||||||
|
pushDocumentCategory(node);
|
||||||
|
|
||||||
|
}else{
|
||||||
layer.msg("文档加载失败");
|
layer.msg("文档加载失败");
|
||||||
}
|
}
|
||||||
}).fail(function () {
|
}).fail(function () {
|
||||||
@@ -142,8 +168,160 @@ $(function () {
|
|||||||
layer.msg("文档加载失败");
|
layer.msg("文档加载失败");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加文档
|
* 创建文档
|
||||||
|
*/
|
||||||
|
function openCreateCatalogDialog($node) {
|
||||||
|
var $then = $("#addDocumentModal");
|
||||||
|
|
||||||
|
var doc_id = $node ? $node.id : 0;
|
||||||
|
|
||||||
|
$then.find("input[name='parent_id']").val(doc_id);
|
||||||
|
|
||||||
|
$then.modal("show");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将一个节点推送到现有数组中
|
||||||
|
* @param $node
|
||||||
|
*/
|
||||||
|
function pushDocumentCategory($node) {
|
||||||
|
for (var index in window.documentCategory){
|
||||||
|
var item = window.documentCategory[index];
|
||||||
|
if(item.id === $node.id){
|
||||||
|
|
||||||
|
window.documentCategory[index] = $node;
|
||||||
|
console.log( window.documentCategory[index]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
window.documentCategory.push($node);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 打开文档编辑界面
|
||||||
|
* @param $node
|
||||||
|
*/
|
||||||
|
function openEditCatalogDialog($node) {
|
||||||
|
var $then = $("#addDocumentModal");
|
||||||
|
var doc_id = parseInt($node ? $node.id : 0);
|
||||||
|
var text = $node ? $node.text : '';
|
||||||
|
var parentId = $node && $node.parent !== '#' ? $node.parent : 0;
|
||||||
|
|
||||||
|
$then.find("input[name='doc_id']").val(doc_id);
|
||||||
|
$then.find("input[name='parent_id']").val(parentId);
|
||||||
|
$then.find("input[name='doc_name']").val(text);
|
||||||
|
|
||||||
|
for (var index in window.documentCategory){
|
||||||
|
var item = window.documentCategory[index];
|
||||||
|
if(item.id === doc_id){
|
||||||
|
$then.find("input[name='doc_identify']").val(item.identify);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$then.modal({ show : true });
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除一个文档
|
||||||
|
* @param $node
|
||||||
|
*/
|
||||||
|
function openDeleteDocumentDialog($node) {
|
||||||
|
var index = layer.confirm('你确定要删除该文档吗?', {
|
||||||
|
btn: ['确定','取消'] //按钮
|
||||||
|
}, function(){
|
||||||
|
|
||||||
|
$.post(window.deleteURL,{"identify" : window.book.identify,"doc_id" : $node.id}).done(function (res) {
|
||||||
|
layer.close(index);
|
||||||
|
if(res.errcode === 0){
|
||||||
|
window.treeCatalog.delete_node($node);
|
||||||
|
resetEditor($node);
|
||||||
|
}else{
|
||||||
|
layer.msg("删除失败",{icon : 2})
|
||||||
|
}
|
||||||
|
}).fail(function () {
|
||||||
|
layer.close(index);
|
||||||
|
layer.msg("删除失败",{icon : 2})
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function saveDocument($is_cover) {
|
||||||
|
var index = null;
|
||||||
|
var node = window.treeCatalog.get_selected();
|
||||||
|
var content = window.editor.getMarkdown();
|
||||||
|
var html = window.editor.getPreviewedHTML();
|
||||||
|
var version = "";
|
||||||
|
if(content === ""){
|
||||||
|
resetEditorChanged(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(!node){
|
||||||
|
layer.msg("获取当前文档信息失败");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var doc_id = parseInt(node[0]);
|
||||||
|
|
||||||
|
for(var i in window.documentCategory){
|
||||||
|
var item = window.documentCategory[i];
|
||||||
|
|
||||||
|
if(item.id === doc_id){
|
||||||
|
version = item.version;
|
||||||
|
console.log(item)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$.ajax({
|
||||||
|
beforeSend : function () {
|
||||||
|
index = layer.load(1, {shade: [0.1,'#fff'] });
|
||||||
|
},
|
||||||
|
url : window.editURL,
|
||||||
|
data : {"identify" : window.book.identify,"doc_id" : node[0],"markdown" : content,"html" : html,"cover" : $is_cover ? "yes":"no","version": version},
|
||||||
|
type :"post",
|
||||||
|
dataType :"json",
|
||||||
|
success : function (res) {
|
||||||
|
layer.close(index);
|
||||||
|
if(res.errcode === 0){
|
||||||
|
resetEditorChanged(false);
|
||||||
|
for(var i in window.documentCategory){
|
||||||
|
var item = window.documentCategory[i];
|
||||||
|
|
||||||
|
if(item.id === doc_id){
|
||||||
|
window.documentCategory[i].version = res.data.version;
|
||||||
|
console.log(res.data)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else if(res.errcode === 6005){
|
||||||
|
var confirmIndex = layer.confirm('你确定要删除该文档吗?', {
|
||||||
|
btn: ['确定','取消'] //按钮
|
||||||
|
}, function(){
|
||||||
|
layer.close(confirmIndex);
|
||||||
|
saveDocument(true);
|
||||||
|
});
|
||||||
|
}else{
|
||||||
|
layer.msg(res.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function resetEditor($node) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function resetEditorChanged($is_change) {
|
||||||
|
if($is_change){
|
||||||
|
$("#markdown-save").removeClass('disabled').addClass('change');
|
||||||
|
}else{
|
||||||
|
$("#markdown-save").removeClass('change').addClass('disabled');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 添加顶级文档
|
||||||
*/
|
*/
|
||||||
$("#addDocumentForm").ajaxForm({
|
$("#addDocumentForm").ajaxForm({
|
||||||
beforeSubmit : function () {
|
beforeSubmit : function () {
|
||||||
@@ -151,29 +329,30 @@ $(function () {
|
|||||||
if (doc_name === ""){
|
if (doc_name === ""){
|
||||||
return showError("目录名称不能为空","#add-error-message")
|
return showError("目录名称不能为空","#add-error-message")
|
||||||
}
|
}
|
||||||
|
window.addDocumentFormIndex = layer.load(1, { shade: [0.1,'#fff'] });
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
success : function (res) {
|
success : function (res) {
|
||||||
if(res.errcode === 0){
|
if(res.errcode === 0){
|
||||||
var data = { "id" : res.data.doc_id,'parent' : res.data.parent_id,"text" : res.data.doc_name};
|
|
||||||
|
var data = { "id" : res.data.doc_id,'parent' : res.data.parent_id === 0 ? '#' : res.data.parent_id ,"text" : res.data.doc_name,"identify" : res.data.identify,"version" : res.data.version};
|
||||||
|
|
||||||
var node = window.treeCatalog.get_node(data.id);
|
var node = window.treeCatalog.get_node(data.id);
|
||||||
if(node){
|
if(node){
|
||||||
window.treeCatalog.rename_node({"id":data.id},data.text);
|
window.treeCatalog.rename_node({"id":data.id},data.text);
|
||||||
|
|
||||||
}else {
|
}else {
|
||||||
var result = window.treeCatalog.create_node(res.data.parent_id, data, 'last');
|
window.treeCatalog.create_node(data.parent, data);
|
||||||
window.treeCatalog.deselect_all();
|
window.treeCatalog.deselect_all();
|
||||||
window.treeCatalog.select_node(data);
|
window.treeCatalog.select_node(data);
|
||||||
window.editor.clear();
|
|
||||||
}
|
}
|
||||||
|
pushDocumentCategory(data);
|
||||||
$("#markdown-save").removeClass('change').addClass('disabled');
|
$("#markdown-save").removeClass('change').addClass('disabled');
|
||||||
$("#addDocumentModal").modal('hide');
|
$("#addDocumentModal").modal('hide');
|
||||||
}else{
|
}else{
|
||||||
showError(res.message,"#add-error-message")
|
showError(res.message,"#add-error-message")
|
||||||
}
|
}
|
||||||
},
|
layer.close(window.addDocumentFormIndex);
|
||||||
error :function () {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -220,7 +399,7 @@ $(function () {
|
|||||||
"action": function (data) {
|
"action": function (data) {
|
||||||
var inst = $.jstree.reference(data.reference);
|
var inst = $.jstree.reference(data.reference);
|
||||||
var node = inst.get_node(data.reference);
|
var node = inst.get_node(data.reference);
|
||||||
editDocumentDialog(node);
|
openEditCatalogDialog(node);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"删除": {
|
"删除": {
|
||||||
@@ -232,23 +411,12 @@ $(function () {
|
|||||||
"action": function (data) {
|
"action": function (data) {
|
||||||
var inst = $.jstree.reference(data.reference);
|
var inst = $.jstree.reference(data.reference);
|
||||||
var node = inst.get_node(data.reference);
|
var node = inst.get_node(data.reference);
|
||||||
deleteDocumentDialog(node);
|
openDeleteDocumentDialog(node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).on('loaded.jstree', function () {
|
}).on('loaded.jstree', function () {
|
||||||
window.treeCatalog = $(this).jstree();
|
window.treeCatalog = $(this).jstree();
|
||||||
var $select_node_id = window.treeCatalog.get_selected();
|
|
||||||
if($select_node_id) {
|
|
||||||
var $select_node = window.treeCatalog.get_node($select_node_id[0])
|
|
||||||
if ($select_node) {
|
|
||||||
$select_node.node = {
|
|
||||||
id: $select_node.id
|
|
||||||
};
|
|
||||||
|
|
||||||
loadDocument($select_node);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -12,6 +12,8 @@
|
|||||||
window.fileUploadURL = "{{urlfor "DocumentController.Upload" "identify" .Model.Identify}}";
|
window.fileUploadURL = "{{urlfor "DocumentController.Upload" "identify" .Model.Identify}}";
|
||||||
window.documentCategory = {{.Result}};
|
window.documentCategory = {{.Result}};
|
||||||
window.book = {{.ModelResult}};
|
window.book = {{.ModelResult}};
|
||||||
|
window.deleteURL = "{{urlfor "DocumentController.Delete" ":key" .Model.Identify}}";
|
||||||
|
window.editURL = "{{urlfor "DocumentController.Content" ":key" .Model.Identify ":id" ""}}"
|
||||||
</script>
|
</script>
|
||||||
<!-- Bootstrap -->
|
<!-- Bootstrap -->
|
||||||
<link href="/static/bootstrap/css/bootstrap.min.css" rel="stylesheet">
|
<link href="/static/bootstrap/css/bootstrap.min.css" rel="stylesheet">
|
||||||
@@ -35,7 +37,7 @@
|
|||||||
<a href="javascript:;" data-toggle="tooltip" data-title="返回"><i class="fa fa-chevron-left" aria-hidden="true"></i></a>
|
<a href="javascript:;" data-toggle="tooltip" data-title="返回"><i class="fa fa-chevron-left" aria-hidden="true"></i></a>
|
||||||
</div>
|
</div>
|
||||||
<div class="editormd-group">
|
<div class="editormd-group">
|
||||||
<a href="javascript:;" data-toggle="tooltip" data-title="保存" class="disabled"><i class="fa fa-save" aria-hidden="true"></i></a>
|
<a href="javascript:;" id="markdown-save" data-toggle="tooltip" data-title="保存" class="disabled save"><i class="fa fa-save" aria-hidden="true" name="save"></i></a>
|
||||||
</div>
|
</div>
|
||||||
<div class="editormd-group">
|
<div class="editormd-group">
|
||||||
<a href="javascript:;" data-toggle="tooltip" data-title="撤销 (Ctrl-Z)"><i class="fa fa-undo first" name="undo" unselectable="on"></i></a>
|
<a href="javascript:;" data-toggle="tooltip" data-title="撤销 (Ctrl-Z)"><i class="fa fa-undo first" name="undo" unselectable="on"></i></a>
|
||||||
@@ -100,7 +102,9 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="manual-editor-container" id="manualEditorContainer">
|
<div class="manual-editor-container" id="manualEditorContainer">
|
||||||
<div class="manual-editormd" id="docEditor"></div>
|
<div class="manual-editormd">
|
||||||
|
<div id="docEditor" class="manual-editormd-active"></div>
|
||||||
|
</div>
|
||||||
<div class="manual-editor-status">
|
<div class="manual-editor-status">
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
@@ -113,6 +117,8 @@
|
|||||||
<div class="modal-dialog" role="document">
|
<div class="modal-dialog" role="document">
|
||||||
<form method="post" action="{{urlfor "DocumentController.Create" ":key" .Model.Identify}}" id="addDocumentForm" class="form-horizontal">
|
<form method="post" action="{{urlfor "DocumentController.Create" ":key" .Model.Identify}}" id="addDocumentForm" class="form-horizontal">
|
||||||
<input type="hidden" name="identify" value="{{.Model.Identify}}">
|
<input type="hidden" name="identify" value="{{.Model.Identify}}">
|
||||||
|
<input type="hidden" name="doc_id" value="0">
|
||||||
|
<input type="hidden" name="parent_id" value="0">
|
||||||
<div class="modal-content">
|
<div class="modal-content">
|
||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
|
||||||
|
|||||||
Reference in New Issue
Block a user