Skip to content

Commit

Permalink
🦄 调整base.js 先new tale 在进行调用
Browse files Browse the repository at this point in the history
  • Loading branch information
nonacosa committed Feb 26, 2017
1 parent b88c467 commit 0fccaa7
Show file tree
Hide file tree
Showing 7 changed files with 165 additions and 112 deletions.
212 changes: 121 additions & 91 deletions src/main/resources/static/admin/js/base.js
Original file line number Diff line number Diff line change
@@ -1,118 +1,148 @@
var _swal = {
alert_del: function (data) {
swal({
title: data.title || '警告信息',
text: data.text || "确定删除吗?",
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: '确定',
cancelButtonText: '取消'
}).then(function () {
$.post(data.url, data.parame, function (result) {
if (result && result.success) {
swal('提示信息', '删除成功', 'success');
setTimeout(function () {
window.location.reload();
}, 2000);
} else {
swal("提示消息", result.msg, 'error');
}
});
}).catch(swal.noop);
}
};

/**
* Tale全局函数对象
* @type {{}}
* Tale全局函数对象 var tale = new $.tale();
*/
var tale = {};
$.extend({
tale: function () {}
});

/**
* 弹出成功对话框
* tale alert删除 // todo: 减少耦合度,链式操作替代 2017-02-27
* @param options
*/
tale.alertOk = function (options) {
options = options || {};
options.title = options.title || '操作成功';
options.text = options.text;
options.showCancelButton = false;
options.showCloseButton = false;
options.type = 'success';
this.alertBox(options);
$.tale.prototype.alert_del = function (options) {
swal({
title: options.title || '警告信息',
text: options.text || "确定删除吗?",
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: '确定',
cancelButtonText: '取消'
}).then(function () {
$.post(options.url, options.parame, function (result) {
if (result && result.success) {
swal('提示信息', '删除成功', 'success');
setTimeout(function () {
window.location.reload();
}, 2000);
} else {
swal("提示消息", result.msg, 'error');
}
});
}).catch(swal.noop);
};

/**
* 弹出错误对话框
*
* @param options
*/
tale.alertError = function (options) {
options = options || {};
options.title = options.title || '错误信息';
options.text = options.text;
options.type = 'error';
this.alertBox(options);
$.tale.prototype.alert_ok = function (options){
swal(option.title || '提示信息', options.text, 'success');
};

/**
* 弹出确认对话框
* @param options
*/
tale.alertQA = function (options) {
options = options || {};
options.title = options.title || '确定要删除吗?';
options.text = options.text;
options.showCancelButton = true;
options.type = 'question';
this.alertBox(options);
$.tale.prototype.alert_error = function(options){
swal(option.title || '提示信息', options.text, 'error');
};

/**
* 弹出警告对话框
* @param options
*/
tale.alertWarn = function (options) {
options = options || {};
options.title = options.title || '警告信息';
options.text = options.text;
options.type = 'warning';
this.alertBox(options);
};
/**
* 公共对话框
* @param options
*/
tale.alertBox = function (options) {
swal({
title: options.title,
text: options.text,
type: options.type,
showCloseButton: options.showCloseButton,
showCancelButton: options.showCancelButton,
showLoaderOnConfirm: options.showLoaderOnConfirm || false,
confirmButtonColor: options.confirmButtonColor || '#3085d6',
cancelButtonColor: options.cancelButtonColor || '#d33',
confirmButtonText: options.confirmButtonText || '确定',
cancelButtonText: options.cancelButtonText || '取消'
}).then(function (e) {
options.then(e);
}).catch(swal.noop);
$.tale.prototype.post = function(option, callback){
$.post(option.url, option.params, function (result) {
if (result && result.success) {
callback(true);

} else {
swal("提示消息", result.msg, 'error');
}
//return this;
});
};

/**
* 显示loading动画
* 显示动画
*/
tale.showLoading = function () {
if($('#tale-loading').length == 0){
$.tale.prototype.showLoading = function(){
if ($('#tale-loading').length == 0) {
$('body').append('<div id="tale-loading"></div>');
}
$('#tale-loading').show();
};

/**
* 隐藏loading动画
* 隐藏动画
*/
tale.hideLoading = function () {
$.tale.prototype.hideLoading = function(){
$('#tale-loading').hide();
};
};

//
///**
// * Tale全局函数对象
// * @type {{}}
// */
//var tale = {};
//

//
///**
// * 弹出确认对话框
// * @param options
// */
//tale.alertQA = function (options) {
// options = options || {};
// options.title = options.title || '确定要删除吗?';
// options.text = options.text;
// options.showCancelButton = true;
// options.type = 'question';
// this.alertBox(options);
//};

///**
// * 弹出警告对话框
// * @param options
// */
//tale.alertWarn = function (options) {
// options = options || {};
// options.title = options.title || '警告信息';
// options.text = options.text;
// options.type = 'warning';
// this.alertBox(options);
//};
///**
// * 公共对话框
// * @param options
// */
//tale.alertBox = function (options) {
// swal({
// title: options.title,
// text: options.text,
// type: options.type,
// showCloseButton: options.showCloseButton,
// showCancelButton: options.showCancelButton,
// showLoaderOnConfirm: options.showLoaderOnConfirm || false,
// confirmButtonColor: options.confirmButtonColor || '#3085d6',
// cancelButtonColor: options.cancelButtonColor || '#d33',
// confirmButtonText: options.confirmButtonText || '确定',
// cancelButtonText: options.cancelButtonText || '取消'
// }).then(function (e) {
// options.then(e);
// }).catch(swal.noop);
//};

///**
// * 显示loading动画
// */
//tale.showLoading = function () {
// if ($('#tale-loading').length == 0) {
// $('body').append('<div id="tale-loading"></div>');
// }
// $('#tale-loading').show();
//};
///**
// * 隐藏loading动画
// */
//tale.hideLoading = function () {
// $('#tale-loading').hide();
//};


3 changes: 2 additions & 1 deletion src/main/resources/templates/admin/article_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ <h4 class="page-title">文章管理</h4>

<script type="text/javascript">
function delPost(cid) {
_swal.alert_del({
var tale = new $.tale();
tale.alert_del({
text: "确定删除这篇文章吗?",
url: "/admin/article/delete",
parame: {cid: cid}
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/templates/admin/attach.html
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ <h4 class="page-title">文件管理</h4>
});

function delAttach(id) {
_swal.alert_del({
var tale = new $.tale();
tale.alert_del({
text: "确定删除该附件吗?",
url: "/admin/attach/delete",
parame: {id: id}
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/templates/admin/category.html
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ <h1 class="panel-title">标签列表</h1>

$('.del-category').click(function () {
var mid = $(this).attr('mid');
_swal.alert_del({
var tale = new $.tale();
tale.alert_del({
text: "确定删除该项吗?",
url: "/admin/category/delete",
parame: {mid: mid}
Expand Down
8 changes: 7 additions & 1 deletion src/main/resources/templates/admin/comment_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ <h4 class="page-title">评论管理</h4>
}

function delComment(coid) {
_swal.alert_del({
var tale = new $.tale();
tale.alert_del({
text: "确定删除该评论吗?",
url: "/admin/comments/delete",
parame: {coid: coid}
Expand All @@ -130,6 +131,11 @@ <h4 class="page-title">评论管理</h4>
}
}
});
var tale = $.tale();
tale.ajax({
url:'/admin/comments/status',
params:params
})
}
</script>

Expand Down
39 changes: 26 additions & 13 deletions src/main/resources/templates/admin/links.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,30 @@ <h4 class="page-title">友链管理</h4>
$('#linkForm').validate({
submitHandler: function (form) {
var params = $("#linkForm").serialize();
$.post('/admin/links/save', params, function (result) {
if (result && result.success) {
$('#linkForm input').val('');
$('#linkForm #sort').val('0');
swal('提示信息', '友链保存成功', 'success');
setTimeout(function () {
window.location.reload();
}, 2000);
} else {
swal("提示消息", result.msg, 'error');
}
});
// $.post('/admin/links/save', params, function (result) {
// if (result && result.success) {
// $('#linkForm input').val('');
// $('#linkForm #sort').val('0');
// swal('提示信息', '友链保存成功', 'success');
// setTimeout(function () {
// window.location.reload();
// }, 2000);
// } else {
// swal("提示消息", result.msg, 'error');
// }
// });
var tale = new $.tale();
tale.post({
url: '/admin/links/save',
params: params
}, function (boolean) {
$('#linkForm input').val('');
$('#linkForm #sort').val('0');
swal('提示信息', '友链保存成功', 'success');
setTimeout(function () {
window.location.reload();
}, 2000);
})
}
});

Expand All @@ -117,7 +129,8 @@ <h4 class="page-title">友链管理</h4>
}

function delLink(mid) {
_swal.alert_del({
var tale = new $.tale();
tale.alert_del({
text: "确定删除该链接吗?",
url: "/admin/links/delete",
parame: {mid: mid}
Expand Down
9 changes: 5 additions & 4 deletions src/main/resources/templates/admin/page_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ <h4 class="page-title">文章管理</h4>

<script type="text/javascript">
function delPost(cid) {
_swal.alert_del({
text:"确定删除这个页面吗?",
url:"/admin/page/delete",
parame:{cid: cid}
var tale = new $.tale();
tale.alert_del({
text: "确定删除这个页面吗?",
url: "/admin/page/delete",
parame: {cid: cid}
})
}

Expand Down

0 comments on commit 0fccaa7

Please sign in to comment.