优化界面交互

pull/25/merge
Minho 2017-05-10 15:42:37 +08:00
parent 42b08a0b18
commit fa20dad73f
1 changed files with 186 additions and 170 deletions

View File

@ -83,59 +83,59 @@
</label> </label>
</div> </div>
</div> </div>
{{/* {{/*
<div class="form-group"> <div class="form-group">
<label>开启评论</label> <label>开启评论</label>
<div class="radio"> <div class="radio">
<label class="radio-inline"> <label class="radio-inline">
<input type="radio" {{if eq .Model.CommentStatus "open"}}checked{{end}} name="comment_status" value="open">允许所有人评论<span class="text"></span> <input type="radio" {{if eq .Model.CommentStatus "open"}}checked{{end}} name="comment_status" value="open">允许所有人评论<span class="text"></span>
</label> </label>
<label class="radio-inline"> <label class="radio-inline">
<input type="radio" {{if eq .Model.CommentStatus "closed"}}checked{{end}} name="comment_status" value="closed">关闭评论<span class="text"></span> <input type="radio" {{if eq .Model.CommentStatus "closed"}}checked{{end}} name="comment_status" value="closed">关闭评论<span class="text"></span>
</label> </label>
<label class="radio-inline"> <label class="radio-inline">
<input type="radio" {{if eq .Model.CommentStatus "group_only"}}checked{{end}} name="comment_status" value="group_only">仅允许参与者评论<span class="text"></span> <input type="radio" {{if eq .Model.CommentStatus "group_only"}}checked{{end}} name="comment_status" value="group_only">仅允许参与者评论<span class="text"></span>
</label> </label>
<label class="radio-inline"> <label class="radio-inline">
<input type="radio" {{if eq .Model.CommentStatus "registered_only"}}checked{{end}} name="comment_status" value="registered_only">仅允许注册者评论<span class="text"></span> <input type="radio" {{if eq .Model.CommentStatus "registered_only"}}checked{{end}} name="comment_status" value="registered_only">仅允许注册者评论<span class="text"></span>
</label> </label>
</div>
</div>
*/}}
{{if eq .Model.PrivatelyOwned 1}}
<div class="form-group">
<label>访问令牌</label>
<div class="row">
<div class="col-sm-10">
<input type="text" name="token" id="token" class="form-control" placeholder="访问令牌" readonly value="{{.Model.PrivateToken}}">
</div>
<div class="col-sm-2">
<button type="button" class="btn btn-success btn-sm" id="createToken" data-loading-text="生成" data-action="create">生成</button>
<button type="button" class="btn btn-danger btn-sm" id="deleteToken" data-loading-text="删除" data-action="delete">删除</button>
</div>
</div>
</div>
{{end}}
<div class="form-group">
<button type="submit" id="btnSaveBookInfo" class="btn btn-success" data-loading-text="保存中...">保存修改</button>
<span id="form-error-message" class="error-message"></span>
</div>
</form>
</div> </div>
<div class="form-right">
<label>
<a href="javascript:;" data-toggle="modal" data-target="#upload-logo-panel">
<img src="{{.Model.Cover}}" onerror="this.src='/static/images/book.png'" alt="封面" style="max-width: 120px;border: 1px solid #999" id="headimgurl">
</a>
</label>
</div>
<div class="clearfix"></div>
</div> </div>
*/}}
{{if eq .Model.PrivatelyOwned 1}}
<div class="form-group">
<label>访问令牌</label>
<div class="row">
<div class="col-sm-10">
<input type="text" name="token" id="token" class="form-control" placeholder="访问令牌" readonly value="{{.Model.PrivateToken}}">
</div>
<div class="col-sm-2">
<button type="button" class="btn btn-success btn-sm" id="createToken" data-loading-text="生成" data-action="create">生成</button>
<button type="button" class="btn btn-danger btn-sm" id="deleteToken" data-loading-text="删除" data-action="delete">删除</button>
</div>
</div>
</div>
{{end}}
<div class="form-group">
<button type="submit" id="btnSaveBookInfo" class="btn btn-success" data-loading-text="保存中...">保存修改</button>
<span id="form-error-message" class="error-message"></span>
</div>
</form>
</div> </div>
<div class="form-right">
<label>
<a href="javascript:;" data-toggle="modal" data-target="#upload-logo-panel">
<img src="{{.Model.Cover}}" onerror="this.src='/static/images/book.png'" alt="封面" style="max-width: 120px;border: 1px solid #999" id="headimgurl">
</a>
</label>
</div>
<div class="clearfix"></div>
</div> </div>
</div> </div>
{{template "widgets/footer.tpl" .}} </div>
</div>
{{template "widgets/footer.tpl" .}}
</div> </div>
<!-- Modal --> <!-- Modal -->
<div class="modal fade" id="changePrivatelyOwnedModal" tabindex="-1" role="dialog" aria-labelledby="changePrivatelyOwnedModalLabel"> <div class="modal fade" id="changePrivatelyOwnedModal" tabindex="-1" role="dialog" aria-labelledby="changePrivatelyOwnedModalLabel">
@ -143,34 +143,34 @@
<form method="post" action="{{urlfor "BookController.PrivatelyOwned" }}" id="changePrivatelyOwnedForm"> <form method="post" action="{{urlfor "BookController.PrivatelyOwned" }}" id="changePrivatelyOwnedForm">
<input type="hidden" name="identify" value="{{.Model.Identify}}"> <input type="hidden" name="identify" value="{{.Model.Identify}}">
<input type="hidden" name="status" value="{{if eq .Model.PrivatelyOwned 0}}close{{else}}open{{end}}"> <input type="hidden" name="status" value="{{if eq .Model.PrivatelyOwned 0}}close{{else}}open{{end}}">
<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">&times;</span></button> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title"> <h4 class="modal-title">
{{if eq .Model.PrivatelyOwned 0}} {{if eq .Model.PrivatelyOwned 0}}
转为私有 转为私有
{{else}}
转为共有
{{end}}
</h4>
</div>
<div class="modal-body">
{{if eq .Model.PrivatelyOwned 0}}
<span style="font-size: 14px;font-weight: 400;">确定将项目转为私有吗?</span>
<p></p>
<p class="text error-message">转为私有后需要通过阅读令牌才能访问该项目。</p>
{{else}} {{else}}
转为共有 <span style="font-size: 14px;font-weight: 400;"> 确定将项目转为公有吗?</span>
<p></p>
<p class="text error-message">转为公有后所有人都可以访问该项目。</p>
{{end}} {{end}}
</h4> </div>
<div class="modal-footer">
<span class="error-message" id="form-error-message1"></span>
<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
<button type="submit" class="btn btn-primary" data-loading-text="变更中..." id="btnChangePrivatelyOwned">确定</button>
</div>
</div> </div>
<div class="modal-body">
{{if eq .Model.PrivatelyOwned 0}}
<span style="font-size: 14px;font-weight: 400;">确定将项目转为私有吗?</span>
<p></p>
<p class="text error-message">转为私有后需要通过阅读令牌才能访问该项目。</p>
{{else}}
<span style="font-size: 14px;font-weight: 400;"> 确定将项目转为公有吗?</span>
<p></p>
<p class="text error-message">转为公有后所有人都可以访问该项目。</p>
{{end}}
</div>
<div class="modal-footer">
<span class="error-message" id="form-error-message1"></span>
<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
<button type="submit" class="btn btn-primary">确定</button>
</div>
</div>
</form> </form>
</div> </div>
</div> </div>
@ -216,22 +216,22 @@
<div class="modal-dialog" role="document"> <div class="modal-dialog" role="document">
<form method="post" id="deleteBookForm" action="{{urlfor "BookController.Delete"}}"> <form method="post" id="deleteBookForm" action="{{urlfor "BookController.Delete"}}">
<input type="hidden" name="identify" value="{{.Model.Identify}}"> <input type="hidden" name="identify" value="{{.Model.Identify}}">
<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">&times;</span></button> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title">删除项目</h4> <h4 class="modal-title">删除项目</h4>
</div>
<div class="modal-body">
<span style="font-size: 14px;font-weight: 400;">确定删除项目吗?</span>
<p></p>
<p class="text error-message">删除项目后将无法找回。</p>
</div>
<div class="modal-footer">
<span id="form-error-message2" class="error-message"></span>
<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
<button type="submit" id="btnDeleteBook" class="btn btn-primary" data-loading-text="删除中...">确定删除</button>
</div>
</div> </div>
<div class="modal-body">
<span style="font-size: 14px;font-weight: 400;">确定删除项目吗?</span>
<p></p>
<p class="text error-message">删除项目后将无法找回。</p>
</div>
<div class="modal-footer">
<span id="form-error-message2" class="error-message"></span>
<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
<button type="submit" id="btnDeleteBook" class="btn btn-primary">确定删除</button>
</div>
</div>
</form> </form>
</div> </div>
</div> </div>
@ -240,25 +240,26 @@
<div class="modal-dialog" role="document"> <div class="modal-dialog" role="document">
<form action="{{urlfor "BookController.Transfer"}}" method="post" id="transferBookForm"> <form action="{{urlfor "BookController.Transfer"}}" method="post" id="transferBookForm">
<input type="hidden" name="identify" value="{{.Model.Identify}}"> <input type="hidden" name="identify" value="{{.Model.Identify}}">
<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">&times;</span></button> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="myModalLabel">项目转让</h4> <h4 class="modal-title" id="myModalLabel">项目转让</h4>
</div> </div>
<div class="modal-body"> <div class="modal-body">
<div class="form-group"> <div class="form-group">
<label class="col-sm-2 control-label">接收账号</label> <label class="col-sm-2 control-label">接收账号</label>
<div class="col-sm-10"> <div class="col-sm-10">
<input type="text" name="account" class="form-control" placeholder="接收者账号" id="receiveAccount" maxlength="50"> <input type="text" name="account" class="form-control" placeholder="接收者账号" id="receiveAccount" maxlength="50">
</div> </div>
</div>
<div class="clearfix"></div>
</div>
<div class="modal-footer">
<span id="form-error-message3" class="error-message"></span>
<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
<button type="submit" id="btnTransferBook" class="btn btn-primary">确定转让</button>
</div> </div>
<div class="clearfix"></div>
</div> </div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
<button type="submit" id="btnTransferBook" class="btn btn-primary">确定转让</button>
</div>
</div>
</form> </form>
</div> </div>
</div> </div>
@ -277,93 +278,108 @@
window.modalHtml = $("#upload-logo-panel").find(".modal-body").html(); window.modalHtml = $("#upload-logo-panel").find(".modal-body").html();
}); });
$("#changePrivatelyOwnedForm").ajaxForm({ $("#changePrivatelyOwnedForm").ajaxForm({
beforeSubmit :function () {
$("#btnChangePrivatelyOwned").button("loading");
},
success :function (res) { success :function (res) {
if(res.errcode === 0){ if(res.errcode === 0){
window.location = window.location.href; window.location = window.location.href;
return;
}else{ }else{
console.log(res.message)
showError(res.message,"#form-error-message1"); showError(res.message,"#form-error-message1");
} }
$("#btnChangePrivatelyOwned").button("reset");
},
error :function () {
showError("服务器异常","#form-error-message1");
$("#btnChangePrivatelyOwned").button("reset");
} }
}); });
$("#createToken,#deleteToken").on("click",function () {
var btn = $(this).button("loading"); $("#createToken,#deleteToken").on("click",function () {
var action = $(this).attr("data-action"); var btn = $(this).button("loading");
$.ajax({ var action = $(this).attr("data-action");
url : "{{urlfor "BookController.CreateToken"}}", $.ajax({
type :"post", url : "{{urlfor "BookController.CreateToken"}}",
data : { "identify" : {{.Model.Identify}} , "action" : action }, type :"post",
dataType : "json", data : { "identify" : {{.Model.Identify}} , "action" : action },
success : function (res) { dataType : "json",
if(res.errcode === 0){ success : function (res) {
$("#token").val(res.data); if(res.errcode === 0){
}else{ $("#token").val(res.data);
alert(res.message); }else{
} alert(res.message);
btn.button("reset"); }
}, btn.button("reset");
error : function () { },
btn.button("reset"); error : function () {
alert("服务器错误"); btn.button("reset");
} alert("服务器错误");
}) ; }
}); }) ;
$("#token").on("focus",function () { });
$(this).select(); $("#token").on("focus",function () {
}); $(this).select();
$("#bookEditForm").ajaxForm({ });
beforeSubmit : function () { $("#bookEditForm").ajaxForm({
var bookName = $.trim($("#bookName").val()); beforeSubmit : function () {
if (bookName === "") { var bookName = $.trim($("#bookName").val());
return showError("项目名称不能为空"); if (bookName === "") {
} return showError("项目名称不能为空");
}
$("#btnSaveBookInfo").button("loading"); $("#btnSaveBookInfo").button("loading");
}, },
success : function (res) { success : function (res) {
if(res.errcode === 0){ if(res.errcode === 0){
showSuccess("保存成功") showSuccess("保存成功")
}else{ }else{
showError("保存失败") showError("保存失败")
} }
$("#btnSaveBookInfo").button("reset"); $("#btnSaveBookInfo").button("reset");
}, },
error : function () { error : function () {
showError("服务错误"); showError("服务错误");
$("#btnSaveBookInfo").button("reset"); $("#btnSaveBookInfo").button("reset");
} }
}); });
$("#deleteBookForm").ajaxForm({ $("#deleteBookForm").ajaxForm({
success : function (res) { beforeSubmit : function () {
if(res.errcode === 0){ $("#btnDeleteBook").button("loading");
window.location = "{{urlfor "BookController.Index"}}"; },
}else{ success : function (res) {
console.log(res.message) if(res.errcode === 0){
showError(res.message,"#form-error-message2"); window.location = "{{urlfor "BookController.Index"}}";
} }else{
} showError(res.message,"#form-error-message2");
}); }
$("#transferBookForm").ajaxForm({ $("#btnDeleteBook").button("reset");
beforeSubmit : function () { },
error : function () {
showError("服务器异常","#form-error-message2");
$("#btnDeleteBook").button("reset");
}
});
$("#transferBookForm").ajaxForm({
beforeSubmit : function () {
var account = $.trim($("#receiveAccount").val()); var account = $.trim($("#receiveAccount").val());
if (account === ""){ if (account === ""){
return showError("接受者账号不能为空") return showError("接受者账号不能为空","#form-error-message3")
} }
$("#btnTransferBook").button("loading"); $("#btnTransferBook").button("loading");
}, },
success : function (res) { success : function (res) {
if(res.errcode === 0){ if(res.errcode === 0){
window.location = window.location.href; window.location = window.location.href;
}else{ }else{
showError(res.message); showError(res.message,"#form-error-message3");
} }
$("#btnTransferBook").button("reset"); $("#btnTransferBook").button("reset");
}, },
error : function () { error : function () {
$("#btnTransferBook").button("reset"); $("#btnTransferBook").button("reset");
} }
}); });
try { try {
var uploader = WebUploader.create({ var uploader = WebUploader.create({