Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加直接保存且不跳转页面功能; 添加Ctrl + S保存功能 #386

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/controllers/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ func (this *PageController) Modify() {
comment := strings.TrimSpace(this.GetString("comment", ""))
isNoticeUser := strings.TrimSpace(this.GetString("is_notice_user", "0"))
isFollowDoc := strings.TrimSpace(this.GetString("is_follow_doc", "0"))
// 保存类型
saveType := strings.TrimSpace(this.GetString("save_type", ""))

// rm document_page_editor-markdown-doc
this.Ctx.Request.PostForm.Del("document_page_editor-markdown-doc")
Expand Down Expand Up @@ -281,7 +283,7 @@ func (this *PageController) Modify() {
}(documentId)

this.InfoLog("修改文档 " + documentId + " 成功")
this.jsonSuccess("文档修改成功!", nil, "/document/index?document_id="+documentId)
this.jsonSuccess("文档修改成功!", saveType, "/document/index?document_id="+documentId)
}

// document share display
Expand Down
18 changes: 15 additions & 3 deletions static/js/modules/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var Page = {
* @param element
* @returns {boolean}
*/
ajaxSave: function (element, sendEmail, isAutoFollow) {
ajaxSave: function (element, sendEmail, isAutoFollow, isConfirm) {

/**
* 成功信息条
Expand Down Expand Up @@ -45,14 +45,26 @@ var Page = {
Storage.remove(storageId);
successBox(result.message, result.data);
}
if (result.redirect.url) {
if (result.redirect.url && result.data == "0") {
var sleepTime = result.redirect.sleep || 3000;
setTimeout(function () {
parent.location.href = result.redirect.url;
}, sleepTime);
}
}

// 直接保存
if(isConfirm == false){
var commentText = ""
var options = {
dataType: 'json',
success: response,
data: {'comment': commentText, 'is_notice_user': "0", 'is_follow_doc': "1", 'save_type':"1"}
};
$(element).ajaxSubmit(options);
return false;
}

var containerHtml = '<div class="container-fluid" style="padding: 20px 20px 0 20px">';
containerHtml += '<textarea name="edit_comment" class="form-control" rows="3" autofocus="autofocus" style="resize:none""></textarea>';
containerHtml += '<div style="margin-top: 8px;text-align: left">';
Expand Down Expand Up @@ -95,7 +107,7 @@ var Page = {
var options = {
dataType: 'json',
success: response,
data: {'comment': commentText, 'is_notice_user': isNoticeUser, 'is_follow_doc': isFollowDoc}
data: {'comment': commentText, 'is_notice_user': isNoticeUser, 'is_follow_doc': isFollowDoc, 'save_type':"0"}
};
$(element).ajaxSubmit(options);
}
Expand Down
13 changes: 12 additions & 1 deletion views/page/edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
<input type="text" name="name" class="form-control" placeholder="请输入文档名称" value="{{$document.name}}" {{if eq $document.parent_id "0"}} readonly="readonly" {{end}}>
</div>
<div class="col-md-2 text-center" >
<button type="button" class="btn btn-primary" onclick="Page.ajaxSave(this.form, {{.sendEmail}}, {{.autoFollowDoc}})"><i class="fa fa-save"></i> 保存</button>
<button type="button" class="btn btn-primary" onclick="Page.ajaxSave(this.form, {{.sendEmail}}, {{.autoFollowDoc}}, true)"><i class="fa fa-save"></i> 确认保存</button>
<button type="button" class="btn btn-primary" onclick="Page.ajaxSave(this.form, {{.sendEmail}}, {{.autoFollowDoc}}, false)"><i class="fa fa-save"></i> 直接保存</button>
<button type="button" class="btn btn-default" onclick="Page.cancelSave('确定要放弃此次修改吗?', '/document/index?document_id={{$document.document_id}}')"><i class="fa fa-mail-reply"></i> 取消</button>
</div>
</div>
Expand All @@ -22,6 +23,16 @@
</form>
</div>
<script type="text/javascript">
document.addEventListener("keydown", function(e) {
if (e.keyCode == 83 && (navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey)) {
e.preventDefault();
// 你的处理逻辑
console.log('Ctrl+S event captured!');
var form = document.getElementById("page_form");
Page.ajaxSave(form, {{.sendEmail}}, {{.autoFollowDoc}}, false);
}
}, false);

if(parent.layoutClose) {
parent.layoutClose();
}
Expand Down