landers.base
Version:
landers.base
75 lines • 3.12 kB
JavaScript
; (function (window, $, Landers) {
Landers = Landers || {};
Landers.msgbox = function (){
var opts;
if (arguments.length == 1) {
args = arguments[0];
if ( Landers.utils.is_string(args)) opts = {type:10, content:args};
if ( Landers.utils.is_array(args) ) opts = {type:args[0], content:args[1]};
if ( Landers.utils.is_json(args) ) opts = {type:args.code || (args.success ? 0 : 10), content:args.message };
} else if (arguments.length == 2) {
var rspn = arguments[0];
opts = {
type : rspn.success ? 0 : 10,
content : rspn.message,
callback : arguments[1]
};
} else {
opts = Landers.helpers.parse_args(arguments, {
'number' : 'type',
'string': 'content',
'boolean': 'lock',
'json' : 'pack',
'function' : 'callback'
});
if (opts.data) {
opts.type = opts.data[0];
opts.content = opts.data[1];
}
};
if ( 'string' == typeof opts.type) {
opts.title = opts.type;
} else {
switch(opts.type) {
case 0:; case true:; case 200:
opts.title = '操作成功'; break;
case 1 : opts.title = '信息提示'; break;
case 10:; case 11:; case false: opts.title = '温馨提示'; break;
case 20 : opts.title = '出错啦'; break;
case 29 : opts.title = '意外错误'; break;
case 39 : opts.title = '非法错误'; break;
case 401 : opts.title = '未登录错误'; break;
case 82 : opts.title = '未登录或登录超时'; break;
case 83 : opts.title = '权限受限制'; break;
case 99 : opts.title = '严重错误'; break;
case 100: opts.title = '调试输出'; break;
};
}
if (Landers.utils.is_object(opts.content)) {
opts.content = Landers.utils.to.json.encode(opts.content);
};
var _ = function(){
Landers.messageBox.show({
id : opts.digid,
title : opts.title,
content : Landers.utils.str.replace(opts.content, '\n', '<br/>'),
fixed : true,
lock : opts.lock !== false,
width : 500,
onclose : function(){
if (opts.type == 82 && Landers.login && Landers.login.show) Landers.login.show();
},
onload : function(){
Landers.response.hide();
},
yes : function(){
if (opts.callback) return opts.callback(this);
}
});
};
setTimeout(function(){
if (Landers.messageBox) _();
else Landers.loader.jsm('landers.msgbox', _, true);
}, 200);
};
})(this, jQuery, Landers);