Skip to content

Commit 876d57c

Browse files
committed
修复了ajax树在空数据无法加载时的js的bug,并加入了浏览器检测
1 parent 72bb62f commit 876d57c

22 files changed

+106
-33
lines changed

.classpath

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/slf4j-api-1.5.8.jar"/>
9090
<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/slf4j-log4j12-1.5.8.jar"/>
9191
<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/ant.jar"/>
92-
<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/DispatchSystemDaemon.jar"/>
9392
<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/libthrift-0.8.0.jar"/>
93+
<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/DispatchSystemDaemon.jar"/>
9494
<classpathentry kind="output" path="WebRoot/WEB-INF/classes"/>
9595
</classpath>
-8.68 KB
Binary file not shown.

WebRoot/index.html

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@
99

1010
<script type="text/javascript" src="res/js/zdialog/zDrag.js"></script>
1111
<script type="text/javascript" src="res/js/zdialog/zDialog.js"></script>
12-
12+
<script type="text/javascript" src="res/js/utils/navigator_test.js"></script>
1313
<link rel="stylesheet" type="text/css" href="res/skin/all.css" />
1414

1515
<script>
1616
$(function() {
17+
if(!isFireFox()){
18+
Dialog.alert("检测到您所使用的不是火狐Firefox浏览器,本软件在其他浏览器上没做进一步兼容性测试,请您使用Mozilla Firefox浏览器");
19+
}
1720
// navi
1821
var navi = new NaviTree({
1922
container_horiz: $('#td-navi'),

WebRoot/page/cronhub_record/done/CronhubHistoryTree.html

+30-8
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,33 @@
33
<head>
44
<title>tree</title>
55
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
6+
67
<script type="text/javascript" src="/res/js/jquery/jquery-1.6.2.min.js"></script>
78
<script type="text/javascript" src="/res/js/jqtree/jqtree.js"></script>
89
<script type="text/javascript" src="/res/js/contextmenu/jquery.contextmenu.js"></script>
10+
911
<link rel="stylesheet" type="text/css" href="/res/skin/all.css" />
12+
1013
<script type="text/javascript">
14+
/** 如果没有加载的元素,就返回空记录提示 **/
15+
function redirectToNoRecordPage(){
16+
var msg = arguments[0]?arguments[0]:"暂无数据";//js的默认参数
17+
self.parent.frames["rightframe"].location.href = "/page/commons/no_record.html";
18+
var tree_hint_msg = "<b style='color:red'>"+msg+"</b>";
19+
if($("span[type='month']").length > 0){
20+
var month_name=$("span[type='month']:first").attr("name");
21+
tree_hint_msg = "<b style='color:red'>"+month_name+"表无数据</b>";
22+
}
23+
$("#imgLoading").replaceWith(tree_hint_msg);
24+
}
1125
$(function() {
1226
var firstLoad = true;
1327
// jqtree
1428
var tree = new IconTree({
1529
container: $('#tree'),
1630
loadUrl: '/record_done/createTree.action?unfold_current_month=true',//后台只有一个action地址,怎么知道到底是第一次请求过来的,还是点击树中某一节点请求过来的呢?全凭有没有id请求参数过来作为判断依据,java后台使用了if (request .getParameterMap().containsKey( "id"))
1731
dataType: 'xml',
18-
timeout: 10000,
32+
timeout: 3000,
1933
indent: 10,
2034
createRequestParam: function(node) {
2135
node.data = { id: node.id };
@@ -32,8 +46,23 @@
3246
node.toggle();
3347
}
3448
},
49+
errback:function(data){
50+
redirectToNoRecordPage("数据获取异常");
51+
},
3552
callback:function(data){
53+
//如果彻底"无月表"
54+
if(data == null){
55+
redirectToNoRecordPage();
56+
firstLoad=false;
57+
return;
58+
}
3659
if(firstLoad){
60+
//check error data that tree only have folder
61+
if($("span[type='day']").length == 0){//如果有月表,但表中无数据
62+
redirectToNoRecordPage();
63+
firstLoad=false;
64+
return;
65+
}
3766
var tableName = $("span[type='day']:first").attr("tableName");
3867
var todayId = $("span[type='day']:first").attr("id");
3968
var location = "/record_done/first_page_view.action?max_per_page=20&tableName="+tableName+"&filter={'equal':{'DATE_FORMAT(start_datetime,\"%Y%m%d\")':"+todayId+"}}";
@@ -42,13 +71,6 @@
4271
}
4372
$("#imgLoading").hide();
4473
}
45-
/**
46-
success:function(data){
47-
//alert("success");
48-
alert($("#2011").attr('type'));
49-
}
50-
**/
51-
//contextmenu: ctxmenu
5274
});
5375
tree.init();
5476
});

WebRoot/page/cronhub_record/undo/CronhubHistoryTree.html

+24-11
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,28 @@
55
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
66

77
<script type="text/javascript" src="/res/js/jquery/jquery-1.6.2.min.js"></script>
8-
98
<script type="text/javascript" src="/res/js/jqtree/jqtree.js"></script>
10-
<script type="text/javascript" src="/res/js/zdialog/zDrag.js"></script>
11-
<script type="text/javascript" src="/res/js/zdialog/zDialog.js"></script>
129
<script type="text/javascript" src="/res/js/contextmenu/jquery.contextmenu.js"></script>
1310

1411
<link rel="stylesheet" type="text/css" href="/res/skin/all.css" />
1512

1613
<script type="text/javascript">
14+
/** 如果没有加载的元素,就返回空记录提示 **/
15+
function redirectToNoRecordPage(){
16+
var msg = arguments[0]?arguments[0]:"暂无数据";//js的默认参数
17+
self.parent.frames["rightframe"].location.href = "/page/commons/no_record.html";
18+
var tree_hint_msg = "<b style='color:red'>"+msg+"</b>";
19+
$("#imgLoading").replaceWith(tree_hint_msg);
20+
}
21+
1722
$(function() {
1823
// jqtree
1924
var firstLoad = true;
2025
var tree = new IconTree({
2126
container: $('#tree'),
2227
loadUrl: '/record_undo/createTree.action',//后台只有一个action地址,怎么知道到底是第一次请求过来的,还是点击树中某一节点请求过来的呢?全凭有没有id请求参数过来作为判断依据,java后台使用了if (request .getParameterMap().containsKey( "id"))
2328
dataType: 'xml',
24-
timeout: 10000,
29+
timeout: 3000,
2530
indent: 10,
2631
createRequestParam: function(node) { //点击文件夹展开,加载下级时传入后台的id
2732
node.data = { id: node.id };
@@ -39,24 +44,32 @@
3944
node.toggle();//否则如果点击的是文件夹,就展开
4045
}
4146
},
47+
errback:function(data){
48+
redirectToNoRecordPage("数据获取异常");
49+
},
4250
callback:function(data){
43-
51+
//如果该表彻底无数据,这是返回<root/>只有根的空xml的情况
52+
if(data == null){
53+
redirectToNoRecordPage();
54+
firstLoad=false;
55+
return;
56+
}
4457
if(firstLoad){
45-
//if($(data).find('node').size()>0 ){
58+
//check error data that tree only have folder
59+
if($("span[type='day']").length == 0){//如果没有"天"的节点
60+
redirectToNoRecordPage();
61+
firstLoad=false;
62+
return;
63+
}
4664
var dateId = $("span[type='day']:first").attr("id");//获取到span里第一个type为day的id(第一个使用了jq的:first)
4765
var location =encodeURI("/record_undo/first_page_view.action?max_per_page=20&filter={'equal':{'DATE_FORMAT(start_datetime,\"%Y%m%d\")':"+dateId+"}}");
4866
self.parent.frames["rightframe"].location.href = location;
49-
//}else{
50-
// self.parent.frames["rightframe"].location.href = "/page/commons/no_record.html";
51-
// this.container.css("text-align","center").html("暂无记录");
52-
//}
5367
firstLoad=false;
5468
}
5569
$("#imgLoading").hide();//隐藏loading图标
5670
}
5771
});
5872
tree.init();
59-
6073
});
6174
</script>
6275
</head>

WebRoot/page/cronhub_task/CronhubTaskView.jsp

+3-1
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,12 @@ function btnImmediateExecClick(){
159159
});
160160
});
161161
}
162+
162163
function hideLongText(){
163164
$(".grid tbody td.cmdClass").each(function(){
164165
var innerStr = $(this).text();
165-
if(innerStr.trim().length>11){
166+
var innerStr = $.trim(innerStr);
167+
if(innerStr.length>11){
166168
var ellipsis = $("<span class='toolbar' title='"+innerStr+"' name='unfoldBtn'><a>...</a></span>").click(function(){
167169
var wholeStr = $(this).attr('title');
168170
var currentFold = $(this).parent().contents().clone(true);

WebRoot/res/js/jqtree/jqtree.js

+10-7
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,20 @@ AjaxModel.prototype.load = function() {
2626
beforeSend: function() {
2727
_this.beforeSend();
2828
},
29-
error: function() {
30-
alert('jqTree Ajax load error');
29+
error: function(data) {
30+
//如果定义了errback,就调用errback
31+
if(_this.hasOwnProperty("errback")){
32+
_this.errback(data);
33+
}else{
34+
alert('jqTree Ajax load error');
35+
}
3136
},
3237
success: function(data) {
3338
data = _this.xmlParse(data);
34-
//if($(data).find('node').size()>0 || $(data).find('menu').size() >0){
39+
if(data!=null){//如果获取到空root节点(也就是说没有数据)
3540
_this.success(data);
36-
_this.callback(data);
37-
//}else{
38-
// _this.callback(data);
39-
//}
41+
}
42+
_this.callback(data);
4043
}
4144
});
4245
}
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
function check(reg) {
3+
var ug = navigator.userAgent.toLowerCase();
4+
return reg.test(ug);
5+
}
6+
function isFireFox() {
7+
var ug = navigator.userAgent.toLowerCase();
8+
var userAgent = navigator.userAgent;
9+
userAgent.innerHTML = "\u6d4f\u89c8\u5668\u7684\u7528\u6237\u4ee3\u7406\u62a5\u5934\uff1a" + ug;
10+
var browserType = "";
11+
var ver = "";
12+
13+
//检测IE及版本
14+
var IE = ug.match(/msie\s*\d\.\d/); //提取浏览器类型及版本信息,注match()方法返回的是数组而不是字符串
15+
var isIE = check(/msie/);
16+
17+
//检测firefox及版本
18+
var firefox = ug.match(/firefox\/\d\.\d/gi);
19+
var isFirefox = check(/firefox/);
20+
return !isIE && isFirefox;
21+
}
22+

src/org/cronhub/managesystem/modules/record/done/action/PageViewAction.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,7 @@ public String findFirstPage() {
4444
orderSql.delete(0, orderSql.length());
4545
orderSql.append(" ORDER BY "
4646
+ ServletActionContext.getRequest().getParameter(
47-
"sort_column")
48-
+ " "
49-
+ ServletActionContext.getRequest().getParameter(
50-
"sort_order"));
47+
"sort_column")+ " " + ServletActionContext.getRequest().getParameter("sort_order"));
5148
}
5249
final String tableName = ServletActionContext.getRequest()
5350
.getParameter("tableName");

src/org/cronhub/managesystem/modules/record/done/boot/AutoRedoRemoteExec.java

+3
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ public void run() {
5555
public TaskTable getTasks() {
5656
TaskTable table = new TaskTable();
5757
final String tableName = RecordDoneUtils.getTableName(new Date());
58+
if(!doneRecordDao.hasTableByName(tableName)){ //if not exists this table,return
59+
return table;
60+
}
5861
FillConfig fillConfig =new FillConfig(false,false);
5962
List<TaskRecordDone> records = doneRecordDao.findAll(tableName,allRedoWhereSql, fillConfig);
6063
for(final TaskRecordDone record : records){

src/org/cronhub/managesystem/modules/record/done/dao/IDoneRecordDao.java

+1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ public interface IDoneRecordDao {
1616
public void update(TaskRecordDone record);
1717
public TaskRecordDone findById(Long id,String tableName,FillConfig config);
1818
public List<TaskRecordDone> findByTaskId(Long taskId,String tableName,FillConfig config);
19+
public boolean hasTableByName(String tableName);
1920
}

src/org/cronhub/managesystem/modules/record/done/dao/impl/DoneRecordDaoImpl.java

+7
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,11 @@ public List<TaskRecordDone> findAll(String tableName, String whereSql,
131131
FillConfig fillConfig) {
132132
return findByPage(tableName,whereSql,fillConfig);
133133
}
134+
@Override
135+
public boolean hasTableByName(String tableName) {
136+
String sql = "SELECT COUNT(TABLE_NAME) FROM INFORMATION_SCHEMA.TABLES WHERE `TABLE_SCHEMA`='cronhub_manage_system' AND `TABLE_NAME` = '"+tableName+"' AND TABLE_TYPE='BASE TABLE'";
137+
return this.jdbcTemplate.queryForInt(sql) > 0;
138+
}
139+
140+
134141
}

0 commit comments

Comments
 (0)