use sweetalert2 to show message in some cases

This commit is contained in:
printempw 2016-08-14 13:38:46 +08:00
parent 08c54acae7
commit 01e4289f77
9 changed files with 479 additions and 249 deletions

View File

@ -2,7 +2,7 @@
* @Author: printempw
* @Date: 2016-07-17 10:54:22
* @Last Modified by: printempw
* @Last Modified time: 2016-07-29 11:10:21
* @Last Modified time: 2016-08-14 13:22:35
*/
'use strict';
@ -63,12 +63,20 @@ $('#login-button').click(function() {
docCookies.setItem('email', data.email, time, '/');
docCookies.setItem('token', json.token, time, '/');
showMsg(json.msg, 'success');
swal({
type: 'success',
html: json.msg
});
window.setTimeout('window.location = "../user"', 1000);
} else {
if (json.login_fails > 3) {
swal({
type: 'error',
html: '你尝试的次数太多啦,请输入验证码'
});
$('#captcha-form').show();
toastr.warning('你尝试的次数太多啦,请输入验证码');
freshCaptcha();
}
@ -138,7 +146,10 @@ $('#register-button').click(function() {
docCookies.setItem('email', email, null, '/');
docCookies.setItem('token', json.token, null, '/');
showMsg(json.msg, 'success');
swal({
type: 'success',
html: json.msg
});
window.setTimeout('window.location = "../user"', 1000);
} else {
showMsg(json.msg, 'warning');
@ -225,8 +236,12 @@ $('#reset-button').click(function() {
},
success: function(json) {
if (json.errno == 0) {
showMsg('重置成功,请登录~', 'success');
window.setTimeout('window.location = "./login"', 1000);
swal({
type: '重置成功,请重新登录~',
html: json.msg
}).then(function() {
window.location = "./login";
});
} else {
showMsg(json.msg, 'warning');
$('#reset-button').html('重置').prop('disabled', '');
@ -239,5 +254,4 @@ $('#reset-button').click(function() {
});
}
return false;
});

View File

@ -2,11 +2,18 @@
* @Author: printempw
* @Date: 2016-07-19 10:46:38
* @Last Modified by: printempw
* @Last Modified time: 2016-08-13 23:23:14
* @Last Modified time: 2016-08-14 13:20:38
*/
'use strict';
$(document).ready(function() {
swal.setDefaults({
confirmButtonText: '确定',
cancelButtonText: '取消'
});
});
$('#page-select').on('change', function() {
// if has query strings
if (getQueryString('filter') != "" || getQueryString('sort') != "") {
@ -26,29 +33,33 @@ $('#private').on('ifToggled', function() {
function addToCloset(tid) {
$.getJSON('../skinlib/info/'+tid, function(json) {
var dom = '<div class="form-group">'+
'<label for="new-name">给你的皮肤起个名字吧~</label>'+
'<input id="new-name" class="form-control" type="text" value="'+json.name+'" />'+
'</div><br />';
showModal(dom, '收藏新皮肤', 'default', 'ajaxAddToCloset('+tid+')');
return;
swal({
title: '给你的皮肤起个名字吧~',
inputValue: json.name,
input: 'text',
showCancelButton: true,
inputValidator: function(value) {
return new Promise(function(resolve, reject) {
if (value) {
resolve();
} else {
reject('你还没有填写名称哦');
}
});
}
}).then(function(result) {
ajaxAddToCloset(tid, result);
});
});
}
function ajaxAddToCloset(tid) {
function ajaxAddToCloset(tid, name) {
// remove interference of modal which is hide
$('.modal').each(function() {
if ($(this).css('display') == "none")
$(this).remove();
});
var name = $('#new-name').val();
if (name == "") {
toastr.info('你还没有填写名称哦');
$('#name').focus(); return;
}
$.ajax({
type: "POST",
url: "../user/closet/add",
@ -56,7 +67,11 @@ function ajaxAddToCloset(tid) {
data: { 'tid': tid, 'name': name },
success: function(json) {
if (json.errno == 0) {
toastr.success(json.msg);
swal({
type: 'success',
html: json.msg
});
$('.modal').modal('hide');
$('a[tid='+tid+']').attr('href', 'javascript:removeFromCloset('+tid+');').attr('title', '从衣柜中移除').addClass('liked');
$('#'+tid).attr('href', 'javascript:removeFromCloset('+tid+');').html('从衣柜中移除');
@ -70,6 +85,13 @@ function ajaxAddToCloset(tid) {
}
function removeFromCloset(tid) {
swal({
text: '确定要从衣柜中移除此材质吗?',
type: 'warning',
showCancelButton: true,
cancelButtonColor: '#3085d6',
confirmButtonColor: '#d33'
}).then(function() {
$.ajax({
type: "POST",
url: "../user/closet/remove",
@ -77,7 +99,11 @@ function removeFromCloset(tid) {
data: { 'tid' : tid },
success: function(json) {
if (json.errno == 0) {
toastr.success(json.msg);
swal({
type: 'success',
html: json.msg
});
$('a[tid='+tid+']').attr('href', 'javascript:addToCloset('+tid+');').attr('title', '添加至衣柜').removeClass('liked');
$('#'+tid).attr('href', 'javascript:addToCloset('+tid+');').html('添加至衣柜');
$('#likes').html(parseInt($('#likes').html()) - 1);
@ -87,6 +113,8 @@ function removeFromCloset(tid) {
},
error: showAjaxError
});
});
}
function init3dCanvas() {
@ -183,17 +211,25 @@ function upload() {
},
success: function(json) {
if (json.errno == 0) {
toastr.success(json.msg);
swal({
type: 'success',
html: json.msg
}).then(function() {
toastr.info('正在跳转...');
window.setTimeout('window.location = "./show?tid='+json.tid+'"', 2500);
window.setTimeout('window.location = "./show?tid='+json.tid+'"', 1000);
});
} else {
swal({
type: 'warning',
html: json.msg
}).then(function() {
$('#upload-button').html('确认上传').prop('disabled', '');
toastr.warning(json.msg);
});
}
},
error: function(json) {
$('#upload-button').html('确认上传').prop('disabled', '');
showModal(json.responseText.replace(/\n/g, '<br />'), 'Fatal Error请联系作者', 'danger');
showAjaxError(json);
}
});
}
@ -201,10 +237,20 @@ function upload() {
}
function changeTextureName(tid) {
var new_name = prompt("请输入新的材质名称:");
if (!new_name) return;
swal({
text: '请输入新的材质名称:',
input: 'text',
showCancelButton: true,
inputValidator: function(value) {
return new Promise(function(resolve, reject) {
if (value) {
resolve();
} else {
reject('你还没有填写名称哦');
}
});
}
}).then(function(new_name) {
$.ajax({
type: "POST",
url: "./rename",
@ -220,6 +266,7 @@ function changeTextureName(tid) {
},
error: showAjaxError
});
});
}
function changePrivacy(tid) {
@ -243,8 +290,11 @@ function changePrivacy(tid) {
}
function deleteTexture(tid) {
if (!window.confirm('真的要删除此材质吗?积分将会被返还')) return;
swal({
text: '真的要删除此材质吗?积分将会被返还',
type: 'warning',
showCancelButton: true
}).then(function() {
$.ajax({
type: "POST",
url: "./delete",
@ -252,12 +302,21 @@ function deleteTexture(tid) {
data: { 'tid': tid },
success: function(json) {
if (json.errno == 0) {
toastr.success(json.msg);
window.setTimeout('window.location = "./"', 1000);
swal({
type: 'success',
html: json.msg
}).then(function() {
toastr.info('正在跳转...');
window.setTimeout('window.location = "./', 1000);
});
} else {
toastr.warning(json.msg);
swal({
type: 'warning',
html: json.msg
});
}
},
error: showAjaxError
});
});
}

View File

@ -2,7 +2,7 @@
* @Author: printempw
* @Date: 2016-07-16 10:02:24
* @Last Modified by: printempw
* @Last Modified time: 2016-07-24 12:28:52
* @Last Modified time: 2016-08-14 13:03:37
*/
'use strict';
@ -146,26 +146,40 @@ $('body').on('click', '.item', function() {
});
function removeFromCloset(tid) {
if (!window.confirm('真的要从您的衣柜中移除此皮肤/披风吗?')) return;
swal({
text: '确定要从衣柜中移除此材质吗?',
type: 'warning',
showCancelButton: true
}).then(function() {
$.ajax({
type: "POST",
url: "./closet/remove",
dataType: "json",
data: { "tid": tid },
data: { 'tid' : tid },
success: function(json) {
if (json.errno == 0)
toastr.success(json.msg);
else
if (json.errno == 0) {
swal({
type: 'success',
html: json.msg
});
$('div[tid='+tid+']').remove();
} else {
toastr.warning(json.msg);
}
},
error: showAjaxError
});
});
}
function setAsAvatar(tid) {
if (!window.confirm('真的要将此材质设置为用户头像吗?(将会自动截取皮肤头部)')) return;
swal({
title: '确定要将此材质设置为用户头像吗?',
text: '将会自动截取皮肤头部',
type: 'question',
showCancelButton: true
}).then(function() {
$.ajax({
type: "POST",
url: "./profile/avatar",
@ -184,12 +198,17 @@ function setAsAvatar(tid) {
},
error: showAjaxError
});
});
}
$(document).ready(function() {
$('input[type=radio]').iCheck({
radioClass: 'iradio_square-blue'
});
swal.setDefaults({
confirmButtonText: '确定',
cancelButtonText: '取消'
});
});
function setTexture() {
@ -213,7 +232,10 @@ function setTexture() {
data: { 'pid' : pid, 'tid' : tid },
success: function(json) {
if (json.errno == 0) {
toastr.success(json.msg);
swal({
type: 'success',
html: json.msg
});
$('#modal-use-as').modal('hide');
} else {
toastr.warning(json.msg);
@ -245,10 +267,22 @@ $('body').on('change', '#preference', function() {
});
function changePlayerMame(pid, current_player_name) {
var new_player_name = prompt("请输入角色名(允许数字、字母以及下划线,是否支持中文角色名请参考本站设置):", current_player_name);
if (!new_player_name) return;
swal({
title: '请输入角色名:',
text: '允许数字、字母以及下划线,是否支持中文角色名请参考本站设置',
inputValue: current_player_name,
input: 'text',
showCancelButton: true,
inputValidator: function(value) {
return new Promise(function(resolve, reject) {
if (value) {
resolve();
} else {
reject('你还没有填写名称哦');
}
});
}
}).then(function(new_player_name) {
$.ajax({
type: "POST",
url: "./player/rename",
@ -256,19 +290,29 @@ function changePlayerMame(pid, current_player_name) {
data: { 'pid' : pid, 'new_player_name' : new_player_name },
success: function(json) {
if (json.errno == 0) {
toastr.success(json.msg);
swal({
type: 'success',
html: json.msg
});
$('td:contains("'+pid+'")').next().html(new_player_name);
} else {
toastr.warning(json.msg);
swal({
type: 'error',
html: json.msg
});
}
},
error: showAjaxError
});
});
}
function clearTexture(pid) {
if (!window.confirm('确定要重置该用户的皮肤/披风吗?')) return;
swal({
text: "确定要重置该用户的皮肤/披风吗?",
type: 'warning',
showCancelButton: true
}).then(function() {
$.ajax({
type: "POST",
url: "./player/texture/clear",
@ -276,18 +320,31 @@ function clearTexture(pid) {
data: { 'pid' : pid },
success: function(json) {
if (json.errno == 0) {
toastr.success(json.msg);
swal({
type: 'success',
html: json.msg
});
} else {
toastr.warning(json.msg);
swal({
type: 'error',
html: json.msg
});
}
},
error: showAjaxError
});
});
}
function deletePlayer(pid) {
if (!window.confirm('真的要删除该玩家吗?这将是永久性的删除')) return;
swal({
title: "真的要删除该玩家吗?",
text: "这将是永久性的删除",
type: 'warning',
showCancelButton: true,
cancelButtonColor: '#3085d6',
confirmButtonColor: '#d33'
}).then(function() {
$.ajax({
type: "POST",
url: "./player/delete",
@ -295,14 +352,20 @@ function deletePlayer(pid) {
data: { 'pid' : pid },
success: function(json) {
if (json.errno == 0) {
toastr.success(json.msg);
$('#'+pid).remove();
swal({
type: 'success',
html: json.msg
});
} else {
toastr.warning(json.msg);
swal({
type: 'error',
html: json.msg
});
}
},
error: showAjaxError
});
});
}
function addNewPlayer() {
@ -313,9 +376,13 @@ function addNewPlayer() {
data: { 'player_name' : $('#player_name').val() },
success: function(json) {
if (json.errno == 0) {
toastr.success(json.msg);
swal({
type: 'success',
html: json.msg
}).then(function() {
$('#modal-add-player').modal('hide');
location.reload();
});
} else {
toastr.warning(json.msg);
}
@ -328,12 +395,18 @@ function changeNickName() {
var new_nickname = $('#new-nickname').val();
if (!new_nickname) {
toastr.warning('你还没有填写新昵称啊');
swal({
type: 'error',
html: '你还没有填写新昵称啊'
});
return;
}
if (!window.confirm('确定要将昵称设置为 '+new_nickname+' 吗?')) return;
swal({
text: '确定要将昵称设置为 ' + new_nickname + ' 吗?',
type: 'question',
showCancelButton: true
}).then(function() {
$.ajax({
type: "POST",
url: "./profile?action=nickname",
@ -341,16 +414,25 @@ function changeNickName() {
data: { 'new_nickname' : new_nickname },
success: function(json) {
if (json.errno == 0) {
toastr.success(json.msg);
swal({
type: 'success',
html: json.msg
});
$('.nickname').each(function() {
$(this).html(new_nickname);
});
} else {
toastr.warning(json.msg);
swal({
type: 'warning',
html: json.msg
});
}
},
error: showAjaxError
});
});
}
function changePassword() {
@ -378,17 +460,22 @@ function changePassword() {
data: { 'current_password': password, 'new_password': new_passwd},
success: function(json) {
if (json.errno == 0) {
toastr.success(json.msg);
swal({
type: 'success',
html: json.msg
}).then(function() {
logout(true, function() {
window.setTimeout('window.location = "../auth/login"', 1000);
window.location = "../auth/login";
});
});
} else {
toastr.warning(json.msg);
swal({
type: 'warning',
html: json.msg
});
}
},
error: function(json) {
showModal(json.responseText.replace(/\n/g, '<br />'), 'Fatal Error请联系作者', 'danger');
}
error: showAjaxError
});
}
return false;
@ -407,15 +494,25 @@ function changeEmail() {
var new_email = $('#new-email').val();
if (!new_email) {
toastr.warning('你还没有填写新邮箱啊'); return;
swal({
type: 'error',
html: '你还没有填写新邮箱啊'
});
return;
}
// check valid email address
if (!/\S+@\S+\.\S+/.test(new_email)) {
toastr.warning('邮箱格式不正确!'); return;
swal({
type: 'warning',
html: '邮箱格式不正确'
}); return;
}
if (!window.confirm('确定要将用户邮箱更改为 '+new_email+' 吗?')) return;
swal({
text: '确定要将用户邮箱更改为 '+new_email+' 吗?',
type: 'question',
showCancelButton: true
}).then(function() {
$.ajax({
type: "POST",
url: "./profile?action=email",
@ -423,24 +520,34 @@ function changeEmail() {
data: { 'new_email' : new_email, 'password' : $('#current-password').val() },
success: function(json) {
if (json.errno == 0) {
toastr.success(json.msg);
swal({
type: 'success',
html: json.msg
}).then(function() {
logout(true, function() {
window.setTimeout('window.location = "../auth/login"', 1000);
window.location = "../auth/login";
});
});
} else {
toastr.warning(json.msg);
swal({
type: 'warning',
html: json.msg
});
}
},
error: showAjaxError
});
});
}
function deleteAccount() {
var password = $('.modal-body>#password').val();
if (!password) {
toastr.warning('请先输入当前用户密码'); return;
swal({
type: 'warning',
html: '请先输入当前用户密码'
}); return;
}
$.ajax({
@ -450,12 +557,19 @@ function deleteAccount() {
data: { 'password' : password },
success: function(json) {
if (json.errno == 0) {
toastr.success(json.msg);
swal({
type: 'success',
html: json.msg
}).then(function() {
logout(true, function() {
window.setTimeout('window.location = "../auth/login"', 1000);
window.location = "../auth/login";
});
});
} else {
toastr.warning(json.msg);
swal({
type: 'warning',
html: json.msg
});
}
},
error: showAjaxError
@ -495,10 +609,14 @@ function sign() {
dataType: "json",
success: function(json) {
if (json.errno == 0) {
toastr.success(json.msg);
swal({
type: 'success',
html: json.msg
}).then(function() {
$('#score').html(json.score);
var dom = '<i class="fa fa-calendar-check-o"></i> &nbsp;'+json.remaining_time+' 小时后可签到';
$('#sign-button').attr('disabled', 'disabled').html(dom);
});
} else {
toastr.warning(json.msg);
}

View File

@ -2,7 +2,7 @@
* @Author: printempw
* @Date: 2016-07-16 09:02:32
* @Last Modified by: printempw
* @Last Modified time: 2016-08-06 18:52:23
* @Last Modified time: 2016-08-14 13:27:11
*/
function showModal(msg, title, type, callback) {
@ -42,9 +42,13 @@ function getQueryString(key) {
function logout(with_out_confirm, callback) {
if (!with_out_confirm) {
if (!window.confirm('确定要登出吗?')) return;
}
swal({
text: '确定要登出吗?',
type: 'warning',
showCancelButton: true,
confirmButtonText: '确定',
cancelButtonText: '取消'
}).then(function() {
$.ajax({
type: "POST",
url: "../auth/logout",
@ -52,15 +56,27 @@ function logout(with_out_confirm, callback) {
success: function(json) {
docCookies.removeItem("email", "/");
docCookies.removeItem("token", "/");
// silent
if (!with_out_confirm) {
toastr.success(json.msg);
window.setTimeout('window.location = "../"', 1000);
} else {
if (callback) callback(json);
}
swal({
type: 'success',
html: json.msg
});
}
});
});
} else {
$.ajax({
type: "POST",
url: "../auth/logout",
dataType: "json",
success: function(json) {
docCookies.removeItem("email", "/");
docCookies.removeItem("token", "/");
if (callback) callback(json);
}
});
}
}
/**
@ -106,4 +122,3 @@ var docCookies = {
return aKeys;
}
};

View File

@ -2,7 +2,7 @@
* @Author: printempw
* @Date: 2016-07-10 17:17:07
* @Last Modified by: printempw
* @Last Modified time: 2016-08-14 09:00:16
* @Last Modified time: 2016-08-14 12:37:06
*/
@import "style.scss";

View File

@ -2,9 +2,11 @@
* @Author: printempw
* @Date: 2016-06-04 20:55:09
* @Last Modified by: printempw
* @Last Modified time: 2016-08-14 09:02:03
* @Last Modified time: 2016-08-14 12:58:39
*/
$font_stack: Ubuntu, 'Segoe UI', 'Microsoft Yahei', 'Microsoft Jhenghei', sans-serif;
@font-face {
font-family: 'Ubuntu';
src: url('../../fonts/ubuntu.woff2') format('woff2');
@ -21,7 +23,16 @@
}
body, h1, h2, h3, h4, h5, h6, .logo {
font-family: Ubuntu, 'Segoe UI', 'Microsoft Yahei', 'Microsoft Jhenghei', sans-serif !important;
font-family: $font_stack !important;
}
.swal2-modal, .swal2-content {
font-family: $font_stack;
font-weight: 400;
}
.swal2-modal h2 {
font-size: 25px;
}
/* fucking webkit autofill */

View File

@ -23,6 +23,7 @@
"toastr": "^2.1.2",
"font-awesome": "Font-Awesome#^4.6.3",
"bootstrap-fileinput": "^4.3.3",
"bootstrap": "^3.3.6"
"bootstrap": "^3.3.6",
"sweetalert2": "^4.1.6"
}
}

View File

@ -2,7 +2,7 @@
* @Author: prpr
* @Date: 2016-07-21 13:38:26
* @Last Modified by: printempw
* @Last Modified time: 2016-08-06 22:14:40
* @Last Modified time: 2016-08-14 13:33:51
*/
var gulp = require('gulp'),
@ -78,6 +78,15 @@ gulp.task('copy', function(cb) {
gulp.src('./assets/bower_components/toastr/toastr.min.js')
.pipe(gulp.dest('./assets/libs/js/'));
gulp.src('./assets/bower_components/sweetalert2/dist/sweetalert2.min.css')
.pipe(gulp.dest('./assets/libs/css/'));
gulp.src('./assets/bower_components/sweetalert2/dist/sweetalert2.min.js')
.pipe(gulp.dest('./assets/libs/js/'));
gulp.src('./assets/bower_components/es6-promise/es6-promise.min.js')
.pipe(gulp.dest('./assets/libs/js/'));
});
gulp.task('lint', function() {
@ -93,7 +102,8 @@ gulp.task('lib-css', function() {
'./assets/libs/css/fileinput.min.css',
'./assets/libs/css/font-awesome.min.css',
'./assets/libs/css/blue.css',
'./assets/libs/css/toastr.min.css'
'./assets/libs/css/toastr.min.css',
'./assets/libs/css/sweetalert2.min.css'
])
.pipe(concat('app.min.css'))
.pipe(cleanCss())
@ -108,6 +118,8 @@ gulp.task('lib-scripts', function() {
'./assets/libs/js/icheck.min.js',
'./assets/libs/js/fileinput.min.js',
'./assets/libs/js/toastr.min.js',
'./assets/libs/js/es6-promise.min.js',
'./assets/libs/js/sweetalert2.min.js',
'./assets/src/js/utils.js'
])
.pipe(concat('app.min.js'))
@ -144,14 +156,14 @@ gulp.task('scripts', function() {
gulp.task('minify', ['sass', 'scripts']);
gulp.task('clean', ['concat', 'minify'], function (cb) {
gulp.task('clean', function (cb) {
return del([
'./assets/libs/css/**',
'./assets/libs/js/**'
], cb);
});
gulp.task('build', ['concat', 'minify', 'clean']);
gulp.task('build', ['concat', 'minify']);
// release
gulp.task('zip', function() {

View File

@ -44,14 +44,14 @@
<p class="texture-name">
<span title="{{ $item->name }}">{{ $item->name }} <small>({{ $item->type }})</small></span>
</p>
<a href="../skinlib/show?tid={{ $item->tid }}" title="在皮肤库中查看" class="more" data-toggle="tooltip" data-placement="bottom"><i class="fa fa-share"></i></a>
<span title="更多" class="more" data-toggle="dropdown" aria-haspopup="true" id="share-button"><i class="fa fa-cog"></i></span>
<ul class="dropdown-menu" aria-labelledby="share-button">
<li><a href="javascript:removeFromCloset({{ $item->tid }});">从衣柜中移除</a></li>
<li><a href="javascript:setAsAvatar({{ $item->tid }});">设为头像</a></li>
</ul>
<span title="更多" class="more" data-toggle="dropdown" aria-haspopup="true" id="share-button"><i class="fa fa-cog"></i></span>
</div>
</div>
@empty